Example #1
0
    def test_list_by_link_ref(self):
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth1",    port=1),
            dict(name="20/eth1",    port=2),
            dict(name="20/eth2",    port=3),
            dict(name="10/eth1.10", port=0, link="10/eth1"),
            dict(name="20/eth2.10", port=0, link="20/eth2"),
            dict(name="20/eth2.20", port=0, link="20/eth2"),
        ]
        ports = [fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p) for p in _ports]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # 10/eth1 -> 10/eth1.10
        link = portmap.FIBCLink(re_id=reid, name="10/eth1")
        ret = table.list_by_link_ref(link)
        self.assertEqual(ret, ports[3:4])

        # 20/eth2 -> 20/eth2.10, 20/eth2.20
        link = portmap.FIBCLink(re_id=reid, name="20/eth2")
        ret = table.list_by_link_ref(link)
        self.assertEqual(ret, ports[4:6])

        # 20/eth1 -> []
        link = portmap.FIBCLink(re_id=reid, name="20/eth1")
        ret = table.list_by_link_ref(link)
        self.assertEqual(ret, [])
Example #2
0
    def test_upper_ports_multi_level(self):
        """
        - 10/eth2 - 10/eth2.10 *
        - 10/eth3 - 10/eth3.10 - 10/eth3.110 *
        """
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth2",     port=2),
            dict(name="10/eth2.10",  port=0, link="10/eth2"),

            dict(name="10/eth3",     port=2),
            dict(name="10/eth3.10",  port=0, link="10/eth3"),
            dict(name="10/eth3.110", port=0, link="10/eth3.10"),
        ]
        ports = [fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p) for p in _ports]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # 10/eth2 -> [10/eth2.10]
        link = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[0])
        ret = table.upper_ports(link)
        self.assertEqual(ret, ports[1:2])


        # 10/eth -> [10/eth3.110]
        link = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[2])
        ret = table.upper_ports(link)
        self.assertEqual(ret, ports[4:5])
Example #3
0
    def test_upper_ports_single_level(self):
        """
        - 10/eth1 *
        """
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth1", port=1),
        ]
        ports = [
            fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p)
            for p in _ports
        ]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # 10/eth1 -> [10/eth1]
        link = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[0])
        ret = table.upper_ports(link)
        self.assertEqual(ret, [])

        # 10/eth2 -> [10/eth2]
        link = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="10/eth2",
                                         port=1)
        ret = table.upper_ports(link)
        self.assertEqual(ret, [])
Example #4
0
    def test_master_port(self):
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth1", port=1),
            dict(name="10/eth2", port=2),
            dict(name="10/eth3", port=3),
            dict(name="20/bond1", port=100, slaves=["10/eth1", "10/eth2"]),
            dict(name="30/vlan1", port=0, link="20/bond1"),
        ]
        ports = [
            fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p)
            for p in _ports
        ]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # 10/eth1 -> 20/bond1
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[0])
        ret = table.master_port(port)
        self.assertEqual(ret, ports[3])

        # 10/eth2 -> 20/bond1
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[1])
        ret = table.master_port(port)
        self.assertEqual(ret, ports[3])

        # 10/eth3 -> KeyError
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[2])
        with self.assertRaises(KeyError):
            table.master_port(port)
Example #5
0
    def test_get_ready_ports(self):
        _ports = [
            # not ready
            dict(name="10/eth0", port=0, vs_port=0, vm_port=0),
            dict(name="10/eth1", port=1, vs_port=0, vm_port=0),
            dict(name="10/eth2", port=0, vs_port=1, vm_port=0),
            dict(name="10/eth3", port=0, vs_port=0, vm_port=1),
            dict(name="10/eth4", port=0, vs_port=1, vm_port=1),
            dict(name="10/eth5", port=1, vs_port=0, vm_port=1),
            dict(name="10/eth6", port=1, vs_port=1, vm_port=0),
            dict(name="10/eth6", port=1, vs_port=1, vm_port=1),
            dict(name="10/eth6", port=1, vs_port=0, vm_port=0, dpenter=True),
            dict(name="10/eth6", port=1, vs_port=1, vm_port=0, dpenter=True),
            dict(name="10/eth6", port=1, vs_port=0, vm_port=1, dpenter=True),
            # ready
            dict(name="10/eth8", port=1, vs_port=1, vm_port=1, dpenter=True),
            dict(name="10/eth7", port=0, vs_port=1, vm_port=1, dpenter=True),
        ]
        ports = [
            fibcdbm.FIBCPortEntry.new(dp_id=_DPID, re_id=_RTID, **p)
            for p in _ports
        ]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        for port in ports[:-2]:
            ready_ports = fibcptm.get_ready_ports(table, port)
            self.assertEqual(ready_ports, [])

        for port in ports[-2:]:
            ready_ports = fibcptm.get_ready_ports(table, port)
            self.assertEqual(len(ready_ports), 1)
            self.assertEqual(ready_ports[0], port)
