summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-02-11 21:46:02 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2018-02-13 15:10:58 +0900
commitbe40351b8aa925a99798998514244a9d700c5691 (patch)
treefab570be6b31f246ad8d2d3ea752903747cd12d7 /packet
parent7a3cc616c3126bff5245c7a97d7fbe2904a67a24 (diff)
packet/bgp: Missing String()/MarshalJSON() of PathAttribute subs
First this patch removes String() and MarshalJSON() functions of PathAttribute struct. This helps to find the struct types which embed PathAttribute struct without having own String() and MarshalJSON() functions. If those functions of PathAttribute struct are unexpectedly called, those functions are not enough to display its contents. Then this patch implements missing String() and MarshalJSON() functions for some struct types which embed PathAttribute struct. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp/bgp.go58
1 files changed, 44 insertions, 14 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index d585133e..1d2e5917 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -4943,20 +4943,6 @@ func (p *PathAttribute) Serialize(value []byte, options ...*MarshallingOption) (
return buf, nil
}
-func (p *PathAttribute) String() string {
- return fmt.Sprintf("{Type: %s, Flags: %s}", p.Type, p.Flags)
-}
-
-func (p *PathAttribute) MarshalJSON() ([]byte, error) {
- return json.Marshal(struct {
- Type BGPAttrType `json:"type"`
- Flags BGPAttrFlag `json:"flags"`
- }{
- Type: p.GetType(),
- Flags: p.Flags,
- })
-}
-
type PathAttributeOrigin struct {
PathAttribute
Value uint8
@@ -7333,6 +7319,16 @@ func (p *PathAttributeAs4Path) String() string {
return strings.Join(params, " ")
}
+func (p *PathAttributeAs4Path) MarshalJSON() ([]byte, error) {
+ return json.Marshal(struct {
+ Type BGPAttrType `json:"type"`
+ Value []*As4PathParam `json:"as_paths"`
+ }{
+ Type: p.GetType(),
+ Value: p.Value,
+ })
+}
+
func NewPathAttributeAs4Path(value []*As4PathParam) *PathAttributeAs4Path {
t := BGP_ATTR_TYPE_AS4_PATH
return &PathAttributeAs4Path{
@@ -7371,6 +7367,22 @@ func (p *PathAttributeAs4Aggregator) Serialize(options ...*MarshallingOption) ([
return p.PathAttribute.Serialize(buf, options...)
}
+func (p *PathAttributeAs4Aggregator) String() string {
+ return fmt.Sprintf("{As4Aggregator: {AS: %d, Address: %s}}", p.Value.AS, p.Value.Address)
+}
+
+func (p *PathAttributeAs4Aggregator) MarshalJSON() ([]byte, error) {
+ return json.Marshal(struct {
+ Type BGPAttrType `json:"type"`
+ AS uint32 `json:"as"`
+ Address string `json:"address"`
+ }{
+ Type: p.GetType(),
+ AS: p.Value.AS,
+ Address: p.Value.Address.String(),
+ })
+}
+
func NewPathAttributeAs4Aggregator(as uint32, address string) *PathAttributeAs4Aggregator {
t := BGP_ATTR_TYPE_AS4_AGGREGATOR
return &PathAttributeAs4Aggregator{
@@ -7572,6 +7584,24 @@ func (p *PathAttributeTunnelEncap) Serialize(options ...*MarshallingOption) ([]b
return p.PathAttribute.Serialize(buf, options...)
}
+func (p *PathAttributeTunnelEncap) String() string {
+ tlvList := make([]string, len(p.Value), len(p.Value))
+ for i, v := range p.Value {
+ tlvList[i] = v.String()
+ }
+ return fmt.Sprintf("{TunnelEncap: %s}", strings.Join(tlvList, ", "))
+}
+
+func (p *PathAttributeTunnelEncap) MarshalJSON() ([]byte, error) {
+ return json.Marshal(struct {
+ Type BGPAttrType `json:"type"`
+ Value []*TunnelEncapTLV `json:"value"`
+ }{
+ Type: p.Type,
+ Value: p.Value,
+ })
+}
+
func NewPathAttributeTunnelEncap(value []*TunnelEncapTLV) *PathAttributeTunnelEncap {
t := BGP_ATTR_TYPE_TUNNEL_ENCAP
return &PathAttributeTunnelEncap{