blob: a58315b050feaf7ef00678fc9f0697596f3f262c [file] [log] [blame]
Matteo Scandoloa229eca2017-08-08 13:05:28 -07001
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 Lane6d9e8e72013-10-22 12:21:03 -070017# Distributed under the OpenFlow Software License (see LICENSE)
18# Copyright (c) 2012, 2013 Big Switch Networks, Inc.
19"""
20Test the bsn_in_ports_128 OXM, which enables the controller to specify a bitmap
21of allowed input ports.
22"""
23
24import logging
25
26from oftest import config
27import oftest.base_tests as base_tests
28import ofp
29import oftest.packet as scapy
30
31from oftest.testutils import *
32
Rich Lanee0aef812014-07-21 18:01:15 -070033@nonstandard
Rich Lane6d9e8e72013-10-22 12:21:03 -070034class 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 Ng6f539642013-10-28 18:17:44 -070040 table_id = test_param_get("table", 0)
Rich Lane6d9e8e72013-10-22 12:21:03 -070041
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 Ng6f539642013-10-28 18:17:44 -070055 table_id=table_id,
Rich Lane6d9e8e72013-10-22 12:21:03 -070056 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 Ng6f539642013-10-28 18:17:44 -070069 table_id=table_id,
Rich Lane6d9e8e72013-10-22 12:21:03 -070070 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)