]>
Commit | Line | Data |
---|---|---|
db2dbd24 LB |
1 | #!/usr/bin/env python |
2 | ||
3 | # | |
4 | # Part of NetDEF Topology Tests | |
5 | # | |
6 | # Copyright (c) 2017 by | |
7 | # Network Device Education Foundation, Inc. ("NetDEF") | |
8 | # | |
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 | |
12 | # in all copies. | |
13 | # | |
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 | |
21 | # OF THIS SOFTWARE. | |
22 | # | |
23 | ||
21b5cd1d | 24 | r""" |
622c4996 | 25 | customize.py: Simple FRR MPLS L3VPN test topology |
db2dbd24 LB |
26 | |
27 | | | |
28 | +----+----+ | |
29 | | ce1 | | |
30 | | 99.0.0.1| CE Router | |
31 | +----+----+ | |
32 | 192.168.1. | .2 ce1-eth0 | |
33 | | .1 r1-eth4 | |
34 | +---------+ | |
35 | | r1 | | |
36 | | 1.1.1.1 | PE Router | |
37 | +----+----+ | |
38 | | .1 r1-eth0 | |
39 | | | |
40 | ~~~~~~~~~~~~~ | |
41 | ~~ sw0 ~~ | |
42 | ~~ 10.0.1.0/24 ~~ | |
43 | ~~~~~~~~~~~~~ | |
44 | |10.0.1.0/24 | |
45 | | | |
46 | | .2 r2-eth0 | |
47 | +----+----+ | |
48 | | r2 | | |
49 | | 2.2.2.2 | P router | |
50 | +--+---+--+ | |
51 | r2-eth2 .2 | | .2 r2-eth1 | |
52 | ______/ \______ | |
53 | / \ | |
54 | ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ | |
55 | ~~ sw2 ~~ ~~ sw1 ~~ | |
56 | ~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~ | |
57 | ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ | |
58 | | / | | |
59 | \ _________/ | | |
60 | \ / \ | |
61 | r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 | |
62 | +----+--+---+ +----+----+ | |
63 | | r3 | | r4 | | |
64 | | 3.3.3.3 | | 4.4.4.4 | PE Routers | |
65 | +-----------+ +---------+ | |
66 | 192.168.1. | .1 192.168.1. | .1 rX-eth4 | |
67 | | .2 | .2 ceX-eth0 | |
68 | +-----+-----+ +----+-----+ | |
69 | | ce2 | | ce3 | | |
70 | | 99.0.0.2 | | 99.0.0.3 | CE Routers | |
71 | +-----+-----+ +----+-----+ | |
72 | | | | |
73 | ||
74 | """ | |
75 | ||
76 | import os | |
db2dbd24 LB |
77 | |
78 | # pylint: disable=C0413 | |
79 | # Import topogen and topotest helpers | |
4953ca97 | 80 | from lib.topogen import get_topogen |
db2dbd24 | 81 | from lib.topolog import logger |
a209417d | 82 | from lib.ltemplate import ltemplateRtrCmd |
db2dbd24 LB |
83 | |
84 | # Required to instantiate the topology builder class. | |
db2dbd24 | 85 | |
787e7624 | 86 | |
db2dbd24 LB |
87 | CWD = os.path.dirname(os.path.realpath(__file__)) |
88 | # test name based on directory | |
89 | TEST = os.path.basename(CWD) | |
90 | ||
787e7624 | 91 | |
e82b531d CH |
92 | def build_topo(tgen): |
93 | "Build function" | |
94 | ||
95 | # This function only purpose is to define allocation and relationship | |
96 | # between routers, switches and hosts. | |
97 | # | |
98 | # Create P/PE routers | |
99 | tgen.add_router("r1") | |
100 | # check for mpls | |
101 | if tgen.hasmpls != True: | |
102 | logger.info("MPLS not available, tests will be skipped") | |
103 | return | |
104 | for routern in range(2, 5): | |
105 | tgen.add_router("r{}".format(routern)) | |
106 | # Create CE routers | |
107 | for routern in range(1, 4): | |
108 | tgen.add_router("ce{}".format(routern)) | |
109 | ||
110 | # CE/PE links | |
111 | tgen.add_link(tgen.gears["ce1"], tgen.gears["r1"], "ce1-eth0", "r1-eth4") | |
112 | tgen.add_link(tgen.gears["ce2"], tgen.gears["r3"], "ce2-eth0", "r3-eth4") | |
113 | tgen.add_link(tgen.gears["ce3"], tgen.gears["r4"], "ce3-eth0", "r4-eth4") | |
114 | ||
115 | # Create a switch with just one router connected to it to simulate a | |
116 | # empty network. | |
117 | switch = {} | |
118 | switch[0] = tgen.add_switch("sw0") | |
119 | switch[0].add_link(tgen.gears["r1"], nodeif="r1-eth0") | |
120 | switch[0].add_link(tgen.gears["r2"], nodeif="r2-eth0") | |
121 | ||
122 | switch[1] = tgen.add_switch("sw1") | |
123 | switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth1") | |
124 | switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth0") | |
125 | switch[1].add_link(tgen.gears["r4"], nodeif="r4-eth0") | |
126 | ||
127 | switch[1] = tgen.add_switch("sw2") | |
128 | switch[1].add_link(tgen.gears["r2"], nodeif="r2-eth2") | |
129 | switch[1].add_link(tgen.gears["r3"], nodeif="r3-eth1") | |
db2dbd24 | 130 | |
db2dbd24 | 131 | |
3eff4cc9 | 132 | def ltemplatePreRouterStartHook(): |
a209417d | 133 | cc = ltemplateRtrCmd() |
c30e3e40 | 134 | tgen = get_topogen() |
787e7624 | 135 | logger.info("pre router-start hook") |
136 | # check for mpls | |
d868d685 | 137 | if tgen.hasmpls != True: |
787e7624 | 138 | logger.info("MPLS not available, skipping setup") |
a209417d | 139 | return False |
787e7624 | 140 | logger.info("setup mpls input") |
a209417d | 141 | return True |
c30e3e40 | 142 | |
787e7624 | 143 | |
3eff4cc9 | 144 | def ltemplatePostRouterStartHook(): |
787e7624 | 145 | logger.info("post router-start hook") |
a209417d | 146 | return True |