Пример #1
0
            def setUp(self):
                l1, l2 = FullDuplexLink(loss_func=LossFunc(0.001, 0.001, 0.001))

                sft1 = SimpleFrameTransmitter(node=l1)
                sft2 = SimpleFrameTransmitter(node=l2)

                self.ft1 = FrameTransmitter(simple_frame_transmitter=sft1,
                    debug_src=1, debug_dest=2)
                self.ft2 = FrameTransmitter(simple_frame_transmitter=sft2,
                    debug_src=2, debug_dest=1)

                rlm1 = RouterLinkManager()
                rlm2 = RouterLinkManager()

                self.dr1 = DatagramRouter(
                    router_name=1,
                    link_manager=rlm1,
                    routing_table=LocalRoutingTable(1, rlm1))
                self.dr2 = DatagramRouter(
                    router_name=2,
                    link_manager=rlm2,
                    routing_table=LocalRoutingTable(2, rlm2))

                rlm1.add_link(2, self.ft1)
                rlm2.add_link(1, self.ft2)

                self.sm1 = RouterServiceManager(self.dr1)
                self.sm2 = RouterServiceManager(self.dr2)
Пример #2
0
            def setUp(self):
                l1, l2 = FullDuplexLink()

                sft1 = SimpleFrameTransmitter(node=l1)
                sft2 = SimpleFrameTransmitter(node=l2)

                self.ft1 = FrameTransmitter(simple_frame_transmitter=sft1,
                    debug_src=1, debug_dest=2)
                self.ft2 = FrameTransmitter(simple_frame_transmitter=sft2,
                    debug_src=2, debug_dest=1)

                rlm1 = RouterLinkManager()
                rlm2 = RouterLinkManager()

                self.dr1 = DatagramRouter(
                    router_name=1,
                    link_manager=rlm1,
                    routing_table=LocalRoutingTable(1, rlm1))
                self.dr2 = DatagramRouter(
                    router_name=2,
                    link_manager=rlm2,
                    routing_table=LocalRoutingTable(2, rlm2))

                rlm1.add_link(2, self.ft1)
                rlm2.add_link(1, self.ft2)

                self.sm1 = RouterServiceManager(self.dr1)
                self.sm2 = RouterServiceManager(self.dr2)

                self.rip_st1 = self.sm1.register_service(RIPService.protocol)
                self.rip_st2 = self.sm2.register_service(RIPService.protocol)

                self.rs1 = RIPService(1, rlm1, self.rip_st1,
                    update_period=0.5, inf_timeout=0.9, remove_timeout=1.6)
                self.rs2 = RIPService(2, rlm2, self.rip_st2,
                    update_period=0.5, inf_timeout=0.9, remove_timeout=1.6)

                self.dr1.set_routing_table(self.rs1.dynamic_routing_table())
                self.dr2.set_routing_table(self.rs2.dynamic_routing_table())
Пример #3
0
        class _TestRouterServiceManager2WithLosses(unittest.TestCase):
            def setUp(self):
                l1, l2 = FullDuplexLink(loss_func=LossFunc(0.001, 0.001, 0.001))

                sft1 = SimpleFrameTransmitter(node=l1)
                sft2 = SimpleFrameTransmitter(node=l2)

                self.ft1 = FrameTransmitter(simple_frame_transmitter=sft1,
                    debug_src=1, debug_dest=2)
                self.ft2 = FrameTransmitter(simple_frame_transmitter=sft2,
                    debug_src=2, debug_dest=1)

                rlm1 = RouterLinkManager()
                rlm2 = RouterLinkManager()

                self.dr1 = DatagramRouter(
                    router_name=1,
                    link_manager=rlm1,
                    routing_table=LocalRoutingTable(1, rlm1))
                self.dr2 = DatagramRouter(
                    router_name=2,
                    link_manager=rlm2,
                    routing_table=LocalRoutingTable(2, rlm2))

                rlm1.add_link(2, self.ft1)
                rlm2.add_link(1, self.ft2)

                self.sm1 = RouterServiceManager(self.dr1)
                self.sm2 = RouterServiceManager(self.dr2)

            def test_transmit(self):
                s1_77 = self.sm1.register_service(77)
                s2_77 = self.sm2.register_service(77)

                d12 = Packet(1, 2, "test")
                s1_77.send(d12)
                self.assertEqual(s2_77.receive(), d12)
                s2_77.send(d12)
                self.assertEqual(s2_77.receive(), d12)

                s1_33 = self.sm1.register_service(33)
                s2_33 = self.sm2.register_service(33)

                d21 = Packet(2, 1, "test 2")
                s2_33.send(d21)
                self.assertEqual(s1_33.receive(), d21)
                s1_33.send(d21)
                self.assertEqual(s1_33.receive(), d21)

                text = "".join(map(chr, xrange(256)))
                d_big = Packet(1, 2, text * 5)
                s1_33.send(d_big)
                self.assertEqual(s2_33.receive(), d_big)

                d12_2 = Packet(1, 2, "test 2")
                d12_3 = Packet(1, 2, "test 3")

                s1_33.send(d12)
                s1_33.send(d12_2)
                self.assertEqual(s2_33.receive(), d12)
                s1_77.send(d12_3)
                self.assertEqual(s2_77.receive(), d12_3)
                self.assertEqual(s2_33.receive(), d12_2)

            def tearDown(self):
                self.sm1.terminate()
                self.sm2.terminate()

                self.dr1.terminate()
                self.dr2.terminate()

                self.ft1.terminate()
                self.ft2.terminate()
