Ejemplo n.º 1
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)
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    def setUp(self):
        self.dummy1 = system.DummyIface()
        self.dummy1.up()
        self.dummy1.addr_add('192.0.2.1/25')

        self.dummy2 = system.DummyIface()
        self.dummy2.up()
        self.dummy2.addr_add('192.0.2.129/26')

        self.zebra = quagga.Zebra()

        self.zclient = pyzclient.ZClient(pyzclient.ZEBRA_ROUTE_OSPF)
Ejemplo n.º 4
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')
Ejemplo n.º 5
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')
Ejemplo n.º 6
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')
Ejemplo n.º 7
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())