diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-22 04:33:09 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-12-22 04:33:09 -0800 |
commit | 6ecf5e15ceda5e8535727d16a3d04e35cb7f51d0 (patch) | |
tree | b69464e974cc00cab9dadd5c1b8a6c66e5cf13b1 /table | |
parent | d2bbac0697bfdbf6395172163cd0d171bb196246 (diff) |
clean up logger usage
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 71 | ||||
-rw-r--r-- | table/path.go | 9 | ||||
-rw-r--r-- | table/table.go | 13 | ||||
-rw-r--r-- | table/table_manager.go | 32 |
4 files changed, 58 insertions, 67 deletions
diff --git a/table/destination.go b/table/destination.go index 7be547c4..f2b4cafe 100644 --- a/table/destination.go +++ b/table/destination.go @@ -18,6 +18,7 @@ package table import ( "encoding/binary" "fmt" + log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" "net" "reflect" @@ -166,7 +167,7 @@ func (dd *DestinationDefault) removeOldPathsFromSource(source *PeerInfo) []Path func (dd *DestinationDefault) validatePath(path Path) { if path == nil || path.getRouteFamily() != dd.ROUTE_FAMILY { - logger.Error("Invalid path. Expected %s path got %s.", dd.ROUTE_FAMILY, path) + log.Error("Invalid path. Expected %s path got %s.", dd.ROUTE_FAMILY, path) } } @@ -190,7 +191,7 @@ func (dest *DestinationDefault) Calculate(localAsn uint32) (Path, string, error) // it becomes best path. dest.knownPathList = append(dest.knownPathList, dest.newPathList[0]) dest.newPathList, _ = deleteAt(dest.newPathList, 0) - logger.Debugf("best path : %s, reason=%s", dest.knownPathList[0], BPR_ONLY_PATH) + log.Debugf("best path : %s, reason=%s", dest.knownPathList[0], BPR_ONLY_PATH) return dest.knownPathList[0], BPR_ONLY_PATH, nil } @@ -198,7 +199,7 @@ func (dest *DestinationDefault) Calculate(localAsn uint32) (Path, string, error) // If we have a new version of old/known path we use it and delete old // one. dest.removeOldPaths() - logger.Debugf("removeOldPaths") + log.Debugf("removeOldPaths") // Collect all new paths into known paths. dest.knownPathList = append(dest.knownPathList, dest.newPathList...) @@ -214,7 +215,7 @@ func (dest *DestinationDefault) Calculate(localAsn uint32) (Path, string, error) // Compute new best path currentBestPath, reason, e := dest.computeKnownBestPath(localAsn) if e != nil { - logger.Error(e) + log.Error(e) } return currentBestPath, reason, e @@ -230,7 +231,7 @@ func (dest *DestinationDefault) Calculate(localAsn uint32) (Path, string, error) //""" func (dest *DestinationDefault) removeWithdrawls() { - logger.Debugf("Removing %d withdrawals", len(dest.withdrawList)) + log.Debugf("Removing %d withdrawals", len(dest.withdrawList)) // If we have no withdrawals, we have nothing to do. if len(dest.withdrawList) == 0 { @@ -240,7 +241,7 @@ func (dest *DestinationDefault) removeWithdrawls() { // If we have some withdrawals and no know-paths, it means it is safe to // delete these withdraws. if len(dest.knownPathList) == 0 { - logger.Debugf("Found %s withdrawals for path(s) that did not get installed", len(dest.withdrawList)) + log.Debugf("Found %s withdrawals for path(s) that did not get installed", len(dest.withdrawList)) dest.withdrawList = dest.withdrawList[len(dest.withdrawList):] } @@ -265,13 +266,13 @@ func (dest *DestinationDefault) removeWithdrawls() { // We do no have any match for this withdraw. if !isFound { - logger.Debugf("No matching path for withdraw found, may be path was not installed into table: %s", withdraw.String()) + log.Debugf("No matching path for withdraw found, may be path was not installed into table: %s", withdraw.String()) } } // If we have partial match. if len(matches) != len(dest.withdrawList) { - logger.Debugf( + log.Debugf( "Did not find match for some withdrawals. Number of matches(%d), number of withdrawals (%d)", len(matches), len(dest.withdrawList)) } @@ -281,14 +282,14 @@ func (dest *DestinationDefault) removeWithdrawls() { var result bool = false dest.knownPathList, result = removeWithPath(dest.knownPathList, path) if !result { - logger.Debugf("could not remove path: %s from knownPathList", path.String()) + log.Debugf("could not remove path: %s from knownPathList", path.String()) } } for _, path := range wMatches { var result bool = false dest.withdrawList, result = removeWithPath(dest.withdrawList, path) if !result { - logger.Debugf("could not remove path: %s from withdrawList", path.String()) + log.Debugf("could not remove path: %s from withdrawList", path.String()) } } } @@ -302,7 +303,7 @@ func (dest *DestinationDefault) computeKnownBestPath(localAsn uint32) (Path, str return nil, "", fmt.Errorf("Need at-least one known path to compute best path") } - logger.Debugf("computeKnownBestPath known pathlist: %d", len(dest.knownPathList)) + log.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 @@ -347,10 +348,10 @@ func (dest *DestinationDefault) removeOldPaths() { match := false knownPaths, match = removeWithPath(knownPaths, oldPath) if !match { - logger.Debugf("not exist withdrawal of old path in known paths: %s ", oldPath.String()) + log.Debugf("not exist withdrawal of old path in known paths: %s ", oldPath.String()) } - logger.Debugf("Implicit withdrawal of old path, "+ + log.Debugf("Implicit withdrawal of old path, "+ "since we have learned new path from same source: %s", oldPath.String()) } } @@ -457,7 +458,7 @@ func computeBestPath(localAsn uint32, path1, path2 Path) (Path, string) { var e error = nil bestPath, e = compareByRouterID(localAsn, path1, path2) if e != nil { - logger.Error(e) + log.Error(e) } bestPathReason = BPR_ROUTER_ID } @@ -473,8 +474,8 @@ 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. - logger.Debugf("enter compareByReachableNexthop") - logger.Debugf("path1: %s, path2: %s", path1, path2) + log.Debugf("enter compareByReachableNexthop") + log.Debugf("path1: %s, path2: %s", path1, path2) return nil } @@ -485,8 +486,8 @@ func compareByHighestWeight(path1, path2 Path) Path { // is configured. // Return: // nil if best path among given paths cannot be decided, else best path. - logger.Debugf("enter compareByHighestWeight") - logger.Debugf("path1: %s, path2: %s", path1, path2) + log.Debugf("enter compareByHighestWeight") + log.Debugf("path1: %s, path2: %s", path1, path2) return nil } @@ -499,7 +500,7 @@ func compareByLocalPref(path1, path2 Path) Path { // we return None. // // # Default local-pref values is 100 - logger.Debugf("enter compareByLocalPref") + log.Debugf("enter compareByLocalPref") _, attribute1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF) _, attribute2 := path2.GetPathAttr(bgp.BGP_ATTR_TYPE_LOCAL_PREF) @@ -528,7 +529,7 @@ 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. - logger.Debugf("enter compareByLocalOrigin") + log.Debugf("enter compareByLocalOrigin") if path1.getSource() == path2.getSource() { return nil } @@ -550,7 +551,7 @@ func compareByASPath(path1, path2 Path) Path { // // Shortest as-path length is preferred. If both path have same lengths, // we return None. - logger.Debugf("enter compareByASPath") + log.Debugf("enter compareByASPath") _, attribute1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) _, attribute2 := path2.GetPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH) @@ -558,7 +559,7 @@ func compareByASPath(path1, path2 Path) Path { asPath2 := attribute2.(*bgp.PathAttributeAsPath) if asPath1 == nil || asPath2 == nil { - logger.Error("it is not possible to compare asPath are not present") + log.Error("it is not possible to compare asPath are not present") } var l1, l2 int @@ -570,9 +571,9 @@ func compareByASPath(path1, path2 Path) Path { l2 += pathParam.ASLen() } - logger.Debugf("l1: %d, l2: %d", l1, l2) - logger.Debug(reflect.TypeOf(asPath1.Value)) - logger.Debug(asPath1.Value) + log.Debugf("l1: %d, l2: %d", l1, l2) + log.Debug(reflect.TypeOf(asPath1.Value)) + log.Debug(asPath1.Value) if l1 > l2 { return path2 } else if l1 < l2 { @@ -587,19 +588,19 @@ 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. - logger.Debugf("enter compareByOrigin") + log.Debugf("enter compareByOrigin") _, attribute1 := path1.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) _, attribute2 := path2.GetPathAttr(bgp.BGP_ATTR_TYPE_ORIGIN) if attribute1 == nil || attribute2 == nil { - logger.Error("it is not possible to compare origin are not present") + log.Error("it is not possible to compare origin are not present") return nil } origin1, n1 := binary.Uvarint(attribute1.(*bgp.PathAttributeOrigin).Value) origin2, n2 := binary.Uvarint(attribute2.(*bgp.PathAttributeOrigin).Value) - logger.Debugf("path1 origin value: %d, %d byte read", origin1, n1) - logger.Debugf("path2 origin value: %d, %d byte read", origin2, n2) + log.Debugf("path1 origin value: %d, %d byte read", origin1, n1) + log.Debugf("path2 origin value: %d, %d byte read", origin2, n2) // If both paths have same origins if origin1 == origin2 { @@ -620,7 +621,7 @@ func compareByMED(path1, path2 Path) Path { // RFC says lower MED is preferred over higher MED value. // compare MED among not only same AS path but also all path, // like bgp always-compare-med - logger.Debugf("enter compareByMED") + log.Debugf("enter compareByMED") getMed := func(path Path) uint32 { _, attribute := path.GetPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC) if attribute == nil { @@ -647,7 +648,7 @@ func compareByASNumber(localAsn uint32, path1, path2 Path) Path { // //eBGP path is preferred over iBGP. If both paths are from same kind of //peers, return None. - logger.Debugf("enter compareByASNumber") + log.Debugf("enter compareByASNumber") getPathSourceAsn := func(path Path) uint32 { var asn uint32 if path.getSource() == nil { @@ -679,8 +680,8 @@ func compareByIGPCost(path1, path2 Path) Path { // // Return None if igp cost is same. // Currently BGPS has no concept of IGP and IGP cost. - logger.Debugf("enter compareByIGPCost") - logger.Debugf("path1: %s, path2: %s", path1, path2) + log.Debugf("enter compareByIGPCost") + log.Debugf("path1: %s, path2: %s", path1, path2) return nil } @@ -691,7 +692,7 @@ func compareByRouterID(localAsn uint32, 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. - logger.Debugf("enter compareByRouterID") + log.Debugf("enter compareByRouterID") getAsn := func(pathSource *PeerInfo) uint32 { if pathSource == nil { return localAsn @@ -826,7 +827,7 @@ func (ipv6d *IPv6Destination) String() string { func (ipv6d *IPv6Destination) getPrefix() net.IP { var ip net.IP - logger.Debugf("type %s", reflect.TypeOf(ipv6d.nlri)) + log.Debugf("type %s", reflect.TypeOf(ipv6d.nlri)) switch p := ipv6d.nlri.(type) { case *bgp.IPv6AddrPrefix: ip = p.IPAddrPrefix.IPAddrPrefixDefault.Prefix diff --git a/table/path.go b/table/path.go index b9362bd9..777e17c6 100644 --- a/table/path.go +++ b/table/path.go @@ -17,6 +17,7 @@ package table import ( "fmt" + log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" "net" "reflect" @@ -56,7 +57,7 @@ type PathDefault struct { func NewPathDefault(rf RouteFamily, source *PeerInfo, nlri bgp.AddrPrefixInterface, sourceVerNum int, nexthop net.IP, isWithdraw bool, pattrs []bgp.PathAttributeInterface, medSetByTargetNeighbor bool) *PathDefault { if !isWithdraw && pattrs == nil { - logger.Error("Need to provide nexthop and patattrs for path that is not a withdraw.") + log.Error("Need to provide nexthop and patattrs for path that is not a withdraw.") return nil } @@ -196,7 +197,7 @@ func (pi *PathDefault) getPrefix() net.IP { func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.PathAttributeInterface, isWithdraw bool) Path { rf := RouteFamily(int(nlri.AFI())<<16 | int(nlri.SAFI())) - logger.Debugf("afi: %d, safi: %d ", int(nlri.AFI()), nlri.SAFI()) + log.Debugf("afi: %d, safi: %d ", int(nlri.AFI()), nlri.SAFI()) var path Path var sourceVerNum int = 1 @@ -206,10 +207,10 @@ func CreatePath(source *PeerInfo, nlri bgp.AddrPrefixInterface, attrs []bgp.Path switch rf { case RF_IPv4_UC: - logger.Debugf("RouteFamily : %s", RF_IPv4_UC.String()) + log.Debugf("RouteFamily : %s", RF_IPv4_UC.String()) path = NewIPv4Path(source, nlri, sourceVerNum, isWithdraw, attrs, false) case RF_IPv6_UC: - logger.Debugf("RouteFamily : %s", RF_IPv6_UC.String()) + log.Debugf("RouteFamily : %s", RF_IPv6_UC.String()) path = NewIPv6Path(source, nlri, sourceVerNum, isWithdraw, attrs, false) } return path diff --git a/table/table.go b/table/table.go index 6f2f23eb..1215d51d 100644 --- a/table/table.go +++ b/table/table.go @@ -16,6 +16,7 @@ package table import ( + log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" "net" "reflect" @@ -55,7 +56,7 @@ func (td *TableDefault) getRoutefamily() RouteFamily { //Implements interface func (td *TableDefault) createDest(nlri *bgp.NLRInfo) Destination { //return NewDestination(td, nlri) - logger.Error("CreateDest NotImplementedError") + log.Error("CreateDest NotImplementedError") return nil } @@ -127,22 +128,22 @@ func deleteDest(table Table, dest Destination) { func (td *TableDefault) validatePath(path Path) { if path == nil || path.getRouteFamily() != td.ROUTE_FAMILY { - logger.Errorf("Invalid path. Expected instance of %s route family path, got %s.", td.ROUTE_FAMILY, path) + log.Errorf("Invalid path. Expected instance of %s route family path, got %s.", td.ROUTE_FAMILY, path) } } func (td *TableDefault) validateNlri(nlri bgp.AddrPrefixInterface) { if nlri == nil { - logger.Error("Invalid Vpnv4 prefix given.") + log.Error("Invalid Vpnv4 prefix given.") } } func getOrCreateDest(table Table, nlri bgp.AddrPrefixInterface) Destination { - logger.Debugf("Table type : %s", reflect.TypeOf(table)) + log.Debugf("Table type : %s", reflect.TypeOf(table)) tableKey := table.tableKey(nlri) dest := table.getDestination(tableKey.String()) // If destination for given prefix does not exist we create it. if dest == nil { - logger.Debugf("dest with key %s is not found", tableKey.String()) + log.Debugf("dest with key %s is not found", tableKey.String()) dest = table.createDest(nlri) table.setDestination(tableKey.String(), dest) } @@ -172,7 +173,7 @@ func (td *TableDefault) setDestination(key string, dest Destination) { func (td *TableDefault) tableKey(nlri bgp.AddrPrefixInterface) net.IP { //need Inheritance over ride //return &nlri.IPAddrPrefix.IPAddrPrefixDefault.Prefix - logger.Error("CreateDest NotImplementedError") + log.Error("CreateDest NotImplementedError") return nil } diff --git a/table/table_manager.go b/table/table_manager.go index 4a71bf6f..c6b15543 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -18,17 +18,9 @@ package table import ( log "github.com/Sirupsen/logrus" "github.com/osrg/gobgp/packet" - "os" "time" ) -var logger *log.Logger = &log.Logger{ - Out: os.Stderr, - Formatter: new(log.JSONFormatter), - Hooks: make(map[log.Level][]log.Hook), - Level: log.InfoLevel, -} - type RouteFamily int const ( @@ -230,22 +222,18 @@ func NewTableManager() *TableManager { return t } -func setLogger(loggerInstance *log.Logger) { - logger = loggerInstance -} - func (manager *TableManager) calculate(destinationList []Destination) ([]Path, []Destination, error) { bestPaths := make([]Path, 0) lostDest := make([]Destination, 0) for _, destination := range destinationList { // compute best path - logger.Infof("Processing destination: %v", destination.String()) + log.Infof("Processing destination: %v", destination.String()) newBestPath, reason, err := destination.Calculate(manager.localAsn) - logger.Debugf("new best path: %v, reason=%v", newBestPath, reason) + log.Debugf("new best path: %v, reason=%v", newBestPath, reason) if err != nil { - logger.Error(err) + log.Error(err) continue } @@ -254,25 +242,25 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ if newBestPath != nil && currentBestPath == newBestPath { // best path is not changed - logger.Debug("best path is not changed") + log.Debug("best path is not changed") continue } if newBestPath == nil { - logger.Debug("best path is nil") + log.Debug("best path is nil") if len(destination.getKnownPathList()) == 0 { // create withdraw path if currentBestPath != nil { - logger.Debug("best path is lost") + log.Debug("best path is lost") destination.setOldBestPath(destination.getBestPath()) lostDest = append(lostDest, destination) } destination.setBestPath(nil) } else { - logger.Error("known path list is not empty") + log.Error("known path list is not empty") } } else { - logger.Debugf("new best path: NLRI: %v, next_hop=%v, reason=%v", + log.Debugf("new best path: NLRI: %v, next_hop=%v, reason=%v", newBestPath.getPrefix().String(), newBestPath.getNexthop().String(), reason) @@ -285,7 +273,7 @@ func (manager *TableManager) calculate(destinationList []Destination) ([]Path, [ rf := destination.getRouteFamily() t := manager.Tables[rf] deleteDest(t, destination) - logger.Debugf("destination removed route_family=%v, destination=%v", rf, destination) + log.Debugf("destination removed route_family=%v, destination=%v", rf, destination) } } return bestPaths, lostDest, nil @@ -315,7 +303,7 @@ func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPM // check msg's type if it's BGPUpdate if message.Header.Type != bgp.BGP_MSG_UPDATE { - logger.Warn("message is not BGPUpdate") + log.Warn("message is not BGPUpdate") return bestPaths, lostDest, nil } |