Skip to content

Commit

Permalink
rename vrfID to vpnID
Browse files Browse the repository at this point in the history
Signed-off-by: YujiOshima <[email protected]>
  • Loading branch information
YujiOshima committed May 25, 2016
1 parent ed9ba34 commit 1dc528f
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion drivers/ipvlan/ipvlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
parentOpt = "parent" // parent interface -o parent
modeOpt = "_mode" // ipvlan mode ux opt suffix
bgpNeighborOpt = "bgp-neighbor" // BGP neighbor address
vrfOpt = "vrf" // BGP vrf ID
vpnOpt = "vpn" // BGP vpn ID
asOpt = "asnum" // BGP AS number default 65000
remoteAsOpt = "rasnum" // BGP remote AS number dafault 65000
subnetAdvertise = "subnet-advertise" // Advertise IP Subnet with BGP
Expand Down
4 changes: 2 additions & 2 deletions drivers/ipvlan/ipvlan_joinleave.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
if n.config.SubnetAdvertise == "" {
//Advertise container route as /32 route
advIP := &net.IPNet{IP: ep.addr.IP, Mask: net.IPv4Mask(255, 255, 255, 255)}
err = routemanager.AdvertiseNewRoute(advIP.String(), n.config.VrfID)
err = routemanager.AdvertiseNewRoute(advIP.String(), n.config.VpnID)
if err != nil {
return err
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func (d *driver) Leave(nid, eid string) error {
if network.config.IpvlanMode == modeL3 && network.config.SubnetAdvertise == "" {
//Withdraw container route as /32 route
witdIP := &net.IPNet{IP: endpoint.addr.IP, Mask: net.IPv4Mask(255, 255, 255, 255)}
err = routemanager.WithdrawRoute(witdIP.String(), network.config.VrfID)
err = routemanager.WithdrawRoute(witdIP.String(), network.config.VpnID)
}
if endpoint == nil {
return fmt.Errorf("could not find endpoint with id %s", eid)
Expand Down
18 changes: 9 additions & 9 deletions drivers/ipvlan/ipvlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (d *driver) createNetwork(config *configuration) error {
if routemanager == nil {
InitRouteMonitering(config.ASnum, config.RemoteASnum)
}
err := routemanager.CreateVrfNetwork(config.Parent, config.VrfID)
err := routemanager.CreateVrfNetwork(config.Parent, config.VpnID)
if err != nil {
return err
}
Expand All @@ -127,13 +127,13 @@ func (d *driver) createNetwork(config *configuration) error {
if config.SubnetAdvertise != "" {
if config.Ipv4Subnets != nil {
for _, subnet := range config.Ipv4Subnets {
err := routemanager.AdvertiseNewRoute(subnet.SubnetIP, config.VrfID)
err := routemanager.AdvertiseNewRoute(subnet.SubnetIP, config.VpnID)
if err != nil {
return err
}
}
for _, subnet := range config.Ipv6Subnets {
err := routemanager.AdvertiseNewRoute(subnet.SubnetIP, config.VrfID)
err := routemanager.AdvertiseNewRoute(subnet.SubnetIP, config.VpnID)
if err != nil {
return err
}
Expand Down Expand Up @@ -179,13 +179,13 @@ func (d *driver) DeleteNetwork(nid string) error {
//Advertise container network subnet
if n.config.Ipv4Subnets != nil {
for _, subnet := range n.config.Ipv4Subnets {
err := routemanager.WithdrawRoute(subnet.SubnetIP, n.config.VrfID)
err := routemanager.WithdrawRoute(subnet.SubnetIP, n.config.VpnID)
if err != nil {
return err
}
}
for _, subnet := range n.config.Ipv6Subnets {
err := routemanager.WithdrawRoute(subnet.SubnetIP, n.config.VrfID)
err := routemanager.WithdrawRoute(subnet.SubnetIP, n.config.VpnID)
if err != nil {
return err
}
Expand Down Expand Up @@ -259,14 +259,14 @@ func (config *configuration) fromOptions(labels map[string]string) error {
case bgpNeighborOpt:
// parse driver option '-o bgp-neighbor'
config.BgpNeighbor = value
case vrfOpt:
// parse driver option '-o vrf'
case vpnOpt:
// parse driver option '-o vpn'
_, err := strconv.Atoi(value)
if err != nil {
logrus.Errorf("vrf ID must be numeral")
logrus.Errorf("vpn ID must be numeral")
return err
}
config.VrfID = value
config.VpnID = value
case asOpt:
// parse driver options '-o asnum'
config.ASnum = value
Expand Down
2 changes: 1 addition & 1 deletion drivers/ipvlan/ipvlan_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type configuration struct {
Ipv4Subnets []*ipv4Subnet
Ipv6Subnets []*ipv6Subnet
BgpNeighbor string
VrfID string
VpnID string
ASnum string
RemoteASnum string
SubnetAdvertise string
Expand Down
6 changes: 3 additions & 3 deletions drivers/ipvlan/l3_route_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ type host struct {
}

type routingInterface interface {
CreateVrfNetwork(ParentIface string, vrfID string) error
AdvertiseNewRoute(localPrefix string, vrfID string) error
WithdrawRoute(localPrefix string, vrfID string) error
CreateVrfNetwork(ParentIface string, vpnID string) error
AdvertiseNewRoute(localPrefix string, vpnID string) error
WithdrawRoute(localPrefix string, vpnID string) error
DiscoverNew(isself bool, Address string) error
DiscoverDelete(isself bool, Address string) error
}
Expand Down
56 changes: 28 additions & 28 deletions drivers/ipvlan/l3_route_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (

type rib struct {
path *bgpapi.Path
vrfID string
vpnID string
}

// BgpRouteManager advertize and withdraw routes by BGP
Expand Down Expand Up @@ -56,8 +56,8 @@ func NewBgpRouteManager(as string, ras string) *BgpRouteManager {
return b
}

//CreateVrfNetwork create vrf in BGP server and start monitoring vrf rib if vrfID="", network use global rib
func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vrfID string) error {
//CreateVrfNetwork create vrf in BGP server and start monitoring vrf rib if vpnID="", network use global rib
func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vpnID string) error {
log.Debugf("BGP Global config : %v", b.bgpGlobalcfg)
if b.bgpGlobalcfg == nil {
log.Debugf("BGP Global config is emply set config")
Expand All @@ -78,35 +78,35 @@ func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vrfID string) err
break
}
}
if vrfID == "" {
if vpnID == "" {
log.Debugf("vrf ID is empty. network paths are in global rib")
return nil
}
b.parentIfaces[vrfID] = parentIface
b.parentIfaces[vpnID] = parentIface
err := cleanExistingRoutes(parentIface)
if err != nil {
log.Debugf("Error cleaning old routes: %s", err)
return err
}
rdrtstr := strconv.Itoa(b.asnum) + ":" + vrfID
rdrtstr := strconv.Itoa(b.asnum) + ":" + vpnID
rd, err := bgp.ParseRouteDistinguisher(rdrtstr)
if err != nil {
log.Errorf("Fail to parse RD from vrfID %s : %s", vrfID, err)
log.Errorf("Fail to parse RD from vpnID %s : %s", vpnID, err)
return err
}
rdSerialized, _ := rd.Serialize()

rt, err := bgp.ParseRouteTarget(rdrtstr)
if err != nil {
log.Errorf("Fail to parse RT from vrfID %s : %s", vrfID, err)
log.Errorf("Fail to parse RT from vpnID %s : %s", vpnID, err)
return err
}
rtSerialized, _ := rt.Serialize()
var rts [][]byte
rts = append(rts, rtSerialized)

arg := &bgpapi.Vrf{
Name: bgpVrfprefix + vrfID,
Name: bgpVrfprefix + vpnID,
Rd: rdSerialized,
ImportRt: rts,
ExportRt: rts,
Expand All @@ -116,8 +116,8 @@ func (b *BgpRouteManager) CreateVrfNetwork(parentIface string, vrfID string) err
return err
}
go func() {
err := b.monitorBestPath(vrfID)
log.Errorf("faital monitoring VrfID %s rib : %v", vrfID, err)
err := b.monitorBestPath(vpnID)
log.Errorf("faital monitoring VpnID %s rib : %v", vpnID, err)
}()
return nil
}
Expand All @@ -143,7 +143,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
bgpCache := &ribCache{
BgpTable: make(map[string]*ribLocal),
}
monitorUpdate, err := bgpCache.handleBgpRibMonitor(p.path, p.vrfID)
monitorUpdate, err := bgpCache.handleBgpRibMonitor(p.path, p.vpnID)
if err != nil {
log.Errorf("error processing bgp update [ %s ]", err)
return err
Expand All @@ -155,7 +155,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
monitorUpdate.IsWithdraw = true
log.Debugf("BGP update has withdrawn the routes: %v ", monitorUpdate)
if route, ok := b.learnedRoutes[monitorUpdate.BgpPrefix.String()]; ok {
err = delNetlinkRoute(route.BgpPrefix, route.NextHop, b.parentIfaces[p.vrfID])
err = delNetlinkRoute(route.BgpPrefix, route.NextHop, b.parentIfaces[p.vpnID])
// If the bgp update contained a withdraw, remove the local netlink route for the remote endpoint
if err != nil {
log.Errorf("Error removing learned bgp route [ %s ]", err)
Expand All @@ -171,7 +171,7 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
b.learnedRoutes[monitorUpdate.BgpPrefix.String()] = monitorUpdate
log.Debugf("Learned routes: %v ", monitorUpdate)

err = addNetlinkRoute(monitorUpdate.BgpPrefix, monitorUpdate.NextHop, b.parentIfaces[p.vrfID])
err = addNetlinkRoute(monitorUpdate.BgpPrefix, monitorUpdate.NextHop, b.parentIfaces[p.vpnID])
if err != nil {
log.Debugf("Error Adding route results [ %s ]", err)
return err
Expand All @@ -186,11 +186,11 @@ func (b *BgpRouteManager) handleRibUpdate(p *rib) error {
return nil
}

func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
func (b *BgpRouteManager) monitorBestPath(VpnID string) error {
var routeFamily uint32
if VrfID == "" {
if VpnID == "" {
routeFamily = uint32(bgp.RF_IPv4_UC)
VrfID = "global"
VpnID = "global"
} else {
routeFamily = uint32(bgp.RF_IPv4_VPN)
}
Expand All @@ -202,7 +202,7 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
for _, d := range currib.Destinations {
for _, p := range d.Paths {
if p.Best {
b.handleRibUpdate(&rib{path: p, vrfID: VrfID})
b.handleRibUpdate(&rib{path: p, vpnID: VpnID})
break
}
}
Expand All @@ -223,7 +223,7 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
EndCh <- struct{}{}
return err
}
err := b.handleRibUpdate(&rib{path: r.Data.(*bgpapi.Destination).Paths[0], vrfID: VrfID})
err := b.handleRibUpdate(&rib{path: r.Data.(*bgpapi.Destination).Paths[0], vpnID: VpnID})
if err != nil {
log.Errorf(err.Error())
continue
Expand All @@ -233,15 +233,15 @@ func (b *BgpRouteManager) monitorBestPath(VrfID string) error {
}

// AdvertiseNewRoute advetise the local namespace IP prefixes to the bgp neighbors
func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VrfID string) error {
func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VpnID string) error {
_, localPrefixCIDR, _ := net.ParseCIDR(localPrefix)
log.Debugf("Adding this hosts container network [ %s ] into the BGP domain", localPrefix)
path := &bgpapi.Path{
Pattrs: make([][]byte, 0),
IsWithdraw: false,
}
var target bgpapi.Resource
if VrfID == "" {
if VpnID == "" {
target = bgpapi.Resource_GLOBAL
} else {
target = bgpapi.Resource_VRF
Expand All @@ -254,7 +254,7 @@ func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VrfID string) er
path.Pattrs = append(path.Pattrs, origin)
arg := &bgpapi.AddPathRequest{
Resource: target,
VrfId: bgpVrfprefix + VrfID,
VrfId: bgpVrfprefix + VpnID,
Path: path,
}
_, err := b.bgpServer.AddPath(arg)
Expand All @@ -265,15 +265,15 @@ func (b *BgpRouteManager) AdvertiseNewRoute(localPrefix string, VrfID string) er
}

//WithdrawRoute withdraw the local namespace IP prefixes to the bgp neighbors
func (b *BgpRouteManager) WithdrawRoute(localPrefix string, VrfID string) error {
func (b *BgpRouteManager) WithdrawRoute(localPrefix string, VpnID string) error {
_, localPrefixCIDR, _ := net.ParseCIDR(localPrefix)
log.Debugf("Withdraw this hosts container network [ %s ] from the BGP domain", localPrefix)
path := &bgpapi.Path{
Pattrs: make([][]byte, 0),
IsWithdraw: true,
}
var target bgpapi.Resource
if VrfID == "" {
if VpnID == "" {
target = bgpapi.Resource_GLOBAL
} else {
target = bgpapi.Resource_VRF
Expand All @@ -286,7 +286,7 @@ func (b *BgpRouteManager) WithdrawRoute(localPrefix string, VrfID string) error
path.Pattrs = append(path.Pattrs, origin)
arg := &bgpapi.DeletePathRequest{
Resource: target,
VrfId: bgpVrfprefix + VrfID,
VrfId: bgpVrfprefix + VpnID,
Path: path,
}
err := b.bgpServer.DeletePath(arg)
Expand Down Expand Up @@ -359,12 +359,12 @@ func (b *BgpRouteManager) DiscoverDelete(isself bool, Address string) error {

return nil
}
func (cache *ribCache) handleBgpRibMonitor(routeMonitor *bgpapi.Path, VrfID string) (*ribLocal, error) {
func (cache *ribCache) handleBgpRibMonitor(routeMonitor *bgpapi.Path, VpnID string) (*ribLocal, error) {
ribLocal := &ribLocal{}
var nlri bgp.AddrPrefixInterface

if len(routeMonitor.Nlri) > 0 {
if VrfID == "global" {
if VpnID == "global" {
nlri = &bgp.IPAddrPrefix{}
err := nlri.DecodeFromBytes(routeMonitor.Nlri)
if err != nil {
Expand All @@ -386,7 +386,7 @@ func (cache *ribCache) handleBgpRibMonitor(routeMonitor *bgpapi.Path, VrfID stri
return nil, err
}
nlriSplit := strings.Split(nlri.String(), ":")
if VrfID != nlriSplit[1] {
if VpnID != nlriSplit[1] {
return nil, nil
}
bgpPrefix, err := parseIPNet(nlriSplit[len(nlriSplit)-1])
Expand Down

0 comments on commit 1dc528f

Please sign in to comment.