1 # Copyright (C) 2017 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 OpenFlow related APIs of ryu.controller module.
22 from ryu.base import app_manager
23 from ryu.lib import hub
24 from ryu.lib import ip
25 from . import ofp_event
31 def register_switch_address(addr, interval=None):
33 Registers a new address to initiate connection to switch.
35 Registers a new IP address and port pair of switch to let
36 ryu.controller.controller.OpenFlowController to try to initiate
39 :param addr: A tuple of (host, port) pair of switch.
40 :param interval: Interval in seconds to try to connect to switch
43 assert ip.valid_ipv4(addr[0]) or ip.valid_ipv6(addr[0])
44 ofp_handler = app_manager.lookup_service_brick(ofp_event.NAME)
45 _TMP_ADDRESSES[addr] = interval
48 # Delays registration if ofp_handler is not started yet
50 if ofp_handler.controller is not None:
51 for a, i in _TMP_ADDRESSES.items():
52 ofp_handler.controller.spawn_client_loop(a, i)
57 hub.spawn(_retry_loop)
60 def unregister_switch_address(addr):
62 Unregister the given switch address.
64 Unregisters the given switch address to let
65 ryu.controller.controller.OpenFlowController stop trying to initiate
68 :param addr: A tuple of (host, port) pair of switch.
70 ofp_handler = app_manager.lookup_service_brick(ofp_event.NAME)
71 # Do nothing if ofp_handler is not started yet
72 if ofp_handler.controller is None:
74 ofp_handler.controller.stop_client_loop(addr)