5 This page describes how to test Ryu VRRP service
7 Running integrated tests
8 ========================
10 Some testing scripts are available.
12 * ryu/tests/integrated/test_vrrp_linux_multi.py
13 * ryu/tests/integrated/test_vrrp_multi.py
15 Each files include how to run in the comment.
19 Running multiple Ryu VRRP in network namespace
20 ==============================================
22 The following command lines set up necessary bridges and interfaces.
24 And then run RYU-VRRP::
26 # ip netns add gateway1
27 # ip netns add gateway2
29 # brctl addbr vrrp-br0
30 # brctl addbr vrrp-br1
32 # ip link add veth0 type veth peer name veth0-br0
33 # ip link add veth1 type veth peer name veth1-br0
34 # ip link add veth2 type veth peer name veth2-br0
35 # ip link add veth3 type veth peer name veth3-br1
36 # ip link add veth4 type veth peer name veth4-br1
37 # ip link add veth5 type veth peer name veth5-br1
39 # brctl addif vrrp-br0 veth0-br0
40 # brctl addif vrrp-br0 veth1-br0
41 # brctl addif vrrp-br0 veth2-br0
42 # brctl addif vrrp-br1 veth3-br1
43 # brctl addif vrrp-br1 veth4-br1
44 # brctl addif vrrp-br1 veth5-br1
46 # ip link set vrrp-br0 up
47 # ip link set vrrp-br1 up
49 # ip link set veth0 up
50 # ip link set veth0-br0 up
51 # ip link set veth1-br0 up
52 # ip link set veth2-br0 up
53 # ip link set veth3-br1 up
54 # ip link set veth4-br1 up
55 # ip link set veth5 up
56 # ip link set veth5-br1 up
58 # ip link set veth1 netns gateway1
59 # ip link set veth2 netns gateway2
60 # ip link set veth3 netns gateway1
61 # ip link set veth4 netns gateway2
63 # ip netns exec gateway1 ip link set veth1 up
64 # ip netns exec gateway2 ip link set veth2 up
65 # ip netns exec gateway1 ip link set veth3 up
66 # ip netns exec gateway2 ip link set veth4 up
68 # ip netns exec gateway1 .ryu-vrrp veth1 '10.0.0.2' 254
69 # ip netns exec gateway2 .ryu-vrrp veth2 '10.0.0.3' 100
72 .. admonition:: Caveats
74 Please make sure that all interfaces and bridges are UP.
75 Don't forget interfaces in netns gateway1/gateway2.
82 -----------------------
83 |Linux Brirge vrrp-br1|
84 -----------------------
85 veth3-br1^ ^ veth4-br1
95 veth1-br0V V veth2-br0
96 -----------------------
97 |Linux Brirge vrrp-br0|
98 -----------------------
105 Here's the helper executable, ryu-vrrp::
107 #!/usr/bin/env python
109 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
110 # Copyright (C) 2013 Isaku Yamahata <yamahata at valinux co jp>
112 # Licensed under the Apache License, Version 2.0 (the "License");
113 # you may not use this file except in compliance with the License.
114 # You may obtain a copy of the License at
116 # http://www.apache.org/licenses/LICENSE-2.0
118 # Unless required by applicable law or agreed to in writing, software
119 # distributed under the License is distributed on an "AS IS" BASIS,
120 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
122 # See the License for the specific language governing permissions and
123 # limitations under the License.
125 from ryu.lib import hub
129 # Right now, we have our own patched copy of ovs python bindings
130 # Once our modification is upstreamed and widely deployed,
133 # NOTE: this modifies sys.path and thus affects the following imports.
134 # eg. oslo.config.cfg.
137 from oslo.config import cfg
144 log.early_init_log(logging.DEBUG)
146 from ryu import flags
147 from ryu import version
148 from ryu.base import app_manager
149 from ryu.controller import controller
150 from ryu.lib import mac as lib_mac
151 from ryu.lib.packet import vrrp
152 from ryu.services.protocols.vrrp import api as vrrp_api
153 from ryu.services.protocols.vrrp import event as vrrp_event
159 _IP_ADDRESS = '10.0.0.1'
163 class VRRPTestRouter(app_manager.RyuApp):
164 def __init__(self, *args, **kwargs):
165 super(VRRPTestRouter, self).__init__(*args, **kwargs)
167 self.logger.debug('vrrp_config %s', args)
168 self._ifname = args[0]
169 self._primary_ip_address = args[1]
170 self._priority = int(args[2])
174 hub.spawn(self._main)
178 interface = vrrp_event.VRRPInterfaceNetworkDevice(
179 lib_mac.DONTCARE, self._primary_ip_address, None, self._ifname)
180 self.logger.debug('%s', interface)
182 ip_addresses = [_IP_ADDRESS]
183 config = vrrp_event.VRRPConfig(
184 version=vrrp.VRRP_VERSION_V3, vrid=_VRID, priority=self._priority,
185 ip_addresses=ip_addresses)
186 self.logger.debug('%s', config)
188 rep = vrrp_api.vrrp_config(self, interface, config)
189 self.logger.debug('%s', rep)
193 vrrp_config = sys.argv[-3:]
194 sys.argv = sys.argv[:-3]
195 CONF(project='ryu', version='ryu-vrrp %s' % version)
198 # always enable ofp for now.
199 app_lists = ['ryu.services.protocols.vrrp.manager',
200 'ryu.services.protocols.vrrp.dumper',
201 'ryu.services.protocols.vrrp.sample_manager']
203 app_mgr = app_manager.AppManager.get_instance()
204 app_mgr.load_apps(app_lists)
205 contexts = app_mgr.create_contexts()
206 app_mgr.instantiate_apps(**contexts)
207 vrrp_router = app_mgr.instantiate(VRRPTestRouter, *vrrp_config, **contexts)
216 if __name__ == "__main__":