diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/placement/optimizers/conductor/api_builder.py | 28 | ||||
-rw-r--r-- | apps/placement/optimizers/conductor/translation.py | 80 | ||||
-rw-r--r-- | apps/route/optimizers/route_opt.mzn | 53 | ||||
-rw-r--r-- | apps/route/optimizers/simple_route_opt.py | 264 |
4 files changed, 306 insertions, 119 deletions
diff --git a/apps/placement/optimizers/conductor/api_builder.py b/apps/placement/optimizers/conductor/api_builder.py index 7b61580..cefde51 100644 --- a/apps/placement/optimizers/conductor/api_builder.py +++ b/apps/placement/optimizers/conductor/api_builder.py @@ -32,7 +32,7 @@ def _build_parameters(group_policies, request_json): :param request_json: parameter data received from a client :return: """ - initial_params = tr.get_opt_query_data(request_json, group_policies['request_param_query']) + initial_params = tr.get_opt_query_data(request_json, group_policies['onap.policies.optimization.QueryPolicy']) params = dict() params.update({"REQUIRED_MEM": initial_params.pop("requiredMemory", "")}) params.update({"REQUIRED_DISK": initial_params.pop("requiredDisk", "")}) @@ -61,22 +61,34 @@ def conductor_api_builder(request_json, flat_policies: list, local_config, templ = Template(open(template).read()) gp = group_policies_gen(flat_policies, local_config) demand_vnf_name_list = [] - for placementDemand in request_json['placementInfo']['placementDemands']: demand_vnf_name_list.append(placementDemand['resourceModuleName'].lower()) - demand_list = tr.gen_demands(request_json, gp['vnfPolicy']) + demand_list = tr.gen_demands(request_json, gp['onap.policies.optimization.VnfPolicy']) + # What's the attribute policy? Need an example attribute_policy_list = tr.gen_attribute_policy(demand_vnf_name_list, gp['attribute']) distance_to_location_policy_list = tr.gen_distance_to_location_policy( - demand_vnf_name_list, gp['distance_to_location']) + demand_vnf_name_list, gp['onap.policies.optimization.DistancePolicy']) + # What's the inventory group policy? A policy to choose the inventory group from existing list? inventory_policy_list = tr.gen_inventory_group_policy(demand_vnf_name_list, gp['inventory_group']) + # What's the instance fit policy, a policy to choose the instance from existing list? resource_instance_policy_list = tr.gen_resource_instance_policy( demand_vnf_name_list, gp['instance_fit']) + # Need an example for the resource_region_policy resource_region_policy_list = tr.gen_resource_region_policy(demand_vnf_name_list, gp['region_fit']) - zone_policy_list = tr.gen_zone_policy(demand_vnf_name_list, gp['zone']) - optimization_policy_list = tr.gen_optimization_policy(demand_vnf_name_list, gp['placement_optimization']) + zone_policy_list = tr.gen_zone_policy(demand_vnf_name_list, gp['onap.policies.optimization.AffinityPolicy']) + optimization_policy_list = tr.gen_optimization_policy(demand_vnf_name_list, + gp['onap.policies.optimization.OptimizationPolicy']) + # Need an example for the instance reservation policy reservation_policy_list = tr.gen_reservation_policy(demand_vnf_name_list, gp['instance_reservation']) - capacity_policy_list = tr.gen_capacity_policy(demand_vnf_name_list, gp['vim_fit']) - hpa_policy_list = tr.gen_hpa_policy(demand_vnf_name_list, gp['hpa']) + capacity_policy_list = tr.gen_capacity_policy(demand_vnf_name_list, gp['onap.policies.optimization.Vim_fit']) + hpa_policy_list = tr.gen_hpa_policy(demand_vnf_name_list, gp['onap.policies.optimization.HpaPolicy']) + #distance_to_location_policy_list = tr.gen_distance_to_location_policy( + # demand_vnf_name_list, gp['distance_to_location']) + # demand_list = tr.gen_demands(request_json, gp['vnfPolicy']) + #zone_policy_list = tr.gen_zone_policy(demand_vnf_name_list, gp['zone']) + #optimization_policy_list = tr.gen_optimization_policy(demand_vnf_name_list, gp['placement_optimization']) + #capacity_policy_list = tr.gen_capacity_policy(demand_vnf_name_list, gp['vim_fit']) + #hpa_policy_list = tr.gen_hpa_policy(demand_vnf_name_list, gp['hpa']) req_params_dict = _build_parameters(gp, request_json) conductor_policies = [attribute_policy_list, distance_to_location_policy_list, inventory_policy_list, resource_instance_policy_list, resource_region_policy_list, zone_policy_list, diff --git a/apps/placement/optimizers/conductor/translation.py b/apps/placement/optimizers/conductor/translation.py index 46bee1d..45deb2d 100644 --- a/apps/placement/optimizers/conductor/translation.py +++ b/apps/placement/optimizers/conductor/translation.py @@ -37,7 +37,7 @@ def get_opt_query_data(req_json, policies): if 'requestParameters' in req_json["placementInfo"]: req_params = req_json["placementInfo"]["requestParameters"] for policy in policies: - for queryProp in policy['content']['queryProperties']: + for queryProp in policy[list(policy.keys())[0]]['properties']['queryProperties']: attr_val = queryProp['value'] if 'value' in queryProp and queryProp['value'] != "" \ else dot_notation(req_params, queryProp['attribute_location']) if attr_val is not None: @@ -53,13 +53,13 @@ def gen_optimization_policy(vnf_list, optimization_policy): """ optimization_policy_list = [] for policy in optimization_policy: - content = policy['content'] + content = policy[list(policy.keys())[0]]['properties'] parameter_list = [] parameters = ["cloud_version", "hpa_score"] for attr in content['objectiveParameter']['parameterAttributes']: parameter = attr['parameter'] if attr['parameter'] in parameters else attr['parameter']+"_between" - vnfs = get_matching_vnfs(attr['resources'], vnf_list) + default, vnfs = get_matching_vnfs(attr['resources'], vnf_list) for vnf in vnfs: value = [vnf] if attr['parameter'] in parameters else [attr['customerLocationInfo'], vnf] parameter_list.append({ @@ -79,14 +79,16 @@ def get_matching_vnfs(resources, vnf_list, match_type="intersection"): :param match_type: "intersection" or "all" or "any" (any => send all_vnfs if there is any intersection) :return: List of matching VNFs """ - resources_lcase = [x.lower() for x in resources] + # Check if it is a default policy + default = True if resources == [] else False + resources_lcase = [x.lower() for x in resources] if not default else [x.lower() for x in vnf_list] if match_type == "all": # don't bother with any comparisons - return resources if set(resources_lcase) <= set(vnf_list) else None - common_vnfs = set(vnf_list) & set(resources_lcase) - common_resources = [x for x in resources if x.lower() in common_vnfs] + return default, resources if set(resources_lcase) <= set(vnf_list) else None + common_vnfs = set(vnf_list) & set(resources_lcase) if not default else set(vnf_list) + common_resources = [x for x in resources if x.lower() in common_vnfs] if not default else list(common_vnfs) if match_type == "intersection": # specifically requested intersection - return list(common_resources) - return resources if common_vnfs else None # "any" match => all resources to be returned + return default, list(common_resources) + return default, resources if common_vnfs else None # "any" match => all resources to be returned def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rtype=None): @@ -102,16 +104,36 @@ def gen_policy_instance(vnf_list, resource_policy, match_type="intersection", rt resource_policy_list = [] related_policies = [] for policy in resource_policy: - pc = policy['content'] - demands = get_matching_vnfs(pc['resources'], vnf_list, match_type=match_type) - resource = {pc['identity']: {'type': pc['policyType'], 'demands': demands}} + pc = policy[list(policy.keys())[0]] + default, demands = get_matching_vnfs(pc['properties']['resources'], vnf_list, match_type=match_type) + resource = {pc['properties']['identity']: {'type': pc['type'], 'demands': demands}} if rtype: - resource[pc['identity']]['properties'] = {'controller': pc[rtype]['controller'], - 'request': json.loads(pc[rtype]['request'])} + resource[pc['properties']['identity']]['properties'] = {'controller': pc[rtype]['controller'], + 'request': json.loads(pc[rtype]['request'])} if demands and len(demands) != 0: - resource_policy_list.append(resource) + # The default policy shall not override the specific policy that already appended + if default: + for d in demands: + resource_repeated = True \ + if {pc['properties']['identity']: {'type': pc['type'], 'demands': d}} \ + in resource_policy_list else False + if resource_repeated: + continue + else: + resource_policy_list.append( + {pc['properties']['identity']: {'type': pc['type'], 'demands': d }}) + policy[list(policy.keys())[0]]['properties']['resources'] = d + related_policies.append(policy) + # Need to override the default policies, here delete the outdated policy stored in the db + if resource in resource_policy_list: + for pc in related_policies: + if pc[list(pc.keys()[0])]['properties']['resources'] == resource: + related_policies.remove(pc) + resource_policy_list.remove(resource) related_policies.append(policy) + resource_policy_list.append(resource) + return resource_policy_list, related_policies @@ -143,9 +165,9 @@ def gen_distance_to_location_policy(vnf_list, distance_to_location_policy): """Get policies governing distance-to-location for VNFs in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, distance_to_location_policy, rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - properties = p_main['content']['distanceProperties'] + properties = p_main[list(p_main.keys())[0]]['properties']['distanceProperties'] pcp_d = properties['distance'] - p_new[p_main['content']['identity']]['properties'] = { + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = { 'distance': pcp_d['operator'] + " " + pcp_d['value'].lower() + " " + pcp_d['unit'].lower(), 'location': properties['locationInfo'] } @@ -156,9 +178,9 @@ def gen_attribute_policy(vnf_list, attribute_policy): """Get policies governing attributes of VNFs in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, attribute_policy, rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - properties = p_main['content']['cloudAttributeProperty'] + properties = p_main[list(p_main.keys())[0]]['properties']['cloudAttributeProperty'] attribute_mapping = policy_config_mapping['filtering_attributes'] # wanted attributes and mapping - p_new[p_main['content']['identity']]['properties'] = { + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = { 'evaluate': dict((k, properties.get(attribute_mapping.get(k))) for k in attribute_mapping.keys()) } return cur_policies # cur_policies gets updated in place... @@ -168,8 +190,9 @@ def gen_zone_policy(vnf_list, zone_policy): """Get zone policies in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, zone_policy, match_type="all", rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - pmz = p_main['content']['affinityProperty'] - p_new[p_main['content']['identity']]['properties'] = {'category': pmz['category'], 'qualifier': pmz['qualifier']} + pmz = p_main[list(p_main.keys())[0]]['properties']['affinityProperties'] + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \ + {'category': pmz['category'], 'qualifier': pmz['qualifier']} return cur_policies @@ -177,8 +200,8 @@ def gen_capacity_policy(vnf_list, capacity_policy): """Get zone policies in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, capacity_policy, rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - pmz = p_main['content']['capacityProperty'] - p_new[p_main['content']['identity']]['properties'] = \ + pmz = p_main[list(p_main.keys())[0]]['properties']['capacityProperty'] + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \ {"controller": pmz['controller'], 'request': json.loads(pmz['request'])} return cur_policies @@ -187,7 +210,8 @@ def gen_hpa_policy(vnf_list, hpa_policy): """Get zone policies in order to populate the Conductor API call""" cur_policies, related_policies = gen_policy_instance(vnf_list, hpa_policy, rtype=None) for p_new, p_main in zip(cur_policies, related_policies): # add additional fields to each policy - p_new[p_main['content']['identity']]['properties'] = {'evaluate': p_main['content']['flavorFeatures']} + p_new[p_main[list(p_main.keys())[0]]['properties']['identity']]['properties'] = \ + {'evaluate': p_main[list(p_main.keys())[0]]['properties']['flavorFeatures']} return cur_policies @@ -213,10 +237,12 @@ def get_candidates_demands(demand): def get_policy_properties(demand, policies): """Get policy_properties for cases where there is a match with the demand""" for policy in policies: - policy_demands = set([x.lower() for x in policy['content'].get('resources', [])]) - if demand['resourceModuleName'].lower() not in policy_demands: + policy_demands = set([x.lower() for x in policy[list(policy.keys())[0]]['properties']['resources']]) + if policy_demands and demand['resourceModuleName'].lower() not in policy_demands: continue # no match for this policy - for policy_property in policy['content']['vnfProperties']: + elif policy_demands == set(): # Append resource name for default policy + policy[list(policy.keys())[0]]['properties'].update(resources=list(demand.get('resourceModuleName'))) + for policy_property in policy[list(policy.keys())[0]]['properties']['vnfProperties']: yield policy_property diff --git a/apps/route/optimizers/route_opt.mzn b/apps/route/optimizers/route_opt.mzn new file mode 100644 index 0000000..7aa73cb --- /dev/null +++ b/apps/route/optimizers/route_opt.mzn @@ -0,0 +1,53 @@ + +% Number of nodes +int: N; + % Start node +0..N-1: Start; + % End node +0..N-1: End; + % Number of edges (directed arcs) +int: M; + % The actual edges +set of int: Edges = 1..M; + % Edge lengths +array[Edges] of int: L; + % Edge start node +array[Edges] of 0..N-1: Edge_Start; +array[Edges] of 0..N-1: Edge_End; + + % Variable indicating if edge is used +array[Edges] of var 0..1: x; + +constraint + forall( i in 0..N-1 ) ( + if i = Start then + % outgoing flow + sum(e in Edges where Edge_Start[e] = i)(x[e]) - + % incoming flow + sum(e in Edges where Edge_End[e] = i)(x[e]) + = 1 + elseif i = End then + sum(e in Edges where Edge_Start[e] = i)(x[e]) - + sum(e in Edges where Edge_End[e] = i)(x[e]) + = -1 + else + sum(e in Edges where Edge_Start[e] = i)(x[e]) - + sum(e in Edges where Edge_End[e] = i)(x[e]) + = 0 + endif + ); + + +solve minimize sum(e in Edges)( L[e] * x[e] ); +%solve satisfy; + +output ["Length: ", show(sum(e in Edges)(L[e] * x[e])), "\n"] ++ + ["Start : ", show(Start), "\n"] ++ + ["End : ", show(End), "\n\n"] ++ + ["Edges in shortest path:\n"] ++ + [ if fix(x[e]) = 1 + then show(Edge_Start[e]) ++ " -> " ++ show(Edge_End[e]) ++ "\n" + else "" + endif | e in Edges + ]; + diff --git a/apps/route/optimizers/simple_route_opt.py b/apps/route/optimizers/simple_route_opt.py index b00180d..27c1141 100644 --- a/apps/route/optimizers/simple_route_opt.py +++ b/apps/route/optimizers/simple_route_opt.py @@ -1,5 +1,5 @@ # ------------------------------------------------------------------------- -# Copyright (c) 2018 Huawei Intellectual Property +# Copyright (c) 2020 Huawei Intellectual Property # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,12 @@ import requests from requests.auth import HTTPBasicAuth from osdf.utils.mdc_utils import mdc_from_json +from osdf.logging.osdf_logging import MH, audit_log, error_log, debug_log +import pymzn +from sklearn import preprocessing +import os +BASE_DIR = os.path.dirname(__file__) class RouteOpt: @@ -31,6 +36,8 @@ class RouteOpt: # DNS server and standard port of AAI.. # TODO: read the port from the configuration and add to DNS aai_host = "https://aai.api.simpledemo.onap.org:8443" + audit_log.info("base directory") + audit_log.info(BASE_DIR) aai_headers = { "X-TransactionId": "9999", "X-FromAppId": "OOF", @@ -50,89 +57,184 @@ class RouteOpt: return True return False + def getLinksName(self, routes,initial_start_edge,initial_end_edge, mappingTable): + routes=list(routes) + arr=routes[0]['x'] + listOfLinks=[] + for i in range(0, len(routes[0]['x'])): + if arr[i] == 1 : + # listOfLinks.append(self.fetchLogicalLinks(initial_start_edge[i], initial_end_edge[i], mappingTable)) + listOfLinks.append(mappingTable[initial_start_edge[i] + ":" + initial_end_edge[i]]) + + return listOfLinks + + # def search(self, ip1, ip2, dic): + # if ip1 == "" or ip2 == "": + # return "" + # else: + # string = ip1 + ":" + ip2 + # return dic[string] + # + # def fetchLogicalLinks(self, initial_start_edge, initial_end_edge, mappingTable): + # link_name=self.search(initial_start_edge, initial_end_edge, mappingTable) + # return link_name + + + # def fetchLogicalLinks(self, initial_start_edge, initial_end_edge, mappingTable): + # return mappingTable[initial_start_edge + ":" + initial_end_edge] + + def solve(self, mzn_model, dzn_data): + return pymzn.minizinc(mzn=mzn_model, data=dzn_data) + + def getLinks(self, mzn_model, dzn_data, initial_start_edge,initial_end_edge, mappingTable): + routes = self.solve(mzn_model, dzn_data) + audit_log.info("mocked minizinc solution====>") + audit_log.info(routes) + + converted_links=self.getLinksName(routes, initial_start_edge,initial_end_edge, mappingTable) + audit_log.info("converted links===>") + audit_log.info(converted_links) + return converted_links + + def addition(self, data): + relationship = data["relationship-list"]["relationship"] + res = "" + for index, eachItem in enumerate(relationship): + if index == len(relationship) - 1: + res += eachItem["accessNodeId"] + else: + res += eachItem["accessNodeId"] + ":" + + return data["link-name"], res + + def createMapTable(self, logical_links): + result = map(self.addition, logical_links) + + parseTemplate = {} + + for eachItem in result: + parseTemplate[eachItem[1]] = eachItem[0] + audit_log.info("mapping table") + audit_log.info(parseTemplate) + return parseTemplate + + def build_dzn_data(self, src_access_node_id, dst_access_node_id): + Edge_Start = [] + Edge_End = [] + logical_links = self.get_logical_links() + audit_log.info("mocked response of AAI received (logical links) successful===>") + audit_log.info(logical_links) + # prepare map table + mappingTable = self.createMapTable(logical_links) + # take the logical link where both the p-interface in same onap + if logical_links is not None: + for logical_link in logical_links: + if not self.isCrossONAPLink(logical_link): + # link is in local ONAP + relationship = logical_link["relationship-list"]["relationship"] + + relationshipStartNode = relationship[0] + relationshipStartNodeID = relationshipStartNode["related-link"].split("/")[-1] + start_accessNodeId = relationshipStartNodeID.split("-")[-3] + Edge_Start.append(start_accessNodeId) + + relationshipEndtNode = relationship[1] + relationshipEndNodeID = relationshipEndtNode["related-link"].split("/")[-1] + end_accessNodeId = relationshipEndNodeID.split("-")[-3] + Edge_End.append(end_accessNodeId) + + audit_log.info("edge start and end array of i/p address are===>") + audit_log.info(Edge_Start) + audit_log.info(Edge_End) + # labeling ip to number for mapping + le = preprocessing.LabelEncoder() + le.fit(Edge_Start + Edge_End) + # print(le.classes_) + dzn_start_edge = le.transform(Edge_Start) + + final_dzn_start_arr = [] + for i in range(0, len(dzn_start_edge)): + final_dzn_start_arr.append(dzn_start_edge[i]) + + final_dzn_end_arr = [] + dzn_end_edge = le.transform(Edge_End) + for j in range(0, len(dzn_end_edge)): + final_dzn_end_arr.append(dzn_end_edge[j]) + + audit_log.info("start and end array that passed in dzn_data===>") + audit_log.info(final_dzn_start_arr) + audit_log.info(final_dzn_end_arr) + + link_cost = [] + for k in range(0, len(final_dzn_start_arr)): + link_cost.append(1) + + audit_log.info("src_access_node_id") + audit_log.info(src_access_node_id) + source= le.transform([src_access_node_id]) + audit_log.info("vallue of source===>") + audit_log.info(source) + if source in final_dzn_start_arr : + start = source[0] + audit_log.info("source node") + audit_log.info(start) + + audit_log.info("dst_access_node_id") + audit_log.info(dst_access_node_id) + destination= le.transform([dst_access_node_id]) + if destination in final_dzn_end_arr : + end = destination[0] + audit_log.info("destination node") + audit_log.info(end) + # data to be prepared in the below format: + dzn_data = { + 'N': self.total_node(final_dzn_start_arr + final_dzn_end_arr), + 'M': len(final_dzn_start_arr), + 'Edge_Start': final_dzn_start_arr, + 'Edge_End': final_dzn_end_arr, + 'L': link_cost, + 'Start': start, + 'End': end, + } + # can not do reverse mapping outside of this scope, so doing here + audit_log.info("reverse mapping after prepared dzn_data") + initial_start_edge=le.inverse_transform(final_dzn_start_arr) + initial_end_edge=le.inverse_transform(final_dzn_end_arr) + audit_log.info(initial_start_edge) + audit_log.info(initial_end_edge) + return dzn_data, initial_start_edge,initial_end_edge, mappingTable + + def total_node(self, node): + nodeSet = set() + for i in range(0, len(node)): + nodeSet.add(node[i]) + total_node = len(nodeSet) + return total_node + def getRoute(self, request): """ - This method checks + This method checks :param logical_link: :return: """ - mdc_from_json(request) - - src_access_node_id = request["srcPort"]["src-access-node-id"] - dst_access_node_id = request["dstPort"]["dst-access-node-id"] - - - ingress_p_interface = None - egress_p_interface = None - - # for the case of request_json for same domain, return the same node with destination update - if src_access_node_id == dst_access_node_id: - data = '{'\ - '"vpns":['\ - '{'\ - '"access-topology-id": "' + request["srcPort"]["src-access-topology-id"] + '",'\ - '"access-client-id": "' + request["srcPort"]["src-access-client-id"] + '",'\ - '"access-provider-id": "' + request["srcPort"]["src-access-provider-id"]+ '",'\ - '"access-node-id": "' + request["srcPort"]["src-access-node-id"]+ '",'\ - '"src-access-ltp-id": "' + request["srcPort"]["src-access-ltp-id"]+ '",'\ - '"dst-access-ltp-id": "' + request["dstPort"]["dst-access-ltp-id"] +'"'\ - '}'\ - ']'\ - '}' - return data - else: - logical_links = self.get_logical_links() - - # take the logical link where both the p-interface in same onap - if logical_links != None: - for logical_link in logical_links.get("logical-link"): - if not self.isCrossONAPLink(logical_link): - # link is in local ONAP - for relationship in logical_link["relationship-list"]["relationship"]: - if relationship["related-to"] == "p-interface": - if src_access_node_id in relationship["related-link"]: - i_interface = relationship["related-link"].split("/")[-1] - ingress_p_interface = i_interface.split("-")[-1] - if dst_access_node_id in relationship["related-link"]: - e_interface = relationship["related-link"].split("/")[-1] - egress_p_interface = e_interface.split("-")[-1] - data = '{'\ - '"vpns":['\ - '{'\ - '"access-topology-id": "' + request["srcPort"]["src-access-topology-id"] + '",'\ - '"access-client-id": "' + request["srcPort"]["src-access-client-id"] + '",'\ - '"access-provider-id": "' + request["srcPort"]["src-access-provider-id"]+ '",'\ - '"access-node-id": "' + request["srcPort"]["src-access-node-id"]+ '",'\ - '"src-access-ltp-id": "' + request["srcPort"]["src-access-ltp-id"]+ '",'\ - '"dst-access-ltp-id": "' + ingress_p_interface +'"'\ - '},'\ - '{' \ - '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"] + '",' \ - '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"]+ '",' \ - '"access-provider-id": "' + request["dstPort"]["dst-access-provider-id"]+ '",' \ - '"access-node-id": "' + request["dstPort"]["dst-access-node-id"]+ '",' \ - '"src-access-ltp-id": "' + egress_p_interface + '",' \ - '"dst-access-ltp-id": "' + request["dstPort"]["dst-access-ltp-id"] + '"' \ - '}'\ - ']'\ - '}' - return data - - - def get_pinterface(self, url): - """ - This method returns details for p interface - :return: details of p interface - """ - aai_req_url = self.aai_host + url - response = requests.get(aai_req_url, - headers=self.aai_headers, - auth=HTTPBasicAuth("AAI", "AAI"), - verify=False) + routeInfo = request["routeInfo"]["routeRequests"] + routeRequest = routeInfo[0] + src_access_node_id = routeRequest["srcPort"]["accessNodeId"] + dst_access_node_id = routeRequest["dstPort"]["accessNodeId"] - if response.status_code == 200: - return response.json() + dzn_data, initial_start_edge, initial_end_edge, mappingTable = self.build_dzn_data(src_access_node_id, dst_access_node_id ) + #mzn_model = "/home/root1/Videos/projects/osdf/test/functest/simulators/osdf/optimizers/routeopt/route_opt.mzn" + mzn_model = os.path.join(BASE_DIR, 'route_opt.mzn') + routeSolutions = self.getLinks(mzn_model, dzn_data, initial_start_edge,initial_end_edge, mappingTable) + + return { + "requestId": request["requestInfo"]["requestId"], + "transactionId": request["requestInfo"]["transactionId"], + "statusMessage": " ", + "requestStatus": "accepted", + "solutions": routeSolutions + } def get_logical_links(self): """ @@ -142,12 +244,6 @@ class RouteOpt: """ logical_link_url = "/aai/v13/network/logical-links?operational-status=up" aai_req_url = self.aai_host + logical_link_url - - response = requests.get(aai_req_url, - headers=self.aai_headers, - auth=HTTPBasicAuth("AAI", "AAI"), - verify=False) - - logical_links = None + response = requests.get(aai_req_url,headers=self.aai_headers,auth=HTTPBasicAuth("AAI", "AAI"),verify=False) if response.status_code == 200: return response.json()
\ No newline at end of file |