summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-11-06 14:18:33 +0900
committerISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-11-06 14:20:22 +0900
commit9643654a5634e7972f0dea837b0f06c0e8417003 (patch)
tree9e3c3f31cebac73927fcb36997b9d2a02f7e1b17
parent1460ef0ba46d0a0836fc5314d5e5c23ba76fd047 (diff)
cli: support specifying med value
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--gobgp/cmd/global.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index d4e4882c..80728c03 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -411,6 +411,21 @@ func extractLocalPref(args []string) ([]string, []byte, error) {
return args, nil, nil
}
+func extractMed(args []string) ([]string, []byte, error) {
+ for idx, arg := range args {
+ if arg == "med" && len(args) > (idx+1) {
+ metric, err := strconv.Atoi(args[idx+1])
+ if err != nil {
+ return nil, nil, err
+ }
+ args = append(args[:idx], args[idx+2:]...)
+ med, _ := bgp.NewPathAttributeMultiExitDisc(uint32(metric)).Serialize()
+ return args, med, nil
+ }
+ }
+ return args, nil, nil
+}
+
func extractAigp(args []string) ([]string, []byte, error) {
for idx, arg := range args {
if arg == "aigp" {
@@ -448,6 +463,15 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
return nil, err
}
+ var med []byte
+ args, med, err = extractMed(args)
+ if err != nil {
+ return nil, err
+ }
+ if med != nil {
+ path.Pattrs = append(path.Pattrs, med)
+ }
+
var localPref []byte
args, localPref, err = extractLocalPref(args)
if err != nil {
@@ -581,8 +605,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> [nexthop <ADDRESS>] [aigp metric <METRIC>] [local-pref <VALUE>] -a ipv4", cmdstr, modtype)
- helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [nexthop <ADDRESS>] [aigp metric <METRIC>] [local-pref <VALUE>] -a ipv6", cmdstr, modtype)
+ helpErrMap[bgp.RF_IPv4_UC] = fmt.Errorf("usage: %s rib %s <PREFIX> [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> [nexthop <ADDRESS>] [med <VALUE>] [local-pref <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>] |