summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-03 16:28:02 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-05 17:24:36 +0900
commitfcd0483362fe2b314550f808c2ef2917d7f94400 (patch)
tree40545d3a426b9dd1848d8a491ebdc1bed3fd1e24 /packet
parenta0f734a6d7e49b6148703f519b601bac3ad30e7b (diff)
cli: support adding a path with route-target from cli command
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp.go26
1 files changed, 24 insertions, 2 deletions
diff --git a/packet/bgp.go b/packet/bgp.go
index 35e70e72..31dde01f 100644
--- a/packet/bgp.go
+++ b/packet/bgp.go
@@ -860,7 +860,7 @@ func getRouteDistinguisher(data []byte) RouteDistinguisherInterface {
return rd
}
-func parseRd(input string) ([]string, error) {
+func parseRdAndRt(input string) ([]string, error) {
exp := regexp.MustCompile("^((\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)|((\\d+)\\.)?(\\d+)):(\\d+)$")
group := exp.FindSubmatch([]byte(input))
if len(group) != 10 {
@@ -874,7 +874,7 @@ func parseRd(input string) ([]string, error) {
}
func ParseRouteDistinguisher(rd string) (RouteDistinguisherInterface, error) {
- elems, err := parseRd(rd)
+ elems, err := parseRdAndRt(rd)
if err != nil {
return nil, err
}
@@ -3235,6 +3235,28 @@ func NewFourOctetAsSpecificExtended(as uint32, localAdmin uint16, isTransitive b
}
}
+func ParseRouteTarget(rt string) (ExtendedCommunityInterface, error) {
+ elems, err := parseRdAndRt(rt)
+ if err != nil {
+ return nil, err
+ }
+ localAdmin, _ := strconv.Atoi(elems[9])
+ ip := net.ParseIP(elems[1])
+ isTransitive := true
+ switch {
+ case ip.To4() != nil:
+ return NewIPv4AddressSpecificExtended(elems[1], uint16(localAdmin), isTransitive), nil
+ case elems[6] == "" && elems[7] == "":
+ asn, _ := strconv.Atoi(elems[8])
+ return NewTwoOctetAsSpecificExtended(uint16(asn), uint32(localAdmin), isTransitive), nil
+ default:
+ fst, _ := strconv.Atoi(elems[7])
+ snd, _ := strconv.Atoi(elems[8])
+ asn := fst<<16 | snd
+ return NewFourOctetAsSpecificExtended(uint32(asn), uint16(localAdmin), isTransitive), nil
+ }
+}
+
type OpaqueExtendedValueInterface interface {
Serialize() ([]byte, error)
String() string