Пример #4
0
        class TestRouterServiceManager2(unittest.TestCase):
            def setUp(self):
                l1, l2 = FullDuplexLink()

                sft1 = SimpleFrameTransmitter(node=l1)
                sft2 = SimpleFrameTransmitter(node=l2)

                self.ft1 = FrameTransmitter(simple_frame_transmitter=sft1,
                    debug_src=1, debug_dest=2)
                self.ft2 = FrameTransmitter(simple_frame_transmitter=sft2,
                    debug_src=2, debug_dest=1)

                rlm1 = RouterLinkManager()
                rlm2 = RouterLinkManager()

                self.dr1 = DatagramRouter(
                    router_name=1,
                    link_manager=rlm1,
                    routing_table=LocalRoutingTable(1, rlm1))
                self.dr2 = DatagramRouter(
                    router_name=2,
                    link_manager=rlm2,
                    routing_table=LocalRoutingTable(2, rlm2))

                rlm1.add_link(2, self.ft1)
                rlm2.add_link(1, self.ft2)

                self.sm1 = RouterServiceManager(self.dr1)
                self.sm2 = RouterServiceManager(self.dr2)

                self.s1_100 = self.sm1.register_service(100)
                self.s2_100 = self.sm2.register_service(100)

            def _test_transmit(self):
                s1_77 = self.sm1.register_service(77)
                s2_77 = self.sm2.register_service(77)

                d12 = Packet(1, 2, "test")
                s1_77.send(d12)
                self.assertEqual(s2_77.receive(), d12)
                s2_77.send(d12)
                self.assertEqual(s2_77.receive(), d12)

                s1_33 = self.sm1.register_service(33)
                s2_33 = self.sm2.register_service(33)

                d21 = Packet(2, 1, "test 2")
                s2_33.send(d21)
                self.assertEqual(s1_33.receive(), d21)
                s1_33.send(d21)
                self.assertEqual(s1_33.receive(), d21)

                text = "".join(map(chr, xrange(256)))
                d_big = Packet(1, 2, text * 5)
                s1_33.send(d_big)
                self.assertEqual(s2_33.receive(), d_big)

                d12_2 = Packet(1, 2, "test 2")
                d12_3 = Packet(1, 2, "test 3")

                s1_33.send(d12)
                s1_33.send(d12_2)
                self.assertEqual(s2_33.receive(), d12)
                s1_77.send(d12_3)
                self.assertEqual(s2_77.receive(), d12_3)
                self.assertEqual(s2_33.receive(), d12_2)

            def test_time(self):
                data = "test"
                self.s1_100.send_data(2, data)
                p = self.s2_100.receive()
                self.assertEqual(p.data, data)
                # TODO: Assume computer is not slow.
                self.assertLess(p.time, 5.0)
                self.assertGreaterEqual(p.time, 0)

            def tearDown(self):
                self.sm1.terminate()
                self.sm2.terminate()

                self.dr1.terminate()
                self.dr2.terminate()

                self.ft1.terminate()
                self.ft2.terminate()
