backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / app / cbench.py
1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2012 Isaku Yamahata <yamahata at valinux co jp>
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
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 """
18 A dumb OpenFlow 1.0 responder for benchmarking the controller framework.
19 Intended to be used with oflops cbench.
20 """
21
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
27
28
29 class Cbench(app_manager.RyuApp):
30     OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
31
32     def __init__(self, *args, **kwargs):
33         super(Cbench, self).__init__(*args, **kwargs)
34
35     @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
36     def packet_in_handler(self, ev):
37         msg = ev.msg
38         datapath = msg.datapath
39         ofproto = datapath.ofproto
40
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)
44
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)