Fix return message format
[optf/osdf.git] / osdfapp.py
index bd5efa7..6ae84cc 100755 (executable)
@@ -125,15 +125,38 @@ def do_placement_opt():
 
 
 @app.route("/api/oof/v1/route", methods=["POST"])
-@auth_basic.login_required
 def do_route_calc():
-    """Perform the basic route calculations and returnn the vpn-bindings
-    TODO:Need to add the new class for the route in the API and model to provide this function
+    """
+    Perform the basic route calculations and returnn the vpn-bindings
     """
     request_json = request.get_json()
     audit_log.info("Calculate Route request received!")
-    return RouteOpt.getRoute(request_json)
-
+    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)
 
 @app.errorhandler(500)
 def internal_failure(error):