From 23d1d4322199bbaae52c52aa0db8db9b000944fe Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Wed, 29 Apr 2015 17:49:51 +0000 Subject: api/gobgp: show multiprotocol capabilities in detail /home/vagrant% gobgp -u 192.168.10.4 neighbor 192.168.10.2 BGP neighbor is 192.168.10.2, remote AS 65001 BGP version 4, remote router ID 192.168.10.2 BGP state = BGP_FSM_ESTABLISHED, up for 00:12:57 BGP OutQ = 0, Flops = 0 Neighbor capabilities: MULTIPROTOCOL(IP,UNICAST): advertised MULTIPROTOCOL(L2VPN,EVPN): advertised MULTIPROTOCOL(IP,ENCAP): advertised MULTIPROTOCOL(IP,ROUTE_TARGET_CONSTRTAINS): received ROUTE_REFRESH: advertised FOUR_OCTET_AS_NUMBER: advertised and received Message statistics: Sent Rcvd Opens: 1 1 Notifications: 0 0 Updates: 0 0 Keepalives: 26 26 Route Refesh: 0 0 Discarded: 0 0 Total: 27 27 Signed-off-by: ISHIDA Wataru --- packet/bgp.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'packet/bgp.go') diff --git a/packet/bgp.go b/packet/bgp.go index 8c719d8d..0cc8aca9 100644 --- a/packet/bgp.go +++ b/packet/bgp.go @@ -171,6 +171,7 @@ type ParameterCapabilityInterface interface { Serialize() ([]byte, error) Len() int Code() BGPCapabilityCode + ToApiStruct() *api.Capability } type DefaultParameterCapability struct { @@ -206,6 +207,12 @@ func (c *DefaultParameterCapability) Len() int { return int(c.CapLen + 2) } +func (c *DefaultParameterCapability) ToApiStruct() *api.Capability { + return &api.Capability{ + Code: api.BGP_CAPABILITY(c.Code()), + } +} + type CapMultiProtocolValue struct { AFI uint16 SAFI uint8 @@ -235,6 +242,13 @@ func (c *CapMultiProtocol) Serialize() ([]byte, error) { return c.DefaultParameterCapability.Serialize() } +func (c *CapMultiProtocol) ToApiStruct() *api.Capability { + return &api.Capability{ + Code: api.BGP_CAPABILITY(c.Code()), + MultiProtocol: &api.AddressFamily{api.AFI(c.CapValue.AFI), api.SAFI(c.CapValue.SAFI)}, + } +} + func NewCapMultiProtocol(afi uint16, safi uint8) *CapMultiProtocol { return &CapMultiProtocol{ DefaultParameterCapability{ @@ -310,6 +324,27 @@ func (c *CapGracefulRestart) Serialize() ([]byte, error) { return c.DefaultParameterCapability.Serialize() } +func (c *CapGracefulRestart) ToApiStruct() *api.Capability { + value := &api.GracefulRestart{ + Flags: uint32(c.CapValue.Flags), + Time: uint32(c.CapValue.Time), + } + tuples := []*api.GracefulRestartTuple{} + for _, t := range c.CapValue.Tuples { + tuple := &api.GracefulRestartTuple{ + Af: &api.AddressFamily{api.AFI(t.AFI), api.SAFI(t.SAFI)}, + Flags: uint32(t.Flags), + } + tuples = append(tuples, tuple) + + } + value.Tuples = tuples + return &api.Capability{ + Code: api.BGP_CAPABILITY(c.Code()), + GracefulRestart: value, + } +} + func NewCapGracefulRestart(flags uint8, time uint16, tuples []CapGracefulRestartTuples) *CapGracefulRestart { return &CapGracefulRestart{ DefaultParameterCapability{ @@ -345,6 +380,13 @@ func (c *CapFourOctetASNumber) Serialize() ([]byte, error) { return c.DefaultParameterCapability.Serialize() } +func (c *CapFourOctetASNumber) ToApiStruct() *api.Capability { + return &api.Capability{ + Code: api.BGP_CAPABILITY(c.Code()), + Asn: c.CapValue, + } +} + func NewCapFourOctetASNumber(asnum uint32) *CapFourOctetASNumber { return &CapFourOctetASNumber{ DefaultParameterCapability{ -- cgit v1.2.3