summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-02-29 20:11:44 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-02-29 20:11:44 +0900
commitbc694ab7ce5443b9f4256bfdc70efa198fd46037 (patch)
tree91ac755d6ff5ef39a3dea4cffc0fe8a767c66579 /packet
parent6d7a5176bf93d8cfa196bfd33edc129835eb6492 (diff)
cli: support ipv4-labeled, ipv6-labeled address family
$ gobgp global rib -a ipv4-labeled add 10.0.0.0/24 100/200 $ gobgp global rib -a ipv4-labeled Network Labels Next Hop AS_PATH Age Attrs *> 10.0.0.0/24 [100, 200] 0.0.0.0 00:00:14 [{Origin: ?}] Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 5e28fdc8..c71d1489 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -1164,6 +1164,27 @@ func NewMPLSLabelStack(labels ...uint32) *MPLSLabelStack {
return &MPLSLabelStack{labels}
}
+func ParseMPLSLabelStack(buf string) (*MPLSLabelStack, error) {
+ elems := strings.Split(buf, "/")
+ labels := make([]uint32, 0, len(elems))
+ if len(elems) == 0 {
+ goto ERR
+ }
+ for _, elem := range elems {
+ i, err := strconv.Atoi(elem)
+ if err != nil {
+ goto ERR
+ }
+ if i < 0 || i > ((1<<20)-1) {
+ goto ERR
+ }
+ labels = append(labels, uint32(i))
+ }
+ return NewMPLSLabelStack(labels...), nil
+ERR:
+ return nil, fmt.Errorf("invalid mpls label stack format")
+}
+
//
// RFC3107 Carrying Label Information in BGP-4
//
@@ -1338,6 +1359,10 @@ func (l *LabeledIPAddrPrefix) Serialize() ([]byte, error) {
return buf, nil
}
+func (l *LabeledIPAddrPrefix) String() string {
+ return fmt.Sprintf("%s/%d", l.Prefix.String(), int(l.Length)-l.Labels.Len()*8)
+}
+
func NewLabeledIPAddrPrefix(length uint8, prefix string, label MPLSLabelStack) *LabeledIPAddrPrefix {
return &LabeledIPAddrPrefix{
IPAddrPrefixDefault{length + uint8(label.Len()*8), net.ParseIP(prefix).To4()},