From 1460ef0ba46d0a0836fc5314d5e5c23ba76fd047 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Fri, 6 Nov 2015 14:14:51 +0900 Subject: cli: support specifying local-preference 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 3152d01d..d4e4882c 100644 --- a/gobgp/cmd/global.go +++ b/gobgp/cmd/global.go @@ -396,6 +396,21 @@ func extractNexthop(rf bgp.RouteFamily, args []string) ([]string, string, error) return args, nexthop, nil } +func extractLocalPref(args []string) ([]string, []byte, error) { + for idx, arg := range args { + if arg == "local-pref" && 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:]...) + localPref, _ := bgp.NewPathAttributeLocalPref(uint32(metric)).Serialize() + return args, localPref, nil + } + } + return args, nil, nil +} + func extractAigp(args []string) ([]string, []byte, error) { for idx, arg := range args { if arg == "aigp" { @@ -433,6 +448,15 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) { return nil, err } + var localPref []byte + args, localPref, err = extractLocalPref(args) + if err != nil { + return nil, err + } + if localPref != nil { + path.Pattrs = append(path.Pattrs, localPref) + } + var aigp []byte args, aigp, err = extractAigp(args) if err != nil { @@ -557,8 +581,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 ] -a ipv4", cmdstr, modtype) - helpErrMap[bgp.RF_IPv6_UC] = fmt.Errorf("usage: %s rib %s [nexthop
] [aigp metric ] -a ipv6", cmdstr, modtype) + 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) fsHelpMsgFmt := fmt.Sprintf(`err: %s usage: %s rib %s match then -a %%s : { %s [] | %s [] | -- cgit v1.2.3