summaryrefslogtreecommitdiffhomepage
path: root/server/mrt.go
diff options
context:
space:
mode:
Diffstat (limited to 'server/mrt.go')
-rw-r--r--server/mrt.go62
1 files changed, 47 insertions, 15 deletions
diff --git a/server/mrt.go b/server/mrt.go
index 06537817..884f21ea 100644
--- a/server/mrt.go
+++ b/server/mrt.go
@@ -28,6 +28,11 @@ import (
"github.com/osrg/gobgp/table"
)
+const (
+ MIN_ROTATION_INTERVAL = 60
+ MIN_DUMP_INTERVAL = 60
+)
+
type mrtWriter struct {
dead chan struct{}
s *BgpServer
@@ -74,7 +79,7 @@ func (m *mrtWriter) loop() error {
if m.rotationInterval != 0 {
rotator.Stop()
}
- if m.dumpInterval == 0 {
+ if m.dumpInterval != 0 {
dump.Stop()
}
w.Stop()
@@ -197,13 +202,7 @@ func (m *mrtWriter) loop() error {
w(b.Bytes())
}
}
- select {
- case <-m.dead:
- drain(nil)
- return nil
- case e := <-w.Event():
- drain(e)
- case <-rotator.C:
+ rotate := func() {
m.file.Close()
file, err := mrtFileOpen(m.filename, m.rotationInterval)
if err == nil {
@@ -214,6 +213,23 @@ func (m *mrtWriter) loop() error {
"Error": err,
}).Warn("can't rotate MRT file")
}
+ }
+
+ select {
+ case <-m.dead:
+ drain(nil)
+ return nil
+ case e := <-w.Event():
+ drain(e)
+ if m.dumpType == config.MRT_TYPE_TABLE && m.rotationInterval != 0 {
+ rotate()
+ }
+ case <-rotator.C:
+ if m.dumpType == config.MRT_TYPE_UPDATES {
+ rotate()
+ } else {
+ w.Generate(WATCH_EVENT_TYPE_TABLE)
+ }
case <-dump.C:
w.Generate(WATCH_EVENT_TYPE_TABLE)
}
@@ -291,21 +307,37 @@ func (m *mrtManager) enable(c *config.MrtConfig) error {
}
rInterval := c.RotationInterval
- if rInterval != 0 && rInterval < 30 {
- log.Info("minimum mrt dump interval is 30 seconds")
- rInterval = 30
- }
dInterval := c.DumpInterval
+
+ setRotationMin := func() {
+ if rInterval < MIN_ROTATION_INTERVAL {
+ log.WithFields(log.Fields{
+ "Topic": "MRT",
+ }).Info("minimum mrt rotation interval is %d seconds", MIN_ROTATION_INTERVAL)
+ rInterval = MIN_ROTATION_INTERVAL
+ }
+ }
+
if c.DumpType == config.MRT_TYPE_TABLE {
- if dInterval < 60 {
- log.Info("minimum mrt dump interval is 30 seconds")
- dInterval = 60
+ if rInterval == 0 {
+ if dInterval < MIN_DUMP_INTERVAL {
+ log.WithFields(log.Fields{
+ "Topic": "MRT",
+ }).Info("minimum mrt dump interval is %d seconds", MIN_DUMP_INTERVAL)
+ dInterval = MIN_DUMP_INTERVAL
+ }
+ } else if dInterval == 0 {
+ setRotationMin()
+ } else {
+ return fmt.Errorf("can't specify both intervals in the table dump type")
}
} else if c.DumpType == config.MRT_TYPE_UPDATES {
+ // ignore the dump interval
dInterval = 0
if len(c.TableName) > 0 {
return fmt.Errorf("can't specify the table name with the update dump type")
}
+ setRotationMin()
}
w, err := newMrtWriter(m.bgpServer, c.DumpType, c.FileName, c.TableName, rInterval, dInterval)