summaryrefslogtreecommitdiffhomepage
path: root/server/server.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-05-10 14:42:38 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-05-10 23:13:21 +0900
commit2b0f16dcc6a47bd8d6518746038b3d65ff55e8c4 (patch)
tree7678378a940b6be7c8ad150362ded0464637c0e3 /server/server.go
parent691d80e5d160b82c8b4dd1d83c959ecdffad318f (diff)
bmp: avoid huge memory allocation for sending paths initially
We had to serialize all the paths once because the paths could be modified later. Now they are immutable so we don't need. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r--server/server.go60
1 files changed, 27 insertions, 33 deletions
diff --git a/server/server.go b/server/server.go
index 3c7bd336..251ce7cb 100644
--- a/server/server.go
+++ b/server/server.go
@@ -2585,6 +2585,7 @@ type WatchEventUpdate struct {
Timestamp time.Time
Payload []byte
PostPolicy bool
+ Init bool
PathList []*table.Path
Neighbor *config.Neighbor
}
@@ -2862,24 +2863,19 @@ func (s *BgpServer) Watch(opts ...WatchOption) (w *Watcher) {
for _, rf := range peer.configuredRFlist() {
_, y := peer.fsm.capMap[bgp.BGP_CAP_FOUR_OCTET_AS_NUMBER]
l, _ := peer.fsm.LocalHostPort()
- for _, path := range peer.adjRibIn.PathList([]bgp.RouteFamily{rf}, false) {
- msgs := table.CreateUpdateMsgFromPaths([]*table.Path{path})
- buf, _ := msgs[0].Serialize()
- w.notify(&WatchEventUpdate{
- Message: msgs[0],
- PeerAS: peer.fsm.peerInfo.AS,
- LocalAS: peer.fsm.peerInfo.LocalAS,
- PeerAddress: peer.fsm.peerInfo.Address,
- LocalAddress: net.ParseIP(l),
- PeerID: peer.fsm.peerInfo.ID,
- FourBytesAs: y,
- Timestamp: path.GetTimestamp(),
- Payload: buf,
- PostPolicy: false,
- Neighbor: configNeighbor,
- PathList: []*table.Path{path},
- })
- }
+ w.notify(&WatchEventUpdate{
+ PeerAS: peer.fsm.peerInfo.AS,
+ LocalAS: peer.fsm.peerInfo.LocalAS,
+ PeerAddress: peer.fsm.peerInfo.Address,
+ LocalAddress: net.ParseIP(l),
+ PeerID: peer.fsm.peerInfo.ID,
+ FourBytesAs: y,
+ Init: true,
+ PostPolicy: false,
+ Neighbor: configNeighbor,
+ PathList: peer.adjRibIn.PathList([]bgp.RouteFamily{rf}, false),
+ })
+
eor := bgp.NewEndOfRib(rf)
eorBuf, _ := eor.Serialize()
w.notify(&WatchEventUpdate{
@@ -2891,6 +2887,7 @@ func (s *BgpServer) Watch(opts ...WatchOption) (w *Watcher) {
PeerID: peer.fsm.peerInfo.ID,
FourBytesAs: y,
Timestamp: time.Now(),
+ Init: true,
Payload: eorBuf,
PostPolicy: false,
Neighbor: configNeighbor,
@@ -2913,21 +2910,17 @@ func (s *BgpServer) Watch(opts ...WatchOption) (w *Watcher) {
if peer, ok := s.neighborMap[peerInfo.Address.String()]; ok {
configNeighbor = w.s.ToConfig(peer, false)
}
- for _, path := range paths {
- msgs := table.CreateUpdateMsgFromPaths([]*table.Path{path})
- buf, _ := msgs[0].Serialize()
- w.notify(&WatchEventUpdate{
- Message: msgs[0],
- PeerAS: peerInfo.AS,
- PeerAddress: peerInfo.Address,
- PeerID: peerInfo.ID,
- Timestamp: path.GetTimestamp(),
- Payload: buf,
- PostPolicy: true,
- Neighbor: configNeighbor,
- PathList: []*table.Path{path},
- })
- }
+
+ w.notify(&WatchEventUpdate{
+ PeerAS: peerInfo.AS,
+ PeerAddress: peerInfo.Address,
+ PeerID: peerInfo.ID,
+ PostPolicy: true,
+ Neighbor: configNeighbor,
+ PathList: paths,
+ Init: true,
+ })
+
eor := bgp.NewEndOfRib(rf)
eorBuf, _ := eor.Serialize()
w.notify(&WatchEventUpdate{
@@ -2939,6 +2932,7 @@ func (s *BgpServer) Watch(opts ...WatchOption) (w *Watcher) {
Payload: eorBuf,
PostPolicy: true,
Neighbor: configNeighbor,
+ Init: true,
})
}
}