Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 1 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 2 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 3 | """ |
| 4 | Test the bsn_in_ports_128 OXM, which enables the controller to specify a bitmap |
| 5 | of allowed input ports. |
| 6 | """ |
| 7 | |
| 8 | import logging |
| 9 | |
| 10 | from oftest import config |
| 11 | import oftest.base_tests as base_tests |
| 12 | import ofp |
| 13 | import oftest.packet as scapy |
| 14 | |
| 15 | from oftest.testutils import * |
| 16 | |
Rich Lane | e0aef81 | 2014-07-21 18:01:15 -0700 | [diff] [blame] | 17 | @nonstandard |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 18 | class MatchInPorts128(base_tests.SimpleDataPlane): |
| 19 | """ |
| 20 | Match on ingress port bitmap |
| 21 | """ |
| 22 | def runTest(self): |
| 23 | in_port1, in_port2, out_port, bad_port = openflow_ports(4) |
Wilson Ng | 6f53964 | 2013-10-28 18:17:44 -0700 | [diff] [blame] | 24 | table_id = test_param_get("table", 0) |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 25 | |
| 26 | # See the loxigen bsn_in_ports input file for encoding details |
| 27 | match = ofp.match([ |
| 28 | ofp.oxm.bsn_in_ports_128_masked(set(), set(range(0,128)) - set((in_port1,in_port2))) |
| 29 | ]) |
| 30 | |
| 31 | pkt = simple_tcp_packet() |
| 32 | |
| 33 | logging.info("Running match test for %s", match.show()) |
| 34 | |
| 35 | delete_all_flows(self.controller) |
| 36 | |
| 37 | logging.info("Inserting flow sending matching packets to port %d", out_port) |
| 38 | request = ofp.message.flow_add( |
Wilson Ng | 6f53964 | 2013-10-28 18:17:44 -0700 | [diff] [blame] | 39 | table_id=table_id, |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 40 | match=match, |
| 41 | instructions=[ |
| 42 | ofp.instruction.apply_actions( |
| 43 | actions=[ |
| 44 | ofp.action.output( |
| 45 | port=out_port, |
| 46 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 47 | buffer_id=ofp.OFP_NO_BUFFER, |
| 48 | priority=1000) |
| 49 | self.controller.message_send(request) |
| 50 | |
| 51 | logging.info("Inserting match-all flow sending packets to controller") |
| 52 | request = ofp.message.flow_add( |
Wilson Ng | 6f53964 | 2013-10-28 18:17:44 -0700 | [diff] [blame] | 53 | table_id=table_id, |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 54 | instructions=[ |
| 55 | ofp.instruction.apply_actions( |
| 56 | actions=[ |
| 57 | ofp.action.output( |
| 58 | port=ofp.OFPP_CONTROLLER, |
| 59 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 60 | buffer_id=ofp.OFP_NO_BUFFER, |
| 61 | priority=1) |
| 62 | self.controller.message_send(request) |
| 63 | |
| 64 | do_barrier(self.controller) |
| 65 | |
| 66 | pktstr = str(pkt) |
| 67 | |
| 68 | logging.info("Sending packet on matching ingress port, expecting output to port %d", out_port) |
| 69 | self.dataplane.send(in_port1, pktstr) |
| 70 | verify_packets(self, pktstr, [out_port]) |
| 71 | |
| 72 | logging.info("Sending packet on other matching ingress port, expecting output to port %d", out_port) |
| 73 | self.dataplane.send(in_port2, pktstr) |
| 74 | verify_packets(self, pktstr, [out_port]) |
| 75 | |
| 76 | logging.info("Sending packet on non-matching ingress port, expecting packet-in") |
| 77 | self.dataplane.send(bad_port, pktstr) |
| 78 | verify_packet_in(self, pktstr, bad_port, ofp.OFPR_ACTION) |