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 aai_host = "https:\\192.168.17.26:8443"
31 "X-TransactionId": "9999",
33 "Content-Type": "application/json",
37 def isCrossONAPLink(self, logical_link):
39 This method checks if cross link is cross onap
43 for relationship in logical_link["logical-links"]["relationsihp-list"]["relationship"]:
44 if relationship["related-to"] == "p-interface":
45 if "external" in relationship["related-link"]:
49 def getRoute(self, request):
56 src_access_node_id = request["srcPort"]["src-access-node-id"]
57 dst_access_node_id = request["dstPort"]["dst-access-node-id"]
59 # for the case of request for same domain, return the same node with destination update
60 if src_access_node_id == dst_access_node_id:
64 "access-topology-id": request["srcPort"]["src-access-topology-id"],
65 "access-client-id": request["srcPort"]["access-client-id"],
66 "access-provider-id": request["srcPort"]["access-provider-id"],
67 "access-node-id": request["srcPort"]["access-node-id"],
68 "src-access-ltp-id": request["srcPort"]["src-access-ltp-id"],
69 "dst-access-ltp-id": request["dstPort"]["dst-access-ltp-id"]
74 ingress_p_interface = None
75 egress_p_interface = None
77 logical_links = self.get_logical_links()
79 # take the logical link where both the p-interface in same onap
80 if logical_links != None:
81 for logical_link in logical_links["results"]:
82 if not self.isCrossONAPLink(logical_link):
84 # link is in local ONAP
85 for relationship in logical_link["logical-links"]["relationsihp-list"]["relationship"]:
86 if relationship["related-to"] == "p-interface":
87 if src_access_node_id in relationship["related-link"]:
88 ingress_p_interface = relationship["related-link"].split("/")[-1]
89 if dst_access_node_id in relationship["related-link"]:
90 egress_p_interface = relationship["related-link"].split("/")[-1]
95 "access-topology-id": request["srcPort"]["src-access-topology-id"],
96 "access-client-id": request["srcPort"]["access-client-id"],
97 "access-provider-id": request["srcPort"]["access-provider-id"],
98 "access-node-id": request["srcPort"]["access-node-id"],
99 "src-access-ltp-id": request["srcPort"]["src-access-ltp-id"],
100 "dst-access-ltp-id": ingress_p_interface
103 "access-topology-id": request["dstPort"]["access-topology-id"],
104 "access-client-id": request["dstPort"]["access-client-id"],
105 "access-provider-id": request["dstPort"]["access-provider-id"],
106 "access-node-id": request["dstPort"]["access-node-id"],
107 "src-access-ltp-id": egress_p_interface,
108 "dst-access-ltp-id": request["dstPort"]["dst-access-ltp-id"]
115 def get_pinterface(self, url):
117 This method returns details for p interface
118 :return: details of p interface
120 aai_req_url = self.aai_host + url
121 response = requests.get(aai_req_url,
122 headers=self.aai_headers,
123 auth=HTTPBasicAuth("", ""))
125 if response.status_code == 200:
129 def get_logical_links(self):
131 This method returns list of all cross ONAP links
132 from /aai/v14/network/logical-links?operation-status="Up"
133 :return: logical-links[]
135 logical_link_url = "/aai/v14/network/logical-links?operation-status=\"Up\""
136 aai_req_url = self.aai_host + logical_link_url
138 response = requests.get(aai_req_url,
139 headers=self.aai_headers,
140 auth=HTTPBasicAuth("", ""))
142 if response.status_code == 200: