mirror of
https://github.com/osrg/gobgp.git
synced 2024-05-11 05:55:10 +00:00
table: add EVPN route family support
Signed-off-by: FUJITA Tomonori <[email protected]>
This commit is contained in:
committed by
FUJITA Tomonori
parent
84f6e0b04c
commit
28feabe1ef
@@ -992,3 +992,16 @@ func (ipv4vpnd *IPv4VPNDestination) MarshalJSON() ([]byte, error) {
|
||||
BestPathIdx: idx,
|
||||
})
|
||||
}
|
||||
|
||||
type EVPNDestination struct {
|
||||
*DestinationDefault
|
||||
//need structure
|
||||
}
|
||||
|
||||
func NewEVPNDestination(nlri bgp.AddrPrefixInterface) *EVPNDestination {
|
||||
EVPNDestination := &EVPNDestination{}
|
||||
EVPNDestination.DestinationDefault = NewDestinationDefault(nlri)
|
||||
EVPNDestination.DestinationDefault.ROUTE_FAMILY = bgp.RF_EVPN
|
||||
//need Processing
|
||||
return EVPNDestination
|
||||
}
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ func createUpdateMsgFromPath(path Path, msg *bgp.BGPMessage) *bgp.BGPMessage {
|
||||
return bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttrs, []bgp.NLRInfo{*nlri})
|
||||
}
|
||||
}
|
||||
} else if rf == bgp.RF_IPv6_UC {
|
||||
} else if rf == bgp.RF_IPv6_UC || rf == bgp.RF_EVPN {
|
||||
if path.IsWithdraw() {
|
||||
if msg != nil {
|
||||
idx, _ := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
|
||||
|
||||
@@ -318,6 +318,9 @@ func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.Path
|
||||
case bgp.RF_IPv4_VPN:
|
||||
log.Debugf("CreatePath RouteFamily : %s", bgp.RF_IPv4_VPN.String())
|
||||
path = NewIPv4VPNPath(source, nlri, isWithdraw, attrs, false, now)
|
||||
case bgp.RF_EVPN:
|
||||
log.Debugf("CreatePath RouteFamily : %s", bgp.RF_EVPN.String())
|
||||
path = NewEVPNPath(source, nlri, isWithdraw, attrs, false, now)
|
||||
}
|
||||
return path
|
||||
}
|
||||
@@ -466,3 +469,69 @@ func (ipv4vpnp *IPv4VPNPath) MarshalJSON() ([]byte, error) {
|
||||
Age: time.Now().Sub(ipv4vpnp.PathDefault.timestamp).Seconds(),
|
||||
})
|
||||
}
|
||||
|
||||
type EVPNPath struct {
|
||||
*PathDefault
|
||||
}
|
||||
|
||||
func NewEVPNPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool, now time.Time) *EVPNPath {
|
||||
EVPNPath := &EVPNPath{}
|
||||
EVPNPath.PathDefault = NewPathDefault(bgp.RF_EVPN, source, nlri, nil, isWithdraw, attrs, medSetByTargetNeighbor, now)
|
||||
if !isWithdraw {
|
||||
_, mpattr := EVPNPath.getPathAttr(bgp.BGP_ATTR_TYPE_MP_REACH_NLRI)
|
||||
EVPNPath.nexthop = mpattr.(*bgp.PathAttributeMpReachNLRI).Nexthop
|
||||
}
|
||||
|
||||
return EVPNPath
|
||||
}
|
||||
|
||||
func (evpnp *EVPNPath) clone(isWithdraw bool) Path {
|
||||
nlri := evpnp.nlri
|
||||
if isWithdraw {
|
||||
if evpnp.IsWithdraw() {
|
||||
log.WithFields(log.Fields{
|
||||
"Topic": "Table",
|
||||
"Key": evpnp.getNlri().String(),
|
||||
"Peer": evpnp.getSource().Address.String(),
|
||||
}).Fatal("Withdraw path is not supposed to be cloned")
|
||||
}
|
||||
}
|
||||
return CreatePath(evpnp.source, nlri, evpnp.pathAttrs, isWithdraw, evpnp.PathDefault.timestamp)
|
||||
}
|
||||
|
||||
func (evpnp *EVPNPath) setPathDefault(pd *PathDefault) {
|
||||
evpnp.PathDefault = pd
|
||||
}
|
||||
|
||||
func (evpnp *EVPNPath) getPathDefault() *PathDefault {
|
||||
return evpnp.PathDefault
|
||||
}
|
||||
|
||||
func (evpnp *EVPNPath) getPrefix() string {
|
||||
addrPrefix := evpnp.nlri.(*bgp.EVPNNLRI)
|
||||
return addrPrefix.String()
|
||||
}
|
||||
|
||||
// return EVPNPath's string representation
|
||||
func (evpnp *EVPNPath) String() string {
|
||||
str := fmt.Sprintf("EVPNPath Source: %v, ", evpnp.getSource())
|
||||
str = str + fmt.Sprintf(" NLRI: %s, ", evpnp.getPrefix())
|
||||
str = str + fmt.Sprintf(" nexthop: %s, ", evpnp.GetNexthop().String())
|
||||
str = str + fmt.Sprintf(" withdraw: %s, ", evpnp.IsWithdraw())
|
||||
//str = str + fmt.Sprintf(" path attributes: %s, ", evpnp.getPathAttributeMap())
|
||||
return str
|
||||
}
|
||||
|
||||
func (evpnp *EVPNPath) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(struct {
|
||||
Network string
|
||||
Nexthop string
|
||||
Attrs []bgp.PathAttributeInterface
|
||||
Age float64
|
||||
}{
|
||||
Network: evpnp.getPrefix(),
|
||||
Nexthop: evpnp.PathDefault.nexthop.String(),
|
||||
Attrs: evpnp.PathDefault.getPathAttrs(),
|
||||
Age: time.Now().Sub(evpnp.PathDefault.timestamp).Seconds(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -381,3 +381,43 @@ func (ipv4vpnt *IPv4VPNTable) MarshalJSON() ([]byte, error) {
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
type EVPNTable struct {
|
||||
*TableDefault
|
||||
//need structure
|
||||
}
|
||||
|
||||
func NewEVPNTable(scope_id int) *EVPNTable {
|
||||
EVPNTable := &EVPNTable{}
|
||||
EVPNTable.TableDefault = NewTableDefault(scope_id)
|
||||
EVPNTable.TableDefault.ROUTE_FAMILY = bgp.RF_EVPN
|
||||
//need Processing
|
||||
return EVPNTable
|
||||
}
|
||||
|
||||
//Creates destination
|
||||
//Implements interface
|
||||
func (ipv4vpnt *EVPNTable) createDest(nlri bgp.AddrPrefixInterface) Destination {
|
||||
return Destination(NewEVPNDestination(nlri))
|
||||
}
|
||||
|
||||
//make tablekey
|
||||
//Implements interface
|
||||
func (ipv4vpnt *EVPNTable) tableKey(nlri bgp.AddrPrefixInterface) string {
|
||||
|
||||
addrPrefix := nlri.(*bgp.EVPNNLRI)
|
||||
return addrPrefix.String()
|
||||
}
|
||||
|
||||
func ParseEVPNPrefix(key string) patricia.Prefix {
|
||||
vpnaddrprefix := strings.Split(key, "/")
|
||||
length, _ := strconv.ParseInt(vpnaddrprefix[1], 10, 0)
|
||||
_, n, _ := net.ParseCIDR(vpnaddrprefix[0] + "/" + strconv.FormatInt((int64(length)-88), 10))
|
||||
|
||||
var buffer bytes.Buffer
|
||||
for i := 0; i < len(n.IP); i++ {
|
||||
buffer.WriteString(fmt.Sprintf("%08b", n.IP[i]))
|
||||
}
|
||||
ones, _ := n.Mask.Size()
|
||||
return patricia.Prefix(buffer.String()[:ones])
|
||||
}
|
||||
|
||||
@@ -140,6 +140,9 @@ func NewTableManager(owner string, rfList []bgp.RouteFamily) *TableManager {
|
||||
t.Tables[bgp.RF_IPv6_UC] = NewIPv6Table(0)
|
||||
case bgp.RF_IPv4_VPN:
|
||||
t.Tables[bgp.RF_IPv4_VPN] = NewIPv4VPNTable(0)
|
||||
case bgp.RF_EVPN:
|
||||
t.Tables[bgp.RF_EVPN] = NewEVPNTable(0)
|
||||
|
||||
}
|
||||
}
|
||||
t.owner = owner
|
||||
|
||||
Reference in New Issue
Block a user