summaryrefslogtreecommitdiffhomepage
path: root/api/attribute.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-19 10:25:50 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-19 12:01:48 +0900
commitb992c538652580cb4150524328dc2c3b13425863 (patch)
tree9911930f2771d7cfb815c9f3624fa13c46766626 /api/attribute.go
parentb73933c4b20e15f468944edd7012a7cc90adf0e7 (diff)
api: Use attribute.proto struct in message Vrf
The current formats of the RD and import/export RTs in message Vrf are the binary type representation, this patch fixes to use the structures defined in attribute.proto file. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'api/attribute.go')
-rw-r--r--api/attribute.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/api/attribute.go b/api/attribute.go
index a4f5734e..65ca6a4f 100644
--- a/api/attribute.go
+++ b/api/attribute.go
@@ -175,6 +175,10 @@ func MarshalRD(rd bgp.RouteDistinguisherInterface) *any.Any {
Assigned: uint32(v.Assigned),
}
default:
+ log.WithFields(log.Fields{
+ "Topic": "protobuf",
+ "RD": rd,
+ }).Warn("invalid rd type to marshal")
return nil
}
a, _ := ptypes.MarshalAny(r)
@@ -695,12 +699,24 @@ func MarshalRT(rt bgp.ExtendedCommunityInterface) *any.Any {
LocalAdmin: uint32(v.LocalAdmin),
}
default:
+ log.WithFields(log.Fields{
+ "Topic": "protobuf",
+ "RT": rt,
+ }).Warn("invalid rt type to marshal")
return nil
}
a, _ := ptypes.MarshalAny(r)
return a
}
+func MarshalRTs(values []bgp.ExtendedCommunityInterface) []*any.Any {
+ rts := make([]*any.Any, 0, len(values))
+ for _, rt := range values {
+ rts = append(rts, MarshalRT(rt))
+ }
+ return rts
+}
+
func UnmarshalRT(a *any.Any) (bgp.ExtendedCommunityInterface, error) {
var value ptypes.DynamicAny
if err := ptypes.UnmarshalAny(a, &value); err != nil {
@@ -721,6 +737,18 @@ func UnmarshalRT(a *any.Any) (bgp.ExtendedCommunityInterface, error) {
return nil, fmt.Errorf("invalid route target type: %s", a.TypeUrl)
}
+func UnmarshalRTs(values []*any.Any) ([]bgp.ExtendedCommunityInterface, error) {
+ rts := make([]bgp.ExtendedCommunityInterface, 0, len(values))
+ for _, an := range values {
+ rt, err := UnmarshalRT(an)
+ if err != nil {
+ return nil, err
+ }
+ rts = append(rts, rt)
+ }
+ return rts, nil
+}
+
func NewExtendedCommunitiesAttributeFromNative(a *bgp.PathAttributeExtendedCommunities) *ExtendedCommunitiesAttribute {
communities := make([]*any.Any, 0, len(a.Value))
for _, value := range a.Value {