Commit 43dd6d66 authored by Felipe Fonseca's avatar Felipe Fonseca
Browse files

Fixed OEDL generation errors

parent 9903ab16
......@@ -528,9 +528,17 @@ class OEDL:
return flease
@classmethod
def build(cls, topology, slice_resource):
def build(cls, topology, slice_resource, active_lease):
oedl = OEDL()
index = 0
vlans = []
for component in active_lease['components']:
if component['resource_type'] == 'vlan':
vlans.append({'name' : component['name'] })
break
for vm in slice_resource['vms']:
# vm_group
vm_group = oedl.def_vm_group(vm['hypervisor']['urn'] + '_group', vm['hypervisor']['urn'], (index==0))
......@@ -543,7 +551,7 @@ class OEDL:
if bridge['role'] == 'experimental':
vm_builder.add_bridge(bridge['name'])
vm_builder.add_vm_group(vm_group)
for vlan in slice_resource['vlans']:
for vlan in vlans:
bridge_counter = 1
for bridge in vm_builder.vm.bridges:
if bridge != "br_control":
......@@ -564,18 +572,26 @@ class OEDL:
connections += [edge['destination'], edge['source']]
for link_connection in connections:
if link_connection['data']['resource_type'] == "openflow_switch" and len(slice_resource['vlans']) != 0:
if link_connection['data']['resource_type'] == "openflow_switch" and len(vlans) != 0:
flowvisor = oedl.def_flowvisor(slice_resource['name'], link_connection['urn'])
new_slice = flowvisor.add_slice(slice_resource['name'], link_connection['urn'], '"tcp:#{controller_ip}:6633"')
match = "in_port={0},dl_vlan={1}".format(link_connection['port'],
slice_resource['vlans'][0]['name'])
vlans[0]['name'])
new_slice.add_flow(link_connection['data']['name'], link_connection['data']['datapathid'], match, link_connection['port'])
return oedl.make_oedl()
@classmethod
def build_stop(cls, topology, slice_resource):
def build_stop(cls, topology, slice_resource, active_lease):
oedl = OEDL()
vlans = []
for component in active_lease['components']:
if component['resource_type'] == 'vlan':
vlans.append({'name' : component['name'] })
break
for vm in slice_resource['vms']:
# vm_group
vm_group = oedl.def_vm_group(vm['hypervisor']['urn'] + '_group', vm['hypervisor']['urn'])
......@@ -588,7 +604,7 @@ class OEDL:
if bridge['role'] == 'experimental':
vm_builder.add_bridge(bridge['name'])
vm_builder.add_vm_group(vm_group)
for vlan in slice_resource['vlans']:
for vlan in vlans:
bridge_counter = 1
for bridge in vm_builder.vm.bridges:
if bridge != "br_control":
......@@ -608,12 +624,12 @@ class OEDL:
connections += [edge['destination'], edge['source']]
for link_connection in connections:
if link_connection['data']['resource_type'] == "openflow_switch" and len(slice_resource['vlans']) != 0:
if link_connection['data']['resource_type'] == "openflow_switch" and len(vlans) != 0:
flowvisor = oedl.def_flowvisor(slice_resource['name'], link_connection['urn'])
new_slice = flowvisor.add_slice(slice_resource['name'], link_connection['urn'],
'"tcp:#{controller_ip}:6633"')
match = "in_port={0},dl_vlan={1}".format(link_connection['port'],
slice_resource['vlans'][0]['name'])
vlans[0]['name'])
new_slice.add_flow(link_connection['data']['name'], link_connection['data']['datapathid'], match,
link_connection['port'])
......
......@@ -619,6 +619,8 @@ def get_slice_min_topology_and_oedl(request, slice_urn):
response = {'error': 'Could not get the slice min topology and oedl'}
try:
slice_resource = SliceResource.get_resource(copy.copy(slice_credential), slice_urn)
active_lease = _get_active_lease(request, slice_urn)
if slice_resource is not None and isinstance(slice_resource, dict):
# Get topology
topology = Resource(member_cred).get_topology_of_testbed()
......@@ -667,8 +669,8 @@ def get_slice_min_topology_and_oedl(request, slice_urn):
response = {
'full_topology': processed_topologies['topology'],
'min_topology': processed_topologies['min_topology'],
'start_oedl_template': OEDL.build(processed_topologies['min_topology'], slice_resource),
'stop_oedl_template': OEDL.build_stop(processed_topologies['min_topology'], slice_resource)
'start_oedl_template': OEDL.build(processed_topologies['min_topology'], slice_resource, active_lease),
'stop_oedl_template': OEDL.build_stop(processed_topologies['min_topology'], slice_resource, active_lease)
}
except Exception as e:
print('Error', str(e))
......@@ -731,6 +733,7 @@ def save_topology_and_get_oedl(request, slice_urn):
response = {'error': 'Could not get the oedl'}
try:
slice_resource = SliceResource.get_resource(copy.copy(slice_credential), slice_urn)
active_lease = _get_active_lease(request, slice_urn)
# print(topology)
if slice_resource is not None and isinstance(slice_resource, dict):
......@@ -743,8 +746,8 @@ def save_topology_and_get_oedl(request, slice_urn):
response = {
'new_topology': new_topology,
'start_oedl_template': OEDL.build(new_topology, slice_resource),
'stop_oedl_template': OEDL.build_stop(new_topology, slice_resource)
'start_oedl_template': OEDL.build(new_topology, slice_resource, active_lease),
'stop_oedl_template': OEDL.build_stop(new_topology, slice_resource, active_lease)
}
except Exception as e:
print(e)
......@@ -753,6 +756,18 @@ def save_topology_and_get_oedl(request, slice_urn):
return JsonResponse(response, json_dumps_params={'indent': 2})
def _get_active_lease(request, slice_urn):
leases = json.loads(get_slice_leases(request, slice_urn).content)['leases']
chosen_lease = None
for lease in leases:
if len(lease['components']) > 0 and lease['status'] == 'active':
chosen_lease = lease
return chosen_lease
# @ch_login_required
# @slice_exist
@csrf_exempt
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment