Esempio n. 1
0
 def setUp(self):
     self.route_node = RouteNode()
Esempio n. 2
0
 def setUp(self):
     self.route_node = RouteNode()
Esempio n. 3
0
class TestRouteNode(unittest.TestCase):
    def setUp(self):
        self.route_node = RouteNode()

    def testRouteAdd(self):
        ''' Add a route '''
        self.failUnlessEqual(self.route_node.routes, [])
        res = self.route_node.route_add(lvl=0, dst=1234, gw=1, rem=Rtt(20))
        self.failUnlessEqual(res, (1, None))
        self.failUnless(isinstance(self.route_node.routes[0], RouteGw))
        self.failUnlessEqual(self.route_node.routes[0].gw, 1)

        # substitute an old route
        res = self.route_node.route_add(lvl=0, dst=1234, gw=1, rem=Rtt(10))
        self.failUnlessEqual(res, (2, Rtt(20)))

        # Add new route
        res = self.route_node.route_add(lvl=0, dst=1234, gw=2, rem=Rtt(5))
        self.failUnlessEqual(res, (1, None))

        self.failUnlessEqual(self.route_node.nroutes(), 2)

    def testRouteGetbyGw(self):
        ''' Getting a route having as gateway "gw" '''
        self.failUnlessEqual(self.route_node.route_getby_gw(5), None)
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(1))
        gw5 = self.route_node.route_getby_gw(5)
        self.failUnlessEqual(gw5.gw, 5)

    def testChangeRouteRem(self):
        ''' Change route rem '''
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))

        res = self.route_node.route_rem(1, Rtt(10))  # Route don't exist
        self.failUnlessEqual(res, (0, None))

        res = self.route_node.route_rem(5, Rtt(10))
        self.failUnlessEqual(res, (1, Rtt(50)))

    def testDeleteRoute(self):
        '''Delete a route'''
        res = self.route_node.route_del(5)
        self.failUnlessEqual(res, 0)

        self.route_node.route_add(lvl=0, dst=123, gw=3, rem=Rtt(50))
        self.route_node.route_add(lvl=0, dst=123, gw=4, rem=Rtt(50))
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))

        res = self.route_node.route_del(5)
        self.failUnlessEqual(res, 1)
        self.failUnlessEqual(
            self.route_node.routes,
            [RouteGw(3, Rtt(50)), RouteGw(4, Rtt(50))])
        res = self.route_node.route_del(3)
        self.failUnlessEqual(self.route_node.routes, [RouteGw(4, Rtt(50))])
        res = self.route_node.route_del(4)
        self.failUnless(self.route_node.is_empty())

    def testIsEmpty(self):
        '''Check if a RouteNode instance is empty '''
        self.failUnlessEqual(self.route_node.is_empty(), True)

        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))
        self.failUnlessEqual(self.route_node.is_empty(), False)

    def testReset(self):
        ''' Delete all routes '''
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))
        self.failUnlessEqual(self.route_node.is_empty(), False)

        self.route_node.route_reset()
        self.failUnlessEqual(self.route_node.is_empty(), True)
Esempio n. 4
0
class TestRouteNode(unittest.TestCase):

    def setUp(self):
        self.route_node = RouteNode()

    def testRouteAdd(self):
        ''' Add a route '''
        self.failUnlessEqual(self.route_node.routes, [])
        res = self.route_node.route_add(lvl=0, dst=1234, gw=1, rem=Rtt(20))
        self.failUnlessEqual(res, (1, None))
        self.failUnless(isinstance(self.route_node.routes[0], RouteGw))
        self.failUnlessEqual(self.route_node.routes[0].gw, 1)

        # substitute an old route
        res = self.route_node.route_add(lvl=0, dst=1234, gw=1, rem=Rtt(10))
        self.failUnlessEqual(res, (2, Rtt(20)))

        # Add new route
        res = self.route_node.route_add(lvl=0, dst=1234, gw=2, rem=Rtt(5))
        self.failUnlessEqual(res, (1, None))

        self.failUnlessEqual(self.route_node.nroutes(), 2)

    def testRouteGetbyGw(self):
        ''' Getting a route having as gateway "gw" '''
        self.failUnlessEqual(self.route_node.route_getby_gw(5), None)
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(1))
        gw5 = self.route_node.route_getby_gw(5)
        self.failUnlessEqual(gw5.gw, 5)

    def testChangeRouteRem(self):
        ''' Change route rem '''
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))

        res = self.route_node.route_rem(1, Rtt(10)) # Route don't exist
        self.failUnlessEqual(res, (0, None))

        res = self.route_node.route_rem(5, Rtt(10))
        self.failUnlessEqual(res, (1, Rtt(50)))

    def testDeleteRoute(self):
        '''Delete a route'''
        res = self.route_node.route_del(5)
        self.failUnlessEqual(res, 0)

        self.route_node.route_add(lvl=0, dst=123, gw=3, rem=Rtt(50))
        self.route_node.route_add(lvl=0, dst=123, gw=4, rem=Rtt(50))
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))

        res = self.route_node.route_del(5)
        self.failUnlessEqual(res, 1)
        self.failUnlessEqual(self.route_node.routes,
                             [RouteGw(3, Rtt(50)), RouteGw(4, Rtt(50))])
        res = self.route_node.route_del(3)
        self.failUnlessEqual(self.route_node.routes, [RouteGw(4, Rtt(50))])
        res = self.route_node.route_del(4)
        self.failUnless(self.route_node.is_empty())

    def testIsEmpty(self):
        '''Check if a RouteNode instance is empty '''
        self.failUnlessEqual(self.route_node.is_empty(), True)

        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))
        self.failUnlessEqual(self.route_node.is_empty(), False)

    def testReset(self):
        ''' Delete all routes '''
        self.route_node.route_add(lvl=0, dst=123, gw=5, rem=Rtt(50))
        self.failUnlessEqual(self.route_node.is_empty(), False)

        self.route_node.route_reset()
        self.failUnlessEqual(self.route_node.is_empty(), True)