@@ -18,7 +18,7 @@ const (
1818
1919type rib struct {
2020 path * bgpapi.Path
21- vrfID string
21+ vpnID string
2222}
2323
2424// BgpRouteManager advertize and withdraw routes by BGP
@@ -56,8 +56,8 @@ func NewBgpRouteManager(as string, ras string) *BgpRouteManager {
5656 return b
5757}
5858
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 {
6161 log .Debugf ("BGP Global config : %v" , b .bgpGlobalcfg )
6262 if b .bgpGlobalcfg == nil {
6363 log .Debugf ("BGP Global config is emply set config" )
@@ -78,35 +78,35 @@ func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vrfID string) err
7878 break
7979 }
8080 }
81- if vrfID == "" {
81+ if vpnID == "" {
8282 log .Debugf ("vrf ID is empty. network paths are in global rib" )
8383 return nil
8484 }
85- b .parentIfaces [vrfID ] = parentIface
85+ b .parentIfaces [vpnID ] = parentIface
8686 err := cleanExistingRoutes (parentIface )
8787 if err != nil {
8888 log .Debugf ("Error cleaning old routes: %s" , err )
8989 return err
9090 }
91- rdrtstr := strconv .Itoa (b .asnum ) + ":" + vrfID
91+ rdrtstr := strconv .Itoa (b .asnum ) + ":" + vpnID
9292 rd , err := bgp .ParseRouteDistinguisher (rdrtstr )
9393 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 )
9595 return err
9696 }
9797 rdSerialized , _ := rd .Serialize ()
9898
9999 rt , err := bgp .ParseRouteTarget (rdrtstr )
100100 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 )
102102 return err
103103 }
104104 rtSerialized , _ := rt .Serialize ()
105105 var rts [][]byte
106106 rts = append (rts , rtSerialized )
107107
108108 arg := & bgpapi.Vrf {
109- Name : bgpVrfprefix + vrfID ,
109+ Name : bgpVrfprefix + vpnID ,
110110 Rd : rdSerialized ,
111111 ImportRt : rts ,
112112 ExportRt : rts ,
@@ -116,8 +116,8 @@ func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vrfID string) err
116116 return err
117117 }
118118 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 )
121121 }()
122122 return nil
123123}
@@ -143,7 +143,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
143143 bgpCache := & ribCache {
144144 BgpTable : make (map [string ]* ribLocal ),
145145 }
146- monitorUpdate , err := bgpCache .handleBgpRibMonitor (p .path , p .vrfID )
146+ monitorUpdate , err := bgpCache .handleBgpRibMonitor (p .path , p .vpnID )
147147 if err != nil {
148148 log .Errorf ("error processing bgp update [ %s ]" , err )
149149 return err
@@ -155,7 +155,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
155155 monitorUpdate .IsWithdraw = true
156156 log .Debugf ("BGP update has withdrawn the routes: %v " , monitorUpdate )
157157 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 ])
159159 // If the bgp update contained a withdraw, remove the local netlink route for the remote endpoint
160160 if err != nil {
161161 log .Errorf ("Error removing learned bgp route [ %s ]" , err )
@@ -171,7 +171,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
171171 b .learnedRoutes [monitorUpdate .BgpPrefix .String ()] = monitorUpdate
172172 log .Debugf ("Learned routes: %v " , monitorUpdate )
173173
174- err = addNetlinkRoute (monitorUpdate .BgpPrefix , monitorUpdate .NextHop , b .parentIfaces [p .vrfID ])
174+ err = addNetlinkRoute (monitorUpdate .BgpPrefix , monitorUpdate .NextHop , b .parentIfaces [p .vpnID ])
175175 if err != nil {
176176 log .Debugf ("Error Adding route results [ %s ]" , err )
177177 return err
@@ -186,11 +186,11 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
186186 return nil
187187}
188188
189- func (b * BgpRouteManager ) monitorBestPath (VrfID string ) error {
189+ func (b * BgpRouteManager ) monitorBestPath (VpnID string ) error {
190190 var routeFamily uint32
191- if VrfID == "" {
191+ if VpnID == "" {
192192 routeFamily = uint32 (bgp .RF_IPv4_UC )
193- VrfID = "global"
193+ VpnID = "global"
194194 } else {
195195 routeFamily = uint32 (bgp .RF_IPv4_VPN )
196196 }
@@ -202,7 +202,7 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
202202 for _ , d := range currib .Destinations {
203203 for _ , p := range d .Paths {
204204 if p .Best {
205- b .handleRibUpdate (& rib {path : p , vrfID : VrfID })
205+ b .handleRibUpdate (& rib {path : p , vpnID : VpnID })
206206 break
207207 }
208208 }
@@ -223,7 +223,7 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
223223 EndCh <- struct {}{}
224224 return err
225225 }
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 })
227227 if err != nil {
228228 log .Errorf (err .Error ())
229229 continue
@@ -233,15 +233,15 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
233233}
234234
235235// 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 {
237237 _ , localPrefixCIDR , _ := net .ParseCIDR (localPrefix )
238238 log .Debugf ("Adding this hosts container network [ %s ] into the BGP domain" , localPrefix )
239239 path := & bgpapi.Path {
240240 Pattrs : make ([][]byte , 0 ),
241241 IsWithdraw : false ,
242242 }
243243 var target bgpapi.Resource
244- if VrfID == "" {
244+ if VpnID == "" {
245245 target = bgpapi .Resource_GLOBAL
246246 } else {
247247 target = bgpapi .Resource_VRF
@@ -254,7 +254,7 @@ func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VrfID string) er
254254 path .Pattrs = append (path .Pattrs , origin )
255255 arg := & bgpapi.AddPathRequest {
256256 Resource : target ,
257- VrfId : bgpVrfprefix + VrfID ,
257+ VrfId : bgpVrfprefix + VpnID ,
258258 Path : path ,
259259 }
260260 _ , err := b .bgpServer .AddPath (arg )
@@ -265,15 +265,15 @@ func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VrfID string) er
265265}
266266
267267//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 {
269269 _ , localPrefixCIDR , _ := net .ParseCIDR (localPrefix )
270270 log .Debugf ("Withdraw this hosts container network [ %s ] from the BGP domain" , localPrefix )
271271 path := & bgpapi.Path {
272272 Pattrs : make ([][]byte , 0 ),
273273 IsWithdraw : true ,
274274 }
275275 var target bgpapi.Resource
276- if VrfID == "" {
276+ if VpnID == "" {
277277 target = bgpapi .Resource_GLOBAL
278278 } else {
279279 target = bgpapi .Resource_VRF
@@ -286,7 +286,7 @@ func (b *BgpRouteManager) WithdrawRoute(localPrefix string, VrfID string) error
286286 path .Pattrs = append (path .Pattrs , origin )
287287 arg := & bgpapi.DeletePathRequest {
288288 Resource : target ,
289- VrfId : bgpVrfprefix + VrfID ,
289+ VrfId : bgpVrfprefix + VpnID ,
290290 Path : path ,
291291 }
292292 err := b .bgpServer .DeletePath (arg )
@@ -359,12 +359,12 @@ func (b *BgpRouteManager) DiscoverDelete(isself bool, Address string) error {
359359
360360 return nil
361361}
362- func (cache * ribCache ) handleBgpRibMonitor (routeMonitor * bgpapi.Path , VrfID string ) (* ribLocal , error ) {
362+ func (cache * ribCache ) handleBgpRibMonitor (routeMonitor * bgpapi.Path , VpnID string ) (* ribLocal , error ) {
363363 ribLocal := & ribLocal {}
364364 var nlri bgp.AddrPrefixInterface
365365
366366 if len (routeMonitor .Nlri ) > 0 {
367- if VrfID == "global" {
367+ if VpnID == "global" {
368368 nlri = & bgp.IPAddrPrefix {}
369369 err := nlri .DecodeFromBytes (routeMonitor .Nlri )
370370 if err != nil {
@@ -386,7 +386,7 @@ func (cache *ribCache) handleBgpRibMonitor(routeMonitor *bgpapi.Path, VrfID stri
386386 return nil , err
387387 }
388388 nlriSplit := strings .Split (nlri .String (), ":" )
389- if VrfID != nlriSplit [1 ] {
389+ if VpnID != nlriSplit [1 ] {
390390 return nil , nil
391391 }
392392 bgpPrefix , err := parseIPNet (nlriSplit [len (nlriSplit )- 1 ])
0 commit comments