summaryrefslogtreecommitdiffhomepage
path: root/doc/source/test-vrrp.rst
blob: 6e3783a1902f0e3d36824e069bc372cc94c88b6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
===================
Testing VRRP Module
===================

This page describes how to test Ryu VRRP service

Running integrated tests
========================

Some testing scripts are available.

* ryu/tests/integrated/test_vrrp_linux_multi.py
* ryu/tests/integrated/test_vrrp_multi.py

Each files include how to run in the comment.
Please refer to it.


Running multiple Ryu VRRP in network namespace
==============================================

The following command lines set up necessary bridges and interfaces.

And then run RYU-VRRP::

    # ip netns add gateway1
    # ip netns add gateway2

    # brctl addbr vrrp-br0
    # brctl addbr vrrp-br1

    # ip link add veth0 type veth peer name veth0-br0
    # ip link add veth1 type veth peer name veth1-br0
    # ip link add veth2 type veth peer name veth2-br0
    # ip link add veth3 type veth peer name veth3-br1
    # ip link add veth4 type veth peer name veth4-br1
    # ip link add veth5 type veth peer name veth5-br1

    # brctl addif vrrp-br0 veth0-br0
    # brctl addif vrrp-br0 veth1-br0
    # brctl addif vrrp-br0 veth2-br0
    # brctl addif vrrp-br1 veth3-br1
    # brctl addif vrrp-br1 veth4-br1
    # brctl addif vrrp-br1 veth5-br1

    # ip link set vrrp-br0 up
    # ip link set vrrp-br1 up

    # ip link set veth0 up
    # ip link set veth0-br0 up
    # ip link set veth1-br0 up
    # ip link set veth2-br0 up
    # ip link set veth3-br1 up
    # ip link set veth4-br1 up
    # ip link set veth5 up
    # ip link set veth5-br1 up

    # ip link set veth1 netns gateway1
    # ip link set veth2 netns gateway2
    # ip link set veth3 netns gateway1
    # ip link set veth4 netns gateway2

    # ip netns exec gateway1 ip link set veth1 up
    # ip netns exec gateway2 ip link set veth2 up
    # ip netns exec gateway1 ip link set veth3 up
    # ip netns exec gateway2 ip link set veth4 up

    # ip netns exec gateway1 .ryu-vrrp veth1 '10.0.0.2' 254
    # ip netns exec gateway2 .ryu-vrrp veth2 '10.0.0.3' 100


.. admonition:: Caveats

   Please make sure that all interfaces and bridges are UP.
   Don't forget interfaces in netns gateway1/gateway2.

::

                    ^ veth5
                    |
                    V veth5-br1
            -----------------------
            |Linux Brirge vrrp-br1|
            -----------------------
     veth3-br1^            ^ veth4-br1
              |            |
         veth3V            V veth4
         ----------       ----------
         |netns   |       |netns   |
         |gateway1|       |gateway2|
         |ryu-vrrp|       |ryu-vrrp|
         ----------       ----------
         veth1^            ^ veth2
              |            |
     veth1-br0V            V veth2-br0
            -----------------------
            |Linux Brirge vrrp-br0|
            -----------------------
                    ^ veth0-br0
                    |
                    V veth0



Here's the helper executable, ryu-vrrp::

    #!/usr/bin/env python
    #
    # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
    # Copyright (C) 2013 Isaku Yamahata <yamahata at valinux co jp>
    #
    # Licensed under the Apache License, Version 2.0 (the "License");
    # you may not use this file except in compliance with the License.
    # You may obtain a copy of the License at
    #
    #    http://www.apache.org/licenses/LICENSE-2.0
    #
    # Unless required by applicable law or agreed to in writing, software
    # distributed under the License is distributed on an "AS IS" BASIS,
    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    # implied.
    # See the License for the specific language governing permissions and
    # limitations under the License.
    
    from ryu.lib import hub
    hub.patch()
    
    # TODO:
    #   Right now, we have our own patched copy of ovs python bindings
    #   Once our modification is upstreamed and widely deployed,
    #   use it
    #
    # NOTE: this modifies sys.path and thus affects the following imports.
    # eg. oslo.config.cfg.
    import ryu.contrib
    
    from oslo.config import cfg
    import logging
    import netaddr
    import sys
    import time
    
    from ryu import log
    log.early_init_log(logging.DEBUG)
    
    from ryu import flags
    from ryu import version
    from ryu.base import app_manager
    from ryu.controller import controller
    from ryu.lib import mac as lib_mac
    from ryu.lib.packet import vrrp
    from ryu.services.protocols.vrrp import api as vrrp_api
    from ryu.services.protocols.vrrp import event as vrrp_event
    
    
    CONF = cfg.CONF
    
    _VRID = 7
    _IP_ADDRESS = '10.0.0.1'
    _PRIORITY = 100
    
    
    class VRRPTestRouter(app_manager.RyuApp):
        def __init__(self, *args, **kwargs):
            super(VRRPTestRouter, self).__init__(*args, **kwargs)
            print args
            self.logger.debug('vrrp_config %s', args)
            self._ifname = args[0]
            self._primary_ip_address = args[1]
            self._priority = int(args[2])
    
        def start(self):
            print 'start'
            hub.spawn(self._main)
    
        def _main(self):
            print self
            interface = vrrp_event.VRRPInterfaceNetworkDevice(
                lib_mac.DONTCARE, self._primary_ip_address, None, self._ifname)
            self.logger.debug('%s', interface)
    
            ip_addresses = [_IP_ADDRESS]
            config = vrrp_event.VRRPConfig(
                version=vrrp.VRRP_VERSION_V3, vrid=_VRID, priority=self._priority,
                ip_addresses=ip_addresses)
            self.logger.debug('%s', config)
    
            rep = vrrp_api.vrrp_config(self, interface, config)
            self.logger.debug('%s', rep)
    
    
    def main():
        vrrp_config = sys.argv[-3:]
        sys.argv = sys.argv[:-3]
        CONF(project='ryu', version='ryu-vrrp %s' % version)
    
        log.init_log()
        # always enable ofp for now.
        app_lists = ['ryu.services.protocols.vrrp.manager',
                     'ryu.services.protocols.vrrp.dumper',
                     'ryu.services.protocols.vrrp.sample_manager']
    
        app_mgr = app_manager.AppManager.get_instance()
        app_mgr.load_apps(app_lists)
        contexts = app_mgr.create_contexts()
        app_mgr.instantiate_apps(**contexts)
        vrrp_router = app_mgr.instantiate(VRRPTestRouter, *vrrp_config, **contexts)
        vrrp_router.start()
    
        while True:
            time.sleep(999999)
    
        app_mgr.close()
    
    
    if __name__ == "__main__":
        main()