From bc694ab7ce5443b9f4256bfdc70efa198fd46037 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Mon, 29 Feb 2016 20:11:44 +0900 Subject: 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 --- packet/bgp.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'packet/bgp.go') 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()}, -- cgit v1.2.3