backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / app / ofctl / api.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2014 YAMAMOTO Takashi <yamamoto 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 # client for ryu.app.ofctl.service
18
19 from ryu.base import app_manager
20 from . import event
21
22
23 def get_datapath(app, dpid=None):
24     """
25     Get datapath object by dpid.
26
27     :param app: Client RyuApp instance
28     :param dpid: Datapath ID (int type) or None to get all datapath objects
29
30     Returns a object of datapath, a list of datapath objects when no dpid
31     given or None when error.
32
33     Raises an exception if any of the given values is invalid.
34
35     Example::
36
37         # ...(snip)...
38         import ryu.app.ofctl.api as ofctl_api
39
40
41         class MyApp(app_manager.RyuApp):
42
43             def _my_handler(self, ev):
44                 # Get all datapath objects
45                 result = ofctl_api.get_datapath(self)
46
47                 # Get the datapath object which has the given dpid
48                 result = ofctl_api.get_datapath(self, dpid=1)
49     """
50     return app.send_request(event.GetDatapathRequest(dpid=dpid))()
51
52
53 def send_msg(app, msg, reply_cls=None, reply_multi=False):
54     """
55     Send an OpenFlow message and wait for reply messages.
56
57     :param app: Client RyuApp instance
58     :param msg: An OpenFlow controller-to-switch message to send
59     :param reply_cls: OpenFlow message class for expected replies.
60         None means no replies are expected.  The default is None.
61     :param reply_multi: True if multipart replies are expected.
62         The default is False.
63
64     If no replies, returns None.
65     If reply_multi=False, returns OpenFlow switch-to-controller message.
66     If reply_multi=True, returns a list of OpenFlow switch-to-controller
67     messages.
68
69     Raise an exception on error.
70
71     Example::
72
73         # ...(snip)...
74         import ryu.app.ofctl.api as ofctl_api
75
76
77         class MyApp(app_manager.RyuApp):
78
79             def _my_handler(self, ev):
80                 # ...(snip)...
81                 msg = parser.OFPPortDescStatsRequest(datapath=datapath)
82                 result = ofctl_api.send_msg(
83                     self, msg,
84                     reply_cls=parser.OFPPortDescStatsReply,
85                     reply_multi=True)
86     """
87     return app.send_request(event.SendMsgRequest(msg=msg,
88                                                  reply_cls=reply_cls,
89                                                  reply_multi=reply_multi))()
90
91
92 app_manager.require_app('ryu.app.ofctl.service', api_style=True)