Matteo Scandolo | a229eca | 2017-08-08 13:05:28 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 17 | # Distributed under the OpenFlow Software License (see LICENSE) |
| 18 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
| 19 | """ |
| 20 | Test the bsn_in_ports_128 OXM, which enables the controller to specify a bitmap |
| 21 | of allowed input ports. |
| 22 | """ |
| 23 | |
| 24 | import logging |
| 25 | |
| 26 | from oftest import config |
| 27 | import oftest.base_tests as base_tests |
| 28 | import ofp |
| 29 | import oftest.packet as scapy |
| 30 | |
| 31 | from oftest.testutils import * |
| 32 | |
Rich Lane | e0aef81 | 2014-07-21 18:01:15 -0700 | [diff] [blame] | 33 | @nonstandard |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 34 | class MatchInPorts128(base_tests.SimpleDataPlane): |
| 35 | """ |
| 36 | Match on ingress port bitmap |
| 37 | """ |
| 38 | def runTest(self): |
| 39 | in_port1, in_port2, out_port, bad_port = openflow_ports(4) |
Wilson Ng | 6f53964 | 2013-10-28 18:17:44 -0700 | [diff] [blame] | 40 | table_id = test_param_get("table", 0) |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 41 | |
| 42 | # See the loxigen bsn_in_ports input file for encoding details |
| 43 | match = ofp.match([ |
| 44 | ofp.oxm.bsn_in_ports_128_masked(set(), set(range(0,128)) - set((in_port1,in_port2))) |
| 45 | ]) |
| 46 | |
| 47 | pkt = simple_tcp_packet() |
| 48 | |
| 49 | logging.info("Running match test for %s", match.show()) |
| 50 | |
| 51 | delete_all_flows(self.controller) |
| 52 | |
| 53 | logging.info("Inserting flow sending matching packets to port %d", out_port) |
| 54 | request = ofp.message.flow_add( |
Wilson Ng | 6f53964 | 2013-10-28 18:17:44 -0700 | [diff] [blame] | 55 | table_id=table_id, |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 56 | match=match, |
| 57 | instructions=[ |
| 58 | ofp.instruction.apply_actions( |
| 59 | actions=[ |
| 60 | ofp.action.output( |
| 61 | port=out_port, |
| 62 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 63 | buffer_id=ofp.OFP_NO_BUFFER, |
| 64 | priority=1000) |
| 65 | self.controller.message_send(request) |
| 66 | |
| 67 | logging.info("Inserting match-all flow sending packets to controller") |
| 68 | request = ofp.message.flow_add( |
Wilson Ng | 6f53964 | 2013-10-28 18:17:44 -0700 | [diff] [blame] | 69 | table_id=table_id, |
Rich Lane | 6d9e8e7 | 2013-10-22 12:21:03 -0700 | [diff] [blame] | 70 | instructions=[ |
| 71 | ofp.instruction.apply_actions( |
| 72 | actions=[ |
| 73 | ofp.action.output( |
| 74 | port=ofp.OFPP_CONTROLLER, |
| 75 | max_len=ofp.OFPCML_NO_BUFFER)])], |
| 76 | buffer_id=ofp.OFP_NO_BUFFER, |
| 77 | priority=1) |
| 78 | self.controller.message_send(request) |
| 79 | |
| 80 | do_barrier(self.controller) |
| 81 | |
| 82 | pktstr = str(pkt) |
| 83 | |
| 84 | logging.info("Sending packet on matching ingress port, expecting output to port %d", out_port) |
| 85 | self.dataplane.send(in_port1, pktstr) |
| 86 | verify_packets(self, pktstr, [out_port]) |
| 87 | |
| 88 | logging.info("Sending packet on other matching ingress port, expecting output to port %d", out_port) |
| 89 | self.dataplane.send(in_port2, pktstr) |
| 90 | verify_packets(self, pktstr, [out_port]) |
| 91 | |
| 92 | logging.info("Sending packet on non-matching ingress port, expecting packet-in") |
| 93 | self.dataplane.send(bad_port, pktstr) |
| 94 | verify_packet_in(self, pktstr, bad_port, ofp.OFPR_ACTION) |