Example #6
0
    def test_lower_port(self):
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth1", port=1),
            dict(name="10/eth2", port=2),
            dict(name="20/eth1", port=3, link="10/eth1"),
            dict(name="20/eth2", port=4, link="10/eth2"),
            dict(name="30/eth1", port=5, link="20/eth1"),
            dict(name="30/eth2", port=6, link="20/eth2"),
        ]
        ports = [
            fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p)
            for p in _ports
        ]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # linked to '10/eth1'
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="30/eth1",
                                         port=6,
                                         link="20/eth1")
        ret = table.lower_port(port)
        self.assertEqual(ret, ports[0])

        # linked to '10/eth2'
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="30/eth2",
                                         port=6,
                                         link="20/eth2")
        ret = table.lower_port(port)
        self.assertEqual(ret, ports[1])

        # 2-linked device
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="30/eth0",
                                         port=0,
                                         link="20/eth0")
        with self.assertRaises(KeyError):
            table.lower_port(port)

        # not linked device.
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="10/eth1",
                                         port=6)
        ret = table.lower_port(port)
        self.assertEqual(ret, port)
Example #7
0
    def test_slave_ports(self):
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth1", port=1),
            dict(name="10/eth2", port=2),
            dict(name="10/eth3", port=3),
            dict(name="10/eth3.10", port=0, link="10/eth3"),
            dict(name="20/bond1", port=100, slaves=["10/eth1", "10/eth2"]),
            dict(name="30/vlan1", port=0, link="20/bond1"),
        ]
        ports = [
            fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p)
            for p in _ports
        ]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # not bond devce.
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="10/eth3",
                                         port=3)
        ret = table.slave_ports(port)
        self.assertEqual(ret, [])

        # vlan tagged, not bond devce.
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="10/eth3.10",
                                         port=0)
        ret = table.slave_ports(port)
        self.assertEqual(ret, [])

        # bond device
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="20/bond1",
                                         port=100,
                                         slaves=["10/eth1", "10/eth2"])
        ret = table.slave_ports(port)
        self.assertEqual(ret, [ports[0], ports[1]])

        # vlan tagged bond device.
        port = fibcdbm.FIBCPortEntry.new(dp_id=dpid,
                                         re_id=reid,
                                         name="30/vlan1",
                                         port=0,
                                         link="20/bond1")
        ret = table.slave_ports(port)
        self.assertEqual(ret, [])
Example #8
0
    def test_find_by_name(self):
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth1", port=1),
            dict(name="20/eth1", port=2),
        ]
        ports = [fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p) for p in _ports]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        ret = table.find_by_name(reid, "10/eth1")
        self.assertEqual(ret, ports[0])

        ret = table.find_by_name(reid, "20/eth1")
        self.assertEqual(ret, ports[1])

        with self.assertRaises(KeyError):
            table.find_by_name(reid, "20/eth0")
