class LLNetDevTests(unittest.TestCase): def setUp(self): self.scenario = Scenario('test') self.scenario.add_interface('eth1', '11:11:11:11:11:11') self.scenario.add_interface('eth0', '00:00:00:00:00:00') self.scenario.add_interface('eth2', '22:22:22:22:22:22') self.scenario.add_interface('eth7', '77:77:77:77:77:77') self.scenario.done = Mock(return_value=False) self.ev = Mock() self.ev.match = Mock(return_value=None) self.scenario.next = Mock(return_value=self.ev) self.fake = FakePyLLNet(self.scenario) self.devs = make_device_list([], []) self.real = WrapPyLLNet(self.devs) self.real._fix_devinfo(self.devs) self.real.pcaps = Mock() self.real.pcaps.get = Mock(return_value=Mock()) def testFakeSendDevName(self): p = Packet() self.fake.send_packet("eth1", p) self.ev.match.assert_called_with(SwitchyTestEvent.EVENT_OUTPUT, device='eth1', packet=p) def testFakeSendDevNum(self): p = Packet() self.fake.send_packet(0, p) self.ev.match.assert_called_with(SwitchyTestEvent.EVENT_OUTPUT, device='eth1', packet=p) self.fake.send_packet(3, p) self.ev.match.assert_called_with(SwitchyTestEvent.EVENT_OUTPUT, device='eth7', packet=p) def testFakeSendIntfObj(self): p = Packet() ifmap = self.scenario.interfaces() self.fake.send_packet(ifmap['eth1'], p) self.ev.match.assert_called_with(SwitchyTestEvent.EVENT_OUTPUT, device='eth1', packet=p) self.fake.send_packet(ifmap['eth2'], p) self.ev.match.assert_called_with(SwitchyTestEvent.EVENT_OUTPUT, device='eth2', packet=p) def testRealSendDevName(self): p = Packet() for d in self.devs: self.real.send_packet(d, p) self.real.pcaps.get.assert_called_with(d, None) def testRealSendDevNum(self): p = Packet() for d,intf in self.real.devinfo.items(): self.real.send_packet(intf.ifnum, p) self.real.pcaps.get.assert_called_with(intf.name, None) def testRealSendIntfObj(self): p = Packet() for d,intf in self.real.devinfo.items(): self.real.send_packet(intf, p) self.real.pcaps.get.assert_called_with(intf.name, None)
def setUp(self): self.scenario = Scenario('test') self.scenario.add_interface('eth1', '11:11:11:11:11:11') self.scenario.add_interface('eth0', '00:00:00:00:00:00') self.scenario.add_interface('eth2', '22:22:22:22:22:22') self.scenario.add_interface('eth7', '77:77:77:77:77:77') self.scenario.done = Mock(return_value=False) self.ev = Mock() self.ev.match = Mock(return_value=None) self.scenario.next = Mock(return_value=self.ev) self.fake = FakePyLLNet(self.scenario) self.devs = make_device_list([], []) self.real = WrapPyLLNet(self.devs) self.real._fix_devinfo(self.devs) self.real.pcaps = Mock() self.real.pcaps.get = Mock(return_value=Mock())
def create_scenario(): s = Scenario("switch tests for LRU mechanism") s.add_interface('eth0', '10:00:00:00:00:01') s.add_interface('eth1', '10:00:00:00:00:02') s.add_interface('eth2', '10:00:00:00:00:03') # 1 testpkt = mk_pkt("30:00:00:00:00:02", "ff:ff:ff:ff:ff:ff", "172.16.42.2", "255.255.255.255") s.expect(PacketInputEvent("eth1", testpkt, display=Ethernet), "An Ethernet frame with a broadcast destination address should arrive on eth1") s.expect(PacketOutputEvent("eth0", testpkt, "eth2", testpkt, display=Ethernet), "The Ethernet frame with a broadcast destination address should be forwarded out ports eth0 and eth2") # 2 testpkt = mk_pkt("30:00:00:00:00:01", "30:00:00:00:00:02", "172.16.42.1", "172.16.42.2") s.expect(PacketInputEvent("eth0", testpkt, display=Ethernet), "An ethernet frame from 1 to 2 arrives on eth0") s.expect(PacketOutputEvent("eth1", testpkt, display=Ethernet), "Frame sent out on eth1 outbound for 2") # 3 testpkt = mk_pkt("30:00:00:00:00:03", "30:00:00:00:00:01", "172.16.42.3", "172.16.42.1") s.expect(PacketInputEvent("eth2", testpkt, display=Ethernet), "An ethernet frame from 3 to 1 arrives on eth2") s.expect(PacketOutputEvent("eth0", testpkt, display=Ethernet), "Frame sent out on eth1 outbound for 2") # 4 testpkt = mk_pkt("30:00:00:00:00:04", "10:00:00:00:00:01", "172.16.42.4", "172.0.0.0") s.expect(PacketInputEvent("eth0", testpkt, display=Ethernet), "An ethernet frame from 4 to switch arrives on eth0") # 5 testpkt = mk_pkt("30:00:00:00:00:05", "30:00:00:00:00:02", "172.16.42.5", "172.16.42.2") s.expect(PacketInputEvent("eth2", testpkt, display=Ethernet), "An ethernet frame from 5 to 2 arrives on eth2") s.expect(PacketOutputEvent("eth1", testpkt, display=Ethernet), "Frame sent out on eth1 outbound for 2") # 6 testpkt = mk_pkt("30:00:00:00:00:06", "30:00:00:00:00:03", "172.16.42.6", "172.16.42.3") s.expect(PacketInputEvent("eth1", testpkt, display=Ethernet), "An ethernet frame from 6 to 3 arrives on eth1") s.expect(PacketOutputEvent("eth0", testpkt, "eth2", testpkt, display=Ethernet), "Frame sent out on all ports except eth1") # 7 testpkt = mk_pkt("30:00:00:00:00:01", "30:00:00:00:00:02", "172.16.42.1", "172.16.42.2") s.expect(PacketInputEvent("eth1", testpkt, display=Ethernet), "An ethernet frame from 1 to 2 arrives on eth1") s.expect(PacketOutputEvent("eth1", testpkt, display=Ethernet), "Frame sent out on eth1 outbound for 2") # 8 testpkt = mk_pkt("30:00:00:00:00:05", "30:00:00:00:00:1", "172.16.42.5", "172.16.42.1") s.expect(PacketInputEvent("eth2", testpkt, display=Ethernet), "An ethernet frame from 5 to 1 arrives on eth2") s.expect(PacketOutputEvent("eth1", testpkt, display=Ethernet), "Frame sent out on eth1 outbound for 1") return s
def create_scenario(): s = Scenario("hub tests") s.add_interface('eth0', '10:00:00:00:00:01') s.add_interface('eth1', '10:00:00:00:00:02') s.add_interface('eth2', '10:00:00:00:00:03') # [address:port] # [01:0] # [01:0][02:1] # [01:0][02:1][03:2] # [01:0][02:1][03:2][04:0] # [02:1][03:2][04:0][05:1][01:0:1] # Add five entries # Change port of entry 01 to eth1 and test to see if the entry is correct # [02:1][03:2][04:0][05:1][01:1] # [02:1][03:2][04:0][05:1][01:1] # Send packet to all destination 01-05 once to refresh the timeout # Delay for 7s, entry should still be in the table # [02:1][03:2][04:0][05:1][01:1] # Delay for 10s, entry should not be there anymore #Table [address:port] pkt = packet('30:00:00:00:00:01', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") pkt = packet('30:00:00:00:00:02', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, "eth2", pkt, display=Ethernet), "Forward: eth0, eth2") pkt = packet('30:00:00:00:00:03', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth2", pkt, display=Ethernet), "Arrive: eth2") s.expect(PacketOutputEvent("eth0", pkt, "eth1", pkt, display=Ethernet), "Forward: eth0, eth1") pkt = packet('30:00:00:00:00:04', '10:00:00:00:00:01') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") pkt = packet('30:00:00:00:00:05', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") pkt = packet('30:00:00:00:00:01', '10:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") pkt = packet('30:00:00:00:00:05', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:02') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:03') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth2", pkt, display=Ethernet), "Forward: eth2") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:04') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:05') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") # Delay for 7s s.expect(PacketInputTimeoutEvent(7.0), "Timeout: 7") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:02') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:03') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth2", pkt, display=Ethernet), "Forward: eth2") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:04') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:05') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") # Delay for 10s s.expect(PacketInputTimeoutEvent(10.0), "Timeout: 1") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:02') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:03') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:04') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:05') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") return s
def create_scenario(): s = Scenario("router tests") s.add_interface('router-eth0', '10:00:00:00:00:01', '192.168.1.1', '255.255.0.0') s.add_interface('router-eth1', '10:00:00:00:00:02', '10.10.0.1', '255.255.0.0') s.add_interface('router-eth2', '10:00:00:00:00:03', '172.16.42.1', '255.255.255.252') s.add_file( 'forwarding_table.txt', '''172.16.0.0 255.255.0.0 192.168.1.2 router-eth0 172.16.128.0 255.255.192.0 10.10.0.254 router-eth1 172.16.64.0 255.255.192.0 10.10.1.254 router-eth1 10.100.0.0 255.255.0.0 172.16.42.2 router-eth2''') #Test item 1, 2, 3 reqpkt = mk_ping("20:00:00:00:00:01", "10:00:00:00:00:01", '192.168.1.100', '172.16.42.2', ttl=64) reqpkt2 = copy.deepcopy(reqpkt) reqpkt2.get_header(Ethernet).src = EthAddr("10:00:00:00:00:03") reqpkt2.get_header(Ethernet).dst = EthAddr("30:00:00:00:00:01") arpreq = create_ip_arp_request("10:00:00:00:00:03", "172.16.42.1", "172.16.42.2") arpresp = mk_arpresp( arpreq, "30:00:00:00:00:01" ) # , "10:00:00:00:00:03", "172.16.42.2", "172.16.42.1") arpreq2 = create_ip_arp_request("10:00:00:00:00:01", "192.168.1.1", "192.168.1.100") arpresp2 = mk_arpresp( arpreq2, "20:00:00:00:00:01" ) # , "10:00:00:00:00:01", "192.168.1.100", "192.168.1.1") resppkt = mk_ping("30:00:00:00:00:01", "10:00:00:00:00:03", '172.16.42.2', '192.168.1.100', reply=True, ttl=64) resppkt2 = copy.deepcopy(resppkt) resppkt2.get_header(Ethernet).src = EthAddr("10:00:00:00:00:01") resppkt2.get_header(Ethernet).dst = EthAddr("20:00:00:00:00:01") ttlmatcher = '''lambda pkt: pkt.get_header(IPv4).ttl == 63''' s.expect( PacketInputEvent("router-eth0", reqpkt, display=IPv4), "IP packet to be forwarded to 172.16.42.2 should arrive on router-eth0" ) s.expect( PacketOutputEvent("router-eth2", arpreq, display=Arp), "Router should send ARP request for 172.16.42.2 out router-eth2 interface" ) s.expect( PacketInputEvent("router-eth2", arpresp, display=Arp), "Router should receive ARP response for 172.16.42.2 on router-eth2 interface" ) s.expect( PacketOutputEvent("router-eth2", reqpkt2, display=IPv4, exact=False, predicates=[ttlmatcher]), "IP packet should be forwarded to 172.16.42.2 out router-eth2") s.expect( PacketInputEvent("router-eth2", resppkt, display=IPv4), "IP packet to be forwarded to 192.168.1.100 should arrive on router-eth2" ) s.expect( PacketOutputEvent("router-eth0", arpreq2, display=Arp), "Router should send ARP request for 192.168.1.100 out router-eth0") s.expect( PacketInputEvent("router-eth0", arpresp2, display=Arp), "Router should receive ARP response for 192.168.1.100 on router-eth0") s.expect( PacketOutputEvent("router-eth0", resppkt2, display=IPv4, exact=False, predicates=[ttlmatcher]), "IP packet should be forwarded to 192.168.1.100 out router-eth0") #Test item 2, 3, 4, 5 testpkt_1 = mk_pkt("06:07:08:09:0a:0b", "10:00:00:00:00:02", False, "", "", "", "", "192.168.1.239", "10.10.50.250") s.expect(PacketInputEvent("router-eth0", testpkt_1), "IP packet for 10.10.50.250 arrives on eth0.") testpkt_arp1 = mk_pkt("10:00:00:00:00:2", "ff:ff:ff:ff:ff:ff", True, "10:00:00:00:00:02", "ff:ff:ff:ff:ff:ff", "10.10.0.1", "10.10.50.250") s.expect(PacketOutputEvent("router-eth1", testpkt_arp1), "ARP request for 10.10.50.250 sent on eth1") testpkt_2 = mk_pkt("ab:cd:ef:ab:cd:ef", "10:00:00:00:00:03", False, "", "", "", "", "172.16.42.12", "172.16.4.3") s.expect( PacketInputEvent("router-eth2", testpkt_2), "IP packet for 172.16.42.3 arrives on eth2. Host 172.16.4.3 does not exist" ) testpkt_arp2 = mk_pkt("10:00:00:00:00:1", "ff:ff:ff:ff:ff:ff", True, "10:00:00:00:00:01", "ff:ff:ff:ff:ff:ff", "192.168.1.1", "192.168.1.2") s.expect(PacketOutputEvent("router-eth0", testpkt_arp2), "ARP request for 192.168.1.2 sent on eth0") s.expect(PacketInputTimeoutEvent(1.5), "The router should timeout on recv_packet") s.expect(PacketOutputEvent("router-eth1", testpkt_arp1), "ARP request for 10.10.50.250 sent on eth1") s.expect(PacketOutputEvent("router-eth0", testpkt_arp2), "ARP request for 192.168.1.2 sent on eth0") s.expect( PacketInputEvent("router-eth2", testpkt_2), "IP packet for 172.16.42.3 arrives on eth2. Host 172.16.4.3 does not exist" ) s.expect(PacketInputTimeoutEvent(1.5), "The router should timeout on recv_packet") s.expect(PacketOutputEvent("router-eth1", testpkt_arp1), "ARP request for 10.10.50.250 sent on eth1") s.expect(PacketOutputEvent("router-eth0", testpkt_arp2), "ARP request for 192.168.1.2 sent on eth0") s.expect(PacketInputEvent("router-eth0", testpkt_1), "IP packet for 10.10.50.250 arrives on eth0.") s.expect(PacketInputTimeoutEvent(1.5), "The router should timeout on recv_packet") s.expect(PacketOutputEvent("router-eth1", testpkt_arp1), "ARP request for 10.10.50.250 sent on eth1") s.expect(PacketOutputEvent("router-eth0", testpkt_arp2), "ARP request for 192.168.1.2 sent on eth0") s.expect(PacketInputEvent("router-eth0", testpkt_1), "IP packet for 10.10.50.250 arrives on eth0.") s.expect(PacketInputTimeoutEvent(1.5), "The router should timeout on recv_packet") s.expect(PacketOutputEvent("router-eth1", testpkt_arp1), "ARP request for 10.10.50.250 sent on eth1") s.expect(PacketOutputEvent("router-eth0", testpkt_arp2), "ARP request for 192.168.1.2 sent on eth0") s.expect(PacketInputTimeoutEvent(1.5), "The router should timeout on recv_packet") return s
def create_scenario(): s = Scenario("router test") s.add_interface('eth0', '10:00:00:00:00:01', '192.168.1.1') s.add_interface('eth1', '10:00:00:00:00:02', '192.168.1.2') s.add_interface('eth2', '10:00:00:00:00:03', '192.168.1.3') pkt = create_ip_arp_request('30:00:00:00:00:01', '142.32.44.1', '192.168.1.2') r_pkt = create_ip_arp_reply('10:00:00:00:00:02', '30:00:00:00:00:01', '192.168.1.2', '142.32.44.1') s.expect(PacketInputEvent('eth0', pkt, display=Ethernet), 'Arp request for router\'s interface eth1') s.expect(PacketOutputEvent("eth0", r_pkt, display=Ethernet), "Arp reply from router") pkt = create_ip_arp_request('30:00:00:00:00:01', '142.32.44.1', '192.168.1.3') r_pkt = create_ip_arp_reply('10:00:00:00:00:03', '30:00:00:00:00:01', '192.168.1.3', '142.32.44.1') s.expect(PacketInputEvent('eth2', pkt, display=Ethernet), 'Arp request for router\'s interface eth2') s.expect(PacketOutputEvent("eth2", r_pkt, display=Ethernet), "Arp reply from router") # #Table [address:port] # # Table [01:0] # pkt = packet('30:00:00:00:00:01', 'ff:ff:ff:ff:ff:ff') # s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0"); # s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") # # Table [01:0][02:1] # pkt = packet('30:00:00:00:00:02', 'ff:ff:ff:ff:ff:ff') # s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1"); # s.expect(PacketOutputEvent("eth0", pkt, "eth2", pkt, display=Ethernet), "Forward: eth0, eth2") # # Table [01:0][02:1][03:2] # pkt = packet('30:00:00:00:00:03', 'ff:ff:ff:ff:ff:ff') # s.expect(PacketInputEvent("eth2", pkt, display=Ethernet), "Arrive: eth2"); # s.expect(PacketOutputEvent("eth0", pkt, "eth1", pkt, display=Ethernet), "Forward: eth0, eth1") # # Table [01:0][02:1][03:2][04:0] # pkt = packet('30:00:00:00:00:04', '10:00:00:00:00:01') # s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0"); # s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") # # Table [02:1][03:2][04:0][05:1][01:0] # pkt = packet('30:00:00:00:00:05', '30:00:00:00:00:01') # s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1"); # s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") # # Table [02:1][03:2][04:0][05:1][01:1] # pkt = packet('30:00:00:00:00:01', '10:00:00:00:00:01') # s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1"); # s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") # # Table [04:0][05:1][01:1][06:2][03:2] # pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:03') # s.expect(PacketInputEvent("eth2", pkt, display=Ethernet), "Arrive: eth2"); # s.expect(PacketOutputEvent("eth2", pkt, display=Ethernet), "Forward: eth2"); # # Table [01:1][06:2][03:2][07:0][05:1] # pkt = packet('30:00:00:00:00:07', '30:00:00:00:00:05') # s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0"); # s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1"); # # Table [06:2][03:2][07:0][05:1][08:0] # pkt = packet('30:00:00:00:00:08', '30:00:00:00:00:01') # s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0"); # s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2"); return s
def create_scenario(): s = Scenario("hub tests") s.add_interface('eth0', '10:00:00:00:00:01') s.add_interface('eth1', '10:00:00:00:00:02') s.add_interface('eth2', '10:00:00:00:00:03') # [01:0:0][02:1:0][03:2:0] # [01:0:0][02:1:0][03:2:0][04:0:0] # [02:1:0][03:2:0][04:0:0][05:1:0][01:0:1] # Add five entries # Change port of entry 01 to eth1 and test to see if the entry is correct # [02:1:0][03:2:0][04:0:0][05:1:0][01:1:1] # [02:1:0][03:2:0][04:0:0][05:1:0][01:1:2] # Increase the traffic count of all other entries to 3 # ........................................ # ........................................ # [01:1:2][02:1:3][03:2:3][04:0:3][05:1:3] # If a new entry is introduced entry 01 should be dropped # [06:2:0][02:1:3][03:2:3][04:0:3][05:1:3] # [07:1:0][02:1:3][03:2:3][04:0:3][05:1:3] # Add the traffic count for entry 7 to 4 # [02:1:3][03:2:3][04:0:3][05:1:3][07:1:4] # If a new entry is added entry 02 should be dropped and entry 07 should remained # [08:1:0][03:2:3][04:0:3][05:1:3][07:1:5] #Table [address:port] pkt = packet('30:00:00:00:00:01', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") pkt = packet('30:00:00:00:00:02', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, "eth2", pkt, display=Ethernet), "Forward: eth0, eth2") pkt = packet('30:00:00:00:00:03', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth2", pkt, display=Ethernet), "Arrive: eth2") s.expect(PacketOutputEvent("eth0", pkt, "eth1", pkt, display=Ethernet), "Forward: eth0, eth1") pkt = packet('30:00:00:00:00:04', '10:00:00:00:00:01') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") pkt = packet('30:00:00:00:00:05', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") pkt = packet('30:00:00:00:00:01', '10:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") pkt = packet('30:00:00:00:00:05', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:02') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:02') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:02') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:03') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth2", pkt, display=Ethernet), "Forward: eth2") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:03') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth2", pkt, display=Ethernet), "Forward: eth2") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:03') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth2", pkt, display=Ethernet), "Forward: eth2") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:04') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:04') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:04') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:05') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:05') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:01', '30:00:00:00:00:05') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth2", pkt, display=Ethernet), "Arrive: eth2") s.expect(PacketOutputEvent("eth0", pkt, "eth1", pkt, display=Ethernet), "Forward: eth0, eth1") pkt = packet('30:00:00:00:00:07', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, "eth2", pkt, display=Ethernet), "Forward: eth0, eth2") pkt = packet('30:00:00:00:00:04', '30:00:00:00:00:07') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:04', '30:00:00:00:00:07') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:04', '30:00:00:00:00:07') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:04', '30:00:00:00:00:07') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") pkt = packet('30:00:00:00:00:08', '30:00:00:00:00:07') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") return s
def create_scenario(): s = Scenario("hub tests") s.add_interface('eth0', '10:00:00:00:00:01') s.add_interface('eth1', '10:00:00:00:00:02') s.add_interface('eth2', '10:00:00:00:00:03') # Make packet 01 the most recently used packet # Change the port of packet 01 from eth0 to eth1 # This is to test if receiving a packet with 01 as the source will change only the port without affecting its position in the table # Then, push packet 01 to the least recently used and check if it is dropped from the table correctly # By receiving a packet (source:08, destination:01) # the entry 08 should be added and the entry 01 should be dropped, and the switch should broadcast the packet because 01 is not in the entry # At the same time, we also tested if the switch send packets out to all ports except for the source # If the switch send the packet out the correct port #Table [address:port] # Table [01:0] pkt = packet('30:00:00:00:00:01', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") # Table [01:0][02:1] pkt = packet('30:00:00:00:00:02', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, "eth2", pkt, display=Ethernet), "Forward: eth0, eth2") # Table [01:0][02:1][03:2] pkt = packet('30:00:00:00:00:03', 'ff:ff:ff:ff:ff:ff') s.expect(PacketInputEvent("eth2", pkt, display=Ethernet), "Arrive: eth2") s.expect(PacketOutputEvent("eth0", pkt, "eth1", pkt, display=Ethernet), "Forward: eth0, eth1") # Table [01:0][02:1][03:2][04:0] pkt = packet('30:00:00:00:00:04', '10:00:00:00:00:01') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") # Table [02:1][03:2][04:0][05:1][01:0] pkt = packet('30:00:00:00:00:05', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketOutputEvent("eth0", pkt, display=Ethernet), "Forward: eth0") # Table [02:1][03:2][04:0][05:1][01:1] pkt = packet('30:00:00:00:00:01', '10:00:00:00:00:01') s.expect(PacketInputEvent("eth1", pkt, display=Ethernet), "Arrive: eth1") s.expect(PacketInputTimeoutEvent(1.0), "Timeout: 1") # Table [04:0][05:1][01:1][06:2][03:2] pkt = packet('30:00:00:00:00:06', '30:00:00:00:00:03') s.expect(PacketInputEvent("eth2", pkt, display=Ethernet), "Arrive: eth2") s.expect(PacketOutputEvent("eth2", pkt, display=Ethernet), "Forward: eth2") # Table [01:1][06:2][03:2][07:0][05:1] pkt = packet('30:00:00:00:00:07', '30:00:00:00:00:05') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, display=Ethernet), "Forward: eth1") # Table [06:2][03:2][07:0][05:1][08:0] pkt = packet('30:00:00:00:00:08', '30:00:00:00:00:01') s.expect(PacketInputEvent("eth0", pkt, display=Ethernet), "Arrive: eth0") s.expect(PacketOutputEvent("eth1", pkt, "eth2", pkt, display=Ethernet), "Forward: eth1, eth2") return s