summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-06-13 22:47:39 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-07-06 11:08:15 +0900
commit51dad96b92fbd483d7674f8f8617cd2bf8ac965b (patch)
treeb9a6da4b026a57e57e66f05e4e0f2c57f9b31419 /packet
parent6192f9020000a8e1d581a3f92c206189a033bf39 (diff)
api: remove table/ usage in util.go
This is a part of work removing table/ usage in api/. api/ will depend on only protobuf stuff and packet/. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp/bgp.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index 145f7d99..01251167 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -1090,6 +1090,34 @@ type AddrPrefixInterface interface {
SetPathLocalIdentifier(uint32)
}
+func LabelString(nlri AddrPrefixInterface) string {
+ label := ""
+ switch n := nlri.(type) {
+ case *LabeledIPAddrPrefix:
+ label = n.Labels.String()
+ case *LabeledIPv6AddrPrefix:
+ label = n.Labels.String()
+ case *LabeledVPNIPAddrPrefix:
+ label = n.Labels.String()
+ case *LabeledVPNIPv6AddrPrefix:
+ label = n.Labels.String()
+ case *EVPNNLRI:
+ switch route := n.RouteTypeData.(type) {
+ case *EVPNEthernetAutoDiscoveryRoute:
+ label = fmt.Sprintf("[%d]", route.Label)
+ case *EVPNMacIPAdvertisementRoute:
+ var l []string
+ for _, i := range route.Labels {
+ l = append(l, strconv.Itoa(int(i)))
+ }
+ label = fmt.Sprintf("[%s]", strings.Join(l, ","))
+ case *EVPNIPPrefixRoute:
+ label = fmt.Sprintf("[%d]", route.Label)
+ }
+ }
+ return label
+}
+
type PrefixDefault struct {
id uint32
localId uint32
@@ -5271,6 +5299,44 @@ type AsPathParamInterface interface {
String() string
}
+func AsPathString(aspath *PathAttributeAsPath) string {
+ s := bytes.NewBuffer(make([]byte, 0, 64))
+ for i, param := range aspath.Value {
+ segType := param.GetType()
+ asList := param.GetAS()
+ if i != 0 {
+ s.WriteString(" ")
+ }
+
+ sep := " "
+ switch segType {
+ case BGP_ASPATH_ATTR_TYPE_CONFED_SEQ:
+ s.WriteString("(")
+ case BGP_ASPATH_ATTR_TYPE_CONFED_SET:
+ s.WriteString("[")
+ sep = ","
+ case BGP_ASPATH_ATTR_TYPE_SET:
+ s.WriteString("{")
+ sep = ","
+ }
+ for j, as := range asList {
+ s.WriteString(fmt.Sprintf("%d", as))
+ if j != len(asList)-1 {
+ s.WriteString(sep)
+ }
+ }
+ switch segType {
+ case BGP_ASPATH_ATTR_TYPE_CONFED_SEQ:
+ s.WriteString(")")
+ case BGP_ASPATH_ATTR_TYPE_CONFED_SET:
+ s.WriteString("]")
+ case BGP_ASPATH_ATTR_TYPE_SET:
+ s.WriteString("}")
+ }
+ }
+ return s.String()
+}
+
type AsPathParam struct {
Type uint8
Num uint8