1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013 Isaku Yamahata <yamahata at valinux co jp>
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 PYTHONPATH=. ./bin/ryu-manager --verbose \
20 ryu.topology.switches \
21 ryu.tests.integrated.test_vrrp_multi \
22 ryu.services.protocols.vrrp.dumper
24 ryu.services.protocols.vrrp.dumper is optional.
26 +---+ ----------------
28 Ryu +---+ | linux bridge |<--veth--> command to generate packets
30 +---+ ----------------
32 configure OVSs to connect ryu
35 # ip link add veth0-ovs type veth peer name veth0-br
36 # ip link add veth1-ovs type veth peer name veth1-br
37 # brctl addif b0 veth0-br
38 # brctl addif b0 veth1-br
40 bridge name bridge id STP enabled interfaces
41 b0 8000.6642e5822497 no veth0-br
43 ovs-system 0000.122038293b55 no
46 # ovs-vsctl add-port s0 veth0-ovs
48 # ovs-vsctl add-port s1 veth1-ovs
49 # ovs-vsctl set-controller s0 tcp:127.0.0.1:6633
50 # ovs-vsctl set bridge s0 protocols='[OpenFlow12]'
51 # ovs-vsctl set-controller s1 tcp:127.0.0.1:6633
52 # ovs-vsctl set bridge s1 protocols='[OpenFlow12]'
54 20c2a046-ae7e-4453-a576-11034db24985
57 Controller "tcp:127.0.0.1:6633"
65 Controller "tcp:127.0.0.1:6633"
73 # ip link veth0-br set up
74 # ip link veth0-ovs set up
75 # ip link veth1-br set up
76 # ip link veth1-ovs set up
80 from ryu.base import app_manager
81 from ryu.controller import handler
82 from ryu.lib import dpid as lib_dpid
83 from ryu.lib import hub
84 from ryu.lib.packet import vrrp
85 from ryu.services.protocols.vrrp import api as vrrp_api
86 from ryu.services.protocols.vrrp import event as vrrp_event
87 from ryu.services.protocols.vrrp import monitor_openflow
88 from ryu.topology import event as topo_event
89 from ryu.topology import api as topo_api
91 from . import vrrp_common
94 class VRRPConfigApp(vrrp_common.VRRPCommon):
98 def __init__(self, *args, **kwargs):
99 super(VRRPConfigApp, self).__init__(*args, **kwargs)
100 self.start_main = False
102 @handler.set_ev_cls(topo_event.EventSwitchEnter)
103 def _switch_enter_handler(self, ev):
107 switches = topo_api.get_switch(self)
108 if len(switches) < 2:
111 self.start_main = True
112 app_mgr = app_manager.AppManager.get_instance()
113 self.logger.debug('%s', app_mgr.applications)
114 self.switches = app_mgr.applications['switches']
115 hub.spawn(self._main)
117 def _configure_vrrp_router(self, vrrp_version, priority,
118 ip_addr, switch_index, vrid):
119 switches = self.switches
120 self.logger.debug('%s', switches.dps)
121 dpid = sorted(switches.dps.keys())[switch_index]
122 self.logger.debug('%s', lib_dpid.dpid_to_str(dpid))
123 self.logger.debug('%s', switches.port_state)
124 # hack: use the smallest port no to avoid picking OVS local port
125 port_no = sorted(switches.port_state[dpid].keys())[0]
126 self.logger.debug('%d', port_no)
127 port = switches.port_state[dpid][port_no]
128 self.logger.debug('%s', port)
130 self.logger.debug('%s', mac)
132 interface = vrrp_event.VRRPInterfaceOpenFlow(
133 mac, ip_addr, None, dpid, port_no)
134 self.logger.debug('%s', interface)
136 config = vrrp_event.VRRPConfig(
137 version=vrrp_version, vrid=vrid, priority=priority,
138 ip_addresses=[ip_addr])
139 self.logger.debug('%s', config)
141 rep = vrrp_api.vrrp_config(self, interface, config)
142 self.logger.debug('%s', rep)