diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-08-06 15:36:09 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-12 08:04:30 +0900 |
commit | 80968977f0721e5899ca7751ec0e762bebc5d5cb (patch) | |
tree | 80159b1129436f7d4cf12193e9ecb3f02f35311c | |
parent | a7682648404d444a44b953e4db0fed1660ce60ee (diff) |
server: store whole capabilities with the same cap code
multi protocol capability may appear several times.
store all of them to show through gobgp cli command.
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | gobgp/neighbor.go | 11 | ||||
-rw-r--r-- | server/peer.go | 15 |
2 files changed, 20 insertions, 6 deletions
diff --git a/gobgp/neighbor.go b/gobgp/neighbor.go index ad82e312..ad700311 100644 --- a/gobgp/neighbor.go +++ b/gobgp/neighbor.go @@ -186,6 +186,8 @@ func showNeighbor(args []string) error { sort.Sort(caps) + firstMp := true + for _, c := range caps { support := "" if m := lookup(c, p.Conf.LocalCap); m != nil { @@ -199,9 +201,14 @@ func showNeighbor(args []string) error { } if c.Code != api.BGP_CAPABILITY_MULTIPROTOCOL { - fmt.Printf(" %s: %s\n", c.Code, support) + fmt.Printf(" %s:\t%s\n", c.Code, support) } else { - fmt.Printf(" %s(%s): %s\n", c.Code, c.MultiProtocol, support) + if firstMp { + fmt.Printf(" %s:\n", c.Code) + firstMp = false + } + fmt.Printf(" %s:\t%s\n", bgp.RouteFamily(c.MultiProtocol), support) + } } fmt.Print(" Message statistics:\n") diff --git a/server/peer.go b/server/peer.go index 0d7e2369..43a9d32a 100644 --- a/server/peer.go +++ b/server/peer.go @@ -37,7 +37,7 @@ type Peer struct { conf config.Neighbor fsm *FSM rfMap map[bgp.RouteFamily]bool - capMap map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface + capMap map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface adjRib *table.AdjRib peerInfo *table.PeerInfo outgoing chan *bgp.BGPMessage @@ -52,7 +52,7 @@ func NewPeer(g config.Global, conf config.Neighbor) *Peer { gConf: g, conf: conf, rfMap: make(map[bgp.RouteFamily]bool), - capMap: make(map[bgp.BGPCapabilityCode]bgp.ParameterCapabilityInterface), + capMap: make(map[bgp.BGPCapabilityCode][]bgp.ParameterCapabilityInterface), } conf.NeighborState.SessionState = uint32(bgp.BGP_FSM_IDLE) @@ -113,7 +113,12 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b for _, p := range body.OptParams { if paramCap, y := p.(*bgp.OptionParameterCapability); y { for _, c := range paramCap.Capability { - peer.capMap[c.Code()] = c + m, ok := peer.capMap[c.Code()] + if !ok { + m = make([]bgp.ParameterCapabilityInterface, 0, 1) + } + peer.capMap[c.Code()] = append(m, c) + if c.Code() == bgp.BGP_CAP_MULTIPROTOCOL { m := c.(*bgp.CapMultiProtocol) r[bgp.AfiSafiToRouteFamily(m.CapValue.AFI, m.CapValue.SAFI)] = true @@ -234,7 +239,9 @@ func (peer *Peer) ToApiStruct() *api.Peer { remoteCap := make([]*api.Capability, 0, len(peer.capMap)) for _, c := range peer.capMap { - remoteCap = append(remoteCap, c.ToApiStruct()) + for _, m := range c { + remoteCap = append(remoteCap, m.ToApiStruct()) + } } caps := capabilitiesFromConfig(&peer.gConf, &peer.conf) |