diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-04-11 09:09:50 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-31 14:28:04 +0900 |
commit | 6d401bedf5a947444a66daf5312719f6dba8b381 (patch) | |
tree | 3372759000a7347cc96004602fcad2d683ef7c39 /server | |
parent | 59420a4c4623492085348e07fb78eaae51182782 (diff) |
packet: create mrt package
move mrt stuff from bgp to mrt package.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/server.go | 35 | ||||
-rw-r--r-- | server/watcher.go | 9 |
2 files changed, 23 insertions, 21 deletions
diff --git a/server/server.go b/server/server.go index 1b59402d..4d0088ad 100644 --- a/server/server.go +++ b/server/server.go @@ -30,6 +30,7 @@ import ( api "github.com/osrg/gobgp/api" "github.com/osrg/gobgp/config" "github.com/osrg/gobgp/packet/bgp" + "github.com/osrg/gobgp/packet/mrt" "github.com/osrg/gobgp/table" "github.com/osrg/gobgp/zebra" "github.com/satori/go.uuid" @@ -2957,20 +2958,20 @@ func (server *BgpServer) handleMrt(grpcReq *GrpcRequest) { return } -func (server *BgpServer) mkMrtPeerIndexTableMsg(t uint32, view string) (*bgp.MRTMessage, error) { - peers := make([]*bgp.Peer, 0, len(server.neighborMap)) +func (server *BgpServer) mkMrtPeerIndexTableMsg(t uint32, view string) (*mrt.MRTMessage, error) { + peers := make([]*mrt.Peer, 0, len(server.neighborMap)) for _, peer := range server.neighborMap { id := peer.fsm.peerInfo.ID.To4().String() ipaddr := peer.conf.Config.NeighborAddress asn := peer.conf.Config.PeerAs - peers = append(peers, bgp.NewPeer(id, ipaddr, asn, true)) + peers = append(peers, mrt.NewPeer(id, ipaddr, asn, true)) } bgpid := server.bgpConfig.Global.Config.RouterId - table := bgp.NewPeerIndexTable(bgpid, view, peers) - return bgp.NewMRTMessage(t, bgp.TABLE_DUMPv2, bgp.PEER_INDEX_TABLE, table) + table := mrt.NewPeerIndexTable(bgpid, view, peers) + return mrt.NewMRTMessage(t, mrt.TABLE_DUMPv2, mrt.PEER_INDEX_TABLE, table) } -func (server *BgpServer) mkMrtRibMsgs(tbl *table.Table, t uint32) ([]*bgp.MRTMessage, error) { +func (server *BgpServer) mkMrtRibMsgs(tbl *table.Table, t uint32) ([]*mrt.MRTMessage, error) { getPeerIndex := func(info *table.PeerInfo) uint16 { var idx uint16 for _, peer := range server.neighborMap { @@ -2982,42 +2983,42 @@ func (server *BgpServer) mkMrtRibMsgs(tbl *table.Table, t uint32) ([]*bgp.MRTMes return idx } - var subtype bgp.MRTSubTypeTableDumpv2 + var subtype mrt.MRTSubTypeTableDumpv2 switch tbl.GetRoutefamily() { case bgp.RF_IPv4_UC: - subtype = bgp.RIB_IPV4_UNICAST + subtype = mrt.RIB_IPV4_UNICAST case bgp.RF_IPv4_MC: - subtype = bgp.RIB_IPV4_MULTICAST + subtype = mrt.RIB_IPV4_MULTICAST case bgp.RF_IPv6_UC: - subtype = bgp.RIB_IPV6_UNICAST + subtype = mrt.RIB_IPV6_UNICAST case bgp.RF_IPv6_MC: - subtype = bgp.RIB_IPV6_MULTICAST + subtype = mrt.RIB_IPV6_MULTICAST default: - subtype = bgp.RIB_GENERIC + subtype = mrt.RIB_GENERIC } var seq uint32 - msgs := make([]*bgp.MRTMessage, 0, len(tbl.GetDestinations())) + msgs := make([]*mrt.MRTMessage, 0, len(tbl.GetDestinations())) for _, dst := range tbl.GetDestinations() { l := dst.GetKnownPathList(table.GLOBAL_RIB_NAME) - entries := make([]*bgp.RibEntry, 0, len(l)) + entries := make([]*mrt.RibEntry, 0, len(l)) for _, p := range l { // mrt doesn't assume to dump locally generated routes if p.IsLocal() { continue } idx := getPeerIndex(p.GetSource()) - e := bgp.NewRibEntry(idx, uint32(p.GetTimestamp().Unix()), p.GetPathAttrs()) + e := mrt.NewRibEntry(idx, uint32(p.GetTimestamp().Unix()), p.GetPathAttrs()) entries = append(entries, e) } // if dst only contains locally generated routes, ignore it if len(entries) == 0 { continue } - rib := bgp.NewRib(seq, dst.GetNlri(), entries) + rib := mrt.NewRib(seq, dst.GetNlri(), entries) seq++ - msg, err := bgp.NewMRTMessage(t, bgp.TABLE_DUMPv2, subtype, rib) + msg, err := mrt.NewMRTMessage(t, mrt.TABLE_DUMPv2, subtype, rib) if err != nil { return nil, err } diff --git a/server/watcher.go b/server/watcher.go index d3befa0e..d08a6ef3 100644 --- a/server/watcher.go +++ b/server/watcher.go @@ -19,6 +19,7 @@ import ( "bytes" log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet/bgp" + "github.com/osrg/gobgp/packet/mrt" "github.com/osrg/gobgp/table" "gopkg.in/tomb.v2" "net" @@ -137,13 +138,13 @@ func (w *mrtWatcher) loop() error { for { serialize := func(ev watcherEvent) ([]byte, error) { m := ev.(*watcherEventUpdateMsg) - subtype := bgp.MESSAGE_AS4 - mp := bgp.NewBGP4MPMessage(m.peerAS, m.localAS, 0, m.peerAddress.String(), m.localAddress.String(), m.fourBytesAs, nil) + subtype := mrt.MESSAGE_AS4 + mp := mrt.NewBGP4MPMessage(m.peerAS, m.localAS, 0, m.peerAddress.String(), m.localAddress.String(), m.fourBytesAs, nil) mp.BGPMessagePayload = m.payload if m.fourBytesAs == false { - subtype = bgp.MESSAGE + subtype = mrt.MESSAGE } - bm, err := bgp.NewMRTMessage(uint32(m.timestamp.Unix()), bgp.BGP4MP, subtype, mp) + bm, err := mrt.NewMRTMessage(uint32(m.timestamp.Unix()), mrt.BGP4MP, subtype, mp) if err != nil { log.WithFields(log.Fields{ "Topic": "mrt", |