]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_l3vpn_to_bgp_vrf/customize.py
4 # Part of NetDEF Topology Tests
6 # Copyright (c) 2017 by
7 # Network Device Education Foundation, Inc. ("NetDEF")
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
25 customize.py: Simple FRR/Quagga MPLS L3VPN test topology
32 192.168.1. | .2 ce1-eth0
51 r2-eth2 .2 | | .2 r2-eth1
54 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
56 ~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~
57 ~~~~~~~~~~~~~ ~~~~~~~~~~~~~
61 r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0
62 +----+--+---+ +----+----+
64 | 3.3.3.3 | | 4.4.4.4 |-------+ PE Routers
65 +-----------+ +---------+ |
66 192.168.1.1 |r3.eth4 192.168.1.1 | r4-eth4 |192.168.2.1
67 .2 | ceX-eth0 .2 | | .2
68 +-----+-----+ +----+-----+ +----+-----+
69 | ce2 | | ce3 | | ce4 |
70 | 99.0.0.2 | | 99.0.0.3 | | 99.0.0.4 | CE Routers
71 +-----+-----+ +----+-----+ +----+-----+
81 # pylint: disable=C0413
82 # Import topogen and topotest helpers
83 from lib
import topotest
84 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
85 from lib
.topolog
import logger
86 from lib
.ltemplate
import ltemplateRtrCmd
88 # Required to instantiate the topology builder class.
89 from mininet
.topo
import Topo
92 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
93 # test name based on directory
94 TEST
= os
.path
.basename(CWD
)
96 class ThisTestTopo(Topo
):
97 "Test topology builder"
98 def build(self
, *_args
, **_opts
):
100 tgen
= get_topogen(self
)
102 # This function only purpose is to define allocation and relationship
103 # between routers, switches and hosts.
105 # Create P/PE routers
107 tgen
.add_router('r1')
108 if tgen
.hasmpls
!= True:
109 logger
.info('MPLS not available, tests will be skipped')
111 mach
= platform
.machine()
112 krel
= platform
.release()
113 if mach
[:1] == 'a' and topotest
.version_cmp(krel
, '4.11') < 0:
114 logger
.info('Need Kernel version 4.11 to run on arm processor')
116 for routern
in range(2, 5):
117 tgen
.add_router('r{}'.format(routern
))
119 for routern
in range(1, 5):
120 tgen
.add_router('ce{}'.format(routern
))
123 tgen
.add_link(tgen
.gears
['ce1'], tgen
.gears
['r1'], 'ce1-eth0', 'r1-eth4')
124 tgen
.add_link(tgen
.gears
['ce2'], tgen
.gears
['r3'], 'ce2-eth0', 'r3-eth4')
125 tgen
.add_link(tgen
.gears
['ce3'], tgen
.gears
['r4'], 'ce3-eth0', 'r4-eth4')
126 tgen
.add_link(tgen
.gears
['ce4'], tgen
.gears
['r4'], 'ce4-eth0', 'r4-eth5')
128 # Create a switch with just one router connected to it to simulate a
131 switch
[0] = tgen
.add_switch('sw0')
132 switch
[0].add_link(tgen
.gears
['r1'], nodeif
='r1-eth0')
133 switch
[0].add_link(tgen
.gears
['r2'], nodeif
='r2-eth0')
135 switch
[1] = tgen
.add_switch('sw1')
136 switch
[1].add_link(tgen
.gears
['r2'], nodeif
='r2-eth1')
137 switch
[1].add_link(tgen
.gears
['r3'], nodeif
='r3-eth0')
138 switch
[1].add_link(tgen
.gears
['r4'], nodeif
='r4-eth0')
140 switch
[1] = tgen
.add_switch('sw2')
141 switch
[1].add_link(tgen
.gears
['r2'], nodeif
='r2-eth2')
142 switch
[1].add_link(tgen
.gears
['r3'], nodeif
='r3-eth1')
144 def ltemplatePreRouterStartHook():
145 cc
= ltemplateRtrCmd()
146 krel
= platform
.release()
148 logger
.info('pre router-start hook, kernel=' + krel
)
149 if topotest
.version_cmp(krel
, '4.15') == 0:
153 logger
.info('setting net.ipv4.tcp_l3mdev_accept={}'.format(l3mdev_accept
))
155 if tgen
.hasmpls
!= True:
156 logger
.info('MPLS not available, skipping setup')
158 #check for normal init
159 if len(tgen
.net
) == 1:
160 logger
.info('Topology not configured, skipping setup')
162 #trace errors/unexpected output
164 #configure r2 mpls interfaces
165 intfs
= ['lo', 'r2-eth0', 'r2-eth1', 'r2-eth2']
167 cc
.doCmd(tgen
, 'r2', 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf
))
169 #configure cust1 VRFs & MPLS
170 rtrs
= ['r1', 'r3', 'r4']
171 cmds
= ['ip link add {0}-cust1 type vrf table 10',
172 'ip ru add oif {0}-cust1 table 10',
173 'ip ru add iif {0}-cust1 table 10',
174 'ip link set dev {0}-cust1 up',
175 'sysctl -w net.ipv4.udp_l3mdev_accept={}'.format(l3mdev_accept
)]
177 router
= tgen
.gears
[rtr
]
179 cc
.doCmd(tgen
, rtr
, cmd
.format(rtr
))
180 cc
.doCmd(tgen
, rtr
, 'ip link set dev {0}-eth4 master {0}-cust1'.format(rtr
))
181 intfs
= [rtr
+'-cust1', 'lo', rtr
+'-eth0', rtr
+'-eth4']
183 cc
.doCmd(tgen
, rtr
, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf
))
184 logger
.info('setup {0} vrf {0}-cust1, {0}-eth4. enabled mpls input.'.format(rtr
))
185 #configure cust2 VRFs & MPLS
187 cmds
= ['ip link add {0}-cust2 type vrf table 20',
188 'ip ru add oif {0}-cust2 table 20',
189 'ip ru add iif {0}-cust2 table 20',
190 'ip link set dev {0}-cust2 up']
193 cc
.doCmd(tgen
, rtr
, cmd
.format(rtr
))
194 cc
.doCmd(tgen
, rtr
, 'ip link set dev {0}-eth5 master {0}-cust2'.format(rtr
))
195 intfs
= [rtr
+'-cust2', rtr
+'-eth5']
197 cc
.doCmd(tgen
, rtr
, 'echo 1 > /proc/sys/net/mpls/conf/{}/input'.format(intf
))
198 logger
.info('setup {0} vrf {0}-cust2, {0}-eth5. enabled mpls input.'.format(rtr
))
199 #put ce4-eth0 into a VRF (no default instance!)
201 cmds
= ['ip link add {0}-cust2 type vrf table 20',
202 'ip ru add oif {0}-cust2 table 20',
203 'ip ru add iif {0}-cust2 table 20',
204 'ip link set dev {0}-cust2 up',
205 'sysctl -w net.ipv4.udp_l3mdev_accept={}'.format(l3mdev_accept
)]
208 cc
.doCmd(tgen
, rtr
, cmd
.format(rtr
))
209 cc
.doCmd(tgen
, rtr
, 'ip link set dev {0}-eth0 master {0}-cust2'.format(rtr
))
210 if cc
.getOutput() != 4:
212 logger
.info('Unexpected output seen ({} times, tests will be skipped'.format(cc
.getOutput()))
215 logger
.info('VRF config successful!')
218 def ltemplatePostRouterStartHook():
219 logger
.info('post router-start hook')