diff options
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 12 | ||||
-rw-r--r-- | table/destination_test.go | 2 | ||||
-rw-r--r-- | table/message.go | 2 | ||||
-rw-r--r-- | table/path.go | 67 | ||||
-rw-r--r-- | table/path_test.go | 4 | ||||
-rw-r--r-- | table/table.go | 19 | ||||
-rw-r--r-- | table/table_manager.go | 11 | ||||
-rw-r--r-- | table/table_test.go | 2 |
8 files changed, 80 insertions, 39 deletions
diff --git a/table/destination.go b/table/destination.go index cfd411ce..ead4797a 100644 --- a/table/destination.go +++ b/table/destination.go @@ -1041,3 +1041,15 @@ func (evpnd *EVPNDestination) MarshalJSON() ([]byte, error) { BestPathIdx: idx, }) } + +type EncapDestination struct { + *DestinationDefault +} + +func NewEncapDestination(nlri bgp.AddrPrefixInterface) *EncapDestination { + d := NewDestinationDefault(nlri) + d.ROUTE_FAMILY = bgp.RF_ENCAP + return &EncapDestination{ + DestinationDefault: d, + } +} diff --git a/table/destination_test.go b/table/destination_test.go index 7205876a..db4e49c1 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -135,7 +135,7 @@ func DestCreatePath(msgs []*ProcessMessage) []Path { nlriList := updateMsgD.NLRI pathAttributes := updateMsgD.PathAttributes nlri_info := nlriList[0] - pathD[i] = CreatePath(msg.fromPeer, &nlri_info, pathAttributes, false, time.Now()) + pathD[i], _ = CreatePath(msg.fromPeer, &nlri_info, pathAttributes, false, time.Now()) } return pathD } diff --git a/table/message.go b/table/message.go index 502dbd4c..70e2ffcd 100644 --- a/table/message.go +++ b/table/message.go @@ -155,7 +155,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 || rf == bgp.RF_EVPN { + } else if rf == bgp.RF_IPv6_UC || rf == bgp.RF_EVPN || rf == bgp.RF_ENCAP { if path.IsWithdraw() { if msg != nil { idx, _ := path.getPathAttr(bgp.BGP_ATTR_TYPE_MP_UNREACH_NLRI) diff --git a/table/path.go b/table/path.go index 9e296edb..62a98aab 100644 --- a/table/path.go +++ b/table/path.go @@ -209,7 +209,8 @@ func (pd *PathDefault) Clone(isWithdraw bool) Path { newPathAttrs[i] = v } - return CreatePath(pd.source, nlri, newPathAttrs, isWithdraw, pd.timestamp) + path, _ := CreatePath(pd.source, nlri, newPathAttrs, isWithdraw, pd.timestamp) + return path } func (pd *PathDefault) GetRouteFamily() bgp.RouteFamily { @@ -311,18 +312,11 @@ func (pi *PathDefault) String() string { } func (pi *PathDefault) getPrefix() string { - switch nlri := pi.nlri.(type) { - case *bgp.NLRInfo: - return nlri.IPAddrPrefix.IPAddrPrefixDefault.String() - case *bgp.WithdrawnRoute: - return nlri.IPAddrPrefix.IPAddrPrefixDefault.String() - } - log.Fatal() - return "" + return pi.nlri.String() } // create Path object based on route family -func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttributeInterface, isWithdraw bool, now time.Time) Path { +func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttributeInterface, isWithdraw bool, now time.Time) (Path, error) { rf := bgp.RouteFamily(int(nlri.AFI())<<16 | int(nlri.SAFI())) log.Debugf("CreatePath afi: %d, safi: %d ", int(nlri.AFI()), nlri.SAFI()) @@ -341,8 +335,13 @@ func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.Path case bgp.RF_EVPN: log.Debugf("CreatePath RouteFamily : %s", bgp.RF_EVPN.String()) path = NewEVPNPath(source, nlri, isWithdraw, attrs, false, now) + case bgp.RF_ENCAP: + log.Debugf("CreatePath RouteFamily : %s", bgp.RF_ENCAP.String()) + path = NewEncapPath(source, nlri, isWithdraw, attrs, false, now) + default: + return path, fmt.Errorf("Unsupported RouteFamily: %s", rf) } - return path + return path, nil } /* @@ -377,7 +376,8 @@ func NewIPv6Path(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool func (ipv6p *IPv6Path) Clone(isWithdraw bool) Path { nlri := ipv6p.nlri - return CreatePath(ipv6p.source, nlri, ipv6p.pathAttrs, isWithdraw, ipv6p.PathDefault.timestamp) + path, _ := CreatePath(ipv6p.source, nlri, ipv6p.pathAttrs, isWithdraw, ipv6p.PathDefault.timestamp) + return path } func (ipv6p *IPv6Path) setPathDefault(pd *PathDefault) { @@ -388,11 +388,6 @@ func (ipv6p *IPv6Path) getPathDefault() *PathDefault { return ipv6p.PathDefault } -func (ipv6p *IPv6Path) getPrefix() string { - addrPrefix := ipv6p.nlri.(*bgp.IPv6AddrPrefix) - return addrPrefix.IPAddrPrefixDefault.String() -} - // return IPv6Path's string representation func (ipv6p *IPv6Path) String() string { str := fmt.Sprintf("IPv6Path Source: %v, ", ipv6p.GetSource()) @@ -415,7 +410,8 @@ func NewIPv4VPNPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw b func (ipv4vpnp *IPv4VPNPath) Clone(isWithdraw bool) Path { nlri := ipv4vpnp.nlri - return CreatePath(ipv4vpnp.source, nlri, ipv4vpnp.pathAttrs, isWithdraw, ipv4vpnp.PathDefault.timestamp) + path, _ := CreatePath(ipv4vpnp.source, nlri, ipv4vpnp.pathAttrs, isWithdraw, ipv4vpnp.PathDefault.timestamp) + return path } func (ipv4vpnp *IPv4VPNPath) setPathDefault(pd *PathDefault) { @@ -426,11 +422,6 @@ func (ipv4vpnp *IPv4VPNPath) getPathDefault() *PathDefault { return ipv4vpnp.PathDefault } -func (ipv4vpnp *IPv4VPNPath) getPrefix() string { - addrPrefix := ipv4vpnp.nlri.(*bgp.LabelledVPNIPAddrPrefix) - return addrPrefix.IPAddrPrefixDefault.String() -} - // return IPv4VPNPath's string representation func (ipv4vpnp *IPv4VPNPath) String() string { str := fmt.Sprintf("IPv4VPNPath Source: %v, ", ipv4vpnp.GetSource()) @@ -467,7 +458,8 @@ func NewEVPNPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool func (evpnp *EVPNPath) Clone(isWithdraw bool) Path { nlri := evpnp.nlri - return CreatePath(evpnp.source, nlri, evpnp.pathAttrs, isWithdraw, evpnp.PathDefault.timestamp) + path, _ := CreatePath(evpnp.source, nlri, evpnp.pathAttrs, isWithdraw, evpnp.PathDefault.timestamp) + return path } func (evpnp *EVPNPath) setPathDefault(pd *PathDefault) { @@ -478,11 +470,6 @@ 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()) @@ -506,3 +493,25 @@ func (evpnp *EVPNPath) MarshalJSON() ([]byte, error) { Age: int64(time.Now().Sub(evpnp.PathDefault.timestamp).Seconds()), }) } + +type EncapPath struct { + *PathDefault +} + +func NewEncapPath(source *PeerInfo, nlri bgp.AddrPrefixInterface, isWithdraw bool, attrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool, now time.Time) *EncapPath { + return &EncapPath{ + PathDefault: NewPathDefault(bgp.RF_ENCAP, source, nlri, isWithdraw, attrs, medSetByTargetNeighbor, now), + } +} + +func (p *EncapPath) setPathDefault(pd *PathDefault) { + p.PathDefault = pd +} +func (p *EncapPath) getPathDefault() *PathDefault { + return p.PathDefault +} + +func (p *EncapPath) Clone(isWithdraw bool) Path { + path, _ := CreatePath(p.source, p.nlri, p.pathAttrs, isWithdraw, p.PathDefault.timestamp) + return path +} diff --git a/table/path_test.go b/table/path_test.go index 3d1e47c9..378e37c7 100644 --- a/table/path_test.go +++ b/table/path_test.go @@ -126,7 +126,7 @@ func TestPathCreatePath(t *testing.T) { nlriList := updateMsgP.NLRI pathAttributes := updateMsgP.PathAttributes nlri_info := nlriList[0] - path := CreatePath(msgP[0].fromPeer, &nlri_info, pathAttributes, false, time.Now()) + path, _ := CreatePath(msgP[0].fromPeer, &nlri_info, pathAttributes, false, time.Now()) assert.NotNil(t, path) } @@ -173,7 +173,7 @@ func PathCreatePath(msgs []*ProcessMessage) []Path { nlriList := updateMsgP.NLRI pathAttributes := updateMsgP.PathAttributes nlri_info := nlriList[0] - pathP[i] = CreatePath(msg.fromPeer, &nlri_info, pathAttributes, false, time.Now()) + pathP[i], _ = CreatePath(msg.fromPeer, &nlri_info, pathAttributes, false, time.Now()) } return pathP } diff --git a/table/table.go b/table/table.go index 4739b292..b1434732 100644 --- a/table/table.go +++ b/table/table.go @@ -334,3 +334,22 @@ func (ipv4vpnt *EVPNTable) tableKey(nlri bgp.AddrPrefixInterface) string { addrPrefix := nlri.(*bgp.EVPNNLRI) return addrPrefix.String() } + +type EncapTable struct { + *TableDefault +} + +func NewEncapTable() *EncapTable { + EncapTable := &EncapTable{} + EncapTable.TableDefault = NewTableDefault(0) + EncapTable.TableDefault.ROUTE_FAMILY = bgp.RF_ENCAP + return EncapTable +} + +func (t *EncapTable) createDest(nlri bgp.AddrPrefixInterface) Destination { + return Destination(NewEncapDestination(nlri)) +} + +func (t *EncapTable) tableKey(nlri bgp.AddrPrefixInterface) string { + return nlri.String() +} diff --git a/table/table_manager.go b/table/table_manager.go index df89a2eb..d56c2e65 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -42,7 +42,7 @@ func (p *ProcessMessage) nlri2Path(now time.Time) []Path { // define local variable to pass nlri's address to CreatePath var nlri bgp.NLRInfo = nlri_info // create Path object - path := CreatePath(p.fromPeer, &nlri, pathAttributes, false, now) + path, _ := CreatePath(p.fromPeer, &nlri, pathAttributes, false, now) pathList = append(pathList, path) } return pathList @@ -56,7 +56,7 @@ func (p *ProcessMessage) withdraw2Path(now time.Time) []Path { // define local variable to pass nlri's address to CreatePath var w bgp.WithdrawnRoute = nlriWithdraw // create withdrawn Path object - path := CreatePath(p.fromPeer, &w, pathAttributes, true, now) + path, _ := CreatePath(p.fromPeer, &w, pathAttributes, true, now) pathList = append(pathList, path) } return pathList @@ -79,7 +79,7 @@ func (p *ProcessMessage) mpreachNlri2Path(now time.Time) []Path { for _, mp := range attrList { nlri_info := mp.Value for _, nlri := range nlri_info { - path := CreatePath(p.fromPeer, nlri, pathAttributes, false, now) + path, _ := CreatePath(p.fromPeer, nlri, pathAttributes, false, now) pathList = append(pathList, path) } } @@ -104,7 +104,7 @@ func (p *ProcessMessage) mpunreachNlri2Path(now time.Time) []Path { nlri_info := mp.Value for _, nlri := range nlri_info { - path := CreatePath(p.fromPeer, nlri, pathAttributes, true, now) + path, _ := CreatePath(p.fromPeer, nlri, pathAttributes, true, now) pathList = append(pathList, path) } } @@ -141,7 +141,8 @@ func NewTableManager(owner string, rfList []bgp.RouteFamily) *TableManager { t.Tables[bgp.RF_IPv4_VPN] = NewIPv4VPNTable(0) case bgp.RF_EVPN: t.Tables[bgp.RF_EVPN] = NewEVPNTable(0) - + case bgp.RF_ENCAP: + t.Tables[bgp.RF_ENCAP] = NewEncapTable() } } t.owner = owner diff --git a/table/table_test.go b/table/table_test.go index 407fbe0a..70e9c86b 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -131,7 +131,7 @@ func TableCreatePath(msgs []*ProcessMessage) []Path { nlriList := updateMsgT.NLRI pathAttributes := updateMsgT.PathAttributes nlri_info := nlriList[0] - pathT[i] = CreatePath(msg.fromPeer, &nlri_info, pathAttributes, false, time.Now()) + pathT[i], _ = CreatePath(msg.fromPeer, &nlri_info, pathAttributes, false, time.Now()) } return pathT } |