Loading src/common/tools/object_factory/Service.py +10 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,16 @@ def json_service_l3nm_planned( status=ServiceStatusEnum.SERVICESTATUS_PLANNED, endpoint_ids=endpoint_ids, constraints=constraints, config_rules=config_rules) def json_service_tapi_planned( service_uuid : str, endpoint_ids : List[Dict] = [], constraints : List[Dict] = [], config_rules : List[Dict] = [], context_uuid : str = DEFAULT_CONTEXT_NAME ): return json_service( service_uuid, ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE, context_id=json_context_id(context_uuid), status=ServiceStatusEnum.SERVICESTATUS_PLANNED, endpoint_ids=endpoint_ids, constraints=constraints, config_rules=config_rules) def json_service_p4_planned( service_uuid : str, endpoint_ids : List[Dict] = [], constraints : List[Dict] = [], config_rules : List[Dict] = [], context_uuid : str = DEFAULT_CONTEXT_NAME Loading src/device/service/drivers/emulated/EmulatedDriver.py +33 −31 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ from device.service.driver_api._Driver import _Driver from device.service.driver_api.AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value from .Constants import SPECIAL_RESOURCE_MAPPINGS from .SyntheticSamplingParameters import SyntheticSamplingParameters, do_sampling from .Tools import compose_resource_endpoint from .Tools import compose_resource_endpoint,connect_to_xr_agent LOGGER = logging.getLogger(__name__) Loading Loading @@ -115,9 +115,12 @@ class EmulatedDriver(_Driver): @metered_subclass_method(METRICS_POOL) def SetConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: chk_type('resources', resources, list) LOGGER.debug('SetConfig: resources=%s', resources) if len(resources) == 0: return [] results = [] if 'ipowdm_ruleset' in str(resources): connect_to_xr_agent(resources) results.append(True) else: resolver = anytree.Resolver(pathattr='name') with self.__lock: for i,resource in enumerate(resources): Loading @@ -132,7 +135,6 @@ class EmulatedDriver(_Driver): LOGGER.exception('Exception validating {:s}: {:s}'.format(str_resource_name, str(resource_key))) results.append(e) # if validation fails, store the exception continue try: resource_value = json.loads(resource_value) except: # pylint: disable=bare-except Loading src/device/service/drivers/emulated/Tools.py +26 −2 Original line number Diff line number Diff line Loading @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. import json import logging from typing import Any, Dict, Optional, Tuple import requests from common.proto.kpi_sample_types_pb2 import KpiSampleType from common.type_checkers.Checkers import chk_attribute, chk_string, chk_type from device.service.driver_api._Driver import RESOURCE_ENDPOINTS Loading Loading @@ -107,3 +109,25 @@ def compose_resource_endpoint(endpoint_data : Dict[str, Any]) -> Optional[Tuple[ except: # pylint: disable=bare-except LOGGER.exception('Problem composing endpoint({:s})'.format(str(endpoint_data))) return None def connect_to_xr_agent(resources): rule_set = resources[0][1]['rule_set'] nodes = [ {'src': { 'uuid': rule_set['src'][0]['uuid'], 'power': rule_set['src'][0]['power'], 'frequency': rule_set['src'][0]['frequency'] }}, {'dst': { 'uuid': rule_set['dst'][0]['uuid'], 'power': rule_set['dst'][0]['power'], 'frequency': rule_set['dst'][0]['frequency'] }} ] url = "http://192.168.88.17:9849/api-v0/transponders" headers = { "Content-Type": "application/json", "Expect": "" } json_data = json.dumps(nodes) requests.post(url, data=json_data, headers=headers, timeout=10) src/device/service/drivers/ietf_l3vpn/IetfL3VpnDriver.py +40 −51 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum, get from .Constants import SPECIAL_RESOURCE_MAPPINGS from .TfsApiClient import TfsApiClient from .Tools import compose_resource_endpoint from .templates.tools import create_request LOGGER = logging.getLogger(__name__) Loading Loading @@ -177,17 +176,6 @@ class IetfL3VpnDriver(_Driver): results = [] if len(resources) == 0: return results with self.__lock: if 'ipowdm' in str(resources): for resource in resources: if 'ipowdm' in str(resource): try: create_request(resource) LOGGER.info('Request created successfully') results.append((resource, True)) except Exception as e: MSG = 'Invalid resource_value type: expected dict, got {:s}' results.append((resource, e)) else: for resource in resources: resource_key, resource_value = resource if RE_IETF_L3VPN_OPERATION.match(resource_key): Loading Loading @@ -232,6 +220,7 @@ class IetfL3VpnDriver(_Driver): results.append((resource_key, e)) return results @metered_subclass_method(METRICS_POOL) def DeleteConfig( self, resources : List[Tuple[str, Any]] Loading src/device/service/drivers/ietf_l3vpn/templates/ipowdm.jsondeleted 100644 → 0 +0 −43 Original line number Diff line number Diff line { "services": [ { "service_id": { "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "IP-Link2"} }, "service_type": 8, "service_status": {"service_status": 1}, "service_endpoint_ids": [ {"device_id": {"device_uuid": {"uuid": ""}},"endpoint_uuid": {"uuid": ""}}, {"device_id": {"device_uuid": {"uuid": ""}},"endpoint_uuid": {"uuid": ""}} ], "service_constraints": [], "service_config": {"config_rules": [ {"action": 1, "ip_link": { "endpoint_id": { "device_id": {"device_uuid": {"uuid": ""}}, "endpoint_uuid": {"uuid": ""} }, "rule_set": { "ip" : "", "mask": "", "vlan": "" } }}, {"action": 1, "ip_link": { "endpoint_id": { "device_id": {"device_uuid": {"uuid": ""}}, "endpoint_uuid": {"uuid": ""} }, "rule_set": { "ip" : "", "mask": "", "vlan": "" } }} ]} } ] } No newline at end of file Loading
src/common/tools/object_factory/Service.py +10 −0 Original line number Diff line number Diff line Loading @@ -74,6 +74,16 @@ def json_service_l3nm_planned( status=ServiceStatusEnum.SERVICESTATUS_PLANNED, endpoint_ids=endpoint_ids, constraints=constraints, config_rules=config_rules) def json_service_tapi_planned( service_uuid : str, endpoint_ids : List[Dict] = [], constraints : List[Dict] = [], config_rules : List[Dict] = [], context_uuid : str = DEFAULT_CONTEXT_NAME ): return json_service( service_uuid, ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE, context_id=json_context_id(context_uuid), status=ServiceStatusEnum.SERVICESTATUS_PLANNED, endpoint_ids=endpoint_ids, constraints=constraints, config_rules=config_rules) def json_service_p4_planned( service_uuid : str, endpoint_ids : List[Dict] = [], constraints : List[Dict] = [], config_rules : List[Dict] = [], context_uuid : str = DEFAULT_CONTEXT_NAME Loading
src/device/service/drivers/emulated/EmulatedDriver.py +33 −31 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ from device.service.driver_api._Driver import _Driver from device.service.driver_api.AnyTreeTools import TreeNode, dump_subtree, get_subnode, set_subnode_value from .Constants import SPECIAL_RESOURCE_MAPPINGS from .SyntheticSamplingParameters import SyntheticSamplingParameters, do_sampling from .Tools import compose_resource_endpoint from .Tools import compose_resource_endpoint,connect_to_xr_agent LOGGER = logging.getLogger(__name__) Loading Loading @@ -115,9 +115,12 @@ class EmulatedDriver(_Driver): @metered_subclass_method(METRICS_POOL) def SetConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: chk_type('resources', resources, list) LOGGER.debug('SetConfig: resources=%s', resources) if len(resources) == 0: return [] results = [] if 'ipowdm_ruleset' in str(resources): connect_to_xr_agent(resources) results.append(True) else: resolver = anytree.Resolver(pathattr='name') with self.__lock: for i,resource in enumerate(resources): Loading @@ -132,7 +135,6 @@ class EmulatedDriver(_Driver): LOGGER.exception('Exception validating {:s}: {:s}'.format(str_resource_name, str(resource_key))) results.append(e) # if validation fails, store the exception continue try: resource_value = json.loads(resource_value) except: # pylint: disable=bare-except Loading
src/device/service/drivers/emulated/Tools.py +26 −2 Original line number Diff line number Diff line Loading @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. import json import logging from typing import Any, Dict, Optional, Tuple import requests from common.proto.kpi_sample_types_pb2 import KpiSampleType from common.type_checkers.Checkers import chk_attribute, chk_string, chk_type from device.service.driver_api._Driver import RESOURCE_ENDPOINTS Loading Loading @@ -107,3 +109,25 @@ def compose_resource_endpoint(endpoint_data : Dict[str, Any]) -> Optional[Tuple[ except: # pylint: disable=bare-except LOGGER.exception('Problem composing endpoint({:s})'.format(str(endpoint_data))) return None def connect_to_xr_agent(resources): rule_set = resources[0][1]['rule_set'] nodes = [ {'src': { 'uuid': rule_set['src'][0]['uuid'], 'power': rule_set['src'][0]['power'], 'frequency': rule_set['src'][0]['frequency'] }}, {'dst': { 'uuid': rule_set['dst'][0]['uuid'], 'power': rule_set['dst'][0]['power'], 'frequency': rule_set['dst'][0]['frequency'] }} ] url = "http://192.168.88.17:9849/api-v0/transponders" headers = { "Content-Type": "application/json", "Expect": "" } json_data = json.dumps(nodes) requests.post(url, data=json_data, headers=headers, timeout=10)
src/device/service/drivers/ietf_l3vpn/IetfL3VpnDriver.py +40 −51 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ from device.service.driver_api.ImportTopologyEnum import ImportTopologyEnum, get from .Constants import SPECIAL_RESOURCE_MAPPINGS from .TfsApiClient import TfsApiClient from .Tools import compose_resource_endpoint from .templates.tools import create_request LOGGER = logging.getLogger(__name__) Loading Loading @@ -177,17 +176,6 @@ class IetfL3VpnDriver(_Driver): results = [] if len(resources) == 0: return results with self.__lock: if 'ipowdm' in str(resources): for resource in resources: if 'ipowdm' in str(resource): try: create_request(resource) LOGGER.info('Request created successfully') results.append((resource, True)) except Exception as e: MSG = 'Invalid resource_value type: expected dict, got {:s}' results.append((resource, e)) else: for resource in resources: resource_key, resource_value = resource if RE_IETF_L3VPN_OPERATION.match(resource_key): Loading Loading @@ -232,6 +220,7 @@ class IetfL3VpnDriver(_Driver): results.append((resource_key, e)) return results @metered_subclass_method(METRICS_POOL) def DeleteConfig( self, resources : List[Tuple[str, Any]] Loading
src/device/service/drivers/ietf_l3vpn/templates/ipowdm.jsondeleted 100644 → 0 +0 −43 Original line number Diff line number Diff line { "services": [ { "service_id": { "context_id": {"context_uuid": {"uuid": "admin"}}, "service_uuid": {"uuid": "IP-Link2"} }, "service_type": 8, "service_status": {"service_status": 1}, "service_endpoint_ids": [ {"device_id": {"device_uuid": {"uuid": ""}},"endpoint_uuid": {"uuid": ""}}, {"device_id": {"device_uuid": {"uuid": ""}},"endpoint_uuid": {"uuid": ""}} ], "service_constraints": [], "service_config": {"config_rules": [ {"action": 1, "ip_link": { "endpoint_id": { "device_id": {"device_uuid": {"uuid": ""}}, "endpoint_uuid": {"uuid": ""} }, "rule_set": { "ip" : "", "mask": "", "vlan": "" } }}, {"action": 1, "ip_link": { "endpoint_id": { "device_id": {"device_uuid": {"uuid": ""}}, "endpoint_uuid": {"uuid": ""} }, "rule_set": { "ip" : "", "mask": "", "vlan": "" } }} ]} } ] } No newline at end of file