def test_it_should_not_return_traffic_to_the_previous_hop(self): l = Link('A') i = Interface(link=l) l.accept("This is a packet.", previous_hop=i) self.assertEqual(0, len(i.received()))
def test_it_should_send_packets_to_a_link(self): l = Link('A') i = Interface(link=l) i.send("This is a packet.") self.assertEqual(1, len(l.forwarded())) self.assertEqual("This is a packet.", l.forwarded()[0])
def test_it_should_get_received_packets_filtered_by_lambda(self): l = Link('A') i = Interface(link=l) l.accept(IPv6(src="2001:db8::2", dst="2001:db8::1")/ICMPv6EchoRequest()) l.accept(IP(src="192.168.0.1", dst="192.168.0.2")/ICMP()) self.assertEqual(1, len(i.received(lbda=lambda p: p.haslayer(IPv6))))
def test_it_should_forward_traffic_to_an_interface(self): l = Link('A') i = Interface(link=l) j = Interface(link=l) l.accept("This is a packet.", previous_hop=i) self.assertEqual(1, len(j.received())) self.assertEqual("This is a packet.", j.received()[0])
def test_it_should_get_received_packets_filtered_by_sequence(self): l = Link('A') i = Interface(link=l) l.accept(IPv6(src="2001:db8::2", dst="2001:db8::1")/ICMPv6EchoRequest(seq=2)) l.accept(IPv6(src="2001:db8::1", dst="2001:db8::2")/ICMPv6EchoReply(seq=2)) self.assertEqual(2, len(i.received(seq=2))) self.assertEqual(0, len(i.received(seq=1)))
def test_it_should_get_received_packets_filtered_by_type(self): l = Link('A') i = Interface(link=l) l.accept(IPv6(src="2001:db8::2", dst="2001:db8::1")/ICMPv6EchoRequest()) l.accept(IPv6(src="2001:db8::1", dst="2001:db8::2")/ICMPv6EchoReply()) self.assertEqual(1, len(i.received(type=ICMPv6EchoRequest))) self.assertTrue(i.received(type=ICMPv6EchoRequest)[0].haslayer(ICMPv6EchoRequest))
def test_it_should_strip_layer_2_frames_from_packets_on_receive(self): l = Link('A') i = Interface(link=l) l.accept(Ether()/IPv6()) self.assertEqual(1, len(i.received())) self.assertFalse(i.received()[0].haslayer('Ether')) self.assertTrue(i.received()[0].haslayer('IPv6'))
def test_it_should_encapsulate_packets_with_layer_2_frames_on_send(self): l = Link('A') i = Interface(link=l) i.send(IPv6()) self.assertEqual(1, len(l.forwarded())) self.assertTrue(l.forwarded()[0].haslayer(Ether)) self.assertTrue(l.forwarded()[0].haslayer(IPv6))
def test_it_should_set_the_source_and_destination_mac_addresses_to_defaults_for_ethernet_link_layer(self): l = Link('A') i = Interface(link=l) i.send(IPv6()) self.assertEqual(1, len(l.forwarded())) self.assertTrue(l.forwarded()[0].haslayer(Ether)) self.assertEqual("00:00:00:00:00:00", l.forwarded()[0].getlayer(Ether).src) self.assertEqual("ff:ff:ff:ff:ff:ff", l.forwarded()[0].getlayer(Ether).dst)
def test_it_should_overwrite_the_destination_mac_of_an_ethernet_frame(self): l = Link('A') i = Interface(link=l) j = MockInterface('if0', '00:b0:d0:86:bb:f7') k = TargetInterface(link_addr="00:b0:d0:bb:cc:ff") t = Tap(l, j, k) i.send(IPv6()) self.assertEqual(1, len(j.sent)) self.assertTrue(j.sent[0].haslayer(Ether)) self.assertTrue(j.sent[0].haslayer(IPv6)) self.assertEqual("00:b0:d0:bb:cc:ff", j.sent[0].getlayer(Ether).dst)
def test_it_should_invoke_on_send_callbacks(self): l = Link('A') i = Interface(link=l) self.called = False self.packet = None def c(p, iface): self.called = True self.packet = p i.on_send(c) i.send("This is a packet.") self.assertTrue(self.called) self.assertEqual("This is a packet.", self.packet)
def test_it_should_accept_packets_from_a_link(self): l = Link('A') i = Interface(link=l) j = Interface(link=l) i.send("This is a packet.") self.assertEqual(1, len(j.received())) self.assertEqual("This is a packet.", j.received()[0])
def test_it_should_get_the_second_v6_global_ip(self): l = Link('A') i = Interface(link=l, ips=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")]) self.assertEqual("2001:500:88:200::11", i.global_ip(offset=1).short_form())
def test_it_should_get_the_default_v6_link_local_ip(self): l = Link('A') i = Interface(link=l, ips=[IPAddress.identify("2001:500:88:200::10"), IPAddress.identify("2001:500:88:200::11"), IPAddress.identify("fe80:500:88:200::10"), IPAddress.identify("192.0.43.10")]) self.assertEqual("fe80:500:88:200::10", i.link_local_ip().short_form())