Example #9
0
    def test_upper_ports_multi_upper(self):
        """
        - 10/eth1
          +- 10/eth1.10 *
          +- 10/eth1.20 *
        - 10/eth2
          +- 10/eth2.10
             +- 10/eth2.110 *
             +- 10/eth2.210 *
          +- 10/eth2.20 *
        """
        dpid = 100
        reid = "1.1.1.1"
        _ports = [
            dict(name="10/eth1", port=1),
            dict(name="10/eth1.10", port=0, link="10/eth1"),
            dict(name="10/eth1.20", port=0, link="10/eth1"),
            dict(name="10/eth2", port=1),
            dict(name="10/eth2.10", port=0, link="10/eth2"),
            dict(name="10/eth2.110", port=0, link="10/eth2.10"),
            dict(name="10/eth2.210", port=0, link="10/eth2.10"),
            dict(name="10/eth2.20", port=0, link="10/eth2"),
        ]
        ports = [
            fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **p)
            for p in _ports
        ]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # 10/eth1 -> 10/eth1.10, eth1.20
        link = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[0])
        ret = table.upper_ports(link)
        self.assertEqual(ret, ports[1:3])

        # 10/eth2 -> eth2.110, eth2.210, 10/eth2.20
        link = fibcdbm.FIBCPortEntry.new(dp_id=dpid, re_id=reid, **_ports[3])
        ret = table.upper_ports(link)
        self.assertEqual(ret, ports[5:8])
Example #10
0
    def test_get_ready_ports_vlan(self):
        _ports = [
            # not ready
            dict(name="10/eth1", port=1, vs_port=1, dpenter=False),  # 0.DOWN
            dict(name="10/eth1.10", port=1, vm_port=0,
                 link="10/eth1"),  # 1.DOWN
            dict(name="10/eth2", port=2, vs_port=0, dpenter=True),  # 2.DOWN
            dict(name="10/eth2.10", port=2, vm_port=2, link="10/eth2"),  # 3.UP
            dict(name="10/eth3", port=3, vs_port=3, dpenter=True),  # 4.UP
            dict(name="10/eth3.10", port=3, vm_port=0,
                 link="10/eth3"),  # 5.DOWN

            # ready
            dict(name="10/eth4", port=3, vs_port=3, dpenter=True),  # 6.UP
            dict(name="10/eth4.10", port=3, vm_port=3, link="10/eth4"),  # 7,UP
            dict(name="10/eth5", port=4, vs_port=4, dpenter=True),  # 8.UP
            dict(name="10/eth5.10", port=4, vm_port=0,
                 link="10/eth5"),  # 9.DOWN
            dict(name="10/eth5.20", port=4, vm_port=4, link="10/eth5"),  #10.UP

            # ready and not ready
            dict(name="10/eth6", port=5, vs_port=5, dpenter=True),  #11.UP
            dict(name="10/eth7.10", port=5, vm_port=5, link="10/eth6"),  #12.UP
            dict(name="10/eth7.20", port=5, vm_port=6, link="10/eth6"),  #13.UP
        ]
        ports = [
            fibcdbm.FIBCPortEntry.new(dp_id=_DPID, re_id=_RTID, **p)
            for p in _ports
        ]
        table = fibcdbm.FIBCDbPortMapTable()
        for port in ports:
            table.add(port)

        # ports[0..5] -> []
        for port in ports[:6]:
            ready_ports = fibcptm.get_ready_ports(table, port)
            self.assertEqual(ready_ports, [])

        # ports[6,7] -> ports[7]
        ready_ports = fibcptm.get_ready_ports(table, ports[6])
        self.assertEqual(len(ready_ports), 1)
        self.assertEqual(ready_ports[0], ports[7])

        ready_ports = fibcptm.get_ready_ports(table, ports[7])
        self.assertEqual(len(ready_ports), 1)
        self.assertEqual(ready_ports[0], ports[7])

        # ports[8] -> ports[10]
        ready_ports = fibcptm.get_ready_ports(table, ports[8])
        self.assertEqual(len(ready_ports), 1)
        self.assertEqual(ready_ports[0], ports[10])

        # ports[9] -> []
        ready_ports = fibcptm.get_ready_ports(table, ports[9])
        self.assertEqual(len(ready_ports), 0)

        # ports[10] -> ports[18]
        ready_ports = fibcptm.get_ready_ports(table, ports[10])
        self.assertEqual(len(ready_ports), 1)
        self.assertEqual(ready_ports[0], ports[10])

        # ports[11] -> ports[12,13]
        ready_ports = fibcptm.get_ready_ports(table, ports[11])
        self.assertEqual(len(ready_ports), 2)
        self.assertEqual(ready_ports[0], ports[12])
        self.assertEqual(ready_ports[1], ports[13])