forked from Maxmawt/LINGI2142-IPMininet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple_topo_med.py
80 lines (69 loc) · 3.13 KB
/
simple_topo_med.py
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
from ipmininet.iptopo import IPTopo
from ipmininet.router.config import BGP, ebgp_session, AccessList, AF_INET6
class SimpleBGPTopoMed(IPTopo):
"""This topology is composed of two AS connected in dual homing
with a higher MED for routes from as4r1 than from as4r2.
Thus, all the traffic coming from AS1 will go through the link
between as1r5 and as4r2."""
def build(self, *args, **kwargs):
"""
+
AS1 | AS4
+-------+ |
| as1r1 +--------+ |
+---+---+ | |
2 | | |
+---+---+ +---+---+ | +-------+
| as1r3 +----+ as1r6 +-------+ as4r1 +--------+
+---+---+ +---+---+ | +-------+ |
| | | |
+---+---+ | | +--+--+ +-------+
| as1r2 | | | | s4 +-----+ as4h1 |
+---+---+ | | +--+--+ +-------+
4 | | | |
+---+---+ +---+---+ | +-------+ |
| as1r4 +----+ as1r5 +-------+ as4r2 +--------+
+-------+ +-------+ | +-------+
|
+
"""
# Add all routers
as1r1 = self.bgp('as1r1')
as1r2 = self.bgp('as1r2')
as1r3 = self.bgp('as1r3')
as1r4 = self.bgp('as1r4')
as1r5 = self.bgp('as1r5', family=AF_INET6(redistribute=('ospf6', 'connected')))
as1r6 = self.bgp('as1r6', family=AF_INET6(redistribute=('ospf6', 'connected')))
as4r1 = self.bgp('as4r1', family=AF_INET6(networks=('dead:beef::/32',)))
as4r2 = self.bgp('as4r2', family=AF_INET6(networks=('dead:beef::/32',)))
# Add the host and the switch
as4h1 = self.addHost('as4h1')
switch = self.addSwitch('s4')
# Add Links
self.addLink(as1r1, as1r6)
self.addLink(as1r1, as1r3, igp_metric=2)
self.addLink(as1r3, as1r2)
self.addLink(as1r3, as1r6)
self.addLink(as1r2, as1r4, igp_metric=4)
self.addLink(as1r4, as1r5)
self.addLink(as1r5, as1r6)
self.addLink(as4r1, as1r6)
self.addLink(as4r2, as1r5)
self.addLink(as4r1, switch)
self.addLink(as4r2, switch)
self.addLink(switch, as4h1)
self.addSubnet((as4r1, as4r2, as4h1), subnets=('dead:beef::/32',))
al = AccessList(name='all', entries=('any',))
as4r1.get_config(BGP).set_med(99, to_peer=as1r6, matching=(al, ))
as4r2.get_config(BGP).set_med(50, to_peer=as1r5, matching=(al, ))
# Add full mesh
self.addAS(4, (as4r1, as4r2))
self.addiBGPFullMesh(1, (as1r1, as1r2, as1r3, as1r4, as1r5, as1r6))
# Add eBGP session
ebgp_session(self, as1r6, as4r1)
ebgp_session(self, as1r5, as4r2)
super(SimpleBGPTopoMed, self).build(*args, **kwargs)
def bgp(self, name, family=AF_INET6()):
r = self.addRouter(name)
r.addDaemon(BGP, address_families=(family,))
return r