From 9643654a5634e7972f0dea837b0f06c0e8417003 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Fri, 6 Nov 2015 14:18:33 +0900 Subject: cli: support specifying med value Signed-off-by: ISHIDA Wataru --- gobgp/cmd/global.go | 28 ++++++++++++++++++++++++++-- 1 file 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 [nexthop
] [aigp metric ] [local-pref ] -a ipv4", cmdstr, modtype) - helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s [nexthop
] [aigp metric ] [local-pref ] -a ipv6", cmdstr, modtype) + helpErrMap[bgp.RF_IPv4_UC] = fmt.Errorf("usage: %s rib %s [nexthop
] [med ] [local-pref ] [aigp metric ] -a ipv4", cmdstr, modtype) + helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s [nexthop
] [med ] [local-pref ] [aigp metric ] -a ipv6", cmdstr, modtype) fsHelpMsgFmt := fmt.Sprintf(`err: %s usage: %s rib %s match then -a %%s : { %s [] | %s [] | -- cgit v1.2.3