summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2018-09-11 01:10:44 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-09-12 21:50:29 +0900
commit9420a664c256d96057f6ed83ad736c1ac0cf3359 (patch)
tree686c136b9f0627a5b3c0c906bf855a81179cd575
parentdec0c7d654374a69fef0789ece16d96913a01a3f (diff)
cli: Support Color Extended Community
This patch enables support for Color Extended Community in the CLI. Usage Example: $ gobgp global rib add -a ipv4 10.0.0.0/24 color 10 $ gobgp global rib -a ipv4 Network Next Hop AS_PATH Age Attrs *> 10.0.0.0/24 0.0.0.0 00:00:00 [{Origin: ?} {Extcomms: [10]}] Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
-rw-r--r--cmd/gobgp/cmd/global.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/cmd/gobgp/cmd/global.go b/cmd/gobgp/cmd/global.go
index 521f6b41..637caf6a 100644
--- a/cmd/gobgp/cmd/global.go
+++ b/cmd/gobgp/cmd/global.go
@@ -51,6 +51,7 @@ const (
VALID
NOT_FOUND
INVALID
+ COLOR
)
var ExtCommNameMap = map[ExtCommType]string{
@@ -68,6 +69,7 @@ var ExtCommNameMap = map[ExtCommType]string{
VALID: "valid",
NOT_FOUND: "not-found",
INVALID: "invalid",
+ COLOR: "color",
}
var ExtCommValueMap = map[string]ExtCommType{
@@ -85,6 +87,7 @@ var ExtCommValueMap = map[string]ExtCommType{
ExtCommNameMap[VALID]: VALID,
ExtCommNameMap[NOT_FOUND]: NOT_FOUND,
ExtCommNameMap[INVALID]: INVALID,
+ ExtCommNameMap[COLOR]: COLOR,
}
func rateLimitParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
@@ -274,6 +277,17 @@ func validationParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
return []bgp.ExtendedCommunityInterface{bgp.NewValidationExtended(typ)}, nil
}
+func colorParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
+ if len(args) != 2 || args[0] != ExtCommNameMap[COLOR] {
+ return nil, fmt.Errorf("invalid color")
+ }
+ color, err := strconv.ParseUint(args[1], 10, 32)
+ if err != nil {
+ return nil, fmt.Errorf("invalid color")
+ }
+ return []bgp.ExtendedCommunityInterface{bgp.NewColorExtended(uint32(color))}, nil
+}
+
var ExtCommParserMap = map[ExtCommType]func([]string) ([]bgp.ExtendedCommunityInterface, error){
ACCEPT: nil,
DISCARD: rateLimitParser,
@@ -289,6 +303,7 @@ var ExtCommParserMap = map[ExtCommType]func([]string) ([]bgp.ExtendedCommunityIn
VALID: validationParser,
NOT_FOUND: validationParser,
INVALID: validationParser,
+ COLOR: colorParser,
}
func ParseExtendedCommunities(args []string) ([]bgp.ExtendedCommunityInterface, error) {