示例#1
0
    def setUp(self):
        self.dummy1 = system.DummyIface()
        self.dummy1.up()
        self.dummy1.addr_add('2001:db8:1:1::1/64', 6)

        self.zebra = quagga.Zebra()

        self.ospf_client = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_OSPF)

        route = pyzclient.Route(None, '2001:db8:1:3::/64')
        route.add_nexthop(ifindex=self.dummy1.index)
        self.ospf_client.add_route(route)

        route = pyzclient.Route(None, '2001:db8:1:4::/64')
        route.add_nexthop(gate='2001:db8:1:1::2')
        self.ospf_client.add_route(route)

        route = pyzclient.Route(None, '2001:db8:1:5::/64')
        route.add_nexthop(gate='fe80::42')
        route.add_nexthop(ifindex=self.dummy1.index)
        self.ospf_client.add_route(route)

        self.bgp_client = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_BGP)
        self.route = pyzclient.Route(None, '2001:db8:2::/48')
        self.route.rib_flags |= pyzclient.ZEBRA_FLAG_INTERNAL
示例#2
0
    def setUp(self):
        self.dummy1 = system.DummyIface()
        self.dummy1.up()
        self.dummy1.addr_add('192.0.2.1/29')

        self.dummy2 = system.DummyIface()
        self.dummy2.up()
        self.dummy2.addr_add('192.0.2.9/29')

        self.zebra = quagga.Zebra()

        self.ospf_client = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_OSPF)

        route = pyzclient.Route(None, '192.0.2.16/29')
        route.add_nexthop(ifindex=self.dummy1.index)
        self.ospf_client.add_route(route)

        route = pyzclient.Route(None, '192.0.2.24/29')
        route.add_nexthop(ifindex=self.dummy2.index)
        self.ospf_client.add_route(route)

        route = pyzclient.Route(None, '192.0.2.32/29')
        route.add_nexthop(gate='192.0.2.2')
        self.ospf_client.add_route(route)

        route = pyzclient.Route(None, '192.0.2.40/29')
        route.add_nexthop(gate='192.0.2.3')
        self.ospf_client.add_route(route)

        self.bgp_client = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_BGP)
        self.route = pyzclient.Route(None, '198.51.100.128/25')
        self.route.rib_flags |= pyzclient.ZEBRA_FLAG_INTERNAL
        time.sleep(0.1)
示例#3
0
    def setUpMultipath(self):
        route = pyzclient.Route(None, '192.0.2.48/29')
        route.add_nexthop(ifindex=self.dummy1.index)
        route.add_nexthop(ifindex=self.dummy2.index)
        self.ospf_client.add_route(route)

        route = pyzclient.Route(None, '192.0.2.56/29')
        route.add_nexthop(gate='192.0.2.4')
        route.add_nexthop(gate='192.0.2.5')
        self.ospf_client.add_route(route)

        route = pyzclient.Route(None, '192.0.2.64/29')
        route.add_nexthop(gate='192.0.2.6', ifindex=self.dummy1.index)
        route.add_nexthop(gate='192.0.2.10', ifindex=self.dummy2.index)
        self.ospf_client.add_route(route)
        time.sleep(0.1)
示例#4
0
    def test_nexthop_ifindex(self):
        route = pyzclient.Route(None, '198.51.100.128/25')
        route.nexthops.append(pyzclient.Nexthop(ifindex=self.dummy1.index))
        route.nexthops.append(pyzclient.Nexthop(ifindex=self.dummy2.index))

        expected_rib = {
            '198.51.100.128/25': {
                'selected': True,
                'nexthops': [
                    {
                        'gate': None,
                        'iface': self.dummy1.name
                    },
                    {
                        'gate': None,
                        'iface': self.dummy2.name
                    }
                ]
            }
        }

        expected_fib = {
            '198.51.100.128/25': {
                'nexthops': [
                    {
                        'gate': None,
                        'iface': self.dummy1.name
                    },
                    {
                        'gate': None,
                        'iface': self.dummy2.name
                    }
                ]
            }
        }

        self.zclient.add_route(route)
        time.sleep(0.1)

        self.assertRoutes(expected_rib, self.zebra.rib('O'))
        self.assertRoutes(expected_fib, system.fib())

        self.zclient.del_route(route)
        time.sleep(0.1)

        self.assertNotIn('198.51.100.128/25', self.zebra.rib('O'))
        self.assertNotIn('198.51.100.128/25', system.fib())

        self.zclient.add_route(route)
        time.sleep(0.1)

        self.assertRoutes(expected_rib, self.zebra.rib('O'))
        self.assertRoutes(expected_fib, system.fib())

        route.nexthops = list(reversed(route.nexthops))
        self.zclient.del_route(route)
        time.sleep(0.1)

        self.assertNotIn('198.51.100.128/25', self.zebra.rib('O'))
        self.assertNotIn('198.51.100.128/25', system.fib())
示例#5
0
    def setUp(self):
        self.dummy1 = system.DummyIface()
        self.dummy1.up()
        self.dummy1.addr_add('192.0.2.1/29')

        self.dummy2 = system.DummyIface()
        self.dummy2.up()
        self.dummy2.addr_add('192.0.2.9/29')

        self.zebra = quagga.Zebra()

        self.zclient = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_OSPF)
        self.route = pyzclient.Route(None, '198.51.100.128/25')
