diff --git a/CURL/ietf-l3vpn-service.json b/CURL/ietf-l3vpn-service.json new file mode 100644 index 0000000000000000000000000000000000000000..eb86c359bbab1feeba0f570be165f5f18349d2b8 --- /dev/null +++ b/CURL/ietf-l3vpn-service.json @@ -0,0 +1,103 @@ +{ + "ietf-l3vpn-svc:l3vpn-svc": { + "vpn-services": { + "vpn-service": [ + {"vpn-id": "ietf-l3vpn-svc"} + ] + }, + "sites": { + "site": [ + { + "site-id": "site_DC1", + "management": {"type": "ietf-l3vpn-svc:provider-managed"}, + "locations": {"location": [{"location-id": "DC1"}]}, + "devices": {"device": [{"device-id": "h1","location": "DC1"}]}, + "site-network-accesses": { + "site-network-access": [ + { + "site-network-access-id": "h1-eth0", + "site-network-access-type": "ietf-l3vpn-svc:multipoint", + "device-reference": "h1", + "vpn-attachment": {"vpn-id": "ietf-l3vpn-svc", "site-role": "ietf-l3vpn-svc:spoke-role"}, + "ip-connection": { + "ipv4": { + "address-allocation-type": "ietf-l3vpn-svc:static-address", + "addresses": { + "provider-address": "10.0.0.1", + "customer-address": "10.0.0.1", + "prefix-length": 8 + } + } + }, + "service": { + "svc-mtu": 1500, + "svc-input-bandwidth": 1000000000, + "svc-output-bandwidth": 1000000000, + "qos": { + "qos-profile": { + "classes": { + "class": [ + { + "class-id": "qos-realtime", + "direction": "ietf-l3vpn-svc:both", + "latency": {"latency-boundary": 10}, + "bandwidth": {"guaranteed-bw-percent": 100} + } + ] + } + } + } + } + } + ] + } + }, + { + "site-id": "site_DC2", + "management": {"type": "ietf-l3vpn-svc:provider-managed"}, + "locations": {"location": [{"location-id": "DC2"}]}, + "devices": {"device": [{"device-id": "h3", "location": "DC2"}]}, + "site-network-accesses": { + "site-network-access": [ + { + "site-network-access-id": "h3-eth0", + "site-network-access-type": "ietf-l3vpn-svc:multipoint", + "device-reference": "h3", + "vpn-attachment": {"vpn-id": "ietf-l3vpn-svc", "site-role": "ietf-l3vpn-svc:hub-role"}, + "ip-connection": { + "ipv4": { + "address-allocation-type": "ietf-l3vpn-svc:static-address", + "addresses": { + "provider-address": "10.0.0.1", + "customer-address": "10.0.0.3", + "prefix-length": 8 + } + } + }, + "service": { + "svc-mtu": 1500, + "svc-input-bandwidth": 1000000000, + "svc-output-bandwidth": 1000000000, + "qos": { + "qos-profile": { + "classes": { + "class": [ + { + "class-id": "qos-realtime", + "direction": "ietf-l3vpn-svc:both", + "latency": {"latency-boundary": 10}, + "bandwidth": {"guaranteed-bw-percent": 100} + } + ] + } + } + } + } + } + ] + } + } + ] + } + } +} diff --git a/capture.pcap b/capture.pcap new file mode 100644 index 0000000000000000000000000000000000000000..d59d71e2b3db7e83af6ce964ff8836ffc545cd57 Binary files /dev/null and b/capture.pcap differ diff --git a/hackfest5/data-2/ietf-l3vpn-service.json b/hackfest5/data-2/ietf-l3vpn-service.json new file mode 100644 index 0000000000000000000000000000000000000000..eb86c359bbab1feeba0f570be165f5f18349d2b8 --- /dev/null +++ b/hackfest5/data-2/ietf-l3vpn-service.json @@ -0,0 +1,103 @@ +{ + "ietf-l3vpn-svc:l3vpn-svc": { + "vpn-services": { + "vpn-service": [ + {"vpn-id": "ietf-l3vpn-svc"} + ] + }, + "sites": { + "site": [ + { + "site-id": "site_DC1", + "management": {"type": "ietf-l3vpn-svc:provider-managed"}, + "locations": {"location": [{"location-id": "DC1"}]}, + "devices": {"device": [{"device-id": "h1","location": "DC1"}]}, + "site-network-accesses": { + "site-network-access": [ + { + "site-network-access-id": "h1-eth0", + "site-network-access-type": "ietf-l3vpn-svc:multipoint", + "device-reference": "h1", + "vpn-attachment": {"vpn-id": "ietf-l3vpn-svc", "site-role": "ietf-l3vpn-svc:spoke-role"}, + "ip-connection": { + "ipv4": { + "address-allocation-type": "ietf-l3vpn-svc:static-address", + "addresses": { + "provider-address": "10.0.0.1", + "customer-address": "10.0.0.1", + "prefix-length": 8 + } + } + }, + "service": { + "svc-mtu": 1500, + "svc-input-bandwidth": 1000000000, + "svc-output-bandwidth": 1000000000, + "qos": { + "qos-profile": { + "classes": { + "class": [ + { + "class-id": "qos-realtime", + "direction": "ietf-l3vpn-svc:both", + "latency": {"latency-boundary": 10}, + "bandwidth": {"guaranteed-bw-percent": 100} + } + ] + } + } + } + } + } + ] + } + }, + { + "site-id": "site_DC2", + "management": {"type": "ietf-l3vpn-svc:provider-managed"}, + "locations": {"location": [{"location-id": "DC2"}]}, + "devices": {"device": [{"device-id": "h3", "location": "DC2"}]}, + "site-network-accesses": { + "site-network-access": [ + { + "site-network-access-id": "h3-eth0", + "site-network-access-type": "ietf-l3vpn-svc:multipoint", + "device-reference": "h3", + "vpn-attachment": {"vpn-id": "ietf-l3vpn-svc", "site-role": "ietf-l3vpn-svc:hub-role"}, + "ip-connection": { + "ipv4": { + "address-allocation-type": "ietf-l3vpn-svc:static-address", + "addresses": { + "provider-address": "10.0.0.1", + "customer-address": "10.0.0.3", + "prefix-length": 8 + } + } + }, + "service": { + "svc-mtu": 1500, + "svc-input-bandwidth": 1000000000, + "svc-output-bandwidth": 1000000000, + "qos": { + "qos-profile": { + "classes": { + "class": [ + { + "class-id": "qos-realtime", + "direction": "ietf-l3vpn-svc:both", + "latency": {"latency-boundary": 10}, + "bandwidth": {"guaranteed-bw-percent": 100} + } + ] + } + } + } + } + } + ] + } + } + ] + } + } +} diff --git a/my_deploy.sh b/my_deploy.sh index 59c7c0a9ad098ff14de4c26bff30e034c1796eb1..8dd134eb1510b967e8b73dff5c14087c95db04a6 100755 --- a/my_deploy.sh +++ b/my_deploy.sh @@ -20,7 +20,7 @@ export TFS_REGISTRY_IMAGES="http://localhost:32000/tfs/" # Set the list of components, separated by spaces, you want to build images for, and deploy. -export TFS_COMPONENTS="context device pathcomp service webui" +export TFS_COMPONENTS="context device pathcomp service webui nbi" # Uncomment to activate Monitoring (old) #export TFS_COMPONENTS="${TFS_COMPONENTS} monitoring" diff --git a/src/device/service/drivers/OpenFlow/OpenFlowDriver.py b/src/device/service/drivers/OpenFlow/OpenFlowDriver.py index 82f3308144fdf7df595b10389591fb2d810a0ed5..541ec83c585a5708305461b8f142e59ff54f3e9b 100644 --- a/src/device/service/drivers/OpenFlow/OpenFlowDriver.py +++ b/src/device/service/drivers/OpenFlow/OpenFlowDriver.py @@ -120,8 +120,8 @@ class OpenFlowDriver(_Driver): cookie = self.__cookie_counter ip_address_source = resource_value_dict.get("ip_address_source", "") ip_address_destination = resource_value_dict.get("ip_address_destination", "") - mac_address_source = resource_value_dict.get("mac_address_source", "") - mac_address_destination = resource_value_dict.get("mac_address_destination", "") + #mac_address_source = resource_value_dict.get("mac_address_source", "") + #mac_address_destination = resource_value_dict.get("mac_address_destination", "") if "h1-h3" in resource_key: priority = 65535 @@ -130,8 +130,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source , "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "dl_dst": mac_address_destination + #"eth_src": mac_address_source, + #"dl_dst": mac_address_destination } elif "h3-h1" in resource_key: priority = 65535 @@ -140,8 +140,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source, "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "dl_dst": mac_address_destination + #"eth_src": mac_address_source, + #"dl_dst": mac_address_destination } elif "h2-h4" in resource_key: @@ -151,8 +151,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source , "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "eth_dst": mac_address_destination + #"eth_src": mac_address_source, + #"eth_dst": mac_address_destination } elif "h4-h2" in resource_key: priority = 1500 @@ -161,8 +161,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source, "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "eth_dst": mac_address_destination + #"eth_src": mac_address_source, + #"eth_dst": mac_address_destination } except (KeyError, ValueError, IndexError) as e: @@ -190,45 +190,45 @@ class OpenFlowDriver(_Driver): ] } - flow_entry_arp_foraward = { - "dpid": dpid, - "priority": 65535, - "match": { - "eth_dst": "ff:ff:ff:ff:ff:ff", - "eth_type": 0x0806 - }, - "instructions": [ - { - "type": "APPLY_ACTIONS", - "actions": [ - { - "type": "OUTPUT", - "port": "0xfffffffb" - } - ] - } - ] - } - flow_entry_arp_reply = { - "dpid": dpid, - "priority": 65535, - "match": { - "eth_type": 0x0806, - "arp_op": 2 - }, - "instructions": [ - { - "type": "APPLY_ACTIONS", - "actions": [ - { - "type": "OUTPUT", - "port": "0xfffffffb" - } - ]}]} - + #flow_entry_arp_foraward = { + # "dpid": dpid, + # "priority": 65535, + # "match": { + # "eth_dst": "ff:ff:ff:ff:ff:ff", + # "eth_type": 0x0806 + # }, + # "instructions": [ + # { + # "type": "APPLY_ACTIONS", + # "actions": [ + # { + # "type": "OUTPUT", + # "port": "0xfffffffb" + # } + # ] + # } + # ] + # } + #flow_entry_arp_reply = { + # "dpid": dpid, + # "priority": 65535, + # "match": { + # "eth_type": 0x0806, + # "arp_op": 2 + # }, + # "instructions": [ + # { + # "type": "APPLY_ACTIONS", + # "actions": [ + # { + # "type": "OUTPUT", + # "port": "0xfffffffb" + # } + # ]}]} +# try: - response = requests.post(url, json=flow_entry_arp_foraward, timeout=self.__timeout, verify=False, auth=self.__auth) - response = requests.post(url, json=flow_entry_arp_reply, timeout=self.__timeout, verify=False, auth=self.__auth) + #response = requests.post(url, json=flow_entry_arp_foraward, timeout=self.__timeout, verify=False, auth=self.__auth) + #response = requests.post(url, json=flow_entry_arp_reply, timeout=self.__timeout, verify=False, auth=self.__auth) response = requests.post(url, json=flow_entry, timeout=self.__timeout, verify=False, auth=self.__auth) response.raise_for_status() results.append(True) @@ -273,8 +273,8 @@ class OpenFlowDriver(_Driver): cookie = self.__cookie_counter ip_address_source = resource_value_dict.get("ip_address_source", "") ip_address_destination = resource_value_dict.get("ip_address_destination", "") - mac_address_source = resource_value_dict.get("mac_address_source", "") - mac_address_destination = resource_value_dict.get("mac_address_destination", "") + #mac_address_source = resource_value_dict.get("mac_address_source", "") + #mac_address_destination = resource_value_dict.get("mac_address_destination", "") if "h1-h3" in resource_key: priority = 65535 @@ -283,8 +283,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source , "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "dl_dst": mac_address_destination, + #"eth_src": mac_address_source, + #"dl_dst": mac_address_destination, "table_id": 0, "cookie": 0, "cookie_mask": 0, @@ -296,8 +296,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source, "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "dl_dst": mac_address_destination, + #"eth_src": mac_address_source, + #"dl_dst": mac_address_destination, "table_id": 0, "cookie": 0, "cookie_mask": 0, @@ -310,8 +310,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source , "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "eth_dst": mac_address_destination, + #"eth_src": mac_address_source, + #"eth_dst": mac_address_destination, "table_id": 0, "cookie": 0, "cookie_mask": 0, @@ -323,8 +323,8 @@ class OpenFlowDriver(_Driver): "eth_type": 0x0800, "ipv4_src": ip_address_source, "ipv4_dst": ip_address_destination, - "eth_src": mac_address_source, - "eth_dst": mac_address_destination, + #"eth_src": mac_address_source, + #"eth_dst": mac_address_destination, "table_id": 0, "cookie": 0, "cookie_mask": 0, @@ -352,42 +352,42 @@ class OpenFlowDriver(_Driver): "port": out_port }]}]} - flow_entry_arp_foraward = { - "dpid": dpid, - "priority": 65535, - "match": { - "eth_dst": "ff:ff:ff:ff:ff:ff", - "eth_type": 0x0806 - }, - "instructions": [ - { - "type": "APPLY_ACTIONS", - "actions": [ - { - "type": "OUTPUT", - "port": "0xfffffffb" - } - ]}]} - flow_entry_arp_reply = { - "dpid": dpid, - "priority": 65535, - "match": { - "eth_type": 0x0806, - "arp_op": 2 - }, - "instructions": [ - { - "type": "APPLY_ACTIONS", - "actions": [ - { - "type": "OUTPUT", - "port": "0xfffffffb" - } - ]}]} + #flow_entry_arp_foraward = { + # "dpid": dpid, + # "priority": 65535, + # "match": { + # "eth_dst": "ff:ff:ff:ff:ff:ff", + # "eth_type": 0x0806 + # }, + # "instructions": [ + # { + # "type": "APPLY_ACTIONS", + # "actions": [ + # { + # "type": "OUTPUT", + # "port": "0xfffffffb" + # } + # ]}]} + #flow_entry_arp_reply = { + # "dpid": dpid, + # "priority": 65535, + # "match": { + # "eth_type": 0x0806, + # "arp_op": 2 + # }, + # "instructions": [ + # { + # "type": "APPLY_ACTIONS", + # "actions": [ + # { + # "type": "OUTPUT", + # "port": "0xfffffffb" + # } + # ]}]} try: - response = requests.post(url, json=flow_entry_arp_foraward, timeout=self.__timeout, verify=False, auth=self.__auth) - response = requests.post(url, json=flow_entry_arp_reply, timeout=self.__timeout, verify=False, auth=self.__auth) + #response = requests.post(url, json=flow_entry_arp_foraward, timeout=self.__timeout, verify=False, auth=self.__auth) + #response = requests.post(url, json=flow_entry_arp_reply, timeout=self.__timeout, verify=False, auth=self.__auth) response = requests.post(url, json=flow_entry, timeout=self.__timeout, verify=False, auth=self.__auth) response.raise_for_status() results.append(True) diff --git a/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/Handlers.py b/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/Handlers.py index 0e8b8013ef5cba1305cdd040ea68efc653eefa5e..8078d9d49afb9de5880d159258003f0db3acfa3e 100644 --- a/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/Handlers.py +++ b/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/Handlers.py @@ -133,7 +133,7 @@ def process_site_network_access( MSG = 'Site Network Access IPv4 Allocation Type: {:s}' raise NotImplementedError(MSG.format(str(ipv4_allocation['address-allocation-type']))) ipv4_allocation_addresses = ipv4_allocation['addresses'] - ipv4_provider_address = ipv4_allocation_addresses['provider-address'] + ipv4_provider_address = ipv4_allocation_addresses.get('provider-address') ipv4_customer_address = ipv4_allocation_addresses['customer-address'] ipv4_prefix_length = ipv4_allocation_addresses['prefix-length' ] diff --git a/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/L3VPN_Services.py b/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/L3VPN_Services.py index 98d950952702d5cf1df8aa29edc50683e56a296e..980e21200f6a6a869af80019306c3df132a4d597 100644 --- a/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/L3VPN_Services.py +++ b/src/nbi/service/rest_server/nbi_plugins/ietf_l3vpn/L3VPN_Services.py @@ -26,11 +26,11 @@ from .YangValidator import YangValidator LOGGER = logging.getLogger(__name__) class L3VPN_Services(Resource): - @HTTP_AUTH.login_required + #@HTTP_AUTH.login_required def get(self): return {} - @HTTP_AUTH.login_required + #@HTTP_AUTH.login_required def post(self): if not request.is_json: raise UnsupportedMediaType('JSON payload is required') request_data : Dict = request.json diff --git a/src/pathcomp/frontend/service/algorithms/tools/ResourceGroups.py b/src/pathcomp/frontend/service/algorithms/tools/ResourceGroups.py index b08830332f7fc6f526a19516b120e94a1a98b232..27be8e00f57e183b4c17b6dea666aea36cd3270b 100644 --- a/src/pathcomp/frontend/service/algorithms/tools/ResourceGroups.py +++ b/src/pathcomp/frontend/service/algorithms/tools/ResourceGroups.py @@ -25,6 +25,7 @@ DEVICE_TYPE_TO_DEEPNESS = { DeviceTypeEnum.EMULATED_CLIENT.value : 90, DeviceTypeEnum.CLIENT.value : 90, + #DeviceTypeEnum.OPENFLOW_RYU_CONTROLLER.value : 80, DeviceTypeEnum.TERAFLOWSDN_CONTROLLER.value : 80, DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER.value : 80, DeviceTypeEnum.IP_SDN_CONTROLLER.value : 80, diff --git a/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py b/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py index 8230092c2decc0b2c988f63a2677f879f7ec944f..91692f2bdf70790ee94986ab7b89c3c29928b29b 100644 --- a/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py +++ b/src/pathcomp/frontend/service/algorithms/tools/ServiceTypes.py @@ -21,7 +21,7 @@ NETWORK_DEVICE_TYPES = { } PACKET_DEVICE_TYPES = { - DeviceTypeEnum.TERAFLOWSDN_CONTROLLER, + DeviceTypeEnum.TERAFLOWSDN_CONTROLLER,#DeviceTypeEnum.OPENFLOW_RYU_CONTROLLER, DeviceTypeEnum.IP_SDN_CONTROLLER, DeviceTypeEnum.EMULATED_IP_SDN_CONTROLLER, DeviceTypeEnum.PACKET_ROUTER, DeviceTypeEnum.EMULATED_PACKET_ROUTER, DeviceTypeEnum.PACKET_SWITCH, DeviceTypeEnum.EMULATED_PACKET_SWITCH, diff --git a/src/service/service/service_handlers/l3nm_ryu/L3NMryuServiceHandler.py b/src/service/service/service_handlers/l3nm_ryu/L3NMryuServiceHandler.py index 0b78861364953d6e3af396b5e10deb31e48a44fd..aa8dc5a184f2f9dc6c67c9c5282ad9865dc4f880 100644 --- a/src/service/service/service_handlers/l3nm_ryu/L3NMryuServiceHandler.py +++ b/src/service/service/service_handlers/l3nm_ryu/L3NMryuServiceHandler.py @@ -21,6 +21,7 @@ from pyparsing import C from pytest import skip from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method from common.proto.context_pb2 import ConfigRule, Device, DeviceId, EndPoint, Service,ConfigRule_Custom,ConfigActionEnum +from common.tools.context_queries.Device import get_device from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set,json_config_rule from common.tools.object_factory.Device import json_device_id @@ -82,24 +83,57 @@ class RYUServiceHandler(_ServiceHandler): return [] service_uuid = self.__service.service_id.service_uuid.uuid service_name= self.__service.name + #get_device_mac_soruce=self._get_endpoint_details(endpoints[0]) + #get_device_mac_destination=self._get_endpoint_details(endpoints[-1]) + #get_device = self.__task_executor.get_device(get_device_mac_soruce) + #get_device_2= self.__task_executor.get_device(get_device_mac_destination) + #LOGGER.debug('get_device_mac_soruce = {:s}'.format(str(get_device))) + #LOGGER.debug('get_device_mac_destination = {:s}'.format(str(get_device_2))) service_configuration_rules=self.__service.service_config.config_rules LOGGER.debug('service_configuration_rules = {:s}'.format(str(service_configuration_rules))) ip_addresses = [] - mac_addresses = [] + #mac_addresses = [] + flow_rules = [] for rule in service_configuration_rules: try: custom_field = rule.custom resource_value_str = custom_field.resource_value resource_value = json.loads(resource_value_str) - ip_address = resource_value.get("address_ip") - mac_address = resource_value.get("mac_address") - ip_addresses.append(ip_address) - mac_addresses.append(mac_address) + resource_key_str = custom_field.resource_key + LOGGER.debug(f"resource_key_str = {resource_key_str}") + #resource_key = json.loads(resource_key_str) + match = re.search(r"/device\[(.*?)\]/", resource_key_str) + if match: + device_name = match.group(1) + if device_name in ['h1', 'h3'] or device_name in ['h2', 'h4']: + flow_rules.append(device_name) + + ip_address = resource_value.get("ip_address") + #mac_address = resource_value.get("mac_address") + if ip_address in ['10.0.0.1', '10.0.0.3'] or ip_address in ['10.0.0.2','10.0.0.4']: + ip_addresses.append(ip_address) + #mac_addresses.append(mac_address) except Exception as e: - print(f"Error parsing rule: {e}, Rule: {rule}") + LOGGER.exception("Error in Rules") LOGGER.debug('ip_address = {:s}'.format(str(ip_addresses))) - LOGGER.debug('mac_address = {:s}'.format(str(mac_addresses))) - LOGGER.debug('service_name = {:s}'.format(str(service_name))) + LOGGER.debug('flow_rules = {:s}'.format(str(flow_rules))) + if len(flow_rules) < 2: + LOGGER.warning('Not enough devices to construct flow rules') + return [] + if len(ip_addresses) < 2: + LOGGER.warning('Not enough IP addresses found') + return [] + #if len(ip_addresses) < 2: + # LOGGER.warning('nothing done: no ip address found') + # return [] + #LOGGER.debug('mac_address = {:s}'.format(str(mac_addresses))) + #if len(mac_addresses) < 2: + # LOGGER.warning('nothing done: no mac address found') + # return [] + #LOGGER.debug('service_name = {:s}'.format(str(service_name))) + #if len(service_name) < 2: + # LOGGER.warning('nothing done: no service name found') + # return [] #LOGGER.debug('service_uuid = {:s}'.format(str(service_uuid))) #LOGGER.debug('self.__settings_handler = {:s}'.format(str(self.__settings_handler.dump_config_rules()))) results = [] @@ -118,24 +152,24 @@ class RYUServiceHandler(_ServiceHandler): if current_device.name == next_device.name: in_port_forward = current_endpoint.name out_port_forward = next_endpoint.name - flow_split = service_name.split('-') + #flow_split = service_name.split('-') dpid_src = int(current_device.name) LOGGER.debug(f"DPID source: {dpid_src}") dpid_dst = int(next_device.name) LOGGER.debug(f"DPID destination: {dpid_dst}") - flow_rule_forward = f"{flow_split[0]}-{flow_split[2]}" - flow_rule_reverse = f"{flow_split[2]}-{flow_split[0]}" + flow_rule_forward = f"{flow_rules[0]}-{flow_rules[1]}" + flow_rule_reverse = f"{flow_rules[1]}-{flow_rules[0]}" ip_address_source = ip_addresses[0] ip_address_destination = ip_addresses[1] - mac_address_source = mac_addresses[0] - mac_address_destination = mac_addresses[1] + #mac_address_source = mac_addresses[0] + #mac_address_destination = mac_addresses[1] forward_resource_value = ({"dpid": current_device.name, "in-port": in_port_forward, "out-port": out_port_forward, "ip_address_source": ip_address_source, "ip_address_destination": ip_address_destination, - "mac_address_source": mac_address_source, - "mac_address_destination": mac_address_destination + #"mac_address_source": mac_address_source, + #"mac_address_destination": mac_address_destination }) forward_rule = json_config_rule_set ( resource_key=f"/device[{current_endpoint.name.split('-')[0]}]/flow[{flow_rule_forward}]", @@ -151,8 +185,8 @@ class RYUServiceHandler(_ServiceHandler): "out-port": out_port_reverse, "ip_address_source": ip_address_destination, "ip_address_destination": ip_address_source, - "mac_address_source": mac_address_destination, - "mac_address_destination": mac_address_source + #"mac_address_source": mac_address_destination, + #"mac_address_destination": mac_address_source } reverse_rule = json_config_rule_set( resource_key=f"/device[{current_endpoint.name.split('-')[0]}]/flow[{flow_rule_reverse}]", @@ -172,13 +206,13 @@ class RYUServiceHandler(_ServiceHandler): resource_value = rule.custom.resource_value LOGGER.debug(f"Resource key in config: {resource_key}, Resource value in config: {resource_value}") except Exception as e: - print(f"Error accessing config rules: {e}") + LOGGER.exception("Error in Configuration Rules") get_config_rules(src_controller) LOGGER.debug(f"Configuration rules: {src_controller.device_config.config_rules}") return results except Exception as e: - LOGGER.error(f"Error in SetEndpoint: {e}") + LOGGER.exception("Error in SetEndpoint") return [e] @metered_subclass_method(METRICS_POOL) @@ -193,25 +227,33 @@ class RYUServiceHandler(_ServiceHandler): service_uuid = self.__service.service_id.service_uuid.uuid service_name= self.__service.name service_configuration_rules=self.__service.service_config.config_rules - #LOGGER.debug('service_configuration_rules = {:s}'.format(str(service_configuration_rules))) + LOGGER.debug('service_configuration_rules = {:s}'.format(str(service_configuration_rules))) ip_addresses = [] - mac_addresses = [] + flow_rules = [] for rule in service_configuration_rules: try: custom_field = rule.custom resource_value_str = custom_field.resource_value resource_value = json.loads(resource_value_str) - ip_address = resource_value.get("address_ip") - mac_address = resource_value.get("mac_address") - ip_addresses.append(ip_address) - mac_addresses.append(mac_address) + resource_key_str = custom_field.resource_key + LOGGER.debug(f"resource_key_str = {resource_key_str}") + #resource_key = json.loads(resource_key_str) + match = re.search(r"/device\[(.*?)\]/", resource_key_str) + if match: + device_name = match.group(1) + else: + device_name = None + if device_name in ['h1', 'h3'] or device_name in ['h2', 'h4']: + flow_rules.append(device_name) + + ip_address = resource_value.get("ip_address") + #mac_address = resource_value.get("mac_address") + if ip_address in ['10.0.0.1', '10.0.0.3'] or ip_address in ['10.0.0.2','10.0.0.4']: + ip_addresses.append(ip_address) except Exception as e: - print(f"Error parsing rule: {e}, Rule: {rule}") + LOGGER.exception("Error in Rules") LOGGER.debug('ip_address = {:s}'.format(str(ip_addresses))) - LOGGER.debug('mac_address = {:s}'.format(str(mac_addresses))) - LOGGER.debug('service_name = {:s}'.format(str(service_name))) - #LOGGER.debug('service_uuid = {:s}'.format(str(service_uuid))) - #LOGGER.debug('self.__settings_handler = {:s}'.format(str(self.__settings_handler.dump_config_rules()))) + LOGGER.debug('flow_rules = {:s}'.format(str(flow_rules))) results = [] try: src_device, src_endpoint, = self._get_endpoint_details(endpoints[0]) @@ -227,24 +269,24 @@ class RYUServiceHandler(_ServiceHandler): if current_device.name == next_device.name: in_port_forward = current_endpoint.name out_port_forward = next_endpoint.name - flow_split = service_name.split('-') + #flow_split = service_name.split('-') dpid_src = int(current_device.name) LOGGER.debug(f"DPID source: {dpid_src}") dpid_dst = int(next_device.name) LOGGER.debug(f"DPID destination: {dpid_dst}") - flow_rule_forward = f"{flow_split[0]}-{flow_split[2]}" - flow_rule_reverse = f"{flow_split[2]}-{flow_split[0]}" + flow_rule_forward = f"{flow_rules[0]}-{flow_rules[1]}" + flow_rule_reverse = f"{flow_rules[1]}-{flow_rules[0]}" ip_address_source = ip_addresses[0] ip_address_destination = ip_addresses[1] - mac_address_source = mac_addresses[0] - mac_address_destination = mac_addresses[1] + #mac_address_source = mac_addresses[0] + #mac_address_destination = mac_addresses[1] forward_resource_value = ({"dpid": current_device.name, "in-port": in_port_forward, "out-port": out_port_forward, "ip_address_source": ip_address_source, "ip_address_destination": ip_address_destination, - "mac_address_source": mac_address_source, - "mac_address_destination": mac_address_destination + #"mac_address_source": mac_address_source, + #"mac_address_destination": mac_address_destination }) forward_rule = json_config_rule_delete ( resource_key=f"/device[{current_endpoint.name.split('-')[0]}]/flow[{flow_rule_forward}]", @@ -259,8 +301,8 @@ class RYUServiceHandler(_ServiceHandler): "out-port": out_port_reverse, "ip_address_source": ip_address_destination, "ip_address_destination": ip_address_source, - "mac_address_source": mac_address_destination, - "mac_address_destination": mac_address_source + #"mac_address_source": mac_address_destination, + #"mac_address_destination": mac_address_source } reverse_rule = json_config_rule_delete( resource_key=f"/device[{current_endpoint.name.split('-')[0]}]/flow[{flow_rule_reverse}]", @@ -291,6 +333,5 @@ class RYUServiceHandler(_ServiceHandler): LOGGER.debug(f"Configuration rules: {src_controller.device_config.config_rules}") return results except Exception as e: - LOGGER.error(f"Error in SetEndpoint: {e}") - return [e] - + LOGGER.exception(f"Error in DeleteEndpoint") + return [e]