summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-10-22 23:41:18 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-02-10 22:15:04 -0800
commitc3dbc58040a289aed7673149145e7d3a4944e183 (patch)
tree740ed445cf9ced36c4dafee0054d380074c802b6
parentdd880838f0aaf46ed729f1812dd7655f627dd7e7 (diff)
packet: add end-of-rib util functions
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--packet/bgp.go25
1 files changed, 25 insertions, 0 deletions
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