forked from cnp3/IPMininet-iBGP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_bgp_community_prepend_as_2.py
96 lines (91 loc) · 3.83 KB
/
simple_bgp_community_prepend_as_2.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
from ipmininet.router.config import BGP, CommunityList
from ipmininet.router.config.zebra import RouteMapSetAction
from simple_bgp_network import SimpleBGPTopo
class PrependAS2Topo(SimpleBGPTopo):
def create_community_lists(self):
community_list = CommunityList(
'prepend-as-once-list', community='2:90')
community_list_2 = CommunityList(
'prepend-as-twice-list', community='2:91')
return [community_list_2, community_list]
def set_route_maps_for_community(self, community_list, as1r1, as2r1, as2r2, as3r1):
if community_list.name == 'prepend-as-once-list':
for route_map_name in ['as3r1-ipv4-out', 'as3r1-ipv6-out']:
as2r2.get_config(BGP).permit(
name=route_map_name,
from_peer=as2r2,
to_peer=as3r1,
matching=(community_list,),
order=20
)
as2r2.get_config(BGP).add_set_action(
name=route_map_name,
direction='out',
peer=as3r1,
matching=(community_list,),
set_action=RouteMapSetAction(
'as-path',
'prepend 2'
)
)
self.route_map_add_exit_policy(
as2r2, route_map_name, route_map_order=20, exit_policy='goto 100')
as2r2.get_config(BGP).permit(
name=route_map_name,
from_peer=as2r2,
to_peer=as3r1,
matching=(community_list,),
order=120
)
as2r2.get_config(BGP).add_set_action(
name=route_map_name,
direction='out',
peer=as3r1,
matching=(community_list,),
set_action=RouteMapSetAction(
'comm-list',
f'{community_list.name} delete'
)
)
self.route_map_add_exit_policy(
as2r2, route_map_name, route_map_order=120, exit_policy='next')
if community_list.name == 'prepend-as-twice-list':
for route_map_name in ['as3r1-ipv4-out', 'as3r1-ipv6-out']:
as2r2.get_config(BGP).permit(
name=route_map_name,
from_peer=as2r2,
to_peer=as3r1,
matching=(community_list,),
order=10
)
as2r2.get_config(BGP).add_set_action(
name=route_map_name,
direction='out',
peer=as3r1,
matching=(community_list,),
set_action=RouteMapSetAction(
'as-path',
'prepend 2 2'
)
)
self.route_map_add_exit_policy(
as2r2, route_map_name, route_map_order=10, exit_policy='goto 100')
as2r2.get_config(BGP).permit(
name=route_map_name,
from_peer=as2r2,
to_peer=as3r1,
matching=(community_list,),
order=110
)
as2r2.get_config(BGP).add_set_action(
name=route_map_name,
direction='out',
peer=as3r1,
matching=(community_list,),
set_action=RouteMapSetAction(
'comm-list',
f'{community_list.name} delete'
)
)
self.route_map_add_exit_policy(
as2r2, route_map_name, route_map_order=110, exit_policy='next')