Skip to content

Commit

Permalink
Merge pull request #144 from mpeuster/master
Browse files Browse the repository at this point in the history
Fix: Ensure that interface names are RTNETLINK compatible
  • Loading branch information
mpeuster authored Jul 19, 2016
2 parents 4ccaf16 + 4fd7cf0 commit c185cc0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/emuvim/api/sonata/dummygatekeeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def _start_vnfd(self, vnfd):
# 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

Expand Down
19 changes: 19 additions & 0 deletions src/emuvim/dcemulator/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ def startCompute(self, name, image=None, command=None, network=None, flavor_name
# 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
Expand Down Expand Up @@ -256,3 +259,19 @@ def assignResourceModel(self, rm):
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

0 comments on commit c185cc0

Please sign in to comment.