Exemplo n.º 1
0
    def test_interface_migration(self):
        node = nemu.Node()
        self.dummyname = "dummy%d" % os.getpid()
        self.assertEquals(
            os.system("%s link add name %s type dummy" %
                      (IP_PATH, self.dummyname)), 0)
        devs = get_devs()
        self.assertTrue(self.dummyname in devs)
        dummyidx = devs[self.dummyname]['idx']

        if0 = node.import_if(self.dummyname)
        self.assertTrue(self.dummyname not in get_devs())

        node_devs = dict([(i.index, i) for i in node.get_interfaces()])
        self.assertTrue(dummyidx in node_devs)

        if0.lladdr = '42:71:e0:90:ca:43'
        if0.mtu = 1400

        devs = get_devs_netns(node)
        self.assertTrue(if0.name in devs)
        self.assertEquals(devs[if0.name]['lladdr'], '42:71:e0:90:ca:43')
        self.assertEquals(devs[if0.name]['mtu'], 1400)

        node.destroy()
        self.assertTrue(self.dummyname in get_devs())
Exemplo n.º 2
0
    def test_interface_migration(self):
        node = nemu.Node()
        self.dummyname = "dummy%d" % os.getpid()
        self.assertEquals(os.system("%s link add name %s type dummy" %
                    (IP_PATH, self.dummyname)), 0)
        devs = get_devs()
        self.assertTrue(self.dummyname in devs)
        dummyidx = devs[self.dummyname]['idx']

        if0 = node.import_if(self.dummyname)
        self.assertTrue(self.dummyname not in get_devs())

        node_devs = dict([(i.index, i) for i in node.get_interfaces()])
        self.assertTrue(dummyidx in node_devs)

        if0.lladdr = '42:71:e0:90:ca:43'
        if0.mtu = 1400

        devs = get_devs_netns(node)
        self.assertTrue(if0.name in devs)
        self.assertEquals(devs[if0.name]['lladdr'], '42:71:e0:90:ca:43')
        self.assertEquals(devs[if0.name]['mtu'], 1400)

        node.destroy()
        self.assertTrue(self.dummyname in get_devs())
Exemplo n.º 3
0
 def test_utils(self):
     devs = get_devs()
     # There should be at least loopback!
     self.assertTrue(len(devs) > 0)
     self.assertTrue('lo' in devs)
     self.assertTrue(devs['lo']['up'])
     self.assertEquals(devs['lo']['lladdr'], '00:00:00:00:00:00')
     self.assertTrue( {
         'address': '127.0.0.1', 'prefix_len': 8,
         'broadcast': None, 'family': 'inet'
         } in devs['lo']['addr'])
Exemplo n.º 4
0
    def test_interface_creation(self):
        node0 = nemu.Node()
        ifaces = []
        for i in range(5):
            ifaces.append(node0.add_if())

        devs = get_devs_netns(node0)
        for i in range(5):
            self.assertTrue(devs['lo']['up'])
            self.assertTrue(ifaces[i].name in devs)

        node_devs = set(node0.get_interfaces())
        self.assertTrue(set(ifaces).issubset(node_devs))
        loopback = node_devs - set(ifaces)  # should be!
        self.assertEquals(len(loopback), 1)
        self.assertEquals(loopback.pop().name, 'lo')

        devs = get_devs()
        for i in range(5):
            peer_name = nemu.iproute.get_if(ifaces[i].control.index).name
            self.assertTrue(peer_name in devs)
Exemplo n.º 5
0
    def test_interface_creation(self):
        node0 = nemu.Node()
        ifaces = []
        for i in range(5):
            ifaces.append(node0.add_if())

        devs = get_devs_netns(node0)
        for i in range(5):
            self.assertTrue(devs['lo']['up'])
            self.assertTrue(ifaces[i].name in devs)

        node_devs = set(node0.get_interfaces())
        self.assertTrue(set(ifaces).issubset(node_devs))
        loopback = node_devs - set(ifaces) # should be!
        self.assertEquals(len(loopback), 1)
        self.assertEquals(loopback.pop().name, 'lo')

        devs = get_devs()
        for i in range(5):
            peer_name = nemu.iproute.get_if(ifaces[i].control.index).name
            self.assertTrue(peer_name in devs)
Exemplo n.º 6
0
    def test_cleanup(self):
        def create_stuff():
            a = nemu.Node()
            b = nemu.Node()
            ifa = a.add_if()
            ifb = b.add_if()
            switch = nemu.Switch()
            switch.connect(ifa)
            switch.connect(ifb)

        # Test automatic destruction
        orig_devs = len(test_util.get_devs())
        create_stuff()
        self.assertEquals(nemu.get_nodes(), [])
        self.assertEquals(orig_devs, len(test_util.get_devs()))

        # Test at_exit hooks
        orig_devs = len(test_util.get_devs())
        chld = os.fork()
        if chld == 0:
            # TODO: not implemented.
            #nemu.set_cleanup_hooks(on_exit = True, on_signals = [])
            create_stuff()
            os._exit(0)
        os.waitpid(chld, 0)
        self.assertEquals(orig_devs, len(test_util.get_devs()))

        # Test signal hooks
        orig_devs = len(test_util.get_devs())
        chld = os.fork()
        if chld == 0:
            # TODO: not implemented.
            #nemu.set_cleanup_hooks(on_exit = False,
            #        on_signals = [signal.SIGTERM])
            create_stuff()
            while True:
                time.sleep(10)
        os.kill(chld, signal.SIGTERM)
        os.waitpid(chld, 0)
        self.assertEquals(orig_devs, len(test_util.get_devs()))
Exemplo n.º 7
0
    def test_cleanup(self):
        def create_stuff():
            a = nemu.Node()
            b = nemu.Node()
            ifa = a.add_if()
            ifb = b.add_if()
            switch = nemu.Switch()
            switch.connect(ifa)
            switch.connect(ifb)

        # Test automatic destruction
        orig_devs = len(test_util.get_devs())
        create_stuff()
        self.assertEquals(nemu.get_nodes(), [])
        self.assertEquals(orig_devs, len(test_util.get_devs()))

        # Test at_exit hooks
        orig_devs = len(test_util.get_devs())
        chld = os.fork()
        if chld == 0:
            # TODO: not implemented.
            #nemu.set_cleanup_hooks(on_exit = True, on_signals = [])
            create_stuff()
            os._exit(0)
        os.waitpid(chld, 0)
        self.assertEquals(orig_devs, len(test_util.get_devs()))

        # Test signal hooks
        orig_devs = len(test_util.get_devs())
        chld = os.fork()
        if chld == 0:
            # TODO: not implemented.
            #nemu.set_cleanup_hooks(on_exit = False,
            #        on_signals = [signal.SIGTERM])
            create_stuff()
            while True:
                time.sleep(10)
        os.kill(chld, signal.SIGTERM)
        os.waitpid(chld, 0)
        self.assertEquals(orig_devs, len(test_util.get_devs()))