|
1
|
|
|
# encoding: utf-8 |
|
2
|
|
|
""" |
|
3
|
|
|
announce/vpn.py |
|
4
|
|
|
|
|
5
|
|
|
Created by Thomas Mangin on 2017-07-09. |
|
6
|
|
|
Copyright (c) 2009-2017 Exa Networks. All rights reserved. |
|
7
|
|
|
License: 3-clause BSD. (See the COPYRIGHT file) |
|
8
|
|
|
""" |
|
9
|
|
|
|
|
10
|
|
|
from exabgp.rib.change import Change |
|
11
|
|
|
|
|
12
|
|
|
from exabgp.bgp.message import OUT |
|
13
|
|
|
|
|
14
|
|
|
from exabgp.protocol.family import AFI |
|
15
|
|
|
from exabgp.protocol.family import SAFI |
|
16
|
|
|
|
|
17
|
|
|
from exabgp.bgp.message.update.nlri import VPLS |
|
18
|
|
|
from exabgp.bgp.message.update.attribute import Attributes |
|
19
|
|
|
|
|
20
|
|
|
from exabgp.configuration.announce import ParseAnnounce |
|
21
|
|
|
|
|
22
|
|
|
from exabgp.configuration.static.parser import attribute |
|
23
|
|
|
from exabgp.configuration.static.parser import origin |
|
24
|
|
|
from exabgp.configuration.static.parser import med |
|
25
|
|
|
from exabgp.configuration.static.parser import as_path |
|
26
|
|
|
from exabgp.configuration.static.parser import local_preference |
|
27
|
|
|
from exabgp.configuration.static.parser import atomic_aggregate |
|
28
|
|
|
from exabgp.configuration.static.parser import aggregator |
|
29
|
|
|
from exabgp.configuration.static.parser import originator_id |
|
30
|
|
|
from exabgp.configuration.static.parser import cluster_list |
|
31
|
|
|
from exabgp.configuration.static.parser import community |
|
32
|
|
|
from exabgp.configuration.static.parser import extended_community |
|
33
|
|
|
from exabgp.configuration.static.parser import name as named |
|
34
|
|
|
from exabgp.configuration.static.parser import split |
|
35
|
|
|
from exabgp.configuration.static.parser import watchdog |
|
36
|
|
|
from exabgp.configuration.static.parser import withdraw |
|
37
|
|
|
|
|
38
|
|
|
from exabgp.configuration.static.mpls import route_distinguisher |
|
39
|
|
|
|
|
40
|
|
|
from exabgp.configuration.l2vpn.parser import vpls |
|
41
|
|
|
from exabgp.configuration.l2vpn.parser import vpls_endpoint |
|
42
|
|
|
from exabgp.configuration.l2vpn.parser import vpls_size |
|
43
|
|
|
from exabgp.configuration.l2vpn.parser import vpls_offset |
|
44
|
|
|
from exabgp.configuration.l2vpn.parser import vpls_base |
|
45
|
|
|
from exabgp.configuration.l2vpn.parser import next_hop |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
class AnnounceVPLS (ParseAnnounce): |
|
49
|
|
|
definition = [ |
|
50
|
|
|
'endpoint <vpls endpoint id; integer>', |
|
51
|
|
|
'base <label base; integer>', |
|
52
|
|
|
'offset <block offet; interger>', |
|
53
|
|
|
'size <block size; integer>', |
|
54
|
|
|
|
|
55
|
|
|
'next-hop <ip>', |
|
56
|
|
|
'med <16 bits number>', |
|
57
|
|
|
'rd <ipv4>:<port>|<16bits number>:<32bits number>|<32bits number>:<16bits number>', |
|
58
|
|
|
'origin IGP|EGP|INCOMPLETE', |
|
59
|
|
|
'as-path [ <asn>.. ]', |
|
60
|
|
|
'local-preference <16 bits number>', |
|
61
|
|
|
'atomic-aggregate', |
|
62
|
|
|
'community <16 bits number>', |
|
63
|
|
|
'extended-community target:<16 bits number>:<ipv4 formated number>', |
|
64
|
|
|
'originator-id <ipv4>', |
|
65
|
|
|
'cluster-list <ipv4>', |
|
66
|
|
|
'label <15 bits number>', |
|
67
|
|
|
'attribute [ generic attribute format ]' |
|
68
|
|
|
'name <mnemonic>', |
|
69
|
|
|
'split /<mask>', |
|
70
|
|
|
'watchdog <watchdog-name>', |
|
71
|
|
|
'withdraw', |
|
72
|
|
|
] |
|
73
|
|
|
|
|
74
|
|
|
syntax = \ |
|
75
|
|
|
'vpls %s\n' % ' '.join(definition) |
|
76
|
|
|
|
|
77
|
|
|
known = { |
|
78
|
|
|
'rd': route_distinguisher, |
|
79
|
|
|
'attribute': attribute, |
|
80
|
|
|
'next-hop': next_hop, |
|
81
|
|
|
'origin': origin, |
|
82
|
|
|
'med': med, |
|
83
|
|
|
'as-path': as_path, |
|
84
|
|
|
'local-preference': local_preference, |
|
85
|
|
|
'atomic-aggregate': atomic_aggregate, |
|
86
|
|
|
'aggregator': aggregator, |
|
87
|
|
|
'originator-id': originator_id, |
|
88
|
|
|
'cluster-list': cluster_list, |
|
89
|
|
|
'community': community, |
|
90
|
|
|
'extended-community': extended_community, |
|
91
|
|
|
'name': named, |
|
92
|
|
|
'split': split, |
|
93
|
|
|
'watchdog': watchdog, |
|
94
|
|
|
'withdraw': withdraw, |
|
95
|
|
|
'endpoint': vpls_endpoint, |
|
96
|
|
|
'offset': vpls_offset, |
|
97
|
|
|
'size': vpls_size, |
|
98
|
|
|
'base': vpls_base, |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
action = { |
|
102
|
|
|
'attribute': 'attribute-add', |
|
103
|
|
|
'origin': 'attribute-add', |
|
104
|
|
|
'med': 'attribute-add', |
|
105
|
|
|
'as-path': 'attribute-add', |
|
106
|
|
|
'local-preference': 'attribute-add', |
|
107
|
|
|
'atomic-aggregate': 'attribute-add', |
|
108
|
|
|
'aggregator': 'attribute-add', |
|
109
|
|
|
'originator-id': 'attribute-add', |
|
110
|
|
|
'cluster-list': 'attribute-add', |
|
111
|
|
|
'community': 'attribute-add', |
|
112
|
|
|
'extended-community': 'attribute-add', |
|
113
|
|
|
'name': 'attribute-add', |
|
114
|
|
|
'split': 'attribute-add', |
|
115
|
|
|
'watchdog': 'attribute-add', |
|
116
|
|
|
'withdraw': 'attribute-add', |
|
117
|
|
|
'next-hop': 'nlri-set', |
|
118
|
|
|
'route-distinguisher': 'nlri-set', |
|
119
|
|
|
'rd': 'nlri-set', |
|
120
|
|
|
'endpoint': 'nlri-set', |
|
121
|
|
|
'offset': 'nlri-set', |
|
122
|
|
|
'size': 'nlri-set', |
|
123
|
|
|
'base': 'nlri-set', |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
assign = { |
|
127
|
|
|
'next-hop': 'nexthop', |
|
128
|
|
|
'rd': 'rd', |
|
129
|
|
|
'route-distinguisher': 'rd', |
|
130
|
|
|
'endpoint': 'endpoint', |
|
131
|
|
|
'offset': 'offset', |
|
132
|
|
|
'size': 'size', |
|
133
|
|
|
'base': 'base', |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
name = 'vpls' |
|
137
|
|
|
afi = None |
|
138
|
|
|
|
|
139
|
|
|
def __init__ (self, tokeniser, scope, error, logger): |
|
140
|
|
|
ParseAnnounce.__init__(self,tokeniser,scope,error,logger) |
|
141
|
|
|
|
|
142
|
|
|
def clear (self): |
|
143
|
|
|
return True |
|
144
|
|
|
|
|
145
|
|
|
def post (self): |
|
146
|
|
|
return self._check() |
|
147
|
|
|
|
|
148
|
|
|
@staticmethod |
|
149
|
|
|
def check (change,afi): |
|
150
|
|
|
# No check performed :-( |
|
151
|
|
|
return True |
|
152
|
|
|
|
|
153
|
|
|
|
|
154
|
|
View Code Duplication |
def l2vpn_vpls (tokeniser,afi,safi): |
|
|
|
|
|
|
155
|
|
|
change = Change( |
|
156
|
|
|
VPLS(None,None,None,None,None), |
|
157
|
|
|
Attributes() |
|
158
|
|
|
) |
|
159
|
|
|
|
|
160
|
|
|
while True: |
|
161
|
|
|
command = tokeniser() |
|
162
|
|
|
|
|
163
|
|
|
if not command: |
|
164
|
|
|
break |
|
165
|
|
|
|
|
166
|
|
|
action = AnnounceVPLS.action[command] |
|
167
|
|
|
|
|
168
|
|
|
if 'nlri-set' in action: |
|
169
|
|
|
change.nlri.assign(AnnounceVPLS.assign[command],AnnounceVPLS.known[command](tokeniser)) |
|
170
|
|
|
elif 'attribute-add' in action: |
|
171
|
|
|
change.attributes.add(AnnounceVPLS.known[command](tokeniser)) |
|
172
|
|
|
elif action == 'nexthop-and-attribute': |
|
173
|
|
|
nexthop,attribute = AnnounceVPLS.known[command](tokeniser) |
|
174
|
|
|
change.nlri.nexthop = nexthop |
|
175
|
|
|
change.attributes.add(attribute) |
|
176
|
|
|
else: |
|
177
|
|
|
raise ValueError('vpls: unknown command "%s"' % command) |
|
178
|
|
|
|
|
179
|
|
|
return [change,] |
|
180
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
@ParseAnnounce.register('vpls','extend-name','l2vpn') |
|
183
|
|
|
def vpls_v4 (tokeniser): |
|
184
|
|
|
return l2vpn_vpls(tokeniser,AFI.l2vpn,SAFI.vpls) |
|
185
|
|
|
|