backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / topology / event.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 #
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
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
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
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import logging
17 from ryu.controller import handler
18 from ryu.controller import event
19
20 LOG = logging.getLogger(__name__)
21
22
23 class EventSwitchBase(event.EventBase):
24     def __init__(self, switch):
25         super(EventSwitchBase, self).__init__()
26         self.switch = switch
27
28     def __str__(self):
29         return '%s<dpid=%s, %s ports>' % \
30             (self.__class__.__name__,
31              self.switch.dp.id, len(self.switch.ports))
32
33
34 class EventSwitchEnter(EventSwitchBase):
35     def __init__(self, switch):
36         super(EventSwitchEnter, self).__init__(switch)
37
38
39 class EventSwitchLeave(EventSwitchBase):
40     def __init__(self, switch):
41         super(EventSwitchLeave, self).__init__(switch)
42
43
44 class EventSwitchReconnected(EventSwitchBase):
45     def __init__(self, switch):
46         super(EventSwitchReconnected, self).__init__(switch)
47
48
49 class EventPortBase(event.EventBase):
50     def __init__(self, port):
51         super(EventPortBase, self).__init__()
52         self.port = port
53
54     def __str__(self):
55         return '%s<%s>' % (self.__class__.__name__, self.port)
56
57
58 class EventPortAdd(EventPortBase):
59     def __init__(self, port):
60         super(EventPortAdd, self).__init__(port)
61
62
63 class EventPortDelete(EventPortBase):
64     def __init__(self, port):
65         super(EventPortDelete, self).__init__(port)
66
67
68 class EventPortModify(EventPortBase):
69     def __init__(self, port):
70         super(EventPortModify, self).__init__(port)
71
72
73 class EventSwitchRequest(event.EventRequestBase):
74     # If dpid is None, reply all list
75     def __init__(self, dpid=None):
76         super(EventSwitchRequest, self).__init__()
77         self.dst = 'switches'
78         self.dpid = dpid
79
80     def __str__(self):
81         return 'EventSwitchRequest<src=%s, dpid=%s>' % \
82             (self.src, self.dpid)
83
84
85 class EventSwitchReply(event.EventReplyBase):
86     def __init__(self, dst, switches):
87         super(EventSwitchReply, self).__init__(dst)
88         self.switches = switches
89
90     def __str__(self):
91         return 'EventSwitchReply<dst=%s, %s>' % \
92             (self.dst, self.switches)
93
94
95 class EventLinkBase(event.EventBase):
96     def __init__(self, link):
97         super(EventLinkBase, self).__init__()
98         self.link = link
99
100     def __str__(self):
101         return '%s<%s>' % (self.__class__.__name__, self.link)
102
103
104 class EventLinkAdd(EventLinkBase):
105     def __init__(self, link):
106         super(EventLinkAdd, self).__init__(link)
107
108
109 class EventLinkDelete(EventLinkBase):
110     def __init__(self, link):
111         super(EventLinkDelete, self).__init__(link)
112
113
114 class EventLinkRequest(event.EventRequestBase):
115     # If dpid is None, reply all list
116     def __init__(self, dpid=None):
117         super(EventLinkRequest, self).__init__()
118         self.dst = 'switches'
119         self.dpid = dpid
120
121     def __str__(self):
122         return 'EventLinkRequest<src=%s, dpid=%s>' % \
123             (self.src, self.dpid)
124
125
126 class EventLinkReply(event.EventReplyBase):
127     def __init__(self, dst, dpid, links):
128         super(EventLinkReply, self).__init__(dst)
129         self.dpid = dpid
130         self.links = links
131
132     def __str__(self):
133         return 'EventLinkReply<dst=%s, dpid=%s, links=%s>' % \
134             (self.dst, self.dpid, len(self.links))
135
136
137 class EventHostRequest(event.EventRequestBase):
138     # if dpid is None, replay all hosts
139     def __init__(self, dpid=None):
140         super(EventHostRequest, self).__init__()
141         self.dst = 'switches'
142         self.dpid = dpid
143
144     def __str__(self):
145         return 'EventHostRequest<src=%s, dpid=%s>' % \
146             (self.src, self.dpid)
147
148
149 class EventHostReply(event.EventReplyBase):
150     def __init__(self, dst, dpid, hosts):
151         super(EventHostReply, self).__init__(dst)
152         self.dpid = dpid
153         self.hosts = hosts
154
155     def __str__(self):
156         return 'EventHostReply<dst=%s, dpid=%s, hosts=%s>' % \
157             (self.dst, self.dpid, len(self.hosts))
158
159
160 class EventHostBase(event.EventBase):
161     def __init__(self, host):
162         super(EventHostBase, self).__init__()
163         self.host = host
164
165     def __str__(self):
166         return '%s<%s>' % (self.__class__.__name__, self.host)
167
168
169 class EventHostAdd(EventHostBase):
170     def __init__(self, host):
171         super(EventHostAdd, self).__init__(host)
172
173
174 # Note: Currently, EventHostDelete will never be raised, because we have no
175 # appropriate way to detect the disconnection of hosts. Just defined for
176 # future use.
177 class EventHostDelete(EventHostBase):
178     def __init__(self, host):
179         super(EventHostDelete, self).__init__(host)
180
181
182 class EventHostMove(event.EventBase):
183     def __init__(self, src, dst):
184         super(EventHostMove, self).__init__()
185         self.src = src
186         self.dst = dst
187
188     def __str__(self):
189         return '%s<src=%s, dst=%s>' % (
190             self.__class__.__name__, self.src, self.dst)
191
192
193 handler.register_service('ryu.topology.switches')