diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-03-11 03:19:51 +0900 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-03-11 03:19:51 +0900 |
commit | bcfc808df4f6bc5551fc4b760630d30748e89d43 (patch) | |
tree | 9b9df368a67fd77893c9ae56e98e85d7f6a7ebb7 | |
parent | 677d4b8147da60f5a5d02834e2bc35f59017b14f (diff) |
cli: enable to add community
$ gobgp global rib add 10.0.0.0/24 community 100:100
$ gobgp global rib add 10.0.0.0/24 community 100
// well known
$ gobgp global rib add 10.0.0.0/24 community no-export
// use , to add multiple communities
$ gobgp global rib add 10.0.0.0/24 community 100:100,200:200
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r-- | gobgp/cmd/global.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go index 9cf88197..77e9c81c 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -490,6 +490,25 @@ func extractMed(args []string) ([]string, bgp.PathAttributeInterface, error) { return args, nil, nil } +func extractCommunity(args []string) ([]string, bgp.PathAttributeInterface, error) { + for idx, arg := range args { + if arg == "community" && len(args) > (idx+1) { + elems := strings.Split(args[idx+1], ",") + comms := make([]uint32, 0, 1) + for _, elem := range elems { + c, err := table.ParseCommunity(elem) + if err != nil { + return nil, nil, err + } + comms = append(comms, c) + } + args = append(args[:idx], args[idx+2:]...) + return args, bgp.NewPathAttributeCommunities(comms), nil + } + } + return args, nil, nil +} + func extractAigp(args []string) ([]string, bgp.PathAttributeInterface, error) { for idx, arg := range args { if arg == "aigp" { @@ -550,6 +569,14 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { attrs = append(attrs, localPref) } + args, community, err := extractCommunity(args) + if err != nil { + return nil, err + } + if community != nil { + attrs = append(attrs, community) + } + args, aigp, err := extractAigp(args) if err != nil { return nil, err @@ -704,8 +731,8 @@ func modPath(resource api.Resource, name, modtype string, args []string) error { } flags := strings.Join(ss, ", ") helpErrMap := map[bgp.RouteFamily]error{} - helpErrMap[bgp.RF_IPv4_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [origin { igp | egp | incomplete }] [nexthop <ADDRESS>] [med <VALUE>] [local-pref <VALUE>] [aigp metric <METRIC>] -a ipv4", cmdstr, modtype) - helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [origin { igp | egp | incomplete }] [nexthop <ADDRESS>] [med <VALUE>] [local-pref <VALUE>] [aigp metric <METRIC>] -a ipv6", cmdstr, modtype) + helpErrMap[bgp.RF_IPv4_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [origin { igp | egp | incomplete }] [nexthop <ADDRESS>] [med <VALUE>] [local-pref <VALUE>] [community <VALUE>] [aigp metric <METRIC>] -a ipv4", cmdstr, modtype) + helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [origin { igp | egp | incomplete }] [nexthop <ADDRESS>] [med <VALUE>] [local-pref <VALUE>] [community <VALUE>] [aigp metric <METRIC>] -a ipv6", cmdstr, modtype) fsHelpMsgFmt := fmt.Sprintf(`err: %s usage: %s rib %s match <MATCH_EXPR> then <THEN_EXPR> -a %%s <MATCH_EXPR> : { %s <PREFIX> [<OFFSET>] | %s <PREFIX> [<OFFSET>] | |