diff options
author | subhash kumar singh <subhash.kumar.singh@huawei.com> | 2018-09-06 21:39:43 +0800 |
---|---|---|
committer | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2018-09-25 05:58:54 +0000 |
commit | ab35ab7d3c95b8c54ae443085277519388cef384 (patch) | |
tree | dbae1ade4296f3a30da8255413d3c214add33024 | |
parent | 6ae89d5df37c626d7bd6f1fcf94571e718f10b02 (diff) |
Fix get route operation
Fix get route operatiaon for CCVPN use case.
Change-Id: I57784a611744d3112e48f41ff742b01d557a4644
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Issue-ID: OPTFRA-334
-rw-r--r-- | osdf/optimizers/routeopt/__init__.py | 17 | ||||
-rw-r--r-- | osdf/optimizers/routeopt/simple_route_opt.py | 82 | ||||
-rwxr-xr-x | osdfapp.py | 34 |
3 files changed, 71 insertions, 62 deletions
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 @@ -34,15 +34,15 @@ import osdf.config.loader import osdf.operation.error_handling import osdf.operation.responses import traceback +from schematics.exceptions import DataError +from requests import RequestException +from optparse import OptionParser from osdf.adapters.policy.interface import get_policies from osdf.config.base import osdf_config from osdf.optimizers.placementopt.conductor.remote_opt_processor import process_placement_opt from osdf.webapp.appcontroller import auth_basic -from optparse import OptionParser from osdf.operation.exceptions import BusinessException from osdf.operation.error_handling import request_exception_to_json_body, internal_error_message -from requests import RequestException -from schematics.exceptions import DataError from osdf.logging.osdf_logging import MH, audit_log, error_log, debug_log from osdf.models.api.placementRequest import PlacementAPI from osdf.models.api.pciOptimizationRequest import PCIOptimizationAPI @@ -145,32 +145,7 @@ def do_route_calc(): """ request_json = request.get_json() audit_log.info("Calculate Route request received!") - src_access_node_id = "" - dst_access_node_id = "" - try: - src_access_node_id = request_json["srcPort"]["src-access-node-id"] - audit_log.info( src_access_node_id ) - dst_access_node_id = request_json["dstPort"]["dst-access-node-id"] - except Exception as ex: - error_log.error("Exception while retriving the src and dst node info") - # 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: - audit_log.info("src and dst are same") - data = '{'\ - '"vpns":['\ - '{'\ - '"access-topology-id": "' + request_json["srcPort"]["src-access-topology-id"] + '",'\ - '"access-client-id": "' + request_json["srcPort"]["src-access-client-id"] + '",'\ - '"access-provider-id": "' + request_json["srcPort"]["src-access-provider-id"]+ '",'\ - '"access-node-id": "' + request_json["srcPort"]["src-access-node-id"]+ '",'\ - '"src-access-ltp-id": "' + request_json["srcPort"]["src-access-ltp-id"]+ '",'\ - '"dst-access-ltp-id": "' + request_json["dstPort"]["dst-access-ltp-id"] +'"'\ - '}'\ - ']'\ - '}' - return data - else: - return RouteOpt.getRoute(request_json) + return RouteOpt().getRoute(request_json) @app.route("/api/oof/v1/pci", methods=["POST"]) @auth_basic.login_required @@ -197,7 +172,6 @@ def internal_failure(error): response.status_code = 500 return response - def get_options(argv): program_version_string = '%%prog %s' % "v1.0" program_longdesc = "" |