示例#6
0
    def setUp(self):
        self.dummy1 = system.DummyIface()
        self.dummy1.up()
        self.dummy1.addr_add('2001:db8:1:1::1/64', 6)

        self.dummy2 = system.DummyIface()
        self.dummy2.up()
        self.dummy2.addr_add('2001:db8:1:2::1/64', 6)

        self.zebra = quagga.Zebra()

        self.zclient = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_OSPF6)
        self.route = pyzclient.Route(None, '2001:db8:2::/48')
示例#7
0
    def test_excessive_nexthops(self):
        route = pyzclient.Route(None, '198.51.100.128/25')
        for i in range(2,126):
            route.nexthops.append(pyzclient.Nexthop('192.0.2.%d' % i))
        self.zclient.add_route(route)
        time.sleep(0.1)

        rib = self.zebra.rib('O')
        # Assert that the route has been completely installed into fib
        self.assertRoutes({
            '198.51.100.128/25': {
                'selected': True,
                'nexthops': [
                    {
                        'gate': '192.0.2.%d' % i,
                    } for i in range(2,126)
                ]
            }
        }, rib)

        # Examine the FIB flags in the RIB and determine which nexthops
        # should be in the FIB
        fib_nexthops = []
        expected_fib = {
            '198.51.100.128/25': {
                'nexthops': fib_nexthops
            }
        }
        for nexthop in rib['198.51.100.128/25']['nexthops']:
            if not nexthop['fib']:
                continue

            fib_nexthops.append({
                'gate': nexthop['gate'],
                'iface': nexthop['iface']
            })

        # Check that at least one nexthop has been installed into fib
        self.assertTrue(fib_nexthops)
        self.assertRoutes(expected_fib, system.fib())

        route.nexhops = list(reversed(route.nexthops))
        self.zclient.del_route(route)
        time.sleep(0.1)

        self.assertNotIn('198.51.100.128/25', self.zebra.rib('O'))
        self.assertNotIn('198.51.100.128/25', system.fib())
示例#8
0
    def setUp(self):
        self.dummy1 = system.DummyIface()
        self.dummy1.up()
        self.dummy1.addr_add('192.0.2.1/29')

        self.dummy2 = system.DummyIface()
        self.dummy2.up()
        self.dummy2.addr_add('192.0.2.9/29')

        self.dummy3 = system.DummyIface()
        self.dummy3.up()
        self.dummy3.addr_add('192.0.2.255/32')

        self.zebra = quagga.Zebra()

        self.zebra.config(
            "route-map src-test permit 10",
            "set src 192.0.2.255",
            "ip protocol ospf route-map src-test"
        )

        self.zclient = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_OSPF)
        self.route = pyzclient.Route(None, '198.51.100.128/25')
示例#9
0
    def test_recursive_deactivate(self):
        self.setUpPrefixList()
        self.zebra.config("no ip protocol ospf")
        self.zebra.config("ip protocol bgp route-map match-test")

        resolving_route = pyzclient.Route(None, '192.0.2.16/29')
        resolving_route.add_nexthop('192.0.2.2')
        self.zclient.add_route(resolving_route)
        time.sleep(0.1)

        with contextlib.closing(pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_BGP)) as bgp_client:
            self.route.rib_flags |= pyzclient.ZEBRA_FLAG_INTERNAL
            self.route.add_nexthop('192.0.2.17')
            bgp_client.add_route(self.route)
            time.sleep(0.1)

            # 192.0.2.17 isn't matched by the prefix list, therefore, the route is rejected
            self.assertRoutes({
                str(self.route.dest): {
                    'selected': False,
                    'nexthops': [
                        {
                            'gate': '192.0.2.17',
                            'fib': False,
                            'active': False
                        }
                    ]
                }
            }, self.zebra.rib('B'))
            self.assertNotIn(str(self.route.dest), system.fib())

            bgp_client.del_route(self.route)
            time.sleep(0.1)

            self.assertNotIn(str(self.route.dest), self.zebra.rib('B'))
            self.assertNotIn(str(self.route.dest), system.fib())

            # permit 192.0.2.17 and re-add route
            self.zebra.config("ip prefix-list test1 seq 10 permit 192.0.2.17/32")

            bgp_client.add_route(self.route)
            time.sleep(0.1)

            self.assertRoutes({
                str(self.route.dest): {
                    'selected': True,
                    'nexthops': [
                        {
                            'active': True,
                            'gate': '192.0.2.17',
                            'resolved': [
                                {
                                    'gate': '192.0.2.2',
                                    'iface': self.dummy1.name,
                                    'fib': True,
                                    'active': True
                                }
                            ],
                        }
                    ]
                }
            }, self.zebra.rib('B'))
            self.assertRoutes({
                str(self.route.dest): {
                    'nexthops': [
                        {
                            'gate': '192.0.2.2',
                            'iface': self.dummy1.name
                        }
                    ]
                }
            }, system.fib())

            bgp_client.del_route(self.route)
            time.sleep(0.1)

            self.assertNotIn(str(self.route.dest), self.zebra.rib('B'))
            self.assertNotIn(str(self.route.dest), system.fib())