use fixed cookie value: 1
[osm/vim-emu.git] / src / emuvim / api / sonata / dummygatekeeper.py
index 432c134..916e168 100755 (executable)
@@ -166,7 +166,9 @@ class Service(object):
         fwd_links = self.nsd["forwarding_graphs"][0]["constituent_virtual_links"]
         eline_fwd_links = [l for l in vlinks if (l["id"] in fwd_links) and (l["connectivity_type"] == "E-Line")]
 
-        cookie = 1  # not clear why this is needed - to check with Steven
+        # cookie is used as identifier for the flowrules installed by the dummygatekeeper
+        # eg. different services get a unique cookie for their flowrules
+        cookie = 1
         for link in eline_fwd_links:
             src_id, src_if_name = link["connection_points_reference"][0].split(":")
             dst_id, dst_if_name = link["connection_points_reference"][1].split(":")
@@ -187,7 +189,6 @@ class Service(object):
                     src_docker_name, dst_docker_name,
                     vnf_src_interface=src_if_name, vnf_dst_interface=dst_if_name,
                     bidirectional=True, cmd="add-flow", cookie=cookie)
-                cookie += 1
 
                 # re-configure the VNFs IP assignment and ensure that a new subnet is used for each E-Link
                 src_vnfi = self._get_vnf_instance(instance_uuid, src_name)
@@ -225,7 +226,16 @@ class Service(object):
             # 3. do the dc.startCompute(name="foobar") call to run the container
             # TODO consider flavors, and other annotations
             intfs = vnfd.get("connection_points")
-            self.vnf_name2docker_name[vnf_name] = GK.get_next_vnf_name()
+
+            # use the vnf_id in the nsd as docker name
+            # so deployed containers can be easily mapped back to the nsd
+            vnf_name2id = defaultdict(lambda: "NotExistingNode",
+                                          reduce(lambda x, y: dict(x, **y),
+                                                 map(lambda d: {d["vnf_name"]: d["vnf_id"]},
+                                                     self.nsd["network_functions"])))
+            self.vnf_name2docker_name[vnf_name] = vnf_name2id[vnf_name]
+            # self.vnf_name2docker_name[vnf_name] = GK.get_next_vnf_name()
+
             LOG.info("Starting %r as %r in DC %r" % (vnf_name, self.vnf_name2docker_name[vnf_name], vnfd.get("dc")))
             LOG.debug("Interfaces for %r: %r" % (vnf_name, intfs))
             vnfi = target_dc.startCompute(self.vnf_name2docker_name[vnf_name], network=intfs, image=docker_name, flavor_name="small")