1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2012 Isaku Yamahata <yamahata at valinux co jp>
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 A dumb OpenFlow 1.0 responder for benchmarking the controller framework.
19 Intended to be used with oflops cbench.
22 from ryu.base import app_manager
23 from ryu.controller import ofp_event
24 from ryu.controller.handler import MAIN_DISPATCHER
25 from ryu.controller.handler import set_ev_cls
26 from ryu.ofproto import ofproto_v1_0
29 class Cbench(app_manager.RyuApp):
30 OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
32 def __init__(self, *args, **kwargs):
33 super(Cbench, self).__init__(*args, **kwargs)
35 @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
36 def packet_in_handler(self, ev):
38 datapath = msg.datapath
39 ofproto = datapath.ofproto
41 match = datapath.ofproto_parser.OFPMatch(
42 ofproto_v1_0.OFPFW_ALL, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0)
45 mod = datapath.ofproto_parser.OFPFlowMod(
46 datapath, match=match, cookie=0, command=ofproto.OFPFC_ADD,
47 idle_timeout=0, hard_timeout=0,
48 priority=ofproto.OFP_DEFAULT_PRIORITY,
49 flags=0, actions=None)
50 datapath.send_msg(mod)