示例#1
0
    def _attach_to_network(self, tapname, vni, macttl, targetip, targetport):
        if tapname in self.vnet_tapname_map:
            vnet = self.vnet_tapname_map[tapname]
            msg = ("Ignoring network addition request for tapname %s,"
                   " already in use for vnet %r" % (tapname, vnet))
            raise ValueError(msg)
        tap = VirtualTap(name=tapname)
        tap.open()
        self.taps.append(tap)
        # Set tap in non-blocking mode
        fcntl.fcntl(tap, fcntl.F_SETFL, os.O_NONBLOCK)

        vn = self._create_vnet(vni=vni, macttl=macttl)
        vn.targets = [(targetip, int(targetport))]
        vn.socket = self.socket
        vn.tap = tap
        tap.vnet = vn
        self.vnet_tapname_map[tapname] = vn

        for t in vn.targets:
            if _ip_is_multicast(t[0]):
                _join_mcast_group(vn.socket, t[0], self.mcastif)

        logging.info("Joined new network, vnet %r over tap %r", tap.vnet, tap)
示例#2
0
 def setUp(self):
     self.tap = VirtualTap("testtap%d")