aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/route/optimizers/simple_route_opt.py149
1 files changed, 83 insertions, 66 deletions
diff --git a/apps/route/optimizers/simple_route_opt.py b/apps/route/optimizers/simple_route_opt.py
index 27c1141..9113516 100644
--- a/apps/route/optimizers/simple_route_opt.py
+++ b/apps/route/optimizers/simple_route_opt.py
@@ -17,6 +17,7 @@
#
import requests
+import json
from requests.auth import HTTPBasicAuth
from osdf.utils.mdc_utils import mdc_from_json
@@ -35,18 +36,14 @@ 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",
"Accept": "application/json",
"Content-Type": "application/json",
- "Real-Time": "true"
}
- def isCrossONAPLink(self, logical_link):
+ def is_cross_onap_link(self, logical_link):
"""
This method checks if cross link is cross onap
:param logical_link:
@@ -57,57 +54,54 @@ class RouteOpt:
return True
return False
- def getLinksName(self, routes,initial_start_edge,initial_end_edge, mappingTable):
+ def get_links_name(self, routes,initial_start_edge,initial_end_edge, mappingTable):
routes=list(routes)
- arr=routes[0]['x']
+ try:
+ arr=routes[0]['x']
+ except Exception as err:
+ audit_log.info("No satisfiable solutions found")
+ raise err
listOfLinks=[]
for i in range(0, len(routes[0]['x'])):
+ individual_link = {}
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]])
+ individual_link["link"] = mappingTable[initial_start_edge[i] + ":" + initial_end_edge[i]]
+ individual_link["start_node"] = initial_start_edge[i]
+ individual_link["end_node"] = initial_end_edge[i]
+ listOfLinks.append(individual_link)
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):
+ def get_links(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)
+ converted_links=self.get_links_name(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):
+ if 'relationship-list' in data.keys():
+ relationship = data["relationship-list"]["relationship"]
+ for index, eachItem in enumerate(relationship):
+ temp = eachItem["relationship-data"][0]
+ if index == len(relationship) - 1:
+ res += temp['relationship-value']
+ else:
+ res += temp['relationship-value'] + ":"
+
+ return data["link-name"], res
+ else:
+ return data["link-name"], res
+
+ def create_map_table(self, logical_links):
result = map(self.addition, logical_links)
parseTemplate = {}
@@ -118,30 +112,47 @@ class RouteOpt:
audit_log.info(parseTemplate)
return parseTemplate
- def build_dzn_data(self, src_access_node_id, dst_access_node_id):
+ def build_dzn_data(self, src_access_node_id, dst_access_node_id, osdf_config):
Edge_Start = []
Edge_End = []
- logical_links = self.get_logical_links()
+ logical_links = self.get_logical_links(osdf_config)
+
+
+ logical_links = logical_links['logical-link']
audit_log.info("mocked response of AAI received (logical links) successful===>")
audit_log.info(logical_links)
# prepare map table
- mappingTable = self.createMapTable(logical_links)
+ mappingTable = self.create_map_table(logical_links)
+ audit_log.info("mapping table created successfully====>")
+ audit_log.info(mappingTable)
# take the logical link where both the p-interface in same onap
if logical_links is not None:
+ audit_log.info('logical links not empty=====>')
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('logical_link')
+ audit_log.info(logical_link)
+
+ if 'relationship-list' in logical_link.keys():
+ if not self.is_cross_onap_link(logical_link):
+ # link is in local ONAP
+ audit_log.info('link is inside onap===>')
+ relationship = logical_link["relationship-list"]["relationship"]
+
+ relationshipStartNode = relationship[0]
+ audit_log.info('relationshipStartNode')
+ audit_log.info(relationshipStartNode)
+ relationshipStartNodeID = relationshipStartNode["related-link"].split("/")[-4]
+ audit_log.info('relationshipStartNodeID')
+ audit_log.info(relationshipStartNodeID)
+ Edge_Start.append(relationshipStartNodeID)
+
+ relationshipEndtNode = relationship[1]
+ relationshipEndNodeID = relationshipEndtNode["related-link"].split("/")[-4]
+ audit_log.info('relationshipEndNodeID')
+ audit_log.info(relationshipEndNodeID)
+ Edge_End.append(relationshipEndNodeID)
+ else:
+ continue
audit_log.info("edge start and end array of i/p address are===>")
audit_log.info(Edge_Start)
@@ -149,7 +160,6 @@ class RouteOpt:
# 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 = []
@@ -211,39 +221,46 @@ class RouteOpt:
total_node = len(nodeSet)
return total_node
- def getRoute(self, request):
+ def get_route(self, request, osdf_config):
"""
This method checks
:param logical_link:
:return:
"""
- routeInfo = request["routeInfo"]["routeRequests"]
- routeRequest = routeInfo[0]
- src_access_node_id = routeRequest["srcPort"]["accessNodeId"]
- dst_access_node_id = routeRequest["dstPort"]["accessNodeId"]
+ try:
+ routeInfo = request["routeInfo"]["routeRequests"]
+ routeRequest = routeInfo[0]
+ src_access_node_id = routeRequest["srcPort"]["accessNodeId"]
+ dst_access_node_id = routeRequest["dstPort"]["accessNodeId"]
- 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')
+ dzn_data, initial_start_edge, initial_end_edge, mappingTable = self.build_dzn_data(src_access_node_id, dst_access_node_id, osdf_config)
+ #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)
+ routeSolutions = self.get_links(mzn_model, dzn_data, initial_start_edge,initial_end_edge, mappingTable)
- return {
+ return {
"requestId": request["requestInfo"]["requestId"],
"transactionId": request["requestInfo"]["transactionId"],
"statusMessage": " ",
"requestStatus": "accepted",
"solutions": routeSolutions
- }
+ }
+ except Exception as err:
+ audit_log.info(err)
+ raise err
- def get_logical_links(self):
+ def get_logical_links(self, osdf_config):
"""
This method returns list of all cross ONAP links
from /aai/v14/network/logical-links?operation-status="Up"
:return: logical-links[]
"""
- logical_link_url = "/aai/v13/network/logical-links?operational-status=up"
- aai_req_url = self.aai_host + logical_link_url
+
+ config = osdf_config.deployment
+ aai_url = config["aaiUrl"]
+ aai_req_url = aai_url + config["aaiGetLinksUrl"]
+
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