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