diff options
-rw-r--r-- | config/serve.go | 34 | ||||
-rw-r--r-- | openswitch/openswitch.go | 15 | ||||
-rw-r--r-- | server/bmp.go | 4 | ||||
-rw-r--r-- | server/collector.go | 13 | ||||
-rw-r--r-- | server/fsm.go | 4 | ||||
-rw-r--r-- | server/mrt.go | 28 | ||||
-rw-r--r-- | server/rpki.go | 36 | ||||
-rw-r--r-- | server/server.go | 54 | ||||
-rw-r--r-- | table/destination.go | 69 | ||||
-rw-r--r-- | table/message.go | 8 | ||||
-rw-r--r-- | table/policy.go | 11 | ||||
-rw-r--r-- | zebra/zapi.go | 48 |
12 files changed, 234 insertions, 90 deletions
diff --git a/config/serve.go b/config/serve.go index 6423dfd7..32bddbea 100644 --- a/config/serve.go +++ b/config/serve.go @@ -42,21 +42,31 @@ func ReadConfigfileServe(path, format string, configCh chan *BgpConfigSet) { goto ERROR } if cnt == 0 { - log.Info("finished reading the config file") + log.WithFields(log.Fields{ + "Topic": "Config", + }).Info("Finished reading the config file") } cnt++ configCh <- c goto NEXT ERROR: if cnt == 0 { - log.Fatal("can't read config file ", path, ", ", err) + log.WithFields(log.Fields{ + "Topic": "Config", + "Error": err, + }).Fatalf("Can't read config file %s", path) } else { - log.Warning("can't read config file ", path, ", ", err) + log.WithFields(log.Fields{ + "Topic": "Config", + "Error": err, + }).Warningf("Can't read config file %s", path) } NEXT: select { case <-sigCh: - log.Info("reload the config file") + log.WithFields(log.Fields{ + "Topic": "Config", + }).Info("Reload the config file") } } } @@ -87,8 +97,12 @@ func UpdateConfig(curC, newC *BgpConfigSet) ([]Neighbor, []Neighbor, []Neighbor, if idx := inSlice(n, curC.Neighbors); idx < 0 { added = append(added, n) } else if !n.Equal(&curC.Neighbors[idx]) { - log.Debug("current neighbor config:", curC.Neighbors[idx]) - log.Debug("new neighbor config:", n) + log.WithFields(log.Fields{ + "Topic": "Config", + }).Debugf("Current neighbor config:%s", curC.Neighbors[idx]) + log.WithFields(log.Fields{ + "Topic": "Config", + }).Debugf("New neighbor config:%s", n) updated = append(updated, n) } } @@ -104,8 +118,12 @@ func UpdateConfig(curC, newC *BgpConfigSet) ([]Neighbor, []Neighbor, []Neighbor, func CheckPolicyDifference(currentPolicy *RoutingPolicy, newPolicy *RoutingPolicy) bool { - log.Debug("current policy : ", currentPolicy) - log.Debug("newPolicy policy : ", newPolicy) + log.WithFields(log.Fields{ + "Topic": "Config", + }).Debugf("Current policy:%s", currentPolicy) + log.WithFields(log.Fields{ + "Topic": "Config", + }).Debugf("New policy:%s", newPolicy) var result bool = false if currentPolicy == nil && newPolicy == nil { diff --git a/openswitch/openswitch.go b/openswitch/openswitch.go index 3d8ca9ff..0b405a9f 100644 --- a/openswitch/openswitch.go +++ b/openswitch/openswitch.go @@ -169,7 +169,9 @@ func parseRouteToGobgp(route ovsdb.RowUpdate, nexthops map[string]ovsdb.Row) (*a nexthop = "::" } if len(nh) == 0 { - log.Debug("nexthop addres does not exist") + log.WithFields(log.Fields{ + "Topic": "openswitch", + }).Debug("nexthop addres does not exist") } else if len(nh) == 1 { if net.ParseIP(nh[0].(string)) == nil { return nil, isWithdraw, isFromGobgp, fmt.Errorf("invalid nexthop address") @@ -286,7 +288,10 @@ func (m *OpsManager) handleVrfUpdate(cli api.GobgpApiClient, update ovsdb.TableU func (m *OpsManager) handleBgpRouterUpdate(cli api.GobgpApiClient, update ovsdb.TableUpdate) { asn, id, err := m.getBGPRouterUUID() if err != nil { - log.Debugf("%s", err) + log.WithFields(log.Fields{ + "Topic": "openswitch", + "Error": err, + }).Debug("Could not get BGP Router UUID") return } for k, v := range update.Rows { @@ -375,7 +380,7 @@ func (m *OpsManager) handleRouteUpdate(cli api.GobgpApiClient, update ovsdb.Tabl log.WithFields(log.Fields{ "Topic": "openswitch", "Path": path, - "Err": err, + "Error": err, }).Debug("failed to parse path") return } @@ -580,7 +585,7 @@ func (m *OpsManager) GobgpMonitor(target string) { log.WithFields(log.Fields{ "Topic": "openswitch", "Type": "MonitorRequest", - "Err": err, + "Error": err, }).Error("failed parse path of gobgp") } o, err := m.TransactPreparation(p) @@ -588,7 +593,7 @@ func (m *OpsManager) GobgpMonitor(target string) { log.WithFields(log.Fields{ "Topic": "openswitch", "Type": "Monitor", - "Err": err, + "Error": err, }).Error("failed transact preparation of ops") } m.opsCh <- o diff --git a/server/bmp.go b/server/bmp.go index 084066ab..3522da98 100644 --- a/server/bmp.go +++ b/server/bmp.go @@ -30,7 +30,7 @@ import ( func (b *bmpClient) tryConnect() *net.TCPConn { interval := 1 for { - log.Debug("connecting bmp server: ", b.host) + log.WithFields(log.Fields{"Topic": "bmp"}).Debugf("Connecting BMP server:%s", b.host) conn, err := net.Dial("tcp", b.host) if err != nil { select { @@ -43,7 +43,7 @@ func (b *bmpClient) tryConnect() *net.TCPConn { interval *= 2 } } else { - log.Info("bmp server is connected, ", b.host) + log.WithFields(log.Fields{"Topic": "bmp"}).Infof("BMP server is connected:%s", b.host) return conn.(*net.TCPConn) } } diff --git a/server/collector.go b/server/collector.go index 583a1999..59f945be 100644 --- a/server/collector.go +++ b/server/collector.go @@ -111,11 +111,11 @@ func path2data(path *table.Path) (map[string]interface{}, map[string]string) { } if err := bgp.FlatUpdate(tags, path.GetNlri().Flat()); err != nil { - log.Error(err) + log.WithFields(log.Fields{"Type": "collector", "Error": err}).Error("NLRI FlatUpdate failed") } for _, p := range path.GetPathAttrs() { if err := bgp.FlatUpdate(tags, p.Flat()); err != nil { - log.Error(err) + log.WithFields(log.Fields{"Type": "collector", "Error": err}).Error("PathAttr FlatUpdate failed") } } return fields, tags @@ -173,15 +173,15 @@ func (c *Collector) loop() { switch msg := ev.(type) { case *WatchEventUpdate: if err := c.writeUpdate(msg); err != nil { - log.Error(err) + log.WithFields(log.Fields{"Type": "collector", "Error": err}).Error("Failed to write update event message") } case *WatchEventPeerState: if err := c.writePeer(msg); err != nil { - log.Error(err) + log.WithFields(log.Fields{"Type": "collector", "Error": err}).Error("Failed to write state changed event message") } case *WatchEventAdjIn: if err := c.writeTable(msg); err != nil { - log.Error(err) + log.WithFields(log.Fields{"Type": "collector", "Error": err}).Error("Failed to write Adj-In event message") } } } @@ -199,12 +199,13 @@ func NewCollector(s *BgpServer, url, dbName string, interval uint64) (*Collector _, _, err = c.Ping(0) if err != nil { log.Error("can not connect to InfluxDB") + log.WithFields(log.Fields{"Type": "collector", "Error": err}).Error("Failed to connect to InfluxDB") return nil, err } q := client.NewQuery("CREATE DATABASE "+dbName, "", "") if response, err := c.Query(q); err != nil || response.Error() != nil { - log.Error("can not create database " + dbName) + log.WithFields(log.Fields{"Type": "collector", "Error": err}).Errorf("Failed to create database:%s", dbName) return nil, err } diff --git a/server/fsm.go b/server/fsm.go index babfde5e..780a2b32 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -436,7 +436,7 @@ func (h *FSMHandler) idle() (bgp.FSMState, FsmStateReason) { return bgp.BGP_FSM_ACTIVE, FSM_IDLE_HOLD_TIMER_EXPIRED } else { - log.Debug("IdleHoldTimer expired, but stay at idle because the admin state is DOWN") + log.WithFields(log.Fields{"Topic": "Peer"}).Debug("IdleHoldTimer expired, but stay at idle because the admin state is DOWN") } case s := <-fsm.adminStateCh: @@ -1263,7 +1263,7 @@ func (h *FSMHandler) loop() error { } e := time.AfterFunc(time.Second*120, func() { - log.Fatal("failed to free the fsm.h.t for ", fsm.pConf.Config.NeighborAddress, oldState, nextState) + log.WithFields(log.Fields{"Topic": "Peer"}).Fatalf("failed to free the fsm.h.t for %s %s %s", fsm.pConf.Config.NeighborAddress, oldState, nextState) }) h.t.Wait() e.Stop() diff --git a/server/mrt.go b/server/mrt.go index dcbd3542..9241eabd 100644 --- a/server/mrt.go +++ b/server/mrt.go @@ -69,7 +69,8 @@ func (m *mrtWriter) loop() error { log.WithFields(log.Fields{ "Topic": "mrt", "Data": m, - }).Warn(err) + "Error": err, + }).Warn("Failed to create MRT message in serialize()") return nil, err } return bm.Serialize() @@ -92,7 +93,7 @@ func (m *mrtWriter) loop() error { log.WithFields(log.Fields{ "Topic": "mrt", "Error": err, - }).Warn(err) + }).Warn("Can't write to destination MRT file") } } @@ -103,7 +104,8 @@ func (m *mrtWriter) loop() error { log.WithFields(log.Fields{ "Topic": "mrt", "Data": e, - }).Warn(err) + "Error": err, + }).Warn("Failed to serialize event") continue } b.Write(buf) @@ -128,7 +130,10 @@ func (m *mrtWriter) loop() error { if err == nil { m.file = file } else { - log.Info("can't rotate mrt file", err) + log.WithFields(log.Fields{ + "Topic": "mrt", + "Error": err, + }).Warn("can't rotate MRT file") } } } @@ -139,6 +144,11 @@ func mrtFileOpen(filename string, interval uint64) (*os.File, error) { if interval != 0 { realname = time.Now().Format(filename) } + log.WithFields(log.Fields{ + "Topic": "mrt", + "Filename": realname, + "Dump Interval": interval, + }).Debug("Setting new MRT destination file") i := len(realname) for i > 0 && os.IsPathSeparator(realname[i-1]) { @@ -153,14 +163,20 @@ func mrtFileOpen(filename string, interval uint64) (*os.File, error) { if j > 0 { if err := os.MkdirAll(realname[0:j-1], 0755); err != nil { - log.Warn(err) + log.WithFields(log.Fields{ + "Topic": "mrt", + "Error": err, + }).Warn("can't create MRT destination directory") return nil, err } } file, err := os.OpenFile(realname, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0644) if err != nil { - log.Warn(err) + log.WithFields(log.Fields{ + "Topic": "mrt", + "Error": err, + }).Warn("can't create MRT destination file") } return file, err } diff --git a/server/rpki.go b/server/rpki.go index c91ee7c0..df105a65 100644 --- a/server/rpki.go +++ b/server/rpki.go @@ -158,7 +158,7 @@ func (m *roaManager) AddServer(host string, lifetime int64) error { lifetime = 3600 } if _, ok := m.clientMap[host]; ok { - return fmt.Errorf("roa server exists %s", host) + return fmt.Errorf("ROA server exists %s", host) } client := NewRoaClient(address, port, m.eventCh, lifetime) m.clientMap[host] = client @@ -169,7 +169,7 @@ func (m *roaManager) AddServer(host string, lifetime int64) error { func (m *roaManager) DeleteServer(host string) error { client, ok := m.clientMap[host] if !ok { - return fmt.Errorf("roa server doesn't exists %s", host) + return fmt.Errorf("ROA server doesn't exists %s", host) } client.reset() delete(m.clientMap, host) @@ -208,7 +208,7 @@ func (m *roaManager) Enable(address string) error { return nil } } - return fmt.Errorf("roa server not found %s", address) + return fmt.Errorf("ROA server not found %s", address) } func (m *roaManager) Disable(address string) error { @@ -219,7 +219,7 @@ func (m *roaManager) Disable(address string) error { return nil } } - return fmt.Errorf("roa server not found %s", address) + return fmt.Errorf("ROA server not found %s", address) } func (m *roaManager) Reset(address string) error { @@ -230,7 +230,7 @@ func (m *roaManager) Reset(address string) error { return nil } } - return fmt.Errorf("roa server not found %s", address) + return fmt.Errorf("ROA server not found %s", address) } func (m *roaManager) SoftReset(address string) error { @@ -242,7 +242,7 @@ func (m *roaManager) SoftReset(address string) error { return nil } } - return fmt.Errorf("roa server not found %s", address) + return fmt.Errorf("ROA server not found %s", address) } func (c *roaManager) ReceiveROA() chan *ROAEvent { @@ -262,12 +262,12 @@ func (m *roaManager) HandleROAEvent(ev *ROAEvent) { if ev.EventType == CONNECTED { ev.conn.Close() } - log.Error("can't find %s roa server configuration", ev.Src) + log.WithFields(log.Fields{"Topic": "rpki"}).Errorf("Can't find %s ROA server configuration", ev.Src) return } switch ev.EventType { case DISCONNECTED: - log.Info("roa server is disconnected, ", ev.Src) + log.WithFields(log.Fields{"Topic": "rpki"}).Infof("ROA server %s is disconnected", ev.Src) client.state.Downtime = time.Now().Unix() // clear state client.endOfData = false @@ -279,7 +279,7 @@ func (m *roaManager) HandleROAEvent(ev *ROAEvent) { client.timer = time.AfterFunc(time.Duration(client.lifetime)*time.Second, client.lifetimeout) client.oldSessionID = client.sessionID case CONNECTED: - log.Info("roa server is connected, ", ev.Src) + log.WithFields(log.Fields{"Topic": "rpki"}).Infof("ROA server %s is connected", ev.Src) client.conn = ev.conn client.state.Uptime = time.Now().Unix() client.t = tomb.Tomb{} @@ -295,9 +295,9 @@ func (m *roaManager) HandleROAEvent(ev *ROAEvent) { // all stale ROAs were deleted -> timer was cancelled // so should not be here. if client.oldSessionID != client.sessionID { - log.Info("reconnected so ignore timeout", client.host) + log.WithFields(log.Fields{"Topic": "rpki"}).Infof("Reconnected to %s. Ignore timeout", client.host) } else { - log.Info("delete all due to timeout", client.host) + log.WithFields(log.Fields{"Topic": "rpki"}).Infof("Deleting all ROAs due to timeout with:%s", client.host) m.deleteAllROA(client.host) } } @@ -330,7 +330,13 @@ func (m *roaManager) deleteROA(roa *ROA) { return } } - log.Info("can't withdraw a roa", roa.Prefix.Prefix.String(), roa.Prefix.Length, roa.AS, roa.MaxLen) + log.WithFields(log.Fields{ + "Topic": "rpki", + "Prefix": roa.Prefix.Prefix.String(), + "Prefix Length": roa.Prefix.Length, + "AS": roa.AS, + "Max Length": roa.MaxLen, + }).Info("Can't withdraw a ROA") } func (m *roaManager) addROA(roa *ROA) { @@ -419,7 +425,11 @@ func (c *roaManager) handleRTRMsg(client *roaClient, state *config.RpkiServerSta received.Error++ } } else { - log.Info("failed to parse a RTR message ", client.host, err) + log.WithFields(log.Fields{ + "Topic": "rpki", + "Host": client.host, + "Error": err, + }).Info("Failed to parse an RTR message") } } diff --git a/server/server.go b/server/server.go index cfbe514f..889e677e 100644 --- a/server/server.go +++ b/server/server.go @@ -76,7 +76,10 @@ func NewTCPListener(address string, port uint32, ch chan *net.TCPConn) (*TCPList conn, err := l.AcceptTCP() if err != nil { close(closeCh) - log.Warn(err) + log.WithFields(log.Fields{ + "Topic": "Peer", + "Error": err, + }).Warn("Failed to AcceptTCP") return err } ch <- conn @@ -148,11 +151,15 @@ func (server *BgpServer) Serve() { handleFsmMsg := func(e *FsmMsg) { peer, found := server.neighborMap[e.MsgSrc] if !found { - log.Warn("Can't find the neighbor ", e.MsgSrc) + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Warnf("Cant't find the neighbor %s", e.MsgSrc) return } if e.Version != peer.fsm.version { - log.Debug("FSM Version inconsistent") + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Debug("FSM version inconsistent") return } server.handleFSMMessage(peer, e) @@ -166,7 +173,11 @@ func (server *BgpServer) Serve() { peer, found := server.neighborMap[remoteAddr] if found { if peer.fsm.adminState != ADMIN_STATE_UP { - log.Debug("new connection for non admin-state-up peer ", remoteAddr, peer.fsm.adminState) + log.WithFields(log.Fields{ + "Topic": "Peer", + "Remote Addr": remoteAddr, + "Admin State": peer.fsm.adminState, + }).Debug("New connection for non admin-state-up peer") conn.Close() return } @@ -196,10 +207,14 @@ func (server *BgpServer) Serve() { conn.Close() return } - log.Debug("accepted a new passive connection from ", remoteAddr) + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Debugf("Accepted a new passive connection from:%s", remoteAddr) peer.PassConn(conn) } else { - log.Info("can't find configuration for a new passive connection from ", remoteAddr) + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Infof("Can't find configuration for a new passive connection from:%s", remoteAddr) conn.Close() } } @@ -641,7 +656,7 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) { log.WithFields(log.Fields{ "Topic": "Peer", "Key": peer.ID(), - }).Debugf("now syncing, suppress sending updates. start deferral timer(%d)", deferral) + }).Debugf("Now syncing, suppress sending updates. start deferral timer(%d)", deferral) time.AfterFunc(time.Second*time.Duration(deferral), deferralExpiredFunc(bgp.RouteFamily(0))) } } else { @@ -1567,10 +1582,14 @@ func (s *BgpServer) GetAdjRib(addr string, family bgp.RouteFamily, in bool, pref var paths []*table.Path if in { paths = peer.adjRibIn.PathList([]bgp.RouteFamily{family}, false) - log.Debugf("RouteFamily=%v adj-rib-in found : %d", family.String(), len(paths)) + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Debugf("RouteFamily=%v adj-rib-in found : %d", family.String(), len(paths)) } else { paths = peer.adjRibOut.PathList([]bgp.RouteFamily{family}, false) - log.Debugf("RouteFamily=%v adj-rib-out found : %d", family.String(), len(paths)) + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Debugf("RouteFamily=%v adj-rib-out found : %d", family.String(), len(paths)) } for i, p := range paths { @@ -1664,7 +1683,9 @@ func (server *BgpServer) addNeighbor(c *config.Neighbor) error { SetTcpMD5SigSockopts(l, addr, c.Config.AuthPassword) } } - log.Info("Add a peer configuration for ", addr) + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Infof("Add a peer configuration for:%s", addr) peer := NewPeer(&server.bgpConfig.Global, c, server.globalRib, server.policy) server.setPolicyByConfig(peer.ID(), c.ApplyPolicy) @@ -1716,16 +1737,23 @@ func (server *BgpServer) deleteNeighbor(c *config.Neighbor, code, subcode uint8) for _, l := range server.Listeners(addr) { SetTcpMD5SigSockopts(l, addr, "") } - log.Info("Delete a peer configuration for ", addr) + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Infof("Delete a peer configuration for:%s", addr) n.fsm.sendNotification(code, subcode, nil, "") go func(addr string) { - t := time.AfterFunc(time.Minute*5, func() { log.Fatal("failed to free the fsm.h.t for ", addr) }) + logfatal := func() { + log.WithFields(log.Fields{ + "Topic": "Peer", + }).Fatalf("Failed to free the fsm.h.t for %s", addr) + } + t := time.AfterFunc(time.Minute*5, logfatal) n.fsm.h.t.Kill(nil) n.fsm.h.t.Wait() t.Stop() - t = time.AfterFunc(time.Minute*5, func() { log.Fatal("failed to free the fsm.h for ", addr) }) + t = time.AfterFunc(time.Minute*5, logfatal) n.fsm.t.Kill(nil) n.fsm.t.Wait() t.Stop() diff --git a/table/destination.go b/table/destination.go index b1fa3509..f5bd2c34 100644 --- a/table/destination.go +++ b/table/destination.go @@ -414,7 +414,9 @@ func (dest *Destination) computeKnownBestPath() (*Path, BestPathReason, error) { return nil, BPR_UNKNOWN, nil } - log.Debugf("computeKnownBestPath known pathlist: %d", len(dest.knownPathList)) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("computeKnownBestPath known pathlist: %d", len(dest.knownPathList)) // We pick the first path as current best path. This helps in breaking // tie between two new paths learned in one cycle for which best-path @@ -521,7 +523,10 @@ func (p paths) Less(i, j int) bool { var e error = nil better, e = compareByRouterID(path1, path2) if e != nil { - log.Error(e) + log.WithFields(log.Fields{ + "Topic": "Table", + "Error": e, + }).Error("Could not get best path by comparing router ID") } reason = BPR_ROUTER_ID } @@ -543,7 +548,9 @@ func compareByReachableNexthop(path1, path2 *Path) *Path { // // If no path matches this criteria, return None. // However RouteServer doesn't need to check reachability, so return nil. - log.Debugf("enter compareByReachableNexthop -- path1: %s, path2: %s", path1, path2) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("enter compareByReachableNexthop -- path1: %s, path2: %s", path1, path2) return nil } @@ -554,7 +561,9 @@ func compareByHighestWeight(path1, path2 *Path) *Path { // is configured. // Return: // nil if best path among given paths cannot be decided, else best path. - log.Debugf("enter compareByHighestWeight -- path1: %s, path2: %s", path1, path2) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("enter compareByHighestWeight -- path1: %s, path2: %s", path1, path2) return nil } @@ -567,7 +576,9 @@ func compareByLocalPref(path1, path2 *Path) *Path { // we return None. // // # Default local-pref values is 100 - log.Debugf("enter compareByLocalPref") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByLocalPref") localPref1, _ := path1.GetLocalPref() localPref2, _ := path2.GetLocalPref() // Highest local-preference value is preferred. @@ -588,7 +599,9 @@ func compareByLocalOrigin(path1, path2 *Path) *Path { // Returns None if given paths have same source. // // If both paths are from same sources we cannot compare them here. - log.Debugf("enter compareByLocalOrigin") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByLocalOrigin") if path1.GetSource().Equal(path2.GetSource()) { return nil } @@ -610,7 +623,9 @@ func compareByASPath(path1, path2 *Path) *Path { // // Shortest as-path length is preferred. If both path have same lengths, // we return None. - log.Debugf("enter compareByASPath") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByASPath") attribute1 := path1.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) attribute2 := path2.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) @@ -626,7 +641,9 @@ func compareByASPath(path1, path2 *Path) *Path { l1 := path1.GetAsPathLen() l2 := path2.GetAsPathLen() - log.Debugf("compareByASPath -- l1: %d, l2: %d", l1, l2) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("compareByASPath -- l1: %d, l2: %d", l1, l2) if l1 > l2 { return path2 } else if l1 < l2 { @@ -641,7 +658,9 @@ func compareByOrigin(path1, path2 *Path) *Path { // // IGP is preferred over EGP; EGP is preferred over Incomplete. // If both paths have same origin, we return None. - log.Debugf("enter compareByOrigin") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByOrigin") attribute1 := path1.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) attribute2 := path2.getPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) @@ -657,7 +676,9 @@ func compareByOrigin(path1, path2 *Path) *Path { origin1, n1 := binary.Uvarint(attribute1.(*bgp.PathAttributeOrigin).Value) origin2, n2 := binary.Uvarint(attribute2.(*bgp.PathAttributeOrigin).Value) - log.Debugf("compareByOrigin -- origin1: %d(%d), origin2: %d(%d)", origin1, n1, origin2, n2) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("compareByOrigin -- origin1: %d(%d), origin2: %d(%d)", origin1, n1, origin2, n2) // If both paths have same origins if origin1 == origin2 { @@ -702,7 +723,9 @@ func compareByMED(path1, path2 *Path) *Path { }() if SelectionOptions.AlwaysCompareMed || isInternal || isSameAS { - log.Debugf("enter compareByMED") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByMED") getMed := func(path *Path) uint32 { attribute := path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) if attribute == nil { @@ -714,7 +737,9 @@ func compareByMED(path1, path2 *Path) *Path { med1 := getMed(path1) med2 := getMed(path2) - log.Debugf("compareByMED -- med1: %d, med2: %d", med1, med2) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("compareByMED -- med1: %d, med2: %d", med1, med2) if med1 == med2 { return nil } else if med1 < med2 { @@ -722,7 +747,9 @@ func compareByMED(path1, path2 *Path) *Path { } return path2 } else { - log.Debugf("skip compareByMED %v %v %v", SelectionOptions.AlwaysCompareMed, isInternal, isSameAS) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("skip compareByMED %v %v %v", SelectionOptions.AlwaysCompareMed, isInternal, isSameAS) return nil } } @@ -733,9 +760,13 @@ func compareByASNumber(path1, path2 *Path) *Path { // //eBGP path is preferred over iBGP. If both paths are from same kind of //peers, return None. - log.Debugf("enter compareByASNumber") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByASNumber") - log.Debugf("compareByASNumber -- p1Asn: %d, p2Asn: %d", path1.GetSource().AS, path2.GetSource().AS) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("compareByASNumber -- p1Asn: %d, p2Asn: %d", path1.GetSource().AS, path2.GetSource().AS) // If one path is from ibgp peer and another is from ebgp peer, take the ebgp path if path1.IsIBGP() != path2.IsIBGP() { if path1.IsIBGP() { @@ -753,7 +784,9 @@ func compareByIGPCost(path1, path2 *Path) *Path { // // Return None if igp cost is same. // Currently BGPS has no concept of IGP and IGP cost. - log.Debugf("enter compareByIGPCost -- path1: %v, path2: %v", path1, path2) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debugf("enter compareByIGPCost -- path1: %v, path2: %v", path1, path2) return nil } @@ -764,7 +797,9 @@ func compareByRouterID(path1, path2 *Path) (*Path, error) { // not pick best-path based on this criteria. // RFC: http://tools.ietf.org/html/rfc5004 // We pick best path between two iBGP paths as usual. - log.Debugf("enter compareByRouterID") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Debug("enter compareByRouterID") // If both paths are from NC we have same router Id, hence cannot compare. if path1.IsLocal() && path2.IsLocal() { diff --git a/table/message.go b/table/message.go index 9a25d98c..9a09d71f 100644 --- a/table/message.go +++ b/table/message.go @@ -143,7 +143,9 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error { if p.Type == bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET { typ = "CONFED_SET" } - log.Warnf("AS4_PATH contains %s segment %s. ignore", typ, p.String()) + log.WithFields(log.Fields{ + "Topic": "Table", + }).Warnf("AS4_PATH contains %s segment %s. ignore", typ, p.String()) continue } as4Len += p.ASLen() @@ -152,7 +154,9 @@ func UpdatePathAttrs4ByteAs(msg *bgp.BGPUpdate) error { } if asLen+asConfedLen < as4Len { - log.Warnf("AS4_PATH is longer than AS_PATH. ignore AS4_PATH") + log.WithFields(log.Fields{ + "Topic": "Table", + }).Warn("AS4_PATH is longer than AS_PATH. ignore AS4_PATH") return nil } diff --git a/table/policy.go b/table/policy.go index 37aa4355..94773346 100644 --- a/table/policy.go +++ b/table/policy.go @@ -1020,7 +1020,9 @@ func (c *NeighborCondition) Option() MatchOption { func (c *NeighborCondition) Evaluate(path *Path, options *PolicyOptions) bool { if len(c.set.list) == 0 { - log.Debug("NeighborList doesn't have elements") + log.WithFields(log.Fields{ + "Topic": "Policy", + }).Debug("NeighborList doesn't have elements") return true } @@ -1597,7 +1599,8 @@ func (a *MedAction) Apply(path *Path, _ *PolicyOptions) *Path { log.WithFields(log.Fields{ "Topic": "Policy", "Type": "Med Action", - }).Warn(err) + "Error": err, + }).Warn("Could not set Med on path") } return path } @@ -1678,7 +1681,7 @@ func (a *AsPathPrependAction) Apply(path *Path, _ *PolicyOptions) *Path { log.WithFields(log.Fields{ "Topic": "Policy", "Type": "AsPathPrepend Action", - }).Warnf("aspath length is zero.") + }).Warn("aspath length is zero.") return path } asn = aspath[0] @@ -1686,7 +1689,7 @@ func (a *AsPathPrependAction) Apply(path *Path, _ *PolicyOptions) *Path { log.WithFields(log.Fields{ "Topic": "Policy", "Type": "AsPathPrepend Action", - }).Warnf("left-most ASN is not seq") + }).Warn("left-most ASN is not seq") return path } } else { diff --git a/zebra/zapi.go b/zebra/zapi.go index 5cca4493..1f995248 100644 --- a/zebra/zapi.go +++ b/zebra/zapi.go @@ -235,13 +235,17 @@ func NewClient(network, address string, typ ROUTE_TYPE) (*Client, error) { if more { b, err := m.Serialize() if err != nil { - log.Warnf("failed to serialize: %s", m) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Warnf("failed to serialize: %s", m) continue } _, err = conn.Write(b) if err != nil { - log.Errorf("failed to write: %s", err) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Errorf("failed to write: %s", err) close(outgoing) } } else { @@ -255,26 +259,38 @@ func NewClient(network, address string, typ ROUTE_TYPE) (*Client, error) { for { headerBuf, err := readAll(conn, HEADER_SIZE) if err != nil { - log.Error("failed to read header: ", err) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Errorf("failed to read header:%s", err) return } - log.Debugf("read header from zebra: %v", headerBuf) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Debugf("read header from zebra: %v", headerBuf) hd := &Header{} err = hd.DecodeFromBytes(headerBuf) if err != nil { - log.Error("failed to decode header: ", err) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Errorf("failed to decode header:%s", err) return } bodyBuf, err := readAll(conn, int(hd.Len-HEADER_SIZE)) if err != nil { - log.Error("failed to read body: ", err) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Errorf("failed to read body:%s", err) return } - log.Debugf("read body from zebra: %v", bodyBuf) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Debugf("read body from zebra: %v", bodyBuf) m, err := ParseMessage(hd, bodyBuf) if err != nil { - log.Warn("failed to parse message: ", err) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Warnf("failed to parse message:%s", err) continue } @@ -298,7 +314,9 @@ func (c *Client) Receive() chan *Message { func (c *Client) Send(m *Message) { defer func() { if err := recover(); err != nil { - log.Debugf("recovered: %s", err) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Debugf("recovered: %s", err) } }() log.WithFields(log.Fields{ @@ -926,13 +944,19 @@ func ParseMessage(hdr *Header, data []byte) (*Message, error) { m.Body = &RouterIDUpdateBody{} case IPV4_ROUTE_ADD, IPV6_ROUTE_ADD, IPV4_ROUTE_DELETE, IPV6_ROUTE_DELETE: m.Body = &IPRouteBody{Api: m.Header.Command} - log.Debugf("ipv4/v6 route add/delete message received: %v", data) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Debugf("ipv4/v6 route add/delete message received: %v", data) case IPV4_NEXTHOP_LOOKUP, IPV6_NEXTHOP_LOOKUP: m.Body = &NexthopLookupBody{Api: m.Header.Command} - log.Debugf("ipv4/v6 nexthop lookup received: %v", data) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Debugf("ipv4/v6 nexthop lookup received: %v", data) case IPV4_IMPORT_LOOKUP: m.Body = &ImportLookupBody{Api: m.Header.Command} - log.Debugf("ipv4 import lookup message received: %v", data) + log.WithFields(log.Fields{ + "Topic": "Zebra", + }).Debugf("ipv4 import lookup message received: %v", data) default: return nil, fmt.Errorf("Unknown zapi command: %d", m.Header.Command) } |