From 10b0930e7120e936e60cc141d00f73f071e39d84 Mon Sep 17 00:00:00 2001
From: gifrerenom <lluis.gifre@cttc.es>
Date: Fri, 23 Jun 2023 17:29:51 +0000
Subject: [PATCH] Interdomain component:

- Added to client method to delete slice
- Corrected computation of slice owner
---
 src/interdomain/client/InterdomainClient.py | 37 ++++++++++++++++-----
 src/interdomain/service/Tools.py            | 26 +++++++++------
 2 files changed, 44 insertions(+), 19 deletions(-)

diff --git a/src/interdomain/client/InterdomainClient.py b/src/interdomain/client/InterdomainClient.py
index f5631de61..ade3ef207 100644
--- a/src/interdomain/client/InterdomainClient.py
+++ b/src/interdomain/client/InterdomainClient.py
@@ -15,7 +15,7 @@
 import grpc, logging
 from common.Constants import ServiceNameEnum
 from common.Settings import get_service_host, get_service_port_grpc
-from common.proto.context_pb2 import AuthenticationResult, Slice, SliceId, SliceStatus, TeraFlowController
+from common.proto.context_pb2 import AuthenticationResult, Empty, Slice, SliceId, SliceStatus, TeraFlowController
 from common.proto.interdomain_pb2_grpc import InterdomainServiceStub
 from common.tools.client.RetryDecorator import retry, delay_exponential
 from common.tools.grpc.Tools import grpc_message_to_json_string
@@ -45,13 +45,6 @@ class InterdomainClient:
         self.channel = None
         self.stub = None
 
-    @RETRY_DECORATOR
-    def RequestSlice(self, request : Slice) -> SliceId:
-        LOGGER.debug('RequestSlice request: {:s}'.format(grpc_message_to_json_string(request)))
-        response = self.stub.RequestSlice(request)
-        LOGGER.debug('RequestSlice result: {:s}'.format(grpc_message_to_json_string(response)))
-        return response
-
     @RETRY_DECORATOR
     def Authenticate(self, request : TeraFlowController) -> AuthenticationResult:
         LOGGER.debug('Authenticate request: {:s}'.format(grpc_message_to_json_string(request)))
@@ -59,6 +52,13 @@ class InterdomainClient:
         LOGGER.debug('Authenticate result: {:s}'.format(grpc_message_to_json_string(response)))
         return response
 
+    @RETRY_DECORATOR
+    def RequestSlice(self, request : Slice) -> SliceId:
+        LOGGER.debug('RequestSlice request: {:s}'.format(grpc_message_to_json_string(request)))
+        response = self.stub.RequestSlice(request)
+        LOGGER.debug('RequestSlice result: {:s}'.format(grpc_message_to_json_string(response)))
+        return response
+
     @RETRY_DECORATOR
     def LookUpSlice(self, request : Slice) -> SliceId:
         LOGGER.debug('LookUpSlice request: {:s}'.format(grpc_message_to_json_string(request)))
@@ -79,3 +79,24 @@ class InterdomainClient:
         response = self.stub.CreateSliceAndAddToCatalog(request)
         LOGGER.debug('CreateSliceAndAddToCatalog result: {:s}'.format(grpc_message_to_json_string(response)))
         return response
+
+    @RETRY_DECORATOR
+    def OrderSliceWithSLA(self, request : Slice) -> SliceId:
+        LOGGER.debug('OrderSliceWithSLA request: {:s}'.format(grpc_message_to_json_string(request)))
+        response = self.stub.OrderSliceWithSLA(request)
+        LOGGER.debug('OrderSliceWithSLA result: {:s}'.format(grpc_message_to_json_string(response)))
+        return response
+
+    @RETRY_DECORATOR
+    def UpdateSlice(self, request : Slice) -> Slice:
+        LOGGER.debug('UpdateSlice request: {:s}'.format(grpc_message_to_json_string(request)))
+        response = self.stub.UpdateSlice(request)
+        LOGGER.debug('UpdateSlice result: {:s}'.format(grpc_message_to_json_string(response)))
+        return response
+
+    @RETRY_DECORATOR
+    def DeleteSlice(self, request : SliceId) -> Empty:
+        LOGGER.debug('DeleteSlice request: {:s}'.format(grpc_message_to_json_string(request)))
+        response = self.stub.DeleteSlice(request)
+        LOGGER.debug('DeleteSlice result: {:s}'.format(grpc_message_to_json_string(response)))
+        return response
diff --git a/src/interdomain/service/Tools.py b/src/interdomain/service/Tools.py
index 609dc6e07..94db60ed2 100644
--- a/src/interdomain/service/Tools.py
+++ b/src/interdomain/service/Tools.py
@@ -32,19 +32,23 @@ def compute_slice_owner(
 ) -> Optional[str]:
     traversed_domain_uuids = {traversed_domain[0] for traversed_domain in traversed_domains}
 
-    existing_topology_ids = context_client.ListTopologyIds(ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)))
-    existing_topology_uuids = {
-        topology_id.topology_uuid.uuid for topology_id in existing_topology_ids.topology_ids
-    }
-    existing_topology_uuids.discard(DEFAULT_TOPOLOGY_NAME)
-    existing_topology_uuids.discard(INTERDOMAIN_TOPOLOGY_NAME)
-
-    candidate_owner_uuids = traversed_domain_uuids.intersection(existing_topology_uuids)
+    existing_topologies = context_client.ListTopologies(ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)))
+    existing_topology_uuids_names = set()
+    DISCARD_TOPOLOGY_NAMES = {DEFAULT_TOPOLOGY_NAME, INTERDOMAIN_TOPOLOGY_NAME}
+    for topology in existing_topologies.topologies:
+        topology_uuid = topology.topology_id.topology_uuid.uuid
+        if topology_uuid in DISCARD_TOPOLOGY_NAMES: continue
+        topology_name = topology.name
+        if topology_name in DISCARD_TOPOLOGY_NAMES: continue
+        existing_topology_uuids_names.add(topology_uuid)
+        existing_topology_uuids_names.add(topology_name)
+
+    candidate_owner_uuids = traversed_domain_uuids.intersection(existing_topology_uuids_names)
     if len(candidate_owner_uuids) != 1:
         data = {
-            'traversed_domain_uuids' : [td_uuid for td_uuid in traversed_domain_uuids ],
-            'existing_topology_uuids': [et_uuid for et_uuid in existing_topology_uuids],
-            'candidate_owner_uuids'  : [co_uuid for co_uuid in candidate_owner_uuids  ],
+            'traversed_domain_uuids'       : [td_uuid for td_uuid in traversed_domain_uuids ],
+            'existing_topology_uuids_names': [et_uuid for et_uuid in existing_topology_uuids_names],
+            'candidate_owner_uuids'        : [co_uuid for co_uuid in candidate_owner_uuids  ],
         }
         LOGGER.warning('Unable to identify slice owner: {:s}'.format(json.dumps(data)))
         return None
-- 
GitLab