backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / tests / integrated / test_vrrp_linux_multi.py
1 # Copyright (C) 2013 Nippon Telegraph and Telephone Corporation.
2 # Copyright (C) 2013 Isaku Yamahata <yamahata at valinux co jp>
3 #
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
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
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
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 r"""
18 Usage:
19 PYTHONPATH=. ./bin/ryu-manager --verbose \
20              ryu.services.protocols.vrrp.dumper \
21              ryu.services.protocols.vrrp.sample_manager.py \
22              ryu.tests.integrated.test_vrrp_linux_multi \
23              ryu.app.rest
24
25 ryu.services.protocols.vrrp.dumper is optional.
26 ryu.app.rest is merely to prevent ryu-manager from exiting.
27
28                     ----------------
29       /--<--veth0-->|              |
30    Ryu              | linux bridge |<--veth2--> command to generate packets
31       \--<--veth1-->|   (vrrpbr)   |
32                     ----------------
33
34
35 # ip link add veth0 type veth peer name veth0-br
36 # ip link add veth1 type veth peer name veth1-br
37 # ip link add veth2 type veth peer name veth2-br
38
39 # brctl addbr vrrpbr
40 # brctl addif vrrpbr veth0-br
41 # brctl addif vrrpbr veth1-br
42 # brctl addif vrrpbr veth2-br
43
44
45 # ip link set veth0 up
46 # ip link set veth0-br up
47 # ip link set veth1 up
48 # ip link set veth1-br up
49 # ip link set veth2 up
50 # ip link set veth2-br up
51 # ip link set vrrpbr up
52
53 if you like, capture packets on each interfaces like
54 # tshark -i vrrpbr
55 # tshark -i veth0
56 # tshark -i veth1
57 # tshark -i veth2
58
59 virtual router mac address: 00:00:5E:00:01:{VRID} = 00:00:5E:00:01:07
60 during working, send packets destined to mac address 00:00:5E:00:01:07
61 from veth2 by packet generator like packeth
62
63 NOTE: vrid: 7 and ip address: 10.0.0.1... are hardcoded below
64 """
65
66 from ryu.base import app_manager
67 from ryu.lib import hub
68 from ryu.lib import mac as lib_mac
69 from ryu.lib.packet import vrrp
70 from ryu.services.protocols.vrrp import api as vrrp_api
71 from ryu.services.protocols.vrrp import event as vrrp_event
72 from ryu.services.protocols.vrrp import monitor_linux
73
74 from . import vrrp_common
75
76
77 class VRRPConfigApp(vrrp_common.VRRPCommon):
78     _IFNAME0 = 'veth0'
79     _IFNAME1 = 'veth1'
80
81     def __init__(self, *args, **kwargs):
82         super(VRRPConfigApp, self).__init__(*args, **kwargs)
83
84     def start(self):
85         hub.spawn(self._main)
86
87     def _configure_vrrp_router(self, vrrp_version, priority,
88                                primary_ip_address, ifname, vrid):
89         interface = vrrp_event.VRRPInterfaceNetworkDevice(
90             lib_mac.DONTCARE_STR, primary_ip_address, None, ifname)
91         self.logger.debug('%s', interface)
92
93         vip = '10.0.%d.1' % vrid
94         ip_addresses = [vip]
95         config = vrrp_event.VRRPConfig(
96             version=vrrp_version, vrid=vrid, priority=priority,
97             ip_addresses=ip_addresses)
98         self.logger.debug('%s', config)
99
100         rep = vrrp_api.vrrp_config(self, interface, config)
101         self.logger.debug('%s', rep)
102
103         return rep