From c3dbc58040a289aed7673149145e7d3a4944e183 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Thu, 22 Oct 2015 23:41:18 +0900 Subject: packet: add end-of-rib util functions Signed-off-by: ISHIDA Wataru --- packet/bgp.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'packet') diff --git a/packet/bgp.go b/packet/bgp.go index c1dd4fcb..a1b797c1 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -6206,6 +6206,18 @@ func (msg *BGPUpdate) Serialize() ([]byte, error) { return buf, nil } +func (msg *BGPUpdate) IsEndOfRib() (bool, RouteFamily) { + if len(msg.WithdrawnRoutes) == 0 && len(msg.NLRI) == 0 { + if len(msg.PathAttributes) == 0 { + return true, RF_IPv4_UC + } else if len(msg.PathAttributes) == 1 && msg.PathAttributes[0].GetType() == BGP_ATTR_TYPE_MP_UNREACH_NLRI { + unreach := msg.PathAttributes[0].(*PathAttributeMpUnreachNLRI) + return true, AfiSafiToRouteFamily(unreach.AFI, unreach.SAFI) + } + } + return false, RouteFamily(0) +} + func NewBGPUpdateMessage(withdrawnRoutes []*IPAddrPrefix, pathattrs []PathAttributeInterface, nlri []*IPAddrPrefix) *BGPMessage { return &BGPMessage{ Header: BGPHeader{Type: BGP_MSG_UPDATE}, @@ -6213,6 +6225,19 @@ func NewBGPUpdateMessage(withdrawnRoutes []*IPAddrPrefix, pathattrs []PathAttrib } } +func NewEndOfRib(family RouteFamily) *BGPMessage { + if family == RF_IPv4_UC { + return NewBGPUpdateMessage(nil, nil, nil) + } else { + afi, safi := RouteFamilyToAfiSafi(family) + unreach := &PathAttributeMpUnreachNLRI{ + AFI: afi, + SAFI: safi, + } + return NewBGPUpdateMessage(nil, []PathAttributeInterface{unreach}, nil) + } +} + type BGPNotification struct { ErrorCode uint8 ErrorSubcode uint8 -- cgit v1.2.3