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
26 This values will need to deleted..
27 only added for the debug purpose
29 # DNS server and standard port of AAI..
30 # TODO: read the port from the configuration and add to DNS
31 aai_host = "https://aai.api.simpledemo.onap.org:8443"
33 "X-TransactionId": "9999",
35 "Content-Type": "application/json",
39 def isCrossONAPLink(self, logical_link):
41 This method checks if cross link is cross onap
45 for relationship in logical_link["logical-links"]["relationship-list"]["relationship"]:
46 if relationship["related-to"] == "p-interface":
47 if "ext-aai-network" in relationship["related-link"]:
51 def getRoute(self, request):
58 src_access_node_id = request["srcPort"]["src-access-node-id"]
59 dst_access_node_id = request["dstPort"]["dst-access-node-id"]
62 ingress_p_interface = None
63 egress_p_interface = None
65 logical_links = self.get_logical_links()
67 # take the logical link where both the p-interface in same onap
68 if logical_links != None:
69 for logical_link in logical_links["results"]:
70 if not self.isCrossONAPLink(logical_link):
72 # link is in local ONAP
73 for relationship in logical_link["logical-links"]["relationship-list"]["relationship"]:
74 if relationship["related-to"] == "p-interface":
75 if src_access_node_id in relationship["related-link"]:
76 ingress_p_interface = relationship["related-link"].split("/")[-1]
77 if dst_access_node_id in relationship["related-link"]:
78 egress_p_interface = relationship["related-link"].split("/")[-1]
83 '"access-topology-id": "' + request["srcPort"]["src-access-topology-id"] + '",'\
84 '"access-client-id": "' + request["srcPort"]["src-access-client-id"] + '",'\
85 '"access-provider-id": "' + request["srcPort"]["src-access-provider-id"]+ '",'\
86 '"access-node-id": "' + request["srcPort"]["src-access-node-id"]+ '",'\
87 '"src-access-ltp-id": "' + request["srcPort"]["src-access-ltp-id"]+ '",'\
88 '"dst-access-ltp-id": "' + ingress_p_interface +'"'\
91 '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"] + '",' \
92 '"access-topology-id": "' + request["dstPort"]["dst-access-topology-id"]+ '",' \
93 '"access-provider-id": "' + request["dstPort"]["dst-access-provider-id"]+ '",' \
94 '"access-node-id": "' + request["dstPort"]["dst-access-node-id"]+ '",' \
95 '"src-access-ltp-id": "' + egress_p_interface + '",' \
96 '"dst-access-ltp-id": "' + request["dstPort"]["dst-access-ltp-id"] + '"' \
104 def get_pinterface(self, url):
106 This method returns details for p interface
107 :return: details of p interface
109 aai_req_url = self.aai_host + url
110 response = requests.get(aai_req_url,
111 headers=self.aai_headers,
112 auth=HTTPBasicAuth("", ""))
114 if response.status_code == 200:
115 return response.json()
118 def get_logical_links(self):
120 This method returns list of all cross ONAP links
121 from /aai/v14/network/logical-links?operation-status="Up"
122 :return: logical-links[]
124 logical_link_url = "/aai/v14/network/logical-links?operation-status=\"Up\""
125 aai_req_url = self.aai_host + logical_link_url
127 response = requests.get(aai_req_url,
128 headers=self.aai_headers,
129 auth=HTTPBasicAuth("", ""))
131 if response.status_code == 200:
132 return response.json()