diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-08 23:09:26 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-09-10 13:58:26 +0900 |
commit | ba3a7ddb02855ffdf799a65c4cad7d75909a1371 (patch) | |
tree | cc3ce109cf39429ea7a02133c9641e9d5f0894b5 /table | |
parent | dae5f4eee235bfa6c81d76d1bf54889e50e7a51d (diff) |
table: add string method for easier debugging
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 15 | ||||
-rw-r--r-- | table/path.go | 14 |
2 files changed, 24 insertions, 5 deletions
diff --git a/table/destination.go b/table/destination.go index de2bf659..61d3e4c8 100644 --- a/table/destination.go +++ b/table/destination.go @@ -76,6 +76,21 @@ func (lhs *PeerInfo) Equal(rhs *PeerInfo) bool { return false } +func (i *PeerInfo) String() string { + if i.Address == nil { + return "local" + } + s := bytes.NewBuffer(make([]byte, 0, 64)) + s.WriteString(fmt.Sprintf("{ %s | ", i.Address)) + s.WriteString(fmt.Sprintf("as: %d", i.AS)) + s.WriteString(fmt.Sprintf(", id: %s", i.ID)) + if i.RouteReflectorClient { + s.WriteString(fmt.Sprintf(", cluster-id: %s", i.RouteReflectorClusterID)) + } + s.WriteString(" }") + return s.String() +} + type Destination struct { routeFamily bgp.RouteFamily nlri bgp.AddrPrefixInterface diff --git a/table/path.go b/table/path.go index 386d39c3..22a068eb 100644 --- a/table/path.go +++ b/table/path.go @@ -297,11 +297,15 @@ func (path *Path) getPathAttr(pattrType bgp.BGPAttrType) (int, bgp.PathAttribute // return Path's string representation func (path *Path) String() string { - str := fmt.Sprintf("Source: %v, ", path.GetSource()) - str += fmt.Sprintf(" NLRI: %s, ", path.getPrefix()) - str += fmt.Sprintf(" nexthop: %s, ", path.GetNexthop()) - str += fmt.Sprintf(" withdraw: %s, ", path.IsWithdraw) - return str + s := bytes.NewBuffer(make([]byte, 0, 64)) + s.WriteString(fmt.Sprintf("{ %s | ", path.getPrefix())) + s.WriteString(fmt.Sprintf("src: %s", path.GetSource())) + s.WriteString(fmt.Sprintf(", nh: %s", path.GetNexthop())) + if path.IsWithdraw { + s.WriteString(", withdraw") + } + s.WriteString(" }") + return s.String() } func (path *Path) getPrefix() string { |