blob: eddcc5a8cd520aa30ab13e0eca0a4fd671df3dab [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)
23
24 # See the loxigen bsn_in_ports input file for encoding details
25 match = ofp.match([
26 ofp.oxm.bsn_in_ports_128_masked(set(), set(range(0,128)) - set((in_port1,in_port2)))
27 ])
28
29 pkt = simple_tcp_packet()
30
31 logging.info("Running match test for %s", match.show())
32
33 delete_all_flows(self.controller)
34
35 logging.info("Inserting flow sending matching packets to port %d", out_port)
36 request = ofp.message.flow_add(
37 table_id=0,
38 match=match,
39 instructions=[
40 ofp.instruction.apply_actions(
41 actions=[
42 ofp.action.output(
43 port=out_port,
44 max_len=ofp.OFPCML_NO_BUFFER)])],
45 buffer_id=ofp.OFP_NO_BUFFER,
46 priority=1000)
47 self.controller.message_send(request)
48
49 logging.info("Inserting match-all flow sending packets to controller")
50 request = ofp.message.flow_add(
51 table_id=0,
52 instructions=[
53 ofp.instruction.apply_actions(
54 actions=[
55 ofp.action.output(
56 port=ofp.OFPP_CONTROLLER,
57 max_len=ofp.OFPCML_NO_BUFFER)])],
58 buffer_id=ofp.OFP_NO_BUFFER,
59 priority=1)
60 self.controller.message_send(request)
61
62 do_barrier(self.controller)
63
64 pktstr = str(pkt)
65
66 logging.info("Sending packet on matching ingress port, expecting output to port %d", out_port)
67 self.dataplane.send(in_port1, pktstr)
68 verify_packets(self, pktstr, [out_port])
69
70 logging.info("Sending packet on other matching ingress port, expecting output to port %d", out_port)
71 self.dataplane.send(in_port2, pktstr)
72 verify_packets(self, pktstr, [out_port])
73
74 logging.info("Sending packet on non-matching ingress port, expecting packet-in")
75 self.dataplane.send(bad_port, pktstr)
76 verify_packet_in(self, pktstr, bad_port, ofp.OFPR_ACTION)