Skip to content

Commit

Permalink
Add methods to check if path is working
Browse files Browse the repository at this point in the history
Using SDNTrace in Control Plane to verify if the path
an EVC was using previously is still deployed to the
switches.
  • Loading branch information
ajoaoff committed Oct 4, 2021
1 parent bc6a345 commit d194f98
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
45 changes: 44 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from uuid import uuid4

import requests
from glom import glom

from kytos.core import log
from kytos.core.common import EntityStatus, GenericEntity
Expand All @@ -14,7 +15,7 @@
from napps.kytos.mef_eline import settings
from napps.kytos.mef_eline.exceptions import FlowModException
from napps.kytos.mef_eline.storehouse import StoreHouse
from napps.kytos.mef_eline.utils import emit_event
from napps.kytos.mef_eline.utils import compare_endpoint_trace, emit_event


class Path(list, GenericEntity):
Expand Down Expand Up @@ -838,6 +839,48 @@ def _prepare_pop_flow(self, in_interface, out_interface, in_vlan,
flow_mod["actions"].insert(0, new_action)
return flow_mod

@staticmethod
def run_sdntrace(uni):
"""Run SDN trace on control plane starting from EVC UNIs."""
endpoint = f'{settings.SDN_TRACE_CP_URL}/trace'
data_uni = {
'trace': {
'switch': {
'dpid': uni.interface.switch.dpid,
'in_port': uni.interface.port_number
}
}
}
if uni.user_tag:
data_uni['trace']['eth'] = {
'dl_type': 0x8100,
'dl_vlan': uni.user_tag.value
}
return requests.put(endpoint, json=data_uni)

def check_traces(self):
"""Check if current_path is deployed comparing with SDN traces."""
trace_a = self.run_sdntrace(self.uni_a).json()['result']
if len(trace_a) != len(self.current_path) + 1:
return False
trace_z = self.run_sdntrace(self.uni_z).json()['result']
if len(trace_z) != len(self.current_path) + 1:
return False

for link, trace1, trace2 in zip(self.current_path,
trace_a[1:],
trace_z[:0:-1]):
if compare_endpoint_trace(
link.endpoint_a,
glom(link.metadata, 's_vlan.value'), trace2) is False:
return False
if compare_endpoint_trace(
link.endpoint_b,
glom(link.metadata, 's_vlan.value'), trace1) is False:
return False

return True


class LinkProtection(EVCDeploy):
"""Class to handle link protection."""
Expand Down
3 changes: 3 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# Base URL of the Pathfinder endpoint
TOPOLOGY_URL = 'http://localhost:8181/api/kytos/topology/v3'

# Base URL of SDN trace CP
SDN_TRACE_CP_URL = 'http://localhost:8181/api/amlight/sdntrace_cp'

# EVC consistency interval
DEPLOY_EVCS_INTERVAL = 60

Expand Down
7 changes: 7 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ def emit_event(controller, name, **kwargs):
event_name = f'kytos/mef_eline.{name}'
event = KytosEvent(name=event_name, content=kwargs)
controller.buffers.app.put(event)


def compare_endpoint_trace(endpoint, vlan, trace):
"""Compare and endpoint with a trace step."""
return endpoint.switch.dpid == trace['dpid']\
and endpoint.port_number == trace['port']\
and vlan == trace['vlan']

0 comments on commit d194f98

Please sign in to comment.