Fix: Ensure that interface names are RTNETLINK compatible
authorpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 19 Jul 2016 07:31:19 +0000 (09:31 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Tue, 19 Jul 2016 07:31:19 +0000 (09:31 +0200)
src/emuvim/api/sonata/dummygatekeeper.py
src/emuvim/dcemulator/node.py

index 20150d0..c41884b 100755 (executable)
@@ -208,7 +208,8 @@ class Service(object):
             # TODO consider flavors, and other annotations
             intfs = vnfd.get("connection_points")
             self.vnfname2num[vnf_name] = GK.get_next_vnf_name()
-            LOG.info("VNF "+vnf_name+" mapped to "+self.vnfname2num[vnf_name]+" on dc "+str(vnfd.get("dc")))
+            LOG.info("Starting %r as %r in DC %r" % (vnf_name, self.vnfname2num[vnf_name], vnfd.get("dc")))
+            LOG.debug("Interfaces for %r: %r" % (vnf_name, intfs))
             vnfi = target_dc.startCompute(self.vnfname2num[vnf_name], network=intfs, image=docker_name, flavor_name="small")
             return vnfi
 
index aa9fb4a..b88913b 100755 (executable)
@@ -191,6 +191,9 @@ class Datacenter(object):
         # if no --net option is given, network = [{}], so 1 empty dict in the list
         # this results in 1 default interface with a default ip address
         for nw in network:
+            # clean up network configuration (e.g. RTNETLINK does not allow ':' in intf names
+            if nw.get("id") is not None:
+                nw["id"] = self._clean_ifname(nw["id"])
             # TODO we cannot use TCLink here (see: https://github.com/mpeuster/containernet/issues/3)
             self.net.addLink(d, self.switch, params1=nw, cls=Link, intfName1=nw.get('id'))
         # do bookkeeping
@@ -256,3 +259,19 @@ class Datacenter(object):
         self.net.rm_registrar.register(self, rm)
         LOG.info("Assigned RM: %r to DC: %r" % (rm, self))
 
+    @staticmethod
+    def _clean_ifname(name):
+        """
+        Cleans up given string to be a
+        RTNETLINK compatible interface name.
+        :param name: string
+        :return: string
+        """
+        if name is None:
+            return "if0"
+        name = name.replace(":", "-")
+        name = name.replace(" ", "-")
+        name = name.replace(".", "-")
+        name = name.replace("_", "-")
+        return name
+