Пример #5
0
        class TestRIPService2(unittest.TestCase):
            def setUp(self):
                l1, l2 = FullDuplexLink()

                sft1 = SimpleFrameTransmitter(node=l1)
                sft2 = SimpleFrameTransmitter(node=l2)

                self.ft1 = FrameTransmitter(simple_frame_transmitter=sft1,
                    debug_src=1, debug_dest=2)
                self.ft2 = FrameTransmitter(simple_frame_transmitter=sft2,
                    debug_src=2, debug_dest=1)

                rlm1 = RouterLinkManager()
                rlm2 = RouterLinkManager()

                self.dr1 = DatagramRouter(
                    router_name=1,
                    link_manager=rlm1,
                    routing_table=LocalRoutingTable(1, rlm1))
                self.dr2 = DatagramRouter(
                    router_name=2,
                    link_manager=rlm2,
                    routing_table=LocalRoutingTable(2, rlm2))

                rlm1.add_link(2, self.ft1)
                rlm2.add_link(1, self.ft2)

                self.sm1 = RouterServiceManager(self.dr1)
                self.sm2 = RouterServiceManager(self.dr2)

                self.rip_st1 = self.sm1.register_service(RIPService.protocol)
                self.rip_st2 = self.sm2.register_service(RIPService.protocol)

                self.rs1 = RIPService(1, rlm1, self.rip_st1,
                    update_period=0.5, inf_timeout=0.9, remove_timeout=1.6)
                self.rs2 = RIPService(2, rlm2, self.rip_st2,
                    update_period=0.5, inf_timeout=0.9, remove_timeout=1.6)

                self.dr1.set_routing_table(self.rs1.dynamic_routing_table())
                self.dr2.set_routing_table(self.rs2.dynamic_routing_table())

            def test_transmit(self):
                s1_77 = self.sm1.register_service(77)
                s2_77 = self.sm2.register_service(77)

                d12 = Packet(1, 2, "test")
                s1_77.send(d12)
                self.assertEqual(s2_77.receive(), d12)
                s2_77.send(d12)
                self.assertEqual(s2_77.receive(), d12)

                s1_33 = self.sm1.register_service(33)
                s2_33 = self.sm2.register_service(33)

                d21 = Packet(2, 1, "test 2")
                s2_33.send(d21)
                self.assertEqual(s1_33.receive(), d21)
                s1_33.send(d21)
                self.assertEqual(s1_33.receive(), d21)

                text = "".join(map(chr, xrange(256)))
                d_big = Packet(1, 2, text * 5)
                s1_33.send(d_big)
                self.assertEqual(s2_33.receive(), d_big)

                d12_2 = Packet(1, 2, "test 2")
                d12_3 = Packet(1, 2, "test 3")

                s1_33.send(d12)
                s1_33.send(d12_2)
                self.assertEqual(s2_33.receive(), d12)
                s1_77.send(d12_3)
                self.assertEqual(s2_77.receive(), d12_3)
                self.assertEqual(s2_33.receive(), d12_2)

            def tearDown(self):
                self.rs1.terminate()
                self.rs2.terminate()

                self.sm1.terminate()
                self.sm2.terminate()

                self.dr1.terminate()
                self.dr2.terminate()

                self.ft1.terminate()
                self.ft2.terminate()
Пример #6
0
        class TestDatagramRouter2(unittest.TestCase):
            def setUp(self):
                l1, l2 = FullDuplexLink()

                sft1 = SimpleFrameTransmitter(node=l1)
                sft2 = SimpleFrameTransmitter(node=l2)

                self.ft1 = FrameTransmitter(simple_frame_transmitter=sft1,
                    debug_src=1, debug_dest=2)
                self.ft2 = FrameTransmitter(simple_frame_transmitter=sft2,
                    debug_src=2, debug_dest=1)

                rlm1 = RouterLinkManager()
                rlm2 = RouterLinkManager()
                
                self.dr1 = DatagramRouter(
                    router_name=1,
                    link_manager=rlm1,
                    routing_table=LocalRoutingTable(1, rlm1))
                self.dr2 = DatagramRouter(
                    router_name=2,
                    link_manager=rlm2,
                    routing_table=LocalRoutingTable(2, rlm2))

                rlm1.add_link(2, self.ft1)
                rlm2.add_link(1, self.ft2)

            def test_transmit(self):
                d12 = datagram(12, 1, 2, "test")
                self.dr1.send(d12)
                self.assertEqual(self.dr2.receive()[1], d12)

                self.dr2.send(d12)
                self.assertEqual(self.dr2.receive()[1], d12)

                d21 = datagram(13, 2, 1, "test 2")
                self.dr2.send(d21)
                self.assertEqual(self.dr1.receive()[1], d21)

                self.dr1.send(d21)
                self.assertEqual(self.dr1.receive()[1], d21)

                text = "".join(map(chr, xrange(256)))
                d_big = datagram(130, 1, 2, text * 5)
                self.dr1.send(d_big)
                self.assertEqual(self.dr2.receive()[1], d_big)

                d12_2 = datagram(14, 1, 2, "test 2")
                d12_3 = datagram(14, 1, 2, "test 3")

                self.dr1.send(d12)
                self.dr1.send(d12_2)
                self.assertEqual(self.dr2.receive()[1], d12)
                self.dr1.send(d12_3)
                self.assertEqual(self.dr2.receive()[1], d12_2)
                self.assertEqual(self.dr2.receive()[1], d12_3)

            def test_invalid_datagram(self):
                self.ft1.send("raw test!")
                self.assertEqual(self.dr2.receive(block=False)[1], None)

                d12 = datagram(12, 1, 2, "test")
                self.dr1.send(d12)
                self.assertEqual(self.dr2.receive()[1], d12)

            def tearDown(self):
                self.dr1.terminate()
                self.dr2.terminate()

                self.ft1.terminate()
                self.ft2.terminate()