aboutsummaryrefslogtreecommitdiffstats
path: root/osdf/optimizers
diff options
context:
space:
mode:
Diffstat (limited to 'osdf/optimizers')
-rw-r--r--osdf/optimizers/pciopt/pci_opt_processor.py49
-rwxr-xr-xosdf/optimizers/placementopt/conductor/conductor.py2
-rw-r--r--osdf/optimizers/routeopt/__init__.py17
-rw-r--r--osdf/optimizers/routeopt/simple_route_opt.py82
4 files changed, 98 insertions, 52 deletions
diff --git a/osdf/optimizers/pciopt/pci_opt_processor.py b/osdf/optimizers/pciopt/pci_opt_processor.py
index 030128e..989f578 100644
--- a/osdf/optimizers/pciopt/pci_opt_processor.py
+++ b/osdf/optimizers/pciopt/pci_opt_processor.py
@@ -20,7 +20,6 @@ import traceback
from requests import RequestException
from osdf.logging.osdf_logging import metrics_log, MH, error_log
-from osdf.models.api.pciOptimizationResponse import PCIOptimizationResponse, Solution, PCISolution
from osdf.operation.error_handling import build_json_error_body
from osdf.utils.interfaces import get_rest_client
from .configdb import request as config_request
@@ -44,26 +43,9 @@ def process_pci_optimation(request_json, osdf_config, flat_policies):
try:
rc = get_rest_client(request_json, service="pcih")
req_id = request_json["requestInfo"]["requestId"]
- transaction_id = request_json['requestInfo']['transactionId']
cell_info_list, network_cell_info = config_request(request_json, osdf_config, flat_policies)
- pci_response = PCIOptimizationResponse()
- pci_response.transactionId = transaction_id
- pci_response.requestId = req_id
- pci_response.requestStatus = 'success'
- pci_response.solutions = Solution()
- pci_response.solutions.networkId = request_json['cellInfo']['networkId']
- pci_response.solutions.pciSolutions = []
-
- for cell in request_json['cellInfo']['cellIdList']:
- pci_solution = optimize(cell['cellId'], network_cell_info, cell_info_list)
- error_log.error(pci_solution)
- sol = pci_solution[0]['pci']
- for k, v in sol.items():
- response = PCISolution()
- response.cellId = get_cell_id(network_cell_info, k)
- response.pci = get_pci_value(network_cell_info, v)
- pci_response.solutions.pciSolutions.append(response)
+ pci_response = get_solutions(cell_info_list, network_cell_info, request_json)
metrics_log.info(MH.inside_worker_thread(req_id))
except Exception as err:
@@ -82,3 +64,32 @@ def process_pci_optimation(request_json, osdf_config, flat_policies):
rc.request(json=pci_response, noresponse=True)
except RequestException: # can't do much here but log it and move on
error_log.error("Error sending asynchronous notification for {} {}".format(req_id, traceback.format_exc()))
+
+
+def get_solutions(cell_info_list, network_cell_info, request_json):
+ return {
+ "transactionId": request_json['requestInfo']['transactionId'],
+ "requestId": request_json["requestInfo"]["requestId"],
+ "requestStatus": "completed",
+ "statusMessage": "success",
+ "solutions": [
+ {
+ 'networkId': request_json['cellInfo']['networkId'],
+ 'pciSolutions': build_solution_list(cell_info_list, network_cell_info, request_json)
+ }
+ ]
+ }
+
+
+def build_solution_list(cell_info_list, network_cell_info, request_json):
+ solution_list = []
+ for cell in request_json['cellInfo']['cellIdList']:
+ opt_solution = optimize(cell, network_cell_info, cell_info_list)
+ sol = opt_solution[0]['pci']
+ for k, v in sol.items():
+ response = {
+ 'cellId': get_cell_id(network_cell_info, k),
+ 'pci': get_pci_value(network_cell_info, v)
+ }
+ solution_list.append(response)
+ return solution_list
diff --git a/osdf/optimizers/placementopt/conductor/conductor.py b/osdf/optimizers/placementopt/conductor/conductor.py
index 29f0bbc..357efd1 100755
--- a/osdf/optimizers/placementopt/conductor/conductor.py
+++ b/osdf/optimizers/placementopt/conductor/conductor.py
@@ -136,7 +136,7 @@ def conductor_response_processor(conductor_response, raw_response, req_id):
name_map = {"physical-location-id": "cloudClli", "host_id": "vnfHostName",
"cloud_version": "cloudVersion", "cloud_owner": "cloudOwner",
"cloud": "cloudRegionId", "service": "serviceInstanceId", "is_rehome": "isRehome",
- "location_id": "locationId", "location_type": "locationType"}
+ "location_id": "locationId", "location_type": "locationType", "directives": "oof_directives"}
for reco in conductor_response['plans'][0]['recommendations']:
for resource in reco.keys():
c = reco[resource]['candidate']
diff --git a/osdf/optimizers/routeopt/__init__.py b/osdf/optimizers/routeopt/__init__.py
new file mode 100644
index 0000000..c235f2a
--- /dev/null
+++ b/osdf/optimizers/routeopt/__init__.py
@@ -0,0 +1,17 @@
+# -------------------------------------------------------------------------
+# Copyright (c) 2018 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.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -------------------------------------------------------------------------
+#
diff --git a/osdf/optimizers/routeopt/simple_route_opt.py b/osdf/optimizers/routeopt/simple_route_opt.py
index d1cf13f..ed179c9 100644
--- a/osdf/optimizers/routeopt/simple_route_opt.py
+++ b/osdf/optimizers/routeopt/simple_route_opt.py
@@ -32,6 +32,7 @@ class RouteOpt:
aai_headers = {
"X-TransactionId": "9999",
"X-FromAppId": "OOF",
+ "Accept": "application/json",
"Content-Type": "application/json",
"Real-Time": "true"
}
@@ -42,10 +43,9 @@ class RouteOpt:
:param logical_link:
:return:
"""
- for relationship in logical_link["logical-links"]["relationship-list"]["relationship"]:
- if relationship["related-to"] == "p-interface":
- if "ext-aai-network" in relationship["related-link"]:
- return True
+ for relationship in logical_link["relationship-list"]["relationship"]:
+ if relationship["related-to"] == "external-aai-network":
+ return True
return False
def getRoute(self, request):
@@ -62,21 +62,8 @@ class RouteOpt:
ingress_p_interface = None
egress_p_interface = None
- 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["results"]:
- if not self.isCrossONAPLink(logical_link):
-
- # link is in local ONAP
- for relationship in logical_link["logical-links"]["relationship-list"]["relationship"]:
- if relationship["related-to"] == "p-interface":
- if src_access_node_id in relationship["related-link"]:
- ingress_p_interface = relationship["related-link"].split("/")[-1]
- if dst_access_node_id in relationship["related-link"]:
- egress_p_interface = relationship["related-link"].split("/")[-1]
-
+ # 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":['\
'{'\
@@ -85,20 +72,48 @@ class RouteOpt:
'"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"] + '"' \
+ '"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):
@@ -109,7 +124,8 @@ class RouteOpt:
aai_req_url = self.aai_host + url
response = requests.get(aai_req_url,
headers=self.aai_headers,
- auth=HTTPBasicAuth("", ""))
+ auth=HTTPBasicAuth("AAI", "AAI"),
+ verify=False)
if response.status_code == 200:
return response.json()
@@ -121,12 +137,14 @@ class RouteOpt:
from /aai/v14/network/logical-links?operation-status="Up"
:return: logical-links[]
"""
- logical_link_url = "/aai/v14/network/logical-links?operation-status=\"Up\""
+ 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("", ""))
+ auth=HTTPBasicAuth("AAI", "AAI"),
+ verify=False)
+ logical_links = None
if response.status_code == 200:
return response.json() \ No newline at end of file