summaryrefslogtreecommitdiffhomepage
path: root/server/dumper.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-09-08 15:13:21 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-09-08 15:29:04 +0900
commit5ae3e111f7d16cdd8c07d2d30fbf21fd50b820bd (patch)
treed45997c34a5e9be644d1b17e9177359a3104fd7f /server/dumper.go
parent54c8d7e19c8c3ce2198a79b10dc04255e4d5e285 (diff)
server: add mrt bgp4mp support
You can enable the feature like: [Global] [Global.GlobalConfig] As = 64512 RouterId = "10.0.255.254" [Global.Mrt] FileName = "update.dump" Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/dumper.go')
-rw-r--r--server/dumper.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/server/dumper.go b/server/dumper.go
new file mode 100644
index 00000000..46281ca6
--- /dev/null
+++ b/server/dumper.go
@@ -0,0 +1,71 @@
+// Copyright (C) 2015 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package server
+
+import (
+ log "github.com/Sirupsen/logrus"
+ "github.com/osrg/gobgp/packet"
+ "os"
+ "time"
+)
+
+type dumper struct {
+ ch chan *broadcastBGPMsg
+}
+
+func (d *dumper) sendCh() chan *broadcastBGPMsg {
+ return d.ch
+}
+
+func newDumper(filename string) (*dumper, error) {
+ f, err := os.Create(filename)
+ if err != nil {
+ return nil, err
+ }
+
+ ch := make(chan *broadcastBGPMsg, 16)
+
+ go func() {
+ for {
+ m := <-ch
+ subtype := bgp.MESSAGE_AS4
+ mp := bgp.NewBGP4MPMessage(m.peerAS, m.localAS, 0, m.peerAddress.String(), m.localAddress.String(), m.fourBytesAs, m.message)
+ if m.fourBytesAs == false {
+ subtype = bgp.MESSAGE
+ }
+ bm, err := bgp.NewMRTMessage(uint32(time.Now().Unix()), bgp.BGP4MP, subtype, mp)
+ if err != nil {
+ log.WithFields(log.Fields{
+ "Topic": "mrt",
+ "Data": m,
+ }).Warn(err)
+ continue
+ }
+ buf, err := bm.Serialize()
+ if err != nil {
+ log.WithFields(log.Fields{
+ "Topic": "mrt",
+ "Data": m,
+ }).Warn(err)
+ } else {
+ f.Write(buf)
+ }
+ }
+ }()
+ return &dumper{
+ ch: ch,
+ }, nil
+}