Nathan Knuth | 418fdc8 | 2016-09-16 22:51:15 -0700 | [diff] [blame] | 1 | import logging |
| 2 | from oftest.testutils import * |
| 3 | import oftest.base_tests as base_tests |
| 4 | import ofp |
| 5 | from scapy.all import Ether |
| 6 | from hexdump import hexdump |
| 7 | |
| 8 | |
| 9 | in_out_port = test_param_get("in_out_port", "ep1") |
| 10 | |
| 11 | |
| 12 | class PacketOutTest(base_tests.SimpleDataPlane): |
| 13 | """ |
| 14 | Test that a packet sent out by the controller is forwarded to the in-out |
| 15 | test port with the out_port encoded as a Dot1Q shim vlan_id |
| 16 | """ |
| 17 | |
| 18 | def runTest(self): |
| 19 | logging.info("Running %s" % self.__class__.__name__) |
| 20 | |
| 21 | # These cleanups are not really needed. We do it to verify connection |
| 22 | # to the agent. |
| 23 | delete_all_flows(self.controller) |
| 24 | delete_all_groups(self.controller) |
| 25 | |
| 26 | # Send packet out and capture it at the in-out port |
| 27 | pktlen = 60 |
| 28 | pkt_kws = dict( |
| 29 | eth_src='de:ad:be:ef:00:01', |
| 30 | eth_dst='de:ad:be:ef:00:02', |
| 31 | ip_src='192.168.0.1', |
| 32 | ip_dst='192.168.0.2' |
| 33 | ) |
| 34 | |
| 35 | pkt = simple_udp_packet(pktlen=pktlen, **pkt_kws) |
| 36 | expected_pkt = simple_udp_packet(pktlen + 4, dl_vlan_enable=True, |
| 37 | vlan_vid=1, **pkt_kws) |
| 38 | |
| 39 | msg = ofp.message.packet_out( |
| 40 | in_port=ofp.OFPP_CONTROLLER, |
| 41 | actions=[ofp.action.output(port=in_out_port)], |
| 42 | buffer_id=ofp.OFP_NO_BUFFER, |
| 43 | data=str(pkt) |
| 44 | ) |
| 45 | self.controller.message_send(msg) |
| 46 | verify_no_errors(self.controller) |
| 47 | |
| 48 | # now verify that we received the correct packet with proper vlan tag |
| 49 | verify_packet(self, str(expected_pkt), in_out_port) |
| 50 | |
| 51 | |
| 52 | class PacketInTest(base_tests.SimpleDataPlane): |
| 53 | """ |
| 54 | Test that a packet arriving at the in-out test port is forwarded to |
| 55 | the controller as a packet-in message with in_port being the vlan_id |
| 56 | of the outer Dot1Q shim (which is popped before the packet is sent in) |
| 57 | """ |
| 58 | |
| 59 | def runTest(self): |
| 60 | logging.info("Running %s" % self.__class__.__name__) |
| 61 | |
| 62 | # These cleanups are not really needed. We do it to verify connection |
| 63 | # to the agent. |
| 64 | delete_all_flows(self.controller) |
| 65 | delete_all_groups(self.controller) |
| 66 | |
| 67 | # Send packet out and capture it at the in-out port |
| 68 | pktlen = 60 |
| 69 | pkt_kws = dict( |
| 70 | eth_src='de:ad:be:ef:00:01', |
| 71 | eth_dst='de:ad:be:ef:00:02', |
| 72 | ip_src='192.168.0.1', |
| 73 | ip_dst='192.168.0.2' |
| 74 | ) |
| 75 | |
| 76 | pkt = simple_udp_packet(pktlen + 4, dl_vlan_enable=True, |
| 77 | vlan_vid=1, **pkt_kws) |
| 78 | expected_pkt = simple_udp_packet(pktlen=pktlen, **pkt_kws) |
| 79 | |
| 80 | # send a test packet into the in_out_port |
| 81 | self.dataplane.send(in_out_port, str(pkt)) |
| 82 | |
| 83 | # expect it to become a packet_in |
| 84 | verify_packet_in(self, str(expected_pkt), 1, ofp.OFPR_ACTION) |