blob: 5bcbca4e45a0e369990b81200f537e961f2838c4 [file] [log] [blame]
Rich Lane6d9e8e72013-10-22 12:21:03 -07001# Distributed under the OpenFlow Software License (see LICENSE)
2# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
3"""
4Test the bsn_in_ports_128 OXM, which enables the controller to specify a bitmap
5of allowed input ports.
6"""
7
8import logging
9
10from oftest import config
11import oftest.base_tests as base_tests
12import ofp
13import oftest.packet as scapy
14
15from oftest.testutils import *
16
Rich Lanee0aef812014-07-21 18:01:15 -070017@nonstandard
Rich Lane6d9e8e72013-10-22 12:21:03 -070018class 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 Ng6f539642013-10-28 18:17:44 -070024 table_id = test_param_get("table", 0)
Rich Lane6d9e8e72013-10-22 12:21:03 -070025
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 Ng6f539642013-10-28 18:17:44 -070039 table_id=table_id,
Rich Lane6d9e8e72013-10-22 12:21:03 -070040 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 Ng6f539642013-10-28 18:17:44 -070053 table_id=table_id,
Rich Lane6d9e8e72013-10-22 12:21:03 -070054 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)