blob: 296a846e0a3873dde510ce96fce2767a89174d74 [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
17class MatchInPorts128(base_tests.SimpleDataPlane):
18 """
19 Match on ingress port bitmap
20 """
21 def runTest(self):
22 in_port1, in_port2, out_port, bad_port = openflow_ports(4)
Wilson Ng6f539642013-10-28 18:17:44 -070023 table_id = test_param_get("table", 0)
Rich Lane6d9e8e72013-10-22 12:21:03 -070024
25 # See the loxigen bsn_in_ports input file for encoding details
26 match = ofp.match([
27 ofp.oxm.bsn_in_ports_128_masked(set(), set(range(0,128)) - set((in_port1,in_port2)))
28 ])
29
30 pkt = simple_tcp_packet()
31
32 logging.info("Running match test for %s", match.show())
33
34 delete_all_flows(self.controller)
35
36 logging.info("Inserting flow sending matching packets to port %d", out_port)
37 request = ofp.message.flow_add(
Wilson Ng6f539642013-10-28 18:17:44 -070038 table_id=table_id,
Rich Lane6d9e8e72013-10-22 12:21:03 -070039 match=match,
40 instructions=[
41 ofp.instruction.apply_actions(
42 actions=[
43 ofp.action.output(
44 port=out_port,
45 max_len=ofp.OFPCML_NO_BUFFER)])],
46 buffer_id=ofp.OFP_NO_BUFFER,
47 priority=1000)
48 self.controller.message_send(request)
49
50 logging.info("Inserting match-all flow sending packets to controller")
51 request = ofp.message.flow_add(
Wilson Ng6f539642013-10-28 18:17:44 -070052 table_id=table_id,
Rich Lane6d9e8e72013-10-22 12:21:03 -070053 instructions=[
54 ofp.instruction.apply_actions(
55 actions=[
56 ofp.action.output(
57 port=ofp.OFPP_CONTROLLER,
58 max_len=ofp.OFPCML_NO_BUFFER)])],
59 buffer_id=ofp.OFP_NO_BUFFER,
60 priority=1)
61 self.controller.message_send(request)
62
63 do_barrier(self.controller)
64
65 pktstr = str(pkt)
66
67 logging.info("Sending packet on matching ingress port, expecting output to port %d", out_port)
68 self.dataplane.send(in_port1, pktstr)
69 verify_packets(self, pktstr, [out_port])
70
71 logging.info("Sending packet on other matching ingress port, expecting output to port %d", out_port)
72 self.dataplane.send(in_port2, pktstr)
73 verify_packets(self, pktstr, [out_port])
74
75 logging.info("Sending packet on non-matching ingress port, expecting packet-in")
76 self.dataplane.send(bad_port, pktstr)
77 verify_packet_in(self, pktstr, bad_port, ofp.OFPR_ACTION)