summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp.go
diff options
context:
space:
mode:
authorHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2015-01-27 20:44:00 +0900
committerHiroshi Yokoi <yokoi.hiroshi@po.ntts.co.jp>2015-01-28 14:53:24 +0900
commit838cf25f000481f4adf9e508e1e533ec7e8977d4 (patch)
tree84e31a2cb1a5991fe252edc6c197c0586fd7e11c /packet/bgp.go
parente53a0b535298758300f1db2bffa6611fea54a9e1 (diff)
packet: add String() to RouteTargetMembershipNLRI and ExtendedCommunityInterface
Diffstat (limited to 'packet/bgp.go')
-rw-r--r--packet/bgp.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index e94b2a86..dc32d45a 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -437,6 +437,7 @@ type AddrPrefixInterface interface {
AFI() uint16
SAFI() uint8
Len() int
+ String() string
}
type IPAddrPrefixDefault struct {
@@ -942,6 +943,10 @@ func (n *RouteTargetMembershipNLRI) SAFI() uint8 {
func (n *RouteTargetMembershipNLRI) Len() int { return 12 }
+func (n *RouteTargetMembershipNLRI) String() string {
+ return fmt.Sprintf("%d:%s/%d", n.AS, n.RouteTarget.String(), n.Len()*8)
+}
+
func rfshift(afi uint16, safi uint8) RouteFamily {
return RouteFamily(int(afi)<<16 | int(safi))
}
@@ -2072,6 +2077,7 @@ func NewPathAttributeMpUnreachNLRI(nlri []AddrPrefixInterface) *PathAttributeMpU
type ExtendedCommunityInterface interface {
Serialize() ([]byte, error)
+ String() string
}
type TwoOctetAsSpecificExtended struct {
@@ -2089,6 +2095,10 @@ func (e *TwoOctetAsSpecificExtended) Serialize() ([]byte, error) {
return buf, nil
}
+func (e *TwoOctetAsSpecificExtended) String() string {
+ return fmt.Sprintf("%d:%d", e.AS, e.LocalAdmin)
+}
+
type IPv4AddressSpecificExtended struct {
SubType uint8
IPv4 net.IP
@@ -2104,6 +2114,10 @@ func (e *IPv4AddressSpecificExtended) Serialize() ([]byte, error) {
return buf, nil
}
+func (e *IPv4AddressSpecificExtended) String() string {
+ return fmt.Sprintf("%s:%d", e.IPv4.String(), e.LocalAdmin)
+}
+
type FourOctetAsSpecificExtended struct {
SubType uint8
AS uint32
@@ -2119,6 +2133,14 @@ func (e *FourOctetAsSpecificExtended) Serialize() ([]byte, error) {
return buf, nil
}
+func (e *FourOctetAsSpecificExtended) String() string {
+ buf := make([]byte, 4)
+ binary.BigEndian.PutUint32(buf, e.AS)
+ asUpper := binary.BigEndian.Uint16(buf[0:2])
+ asLower := binary.BigEndian.Uint16(buf[2:])
+ return fmt.Sprintf("%d.%d:%d", asUpper, asLower, e.LocalAdmin)
+}
+
type OpaqueExtended struct {
Value []byte
}
@@ -2130,6 +2152,13 @@ func (e *OpaqueExtended) Serialize() ([]byte, error) {
return buf, nil
}
+func (e *OpaqueExtended) String() string {
+ buf := make([]byte, 8)
+ copy(buf[1:], e.Value)
+ v := binary.BigEndian.Uint64(buf)
+ return fmt.Sprintf("%d", v)
+}
+
type UnknownExtended struct {
Type BGPAttrType
Value []byte
@@ -2142,6 +2171,13 @@ func (e *UnknownExtended) Serialize() ([]byte, error) {
return buf, nil
}
+func (e *UnknownExtended) String() string {
+ buf := make([]byte, 8)
+ copy(buf[1:], e.Value)
+ v := binary.BigEndian.Uint64(buf)
+ return fmt.Sprintf("%d", v)
+}
+
type PathAttributeExtendedCommunities struct {
PathAttribute
Value []ExtendedCommunityInterface