1 # -------------------------------------------------------------------------
2 # Copyright (c) 2018 Huawei Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
20 from requests.auth import HTTPBasicAuth
22 from osdf.utils.mdc_utils import mdc_from_json
28 This values will need to deleted..
29 only added for the debug purpose
31 # DNS server and standard port of AAI..
32 # TODO: read the port from the configuration and add to DNS
33 aai_host = "https://aai.api.simpledemo.onap.org:8443"
35 "X-TransactionId": "9999",
37 "Accept": "application/json",
38 "Content-Type": "application/json",
42 def isCrossONAPLink(self, logical_link):
44 This method checks if cross link is cross onap
48 for relationship in logical_link["relationship-list"]["relationship"]:
49 if relationship["related-to"] == "ext-aai-network":
53 def getRoute(self, request):
59 mdc_from_json(request)
61 src_access_node_id = request["srcPort"]["src-access-node-id"]
62 dst_access_node_id = request["dstPort"]["dst-access-node-id"]
65 ingress_p_interface = None
66 egress_p_interface = None
68 # for the case of request_json for same domain, return the same node with destination update
69 if src_access_node_id == dst_access_node_id:
73 '"access-topology-id": "' + request["srcPort"]["src-access-topology-id"] + '",'\
74 '"access-client-id": "' + request["srcPort"]["src-access-client-id"] + '",'\
75 '"access-provider-id": "' + request["srcPort"]["src-access-provider-id"]+ '",'\
76 '"access-node-id": "' + request["srcPort"]["src-access-node-id"]+ '",'\
77 '"src-access-ltp-id": "' + request["srcPort"]["src-access-ltp-id"]+ '",'\
78 '"dst-access-ltp-id": "' + request["dstPort"]["dst-access-ltp-id"] +'"'\
84 logical_links = self.get_logical_links()
86 # take the logical link where both the p-interface in same onap
87 if logical_links != None:
88 for logical_link in logical_links.get("logical-link"):
89 if not self.isCrossONAPLink(logical_link):
90 # link is in local ONAP
91 for relationship in logical_link["relationship-list"]["relationship"]:
92 if relationship["related-to"] == "p-interface":
93 if src_access_node_id in relationship["related-link"]:
94 i_interface = relationship["related-link"].split("/")[-1]
95 ingress_p_interface = i_interface.split("-")[-1]
96 if dst_access_node_id in relationship["related-link"]:
97 e_interface = relationship["related-link"].split("/")[-1]
98 egress_p_interface = e_interface.split("-")[-1]
102 '"access-topology-id": "' + request["srcPort"]["src-access-topology-id"] + '",'\
103 '"access-client-id": "' + request["srcPort"]["src-access-client-id"] + '",'\
104 '"access-provider-id": "' + request["srcPort"]["src-access-provider-id"]+ '",'\
105 '"access-node-id": "' + request["srcPort"]["src-access-node-id"]+ '",'\
106 '"src-access-ltp-id": "' + request["srcPort"]["src-access-ltp-id"]+ '",'\
107 '"dst-access-ltp-id": "' + ingress_p_interface +'"'\
110 '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"] + '",' \
111 '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"]+ '",' \
112 '"access-provider-id": "' + request["dstPort"]["dst-access-provider-id"]+ '",' \
113 '"access-node-id": "' + request["dstPort"]["dst-access-node-id"]+ '",' \
114 '"src-access-ltp-id": "' + egress_p_interface + '",' \
115 '"dst-access-ltp-id": "' + request["dstPort"]["dst-access-ltp-id"] + '"' \
122 def get_pinterface(self, url):
124 This method returns details for p interface
125 :return: details of p interface
127 aai_req_url = self.aai_host + url
128 response = requests.get(aai_req_url,
129 headers=self.aai_headers,
130 auth=HTTPBasicAuth("AAI", "AAI"),
133 if response.status_code == 200:
134 return response.json()
137 def get_logical_links(self):
139 This method returns list of all cross ONAP links
140 from /aai/v14/network/logical-links?operation-status="Up"
141 :return: logical-links[]
143 logical_link_url = "/aai/v13/network/logical-links?operational-status=up"
144 aai_req_url = self.aai_host + logical_link_url
146 response = requests.get(aai_req_url,
147 headers=self.aai_headers,
148 auth=HTTPBasicAuth("AAI", "AAI"),
152 if response.status_code == 200:
153 return response.json()