|
| 1 | +## Can't run Crash or Output tests because EtherEncap requires metadata to be set first # |
| 2 | + |
| 3 | +def etherencap_crashtest(): |
| 4 | + encap1 = EtherEncap() |
| 5 | + src = Source() |
| 6 | + metadata = SetMetadata(attrs=[{"name": "ether_src", "size": 6, "value_bin": b'\xde\xad\xbe\xef\x12\x34'}, |
| 7 | + {"name": "ether_dst", "size": 6, "value_bin": b'\x12\x34\xde\xad\xbe\xef'}, |
| 8 | + {"name" : "ether_type", "size": 2, "value_bin": b'\x08\x00'}]) |
| 9 | + rwtemp = [ |
| 10 | + bytes(gen_packet( |
| 11 | + scapy.UDP, |
| 12 | + "172.12.0.3", |
| 13 | + "127.12.0.4")), |
| 14 | + bytes(gen_packet( |
| 15 | + scapy.TCP, |
| 16 | + "192.168.32.4", |
| 17 | + "1.2.3.4"))] |
| 18 | + src -> Rewrite(templates=rwtemp) -> metadata -> encap1 -> Sink() |
| 19 | + bess.resume_all() |
| 20 | + time.sleep(5) |
| 21 | + bess.pause_all() |
| 22 | + |
| 23 | + |
| 24 | +CUSTOM_TEST_FUNCTIONS.append(etherencap_crashtest) |
| 25 | + |
| 26 | +## See if it correctly wraps IP packet in Ether header |
| 27 | +def metadata_outputtest_fixedvalues(): |
| 28 | + eth = scapy.Ether(src='de:ad:be:ef:12:34', dst='12:34:de:ad:be:ef') |
| 29 | + ip = scapy.IP(src="1.2.3.4", dst="2.3.4.5", ttl=98) |
| 30 | + udp = scapy.UDP(sport=10001, dport=10002) |
| 31 | + payload = 'helloworld' |
| 32 | + |
| 33 | + test_packet_in = ip/udp/payload |
| 34 | + test_packet_out = eth/ip/udp/payload |
| 35 | + |
| 36 | + sockname = "metadata_fixedvalues" + SCRIPT_STARTTIME |
| 37 | + socket_port, mysocket = gen_socket_and_port(sockname) |
| 38 | + |
| 39 | + indriver = PortInc(port=sockname) |
| 40 | + outdriver = PortOut(port=sockname) |
| 41 | + |
| 42 | + encap2 = EtherEncap() |
| 43 | + metadata = SetMetadata(attrs=[{"name": "ether_src", "size": 6, "value_bin": b'\xde\xad\xbe\xef\x12\x34'}, |
| 44 | + {"name": "ether_dst", "size": 6, "value_bin": b'\x12\x34\xde\xad\xbe\xef'}, |
| 45 | + {"name" : "ether_type", "size": 2, "value_bin": b'\x08\x00'}]) |
| 46 | + indriver -> metadata -> encap2 -> outdriver |
| 47 | + |
| 48 | + bess.resume_all() |
| 49 | + mysocket.send(bytes(test_packet_in)) |
| 50 | + return_data = mysocket.recv(2048) |
| 51 | + bess.pause_all() |
| 52 | + assert(bytes(return_data) == bytes(test_packet_out)) |
| 53 | + |
| 54 | +CUSTOM_TEST_FUNCTIONS.append(metadata_outputtest_fixedvalues) |
0 commit comments