Ejemplo n.º 1
0
 def testIterHumanReadable(self):
     routes = [('foo', '192.168.1.0', 32), ('bar', '192.168.1.0', 24)]
     net = RoutingTable()
     for route, ip, mask in routes:
         net.addSubnet(route, ip, mask)
     for expected, actual in zip(routes, net.iterHumanReadable()):
         self.assertEquals(expected, actual)
Ejemplo n.º 2
0
 def testAddRemove(self):
     net = RoutingTable()
     net.addSubnet('foo', '192.168.0.0', 24)
     net.addSubnet('foo', '192.168.1.0', 24)
     self.assertEquals(len(net), 2)
     net.removeSubnet('foo', '192.168.0.0', 24)
     net.removeSubnet('foo', '192.168.1.0', 24)
     self.assertEquals(len(net), 0)
Ejemplo n.º 3
0
 def testIterHumanReadable(self):
     routes = [('foo', '192.168.1.0', 32),
               ('bar', '192.168.1.0', 24)]
     net = RoutingTable()
     for route, ip, mask in routes:
         net.addSubnet(route, ip, mask)
     for expected, actual in zip(routes, net.iterHumanReadable()):
         self.assertEquals(expected, actual)
Ejemplo n.º 4
0
    def assertParseEquals(self, string, routes, **kwargs):
        f = StringIO.StringIO(string)
        net = RoutingTable.fromFile(f, **kwargs)
        f.close()

        expectednet = RoutingTable()
        for route in routes:
            expectednet.addSubnet(*route)
        self.assertEquals(list(iter(net)), list(iter(expectednet)))
Ejemplo n.º 5
0
    def assertParseEquals(self, string, routes, **kwargs):
        f = StringIO.StringIO(string)
        net = RoutingTable.fromFile(f, **kwargs)
        f.close()

        expectednet = RoutingTable()
        for route in routes:
            expectednet.addSubnet(*route)
        self.assertEquals(list(iter(net)),
                          list(iter(expectednet)))
Ejemplo n.º 6
0
    def testBasicRouting(self):
        net = RoutingTable()

        def ar(ip, route):
            self.assertEquals(net.route(ip), route)

        ar('192.168.1.0', None)

        net.addSubnet('foo', '192.168.1.0', 24)

        ar('192.168.1.0', 'foo')
        ar('192.168.1.10', 'foo')
        ar('192.168.1.255', 'foo')

        ar('192.168.0.255', None)
        ar('192.168.2.0', None)

        net.addSubnet('foo', '192.168.2.0', 24)

        ar('192.168.0.255', None)
        ar('192.168.1.255', 'foo')
        ar('192.168.2.0', 'foo')

        net.removeSubnet('foo', '192.168.1.0', 24)
        net.removeSubnet('foo', '192.168.2.0', 24)

        ar('192.168.1.0', None)
        ar('192.168.1.10', None)
        ar('192.168.1.255', None)
        ar('192.168.0.255', None)
        ar('192.168.2.0', None)
Ejemplo n.º 7
0
    def testBasicRouting(self):
        net = RoutingTable()

        def ar(ip, route):
            self.assertEquals(net.route(ip), route)

        ar('192.168.1.0', None)

        net.addSubnet('foo', '192.168.1.0', 24)

        ar('192.168.1.0', 'foo')
        ar('192.168.1.10', 'foo')
        ar('192.168.1.255', 'foo')

        ar('192.168.0.255', None)
        ar('192.168.2.0', None)

        net.addSubnet('foo', '192.168.2.0', 24)

        ar('192.168.0.255', None)
        ar('192.168.1.255', 'foo')
        ar('192.168.2.0', 'foo')

        net.removeSubnet('foo', '192.168.1.0', 24)
        net.removeSubnet('foo', '192.168.2.0', 24)

        ar('192.168.1.0', None)
        ar('192.168.1.10', None)
        ar('192.168.1.255', None)
        ar('192.168.0.255', None)
        ar('192.168.2.0', None)
Ejemplo n.º 8
0
    def testRoutingPrecedence(self):
        net = RoutingTable()

        def ar(ip, route):
            self.assertEquals(net.route(ip), route)

        net.addSubnet('foo', '192.168.1.0', 32)
        net.addSubnet('bar', '192.168.1.0', 24)

        self.assertRaises(ValueError,
                          net.addSubnet,
                          'baz', '192.168.1.0', 16)

        net.addSubnet('baz', '192.168.0.0', 16)

        ar('192.168.1.0', 'foo')
        ar('192.168.1.1', 'bar')
        ar('192.168.2.1', 'baz')
Ejemplo n.º 9
0
 def testAddRemove(self):
     net = RoutingTable()
     net.addSubnet('foo', '192.168.0.0', 24)
     net.addSubnet('foo', '192.168.1.0', 24)
     self.assertEquals(len(net), 2)
     net.removeSubnet('foo', '192.168.0.0', 24)
     net.removeSubnet('foo', '192.168.1.0', 24)
     self.assertEquals(len(net), 0)
Ejemplo n.º 10
0
    def testRouteIteration(self):
        net = RoutingTable()

        net.addSubnet('foo', '192.168.1.0', 24)
        net.addSubnet('bar', '0.0.0.0', 0)

        # Now, an IP in 'foo' should iterate foo, bar, None.
        tests = [('192.168.1.1', ['foo', 'bar', None]),
                 ('203.10.7.20', ['bar', None])]

        for ip, expected in tests:
            results = [result for result in net.route_iter(ip)]
            self.assertEquals(expected, results)
Ejemplo n.º 11
0
    def testRouteIteration(self):
        net = RoutingTable()

        net.addSubnet('foo', '192.168.1.0', 24)
        net.addSubnet('bar', '0.0.0.0', 0)

        # Now, an IP in 'foo' should iterate foo, bar, None.
        tests = [('192.168.1.1', ['foo', 'bar', None]),
                 ('203.10.7.20', ['bar', None])]

        for ip, expected in tests:
            results = [result for result in net.route_iter(ip)]
            self.assertEquals(expected, results)
Ejemplo n.º 12
0
    def testRoutingPrecedence(self):
        net = RoutingTable()

        def ar(ip, route):
            self.assertEquals(net.route(ip), route)

        net.addSubnet('foo', '192.168.1.0', 32)
        net.addSubnet('bar', '192.168.1.0', 24)

        self.assertRaises(ValueError, net.addSubnet, 'baz', '192.168.1.0', 16)

        net.addSubnet('baz', '192.168.0.0', 16)

        ar('192.168.1.0', 'foo')
        ar('192.168.1.1', 'bar')
        ar('192.168.2.1', 'baz')
Ejemplo n.º 13
0
    def assertRouteNamesOrder(self, string, routeNames):
        f = StringIO.StringIO(string)
        net = RoutingTable.fromFile(f)
        f.close()

        self.assertEquals(net.getRouteNames(), routeNames)
Ejemplo n.º 14
0
    def assertRouteNamesOrder(self, string, routeNames):
        f = StringIO.StringIO(string)
        net = RoutingTable.fromFile(f)
        f.close()

        self.assertEquals(net.getRouteNames(), routeNames)