Skip to content

Commit

Permalink
mrt: Enable to dump locally generated routes
Browse files Browse the repository at this point in the history
For reloading locally generated routes by using MRT dump file, this
patch enables to include locally generated routes into TABLE_DUMPv2
records.

Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
  • Loading branch information
iwaseyusuke committed May 11, 2018
1 parent 2b0f16d commit 04f36f0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions server/mrt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import (
"os"
"time"

log "github.com/sirupsen/logrus"

"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
"github.com/osrg/gobgp/packet/mrt"
"github.com/osrg/gobgp/table"
log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -114,12 +115,16 @@ func (m *mrtWriter) loop() error {
}
case *WatchEventTable:
t := uint32(time.Now().Unix())
peers := make([]*mrt.Peer, 0, len(e.Neighbor))

peers := make([]*mrt.Peer, 1, len(e.Neighbor)+1)
// Adding dummy Peer record for locally generated routes
peers[0] = mrt.NewPeer("0.0.0.0", "0.0.0.0", 0, true)
neighborMap := make(map[string]*config.Neighbor)
for _, pconf := range e.Neighbor {
peers = append(peers, mrt.NewPeer(pconf.State.RemoteRouterId, pconf.State.NeighborAddress, pconf.Config.PeerAs, true))
neighborMap[pconf.State.NeighborAddress] = pconf
}

if bm, err := mrt.NewMRTMessage(t, mrt.TABLE_DUMPv2, mrt.PEER_INDEX_TABLE, mrt.NewPeerIndexTable(e.RouterId, "", peers)); err != nil {
log.WithFields(log.Fields{
"Topic": "mrt",
Expand Down Expand Up @@ -177,11 +182,10 @@ func (m *mrtWriter) loop() error {
entries := make([]*mrt.RibEntry, 0, len(pathList))
entriesAddPath := make([]*mrt.RibEntry, 0, len(pathList))
for _, path := range pathList {
if path.IsLocal() {
continue
}
isAddPath := false
if neighbor, ok := neighborMap[path.GetSource().Address.String()]; ok {
if path.IsLocal() {
isAddPath = true
} else if neighbor, ok := neighborMap[path.GetSource().Address.String()]; ok {
isAddPath = neighbor.IsAddPathReceiveEnabled(path.GetRouteFamily())
}
if !isAddPath {
Expand Down

0 comments on commit 04f36f0

Please sign in to comment.