-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_exabgp_demo.py
123 lines (106 loc) Β· 3.19 KB
/
test_exabgp_demo.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2018-2021 Bruno Bernard for NetDEF, Inc.
"""
Demo testing of ExaBGP
"""
# pylint: disable=unused-wildcard-import,wildcard-import,unused-argument,redefined-outer-name,attribute-defined-outside-init
from topotato import *
from topotato.exabgp import ExaBGP
@topology_fixture()
def topology(topo):
"""
[ r1 ]
|
{ s1 }---[ r3 ]
|
[ r2 ]
"""
class Configs(FRRConfigs):
routers = ["r1", "r2", "r3"]
zebra = """
#% extends "boilerplate.conf"
#% block main
#% for iface in router.ifaces
interface {{ iface.ifname }}
ip address {{ iface.ip4[0] }}
!
#% endfor
ip forwarding
!
#% endblock
"""
bgpd = """
#% block main
#% if router.name == 'r1'
router bgp 65534
no bgp ebgp-requires-policy
neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} remote-as 65001
neighbor {{ routers.r2.ifaces[0].ip4[0].ip }} timers 3 10
neighbor {{ routers.r3.ifaces[0].ip4[0].ip }} remote-as 65002
neighbor {{ routers.r3.ifaces[0].ip4[0].ip }} timers 3 10
!
#% endif
#% endblock
"""
class ExaBGPDemo(TestBase, AutoFixture, topo=topology, configs=Configs):
@topotatofunc
def prepare(self, r2, r3):
configuration = """
neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} {
router-id {{ routers.r2.ifaces[0].ip4[0].ip }};
local-address {{ routers.r2.ifaces[0].ip4[0].ip }};
local-as 65001;
peer-as 65534;
}
"""
self.peer = ExaBGP(r2, configuration)
yield from self.peer.start()
configuration2 = """
neighbor {{ routers.r1.ifaces[0].ip4[0].ip }} {
router-id {{ routers.r3.ifaces[0].ip4[0].ip }};
local-address {{ routers.r3.ifaces[0].ip4[0].ip }};
local-as 65002;
peer-as 65534;
}
"""
self.peer2 = ExaBGP(r3, configuration2)
yield from self.peer2.start()
@topotatofunc
def bgp_check(self, r1, r2, r3):
expected = {
"ipv4Unicast": {
"peers": {
f"{r2.ifaces[0].ip4[0].ip}": {"state": "Established"},
f"{r3.ifaces[0].ip4[0].ip}": {"state": "Established"},
}
}
}
yield from AssertVtysh.make(
r1, "bgpd", "show ip bgp summary json", maxwait=5.0, compare=expected
)
@topotatofunc
def exabgp_announcement(self, r1):
yield from self.peer2.execute(
f"neighbor {r1.ifaces[0].ip4[0].ip} announce route 100.10.0.0/24 next-hop self"
)
expected = {
"routes": {
"100.10.0.0/24": [
{
"valid": True,
"network": "100.10.0.0/24",
"peerId": "10.101.0.3",
"path": "65002",
"origin": "IGP",
"nexthops": [
{
"ip": "10.101.0.3",
}
],
}
]
}
}
yield from AssertVtysh.make(
r1, "bgpd", "show ip bgp json", maxwait=5.0, compare=expected
)