backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / app / ofctl / event.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 import numbers
18
19 from ryu.controller import event
20
21
22 # base classes
23
24 class _RequestBase(event.EventRequestBase):
25     def __init__(self):
26         self.dst = 'ofctl_service'
27
28
29 class _ReplyBase(event.EventReplyBase):
30     pass
31
32
33 # get datapath
34
35 class GetDatapathRequest(_RequestBase):
36     def __init__(self, dpid=None):
37         assert dpid is None or isinstance(dpid, numbers.Integral)
38         super(GetDatapathRequest, self).__init__()
39         self.dpid = dpid
40
41
42 # send msg
43
44 class SendMsgRequest(_RequestBase):
45     def __init__(self, msg, reply_cls=None, reply_multi=False):
46         super(SendMsgRequest, self).__init__()
47         self.msg = msg
48         self.reply_cls = reply_cls
49         self.reply_multi = reply_multi
50
51
52 # generic reply
53
54 class Reply(_ReplyBase):
55     def __init__(self, result=None, exception=None):
56         self.result = result
57         self.exception = exception
58
59     def __call__(self):
60         if self.exception:
61             raise self.exception
62         return self.result