1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
17 from ryu.controller import handler
18 from ryu.controller import event
20 LOG = logging.getLogger(__name__)
23 class EventSwitchBase(event.EventBase):
24 def __init__(self, switch):
25 super(EventSwitchBase, self).__init__()
29 return '%s<dpid=%s, %s ports>' % \
30 (self.__class__.__name__,
31 self.switch.dp.id, len(self.switch.ports))
34 class EventSwitchEnter(EventSwitchBase):
35 def __init__(self, switch):
36 super(EventSwitchEnter, self).__init__(switch)
39 class EventSwitchLeave(EventSwitchBase):
40 def __init__(self, switch):
41 super(EventSwitchLeave, self).__init__(switch)
44 class EventSwitchReconnected(EventSwitchBase):
45 def __init__(self, switch):
46 super(EventSwitchReconnected, self).__init__(switch)
49 class EventPortBase(event.EventBase):
50 def __init__(self, port):
51 super(EventPortBase, self).__init__()
55 return '%s<%s>' % (self.__class__.__name__, self.port)
58 class EventPortAdd(EventPortBase):
59 def __init__(self, port):
60 super(EventPortAdd, self).__init__(port)
63 class EventPortDelete(EventPortBase):
64 def __init__(self, port):
65 super(EventPortDelete, self).__init__(port)
68 class EventPortModify(EventPortBase):
69 def __init__(self, port):
70 super(EventPortModify, self).__init__(port)
73 class EventSwitchRequest(event.EventRequestBase):
74 # If dpid is None, reply all list
75 def __init__(self, dpid=None):
76 super(EventSwitchRequest, self).__init__()
81 return 'EventSwitchRequest<src=%s, dpid=%s>' % \
85 class EventSwitchReply(event.EventReplyBase):
86 def __init__(self, dst, switches):
87 super(EventSwitchReply, self).__init__(dst)
88 self.switches = switches
91 return 'EventSwitchReply<dst=%s, %s>' % \
92 (self.dst, self.switches)
95 class EventLinkBase(event.EventBase):
96 def __init__(self, link):
97 super(EventLinkBase, self).__init__()
101 return '%s<%s>' % (self.__class__.__name__, self.link)
104 class EventLinkAdd(EventLinkBase):
105 def __init__(self, link):
106 super(EventLinkAdd, self).__init__(link)
109 class EventLinkDelete(EventLinkBase):
110 def __init__(self, link):
111 super(EventLinkDelete, self).__init__(link)
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'
122 return 'EventLinkRequest<src=%s, dpid=%s>' % \
123 (self.src, self.dpid)
126 class EventLinkReply(event.EventReplyBase):
127 def __init__(self, dst, dpid, links):
128 super(EventLinkReply, self).__init__(dst)
133 return 'EventLinkReply<dst=%s, dpid=%s, links=%s>' % \
134 (self.dst, self.dpid, len(self.links))
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'
145 return 'EventHostRequest<src=%s, dpid=%s>' % \
146 (self.src, self.dpid)
149 class EventHostReply(event.EventReplyBase):
150 def __init__(self, dst, dpid, hosts):
151 super(EventHostReply, self).__init__(dst)
156 return 'EventHostReply<dst=%s, dpid=%s, hosts=%s>' % \
157 (self.dst, self.dpid, len(self.hosts))
160 class EventHostBase(event.EventBase):
161 def __init__(self, host):
162 super(EventHostBase, self).__init__()
166 return '%s<%s>' % (self.__class__.__name__, self.host)
169 class EventHostAdd(EventHostBase):
170 def __init__(self, host):
171 super(EventHostAdd, self).__init__(host)
174 # Note: Currently, EventHostDelete will never be raised, because we have no
175 # appropriate way to detect the disconnection of hosts. Just defined for
177 class EventHostDelete(EventHostBase):
178 def __init__(self, host):
179 super(EventHostDelete, self).__init__(host)
182 class EventHostMove(event.EventBase):
183 def __init__(self, src, dst):
184 super(EventHostMove, self).__init__()
189 return '%s<src=%s, dst=%s>' % (
190 self.__class__.__name__, self.src, self.dst)
193 handler.register_service('ryu.topology.switches')