@@ -18,7 +18,7 @@ const (
18
18
19
19
type rib struct {
20
20
path * bgpapi.Path
21
- vrfID string
21
+ vpnID string
22
22
}
23
23
24
24
// BgpRouteManager advertize and withdraw routes by BGP
@@ -56,8 +56,8 @@ func NewBgpRouteManager(as string, ras string) *BgpRouteManager {
56
56
return b
57
57
}
58
58
59
- //CreateVrfNetwork create vrf in BGP server and start monitoring vrf rib if vrfID ="", network use global rib
60
- func (b * BgpRouteManager ) CreateVrfNetwork (parentIface string , vrfID string ) error {
59
+ //CreateVrfNetwork create vrf in BGP server and start monitoring vrf rib if vpnID ="", network use global rib
60
+ func (b * BgpRouteManager ) CreateVrfNetwork (parentIface string , vpnID string ) error {
61
61
log .Debugf ("BGP Global config : %v" , b .bgpGlobalcfg )
62
62
if b .bgpGlobalcfg == nil {
63
63
log .Debugf ("BGP Global config is emply set config" )
@@ -78,35 +78,35 @@ func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vrfID string) err
78
78
break
79
79
}
80
80
}
81
- if vrfID == "" {
81
+ if vpnID == "" {
82
82
log .Debugf ("vrf ID is empty. network paths are in global rib" )
83
83
return nil
84
84
}
85
- b .parentIfaces [vrfID ] = parentIface
85
+ b .parentIfaces [vpnID ] = parentIface
86
86
err := cleanExistingRoutes (parentIface )
87
87
if err != nil {
88
88
log .Debugf ("Error cleaning old routes: %s" , err )
89
89
return err
90
90
}
91
- rdrtstr := strconv .Itoa (b .asnum ) + ":" + vrfID
91
+ rdrtstr := strconv .Itoa (b .asnum ) + ":" + vpnID
92
92
rd , err := bgp .ParseRouteDistinguisher (rdrtstr )
93
93
if err != nil {
94
- log .Errorf ("Fail to parse RD from vrfID %s : %s" , vrfID , err )
94
+ log .Errorf ("Fail to parse RD from vpnID %s : %s" , vpnID , err )
95
95
return err
96
96
}
97
97
rdSerialized , _ := rd .Serialize ()
98
98
99
99
rt , err := bgp .ParseRouteTarget (rdrtstr )
100
100
if err != nil {
101
- log .Errorf ("Fail to parse RT from vrfID %s : %s" , vrfID , err )
101
+ log .Errorf ("Fail to parse RT from vpnID %s : %s" , vpnID , err )
102
102
return err
103
103
}
104
104
rtSerialized , _ := rt .Serialize ()
105
105
var rts [][]byte
106
106
rts = append (rts , rtSerialized )
107
107
108
108
arg := & bgpapi.Vrf {
109
- Name : bgpVrfprefix + vrfID ,
109
+ Name : bgpVrfprefix + vpnID ,
110
110
Rd : rdSerialized ,
111
111
ImportRt : rts ,
112
112
ExportRt : rts ,
@@ -116,8 +116,8 @@ func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vrfID string) err
116
116
return err
117
117
}
118
118
go func () {
119
- err := b .monitorBestPath (vrfID )
120
- log .Errorf ("faital monitoring VrfID %s rib : %v" , vrfID , err )
119
+ err := b .monitorBestPath (vpnID )
120
+ log .Errorf ("faital monitoring VpnID %s rib : %v" , vpnID , err )
121
121
}()
122
122
return nil
123
123
}
@@ -143,7 +143,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
143
143
bgpCache := & ribCache {
144
144
BgpTable : make (map [string ]* ribLocal ),
145
145
}
146
- monitorUpdate , err := bgpCache .handleBgpRibMonitor (p .path , p .vrfID )
146
+ monitorUpdate , err := bgpCache .handleBgpRibMonitor (p .path , p .vpnID )
147
147
if err != nil {
148
148
log .Errorf ("error processing bgp update [ %s ]" , err )
149
149
return err
@@ -155,7 +155,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
155
155
monitorUpdate .IsWithdraw = true
156
156
log .Debugf ("BGP update has withdrawn the routes: %v " , monitorUpdate )
157
157
if route , ok := b .learnedRoutes [monitorUpdate .BgpPrefix .String ()]; ok {
158
- err = delNetlinkRoute (route .BgpPrefix , route .NextHop , b .parentIfaces [p .vrfID ])
158
+ err = delNetlinkRoute (route .BgpPrefix , route .NextHop , b .parentIfaces [p .vpnID ])
159
159
// If the bgp update contained a withdraw, remove the local netlink route for the remote endpoint
160
160
if err != nil {
161
161
log .Errorf ("Error removing learned bgp route [ %s ]" , err )
@@ -171,7 +171,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
171
171
b .learnedRoutes [monitorUpdate .BgpPrefix .String ()] = monitorUpdate
172
172
log .Debugf ("Learned routes: %v " , monitorUpdate )
173
173
174
- err = addNetlinkRoute (monitorUpdate .BgpPrefix , monitorUpdate .NextHop , b .parentIfaces [p .vrfID ])
174
+ err = addNetlinkRoute (monitorUpdate .BgpPrefix , monitorUpdate .NextHop , b .parentIfaces [p .vpnID ])
175
175
if err != nil {
176
176
log .Debugf ("Error Adding route results [ %s ]" , err )
177
177
return err
@@ -186,11 +186,11 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
186
186
return nil
187
187
}
188
188
189
- func (b * BgpRouteManager ) monitorBestPath (VrfID string ) error {
189
+ func (b * BgpRouteManager ) monitorBestPath (VpnID string ) error {
190
190
var routeFamily uint32
191
- if VrfID == "" {
191
+ if VpnID == "" {
192
192
routeFamily = uint32 (bgp .RF_IPv4_UC )
193
- VrfID = "global"
193
+ VpnID = "global"
194
194
} else {
195
195
routeFamily = uint32 (bgp .RF_IPv4_VPN )
196
196
}
@@ -202,7 +202,7 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
202
202
for _ , d := range currib .Destinations {
203
203
for _ , p := range d .Paths {
204
204
if p .Best {
205
- b .handleRibUpdate (& rib {path : p , vrfID : VrfID })
205
+ b .handleRibUpdate (& rib {path : p , vpnID : VpnID })
206
206
break
207
207
}
208
208
}
@@ -223,7 +223,7 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
223
223
EndCh <- struct {}{}
224
224
return err
225
225
}
226
- err := b .handleRibUpdate (& rib {path : r .Data .(* bgpapi.Destination ).Paths [0 ], vrfID : VrfID })
226
+ err := b .handleRibUpdate (& rib {path : r .Data .(* bgpapi.Destination ).Paths [0 ], vpnID : VpnID })
227
227
if err != nil {
228
228
log .Errorf (err .Error ())
229
229
continue
@@ -233,15 +233,15 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
233
233
}
234
234
235
235
// AdvertiseNewRoute advetise the local namespace IP prefixes to the bgp neighbors
236
- func (b * BgpRouteManager ) AdvertiseNewRoute (localPrefix string , VrfID string ) error {
236
+ func (b * BgpRouteManager ) AdvertiseNewRoute (localPrefix string , VpnID string ) error {
237
237
_ , localPrefixCIDR , _ := net .ParseCIDR (localPrefix )
238
238
log .Debugf ("Adding this hosts container network [ %s ] into the BGP domain" , localPrefix )
239
239
path := & bgpapi.Path {
240
240
Pattrs : make ([][]byte , 0 ),
241
241
IsWithdraw : false ,
242
242
}
243
243
var target bgpapi.Resource
244
- if VrfID == "" {
244
+ if VpnID == "" {
245
245
target = bgpapi .Resource_GLOBAL
246
246
} else {
247
247
target = bgpapi .Resource_VRF
@@ -254,7 +254,7 @@ func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VrfID string) er
254
254
path .Pattrs = append (path .Pattrs , origin )
255
255
arg := & bgpapi.AddPathRequest {
256
256
Resource : target ,
257
- VrfId : bgpVrfprefix + VrfID ,
257
+ VrfId : bgpVrfprefix + VpnID ,
258
258
Path : path ,
259
259
}
260
260
_ , err := b .bgpServer .AddPath (arg )
@@ -265,15 +265,15 @@ func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VrfID string) er
265
265
}
266
266
267
267
//WithdrawRoute withdraw the local namespace IP prefixes to the bgp neighbors
268
- func (b * BgpRouteManager ) WithdrawRoute (localPrefix string , VrfID string ) error {
268
+ func (b * BgpRouteManager ) WithdrawRoute (localPrefix string , VpnID string ) error {
269
269
_ , localPrefixCIDR , _ := net .ParseCIDR (localPrefix )
270
270
log .Debugf ("Withdraw this hosts container network [ %s ] from the BGP domain" , localPrefix )
271
271
path := & bgpapi.Path {
272
272
Pattrs : make ([][]byte , 0 ),
273
273
IsWithdraw : true ,
274
274
}
275
275
var target bgpapi.Resource
276
- if VrfID == "" {
276
+ if VpnID == "" {
277
277
target = bgpapi .Resource_GLOBAL
278
278
} else {
279
279
target = bgpapi .Resource_VRF
@@ -286,7 +286,7 @@ func (b *BgpRouteManager) WithdrawRoute(localPrefix string, VrfID string) error
286
286
path .Pattrs = append (path .Pattrs , origin )
287
287
arg := & bgpapi.DeletePathRequest {
288
288
Resource : target ,
289
- VrfId : bgpVrfprefix + VrfID ,
289
+ VrfId : bgpVrfprefix + VpnID ,
290
290
Path : path ,
291
291
}
292
292
err := b .bgpServer .DeletePath (arg )
@@ -359,12 +359,12 @@ func (b *BgpRouteManager) DiscoverDelete(isself bool, Address string) error {
359
359
360
360
return nil
361
361
}
362
- func (cache * ribCache ) handleBgpRibMonitor (routeMonitor * bgpapi.Path , VrfID string ) (* ribLocal , error ) {
362
+ func (cache * ribCache ) handleBgpRibMonitor (routeMonitor * bgpapi.Path , VpnID string ) (* ribLocal , error ) {
363
363
ribLocal := & ribLocal {}
364
364
var nlri bgp.AddrPrefixInterface
365
365
366
366
if len (routeMonitor .Nlri ) > 0 {
367
- if VrfID == "global" {
367
+ if VpnID == "global" {
368
368
nlri = & bgp.IPAddrPrefix {}
369
369
err := nlri .DecodeFromBytes (routeMonitor .Nlri )
370
370
if err != nil {
@@ -386,7 +386,7 @@ func (cache *ribCache) handleBgpRibMonitor(routeMonitor *bgpapi.Path, VrfID stri
386
386
return nil , err
387
387
}
388
388
nlriSplit := strings .Split (nlri .String (), ":" )
389
- if VrfID != nlriSplit [1 ] {
389
+ if VpnID != nlriSplit [1 ] {
390
390
return nil , nil
391
391
}
392
392
bgpPrefix , err := parseIPNet (nlriSplit [len (nlriSplit )- 1 ])
0 commit comments