Newer
Older
temp_links2.append(list(dst_links.keys())[0])
if len(temp_links2) == 2:
[t_src, roadm_src] = temp_links2[0].split('-')
[roadm_dst, t_dst] = temp_links2[1].split('-')
temp_path.append(t_src)
temp_path.append(roadm_src)
temp_path.append(roadm_dst)
temp_path.append(t_dst)
existing_ob = self.get_optical_bands(roadm_src, roadm_dst)
if len(existing_ob) > 0:
print("INFO: Evaluating existing OB {}".format(existing_ob))
#first checking in existing OB
ob_found = 0
for ob_id in existing_ob:
if "is_active" in self.optical_bands[ob_id].keys():
is_active = self.optical_bands[ob_id]["is_active"]
if not is_active:
continue
op, num_slots = map_rate_to_slot(rate)
if debug:
print(temp_links2)
c_slots, l_slots, s_slots = self.get_slots(temp_links2, num_slots, ob_id)
if debug:
print('c_slots',c_slots)
print('l_slots',l_slots)
print('s_slots',s_slots)
if len(c_slots) >= num_slots or len(l_slots) >= num_slots or len(s_slots) >= num_slots:
flow_list, band_range, slots, fiber_f, fiber_b = self.select_slots_and_ports_fs(temp_links2, num_slots,
c_slots,
l_slots, s_slots, bidir,
ob_id)
f0, band = frequency_converter(band_range, slots)
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
if debug:
print(f0, band)
print("INFO: RSA completed for Flex Lightpath with OB already in place")
if flow_list is None:
self.null_values(self.flow_id)
continue
slots_i = []
for i in slots:
slots_i.append(int(i))
# return links, path, flow_list, band_range, slots, fiber_f, fiber_b, op, num_slots, f0, band
# links, path, flows, bx, slots, fiber_f, fiber_b, op, n_slots, f0, band
self.db_flows[self.flow_id]["flows"] = flow_list
self.db_flows[self.flow_id]["band_type"] = band_range
self.db_flows[self.flow_id]["slots"] = slots_i
self.db_flows[self.flow_id]["fiber_forward"] = fiber_f
self.db_flows[self.flow_id]["fiber_backward"] = fiber_b
self.db_flows[self.flow_id]["op-mode"] = op
self.db_flows[self.flow_id]["n_slots"] = num_slots
self.db_flows[self.flow_id]["links"] = temp_links2
self.db_flows[self.flow_id]["path"] = temp_path
self.db_flows[self.flow_id]["band"] = band
self.db_flows[self.flow_id]["freq"] = f0
self.db_flows[self.flow_id]["is_active"] = True
self.db_flows[self.flow_id]["parent_opt_band"] = ob_id
self.db_flows[self.flow_id]["new_optical_band"] = 0
self.optical_bands[ob_id]["served_lightpaths"].append(self.flow_id)
'''
if bidir:
rev_ob_id = self.optical_bands[ob_id]["reverse_optical_band_id"]
self.optical_bands[rev_ob_id]["served_lightpaths"].append(self.flow_id)
'''
return self.flow_id, ob_id
else:
print("not enough slots")
print("trying to extend OB {} and band {}".format(ob_id,band))
new_slots = self.extend_optical_band(ob_id, band=None)
if debug :
print ('new_slots',new_slots)
if len(new_slots) > 0:
band_type = self.optical_bands[ob_id]["band_type"]
c_slots = []
l_slots = []
s_slots = []
if band_type == "c_slots":
c_slots = new_slots
elif band_type == "l_slots":
l_slots = new_slots
else:
s_slots = new_slots
op, num_slots = map_rate_to_slot(rate)
if debug:
print('num_slots2',num_slots)
print('temp_links2',temp_links2)
c_slots, l_slots, s_slots = self.get_slots(temp_links2, num_slots, ob_id)
if debug:
print('c_slots',c_slots)
print('l_slots',l_slots)
print('s_slots',s_slots)
#print(c_slots)
#print(l_slots)
#print(s_slots)
if len(c_slots) >= num_slots or len(l_slots) >= num_slots or len(s_slots) >= num_slots:
flow_list, band_range, slots, fiber_f, fiber_b = self.select_slots_and_ports_fs(
temp_links2, num_slots,
c_slots,
l_slots, s_slots, bidir,
ob_id)
f0, band = frequency_converter(band_range, slots)
if debug:
print('f0, band',f0, band)
print("INFO: RSA completed Exetnding for Flex Lightpath with OB already in place")
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
if flow_list is None:
self.null_values(self.flow_id)
continue
slots_i = []
for i in slots:
slots_i.append(int(i))
# return links, path, flow_list, band_range, slots, fiber_f, fiber_b, op, num_slots, f0, band
# links, path, flows, bx, slots, fiber_f, fiber_b, op, n_slots, f0, band
self.db_flows[self.flow_id]["flows"] = flow_list
self.db_flows[self.flow_id]["band_type"] = band_range
self.db_flows[self.flow_id]["slots"] = slots_i
self.db_flows[self.flow_id]["fiber_forward"] = fiber_f
self.db_flows[self.flow_id]["fiber_backward"] = fiber_b
self.db_flows[self.flow_id]["op-mode"] = op
self.db_flows[self.flow_id]["n_slots"] = num_slots
self.db_flows[self.flow_id]["links"] = temp_links2
self.db_flows[self.flow_id]["path"] = temp_path
self.db_flows[self.flow_id]["band"] = band
self.db_flows[self.flow_id]["freq"] = f0
self.db_flows[self.flow_id]["is_active"] = True
self.db_flows[self.flow_id]["parent_opt_band"] = ob_id
#self.db_flows[self.flow_id]["new_optical_band"] = 1
self.db_flows[self.flow_id]["new_optical_band"] = 2
self.optical_bands[ob_id]["served_lightpaths"].append(self.flow_id)
'''
if bidir:
rev_ob_id = self.optical_bands[ob_id]["reverse_optical_band_id"]
self.optical_bands[rev_ob_id]["served_lightpaths"].append(self.flow_id)
'''
return self.flow_id, ob_id
else:
print("it is not possible to allocate connection in extended OB {}".format(ob_id))
if band is None:
print("INFO: Not existing optical-band meeting the requirements")
else:
print("INFO: optical-band width specified")
#if no OB I create a new one
links, path = self.compute_path(src, dst)
optical_band_id, temp_links = self.create_optical_band(links, path, bidir, num_slots_ob)
op, num_slots = map_rate_to_slot(rate)
if debug:
print(temp_links)
c_slots, l_slots, s_slots = self.get_slots(temp_links, num_slots, optical_band_id)
if debug:
print('c_slots',c_slots)
print('l_slots',l_slots)
print('s_slots',s_slots)
if len(c_slots) > 0 or len(l_slots) > 0 or len(s_slots) > 0:
flow_list, band_range, slots, fiber_f, fiber_b = self.select_slots_and_ports_fs(temp_links, num_slots, c_slots,
l_slots, s_slots, bidir, optical_band_id)
f0, band = frequency_converter(band_range, slots)
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
if debug:
print(f0, band)
print("INFO: RSA completed for FLex Lightpath with new OB")
if flow_list is None:
self.null_values(self.flow_id)
return self.flow_id, optical_band_id
slots_i = []
for i in slots:
slots_i.append(int(i))
self.db_flows[self.flow_id]["flows"] = flow_list
self.db_flows[self.flow_id]["band_type"] = band_range
self.db_flows[self.flow_id]["slots"] = slots_i
self.db_flows[self.flow_id]["fiber_forward"] = fiber_f
self.db_flows[self.flow_id]["fiber_backward"] = fiber_b
self.db_flows[self.flow_id]["op-mode"] = op
self.db_flows[self.flow_id]["n_slots"] = num_slots
self.db_flows[self.flow_id]["links"] = temp_links
self.db_flows[self.flow_id]["path"] = path
self.db_flows[self.flow_id]["band"] = band
self.db_flows[self.flow_id]["freq"] = f0
self.db_flows[self.flow_id]["is_active"] = True
self.db_flows[self.flow_id]["parent_opt_band"] = optical_band_id
self.db_flows[self.flow_id]["new_optical_band"] = 1
self.optical_bands[optical_band_id]["served_lightpaths"].append(self.flow_id)
'''
if bidir:
rev_ob_id = self.optical_bands[optical_band_id]["reverse_optical_band_id"]
self.optical_bands[rev_ob_id]["served_lightpaths"].append(self.flow_id)
'''
def extend_optical_band(self, ob_id, band=None):
ob = self.optical_bands[ob_id]
links = ob["links"]
old_band = ob["band"]
band_type = ob["band_type"]
f0 = ob["freq"]
slots = ob[band_type]
if band is None:
num_slots_ob = map_band_to_slot(old_band/1000.0)
else:
num_slots_ob = map_band_to_slot(band)
new_slots = []
for l in links:
link = self.get_link_by_name(l)
fib = link["optical_details"][band_type]
#s_slots = get_side_slots_on_link(link, band_type, num_slots_ob, slots)
#s_slots, s_num = get_side_slots_on_link(fib, num_slots_ob, slots)
s_slots,s_num = get_side_slots_on_link_v2(fib, num_slots_ob, slots)
print("NEW SLOTS {} and s_num {}".format(s_slots,s_num))
if len(new_slots) == 0:
new_slots = s_slots
else:
if len(new_slots) < s_num:
new_slots = list_in_list(new_slots, s_slots)
print(" NEW SLOTS extend_optical_band {}".format(new_slots))
self.augment_optical_band(ob_id, new_slots, band_type)
new_band = int(len(new_slots)*12.5*1000)
print("{}, {},{},{} ".format(old_band, f0, len(new_slots), new_band))
final_band = old_band + new_band
final_f0 = int(f0 + new_band/2)
print("{}, {}".format(final_band, final_f0))
ob["band"] = final_band
ob["freq"] = final_f0
for link_x in links:
link = self.get_link_by_name(link_x)
fib = link["optical_details"]
self.update_link(fib, new_slots, band_type)
return new_slots