1 # Copyright (C) 2013 Stratosphere Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # vim: tabstop=4 shiftwidth=4 softtabstop=4
22 from nose.tools import *
24 from ryu.controller import ofp_event
25 from ryu.controller.handler import (
29 from ryu.lib.packet import vlan, ethernet, ipv4
30 from ryu.lib.ofp_pktinfilter import packet_in_filter, RequiredTypeFilter
31 from ryu.lib import mac
32 from ryu.ofproto import ether, ofproto_v1_3, ofproto_v1_3_parser
33 from ryu.ofproto.ofproto_protocol import ProtocolDesc
36 LOG = logging.getLogger('test_pktinfilter')
39 class _PacketInFilterApp(object):
40 @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
41 @packet_in_filter(RequiredTypeFilter, {'types': [
44 def packet_in_handler(self, ev):
48 class Test_packet_in_filter(unittest.TestCase):
50 """ Test case for pktinfilter
54 self.app = _PacketInFilterApp()
59 def test_pkt_in_filter_pass(self):
60 datapath = ProtocolDesc(version=ofproto_v1_3.OFP_VERSION)
61 e = ethernet.ethernet(mac.BROADCAST_STR,
68 pkt_in = ofproto_v1_3_parser.OFPPacketIn(datapath,
69 data=six.binary_type(pkt.data))
70 ev = ofp_event.EventOFPPacketIn(pkt_in)
71 ok_(self.app.packet_in_handler(ev))
73 def test_pkt_in_filter_discard(self):
74 datapath = ProtocolDesc(version=ofproto_v1_3.OFP_VERSION)
75 e = ethernet.ethernet(mac.BROADCAST_STR,
81 pkt_in = ofproto_v1_3_parser.OFPPacketIn(datapath,
82 data=six.binary_type(pkt.data))
83 ev = ofp_event.EventOFPPacketIn(pkt_in)
84 ok_(not self.app.packet_in_handler(ev))
86 def test_pkt_in_filter_truncated(self):
87 datapath = ProtocolDesc(version=ofproto_v1_3.OFP_VERSION)
89 pkt_in = ofproto_v1_3_parser.OFPPacketIn(datapath,
91 ev = ofp_event.EventOFPPacketIn(pkt_in)
92 ok_(not self.app.packet_in_handler(ev))