summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-07 14:09:15 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-11-07 17:30:48 +0900
commit4c66cd4f91b2f6cdff2373a83d13932affa7ff05 (patch)
treef986bc2cdc80bfd55fb8a095b665ce2a10256ee6
parent433440067d8084556a31ffd4b8bfa8671bfcaab2 (diff)
gobgp: unexport cmd/
Only stuff in pkg/ should be exported. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--cmd/gobgp/cmd/bmp.go10
-rw-r--r--cmd/gobgp/cmd/common.go163
-rw-r--r--cmd/gobgp/cmd/common_test.go10
-rw-r--r--cmd/gobgp/cmd/global.go332
-rw-r--r--cmd/gobgp/cmd/global_test.go2
-rw-r--r--cmd/gobgp/cmd/monitor.go16
-rw-r--r--cmd/gobgp/cmd/mrt.go8
-rw-r--r--cmd/gobgp/cmd/neighbor.go134
-rw-r--r--cmd/gobgp/cmd/policy.go88
-rw-r--r--cmd/gobgp/cmd/root.go16
-rw-r--r--cmd/gobgp/cmd/rpki.go10
-rw-r--r--cmd/gobgp/cmd/vrf.go26
12 files changed, 405 insertions, 410 deletions
diff --git a/cmd/gobgp/cmd/bmp.go b/cmd/gobgp/cmd/bmp.go
index c176d770..8a58bbc5 100644
--- a/cmd/gobgp/cmd/bmp.go
+++ b/cmd/gobgp/cmd/bmp.go
@@ -48,7 +48,7 @@ func modBmpServer(cmdType string, args []string) error {
var err error
switch cmdType {
- case CMD_ADD:
+ case cmdAdd:
policyType := api.AddBmpRequest_PRE
if len(args) > 1 {
switch args[1] {
@@ -69,7 +69,7 @@ func modBmpServer(cmdType string, args []string) error {
Port: port,
Type: policyType,
})
- case CMD_DEL:
+ case cmdDel:
_, err = client.DeleteBmp(ctx, &api.DeleteBmpRequest{
Address: address,
Port: port,
@@ -78,12 +78,12 @@ func modBmpServer(cmdType string, args []string) error {
return err
}
-func NewBmpCmd() *cobra.Command {
+func newBmpCmd() *cobra.Command {
bmpCmd := &cobra.Command{
- Use: CMD_BMP,
+ Use: cmdBMP,
}
- for _, w := range []string{CMD_ADD, CMD_DEL} {
+ for _, w := range []string{cmdAdd, cmdDel} {
subcmd := &cobra.Command{
Use: w,
Run: func(cmd *cobra.Command, args []string) {
diff --git a/cmd/gobgp/cmd/common.go b/cmd/gobgp/cmd/common.go
index 93a7fca5..eaa09dbe 100644
--- a/cmd/gobgp/cmd/common.go
+++ b/cmd/gobgp/cmd/common.go
@@ -31,59 +31,56 @@ import (
"github.com/osrg/gobgp/pkg/packet/bgp"
)
-const GLOBAL_RIB_NAME = "global"
+const globalRIBName = "global"
const (
- CMD_GLOBAL = "global"
- CMD_NEIGHBOR = "neighbor"
- CMD_POLICY = "policy"
- CMD_RIB = "rib"
- CMD_ADD = "add"
- CMD_DEL = "del"
- CMD_ALL = "all"
- CMD_SET = "set"
- CMD_LOCAL = "local"
- CMD_ADJ_IN = "adj-in"
- CMD_ADJ_OUT = "adj-out"
- CMD_RESET = "reset"
- CMD_SOFT_RESET = "softreset"
- CMD_SOFT_RESET_IN = "softresetin"
- CMD_SOFT_RESET_OUT = "softresetout"
- CMD_SHUTDOWN = "shutdown"
- CMD_ENABLE = "enable"
- CMD_DISABLE = "disable"
- CMD_PREFIX = "prefix"
- CMD_ASPATH = "as-path"
- CMD_COMMUNITY = "community"
- CMD_EXTCOMMUNITY = "ext-community"
- CMD_IMPORT = "import"
- CMD_EXPORT = "export"
- CMD_IN = "in"
- CMD_MONITOR = "monitor"
- CMD_MRT = "mrt"
- CMD_DUMP = "dump"
- CMD_INJECT = "inject"
- CMD_RPKI = "rpki"
- CMD_RPKI_TABLE = "table"
- CMD_RPKI_SERVER = "server"
- CMD_VRF = "vrf"
- CMD_ACCEPTED = "accepted"
- CMD_REJECTED = "rejected"
- CMD_STATEMENT = "statement"
- CMD_CONDITION = "condition"
- CMD_ACTION = "action"
- CMD_UPDATE = "update"
- CMD_ROTATE = "rotate"
- CMD_BMP = "bmp"
- CMD_LARGECOMMUNITY = "large-community"
- CMD_SUMMARY = "summary"
- CMD_VALIDATION = "validation"
+ cmdGlobal = "global"
+ cmdNeighbor = "neighbor"
+ cmdPolicy = "policy"
+ cmdRib = "rib"
+ cmdAdd = "add"
+ cmdDel = "del"
+ cmdAll = "all"
+ cmdSet = "set"
+ cmdLocal = "local"
+ cmdAdjIn = "adj-in"
+ cmdAdjOut = "adj-out"
+ cmdReset = "reset"
+ cmdSoftReset = "softreset"
+ cmdSoftResetIn = "softresetin"
+ cmdSoftResetOut = "softresetout"
+ cmdShutdown = "shutdown"
+ cmdEnable = "enable"
+ cmdDisable = "disable"
+ cmdPrefix = "prefix"
+ cmdAspath = "as-path"
+ cmdCommunity = "community"
+ cmdExtcommunity = "ext-community"
+ cmdImport = "import"
+ cmdExport = "export"
+ cmdIn = "in"
+ cmdMonitor = "monitor"
+ cmdMRT = "mrt"
+ cmdInject = "inject"
+ cmdRPKI = "rpki"
+ cmdRPKITable = "table"
+ cmdRPKIServer = "server"
+ cmdVRF = "vrf"
+ cmdAccepted = "accepted"
+ cmdRejected = "rejected"
+ cmdStatement = "statement"
+ cmdCondition = "condition"
+ cmdAction = "action"
+ cmdUpdate = "update"
+ cmdBMP = "bmp"
+ cmdLargecommunity = "large-community"
+ cmdSummary = "summary"
)
const (
- PARAM_FLAG = iota
- PARAM_SINGLE
- PARAM_LIST
+ paramFlag = iota
+ paramSingle
+ paramList
)
var subOpts struct {
@@ -164,15 +161,15 @@ func extractReserved(args []string, keys map[string]int) (map[string][]string, e
continue
}
switch keys[k] {
- case PARAM_FLAG:
+ case paramFlag:
if len(v) != 0 {
return nil, fmt.Errorf("%s should not have arguments", k)
}
- case PARAM_SINGLE:
+ case paramSingle:
if len(v) != 1 {
return nil, fmt.Errorf("%s should have one argument", k)
}
- case PARAM_LIST:
+ case paramList:
if len(v) == 0 {
return nil, fmt.Errorf("%s should have one or more arguments", k)
}
@@ -227,67 +224,67 @@ func addr2AddressFamily(a net.IP) *api.Family {
}
var (
- IPv4_UC = &api.Family{
+ ipv4UC = &api.Family{
Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_UNICAST,
}
- IPv6_UC = &api.Family{
+ ipv6UC = &api.Family{
Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_UNICAST,
}
- IPv4_VPN = &api.Family{
+ ipv4VPN = &api.Family{
Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_VPN,
}
- IPv6_VPN = &api.Family{
+ ipv6VPN = &api.Family{
Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_MPLS_VPN,
}
- IPv4_MPLS = &api.Family{
+ ipv4MPLS = &api.Family{
Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_MPLS_LABEL,
}
- IPv6_MPLS = &api.Family{
+ ipv6MPLS = &api.Family{
Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_MPLS_LABEL,
}
- EVPN = &api.Family{
+ evpn = &api.Family{
Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_EVPN,
}
- IPv4_ENCAP = &api.Family{
+ ipv4Encap = &api.Family{
Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ENCAPSULATION,
}
- IPv6_ENCAP = &api.Family{
+ ipv6Encap = &api.Family{
Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_ENCAPSULATION,
}
- RTC = &api.Family{
+ rtc = &api.Family{
Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_ROUTE_TARGET_CONSTRAINTS,
}
- IPv4_FS = &api.Family{
+ ipv4Flowspec = &api.Family{
Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST,
}
- IPv6_FS = &api.Family{
+ ipv6Flowspec = &api.Family{
Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_FLOW_SPEC_UNICAST,
}
- IPv4_VPN_FS = &api.Family{
+ ipv4VPNflowspec = &api.Family{
Afi: api.Family_AFI_IP,
Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}
- IPv6_VPN_FS = &api.Family{
+ ipv6VPNflowspec = &api.Family{
Afi: api.Family_AFI_IP6,
Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}
- L2_VPN_FS = &api.Family{
+ l2VPNflowspec = &api.Family{
Afi: api.Family_AFI_L2VPN,
Safi: api.Family_SAFI_FLOW_SPEC_VPN,
}
- OPAQUE = &api.Family{
+ opaque = &api.Family{
Afi: api.Family_AFI_OPAQUE,
Safi: api.Family_SAFI_KEY_VALUE,
}
@@ -298,37 +295,37 @@ func checkAddressFamily(def *api.Family) (*api.Family, error) {
var e error
switch subOpts.AddressFamily {
case "ipv4", "v4", "4":
- f = IPv4_UC
+ f = ipv4UC
case "ipv6", "v6", "6":
- f = IPv6_UC
+ f = ipv6UC
case "ipv4-l3vpn", "vpnv4", "vpn-ipv4":
- f = IPv4_VPN
+ f = ipv4VPN
case "ipv6-l3vpn", "vpnv6", "vpn-ipv6":
- f = IPv6_VPN
+ f = ipv6VPN
case "ipv4-labeled", "ipv4-labelled", "ipv4-mpls":
- f = IPv4_MPLS
+ f = ipv4MPLS
case "ipv6-labeled", "ipv6-labelled", "ipv6-mpls":
- f = IPv6_MPLS
+ f = ipv6MPLS
case "evpn":
- f = EVPN
+ f = evpn
case "encap", "ipv4-encap":
- f = IPv4_ENCAP
+ f = ipv4Encap
case "ipv6-encap":
- f = IPv6_ENCAP
+ f = ipv6Encap
case "rtc":
- f = RTC
+ f = rtc
case "ipv4-flowspec", "ipv4-flow", "flow4":
- f = IPv4_FS
+ f = ipv4Flowspec
case "ipv6-flowspec", "ipv6-flow", "flow6":
- f = IPv6_FS
+ f = ipv6Flowspec
case "ipv4-l3vpn-flowspec", "ipv4vpn-flowspec", "flowvpn4":
- f = IPv4_VPN_FS
+ f = ipv4VPNflowspec
case "ipv6-l3vpn-flowspec", "ipv6vpn-flowspec", "flowvpn6":
- f = IPv6_VPN_FS
+ f = ipv6VPNflowspec
case "l2vpn-flowspec":
- f = L2_VPN_FS
+ f = l2VPNflowspec
case "opaque":
- f = OPAQUE
+ f = opaque
case "":
f = def
default:
diff --git a/cmd/gobgp/cmd/common_test.go b/cmd/gobgp/cmd/common_test.go
index d7bb87b2..8a2ae0dc 100644
--- a/cmd/gobgp/cmd/common_test.go
+++ b/cmd/gobgp/cmd/common_test.go
@@ -26,11 +26,11 @@ func Test_ExtractReserved(t *testing.T) {
assert := assert.New(t)
args := strings.Split("10 rt 100:100 med 10 nexthop 10.0.0.1 aigp metric 10 local-pref 100", " ")
keys := map[string]int{
- "rt": PARAM_LIST,
- "med": PARAM_SINGLE,
- "nexthop": PARAM_SINGLE,
- "aigp": PARAM_LIST,
- "local-pref": PARAM_SINGLE}
+ "rt": paramList,
+ "med": paramSingle,
+ "nexthop": paramSingle,
+ "aigp": paramList,
+ "local-pref": paramSingle}
m, _ := extractReserved(args, keys)
assert.True(len(m["rt"]) == 1)
assert.True(len(m["med"]) == 1)
diff --git a/cmd/gobgp/cmd/global.go b/cmd/gobgp/cmd/global.go
index 637caf6a..43b8593b 100644
--- a/cmd/gobgp/cmd/global.go
+++ b/cmd/gobgp/cmd/global.go
@@ -34,71 +34,71 @@ import (
"github.com/osrg/gobgp/pkg/packet/bgp"
)
-type ExtCommType int
+type extCommType int
const (
- ACCEPT ExtCommType = iota
- DISCARD
- RATE
- REDIRECT
- MARK
- ACTION
- RT
- ENCAP
- ESI_LABEL
- ROUTER_MAC
- DEFAULT_GATEWAY
- VALID
- NOT_FOUND
- INVALID
- COLOR
+ ctAccept extCommType = iota
+ ctDiscard
+ ctRate
+ ctRedirect
+ ctMark
+ ctAction
+ ctRT
+ ctEncap
+ ctESILabel
+ ctRouterMAC
+ ctDefaultGateway
+ ctValid
+ ctNotFound
+ ctInvalid
+ ctColor
)
-var ExtCommNameMap = map[ExtCommType]string{
- ACCEPT: "accept",
- DISCARD: "discard",
- RATE: "rate-limit",
- REDIRECT: "redirect",
- MARK: "mark",
- ACTION: "action",
- RT: "rt",
- ENCAP: "encap",
- ESI_LABEL: "esi-label",
- ROUTER_MAC: "router-mac",
- DEFAULT_GATEWAY: "default-gateway",
- VALID: "valid",
- NOT_FOUND: "not-found",
- INVALID: "invalid",
- COLOR: "color",
+var extCommNameMap = map[extCommType]string{
+ ctAccept: "accept",
+ ctDiscard: "discard",
+ ctRate: "rate-limit",
+ ctRedirect: "redirect",
+ ctMark: "mark",
+ ctAction: "action",
+ ctRT: "rt",
+ ctEncap: "encap",
+ ctESILabel: "esi-label",
+ ctRouterMAC: "router-mac",
+ ctDefaultGateway: "default-gateway",
+ ctValid: "valid",
+ ctNotFound: "not-found",
+ ctInvalid: "invalid",
+ ctColor: "color",
}
-var ExtCommValueMap = map[string]ExtCommType{
- ExtCommNameMap[ACCEPT]: ACCEPT,
- ExtCommNameMap[DISCARD]: DISCARD,
- ExtCommNameMap[RATE]: RATE,
- ExtCommNameMap[REDIRECT]: REDIRECT,
- ExtCommNameMap[MARK]: MARK,
- ExtCommNameMap[ACTION]: ACTION,
- ExtCommNameMap[RT]: RT,
- ExtCommNameMap[ENCAP]: ENCAP,
- ExtCommNameMap[ESI_LABEL]: ESI_LABEL,
- ExtCommNameMap[ROUTER_MAC]: ROUTER_MAC,
- ExtCommNameMap[DEFAULT_GATEWAY]: DEFAULT_GATEWAY,
- ExtCommNameMap[VALID]: VALID,
- ExtCommNameMap[NOT_FOUND]: NOT_FOUND,
- ExtCommNameMap[INVALID]: INVALID,
- ExtCommNameMap[COLOR]: COLOR,
+var extCommValueMap = map[string]extCommType{
+ extCommNameMap[ctAccept]: ctAccept,
+ extCommNameMap[ctDiscard]: ctDiscard,
+ extCommNameMap[ctRate]: ctRate,
+ extCommNameMap[ctRedirect]: ctRedirect,
+ extCommNameMap[ctMark]: ctMark,
+ extCommNameMap[ctAction]: ctAction,
+ extCommNameMap[ctRT]: ctRT,
+ extCommNameMap[ctEncap]: ctEncap,
+ extCommNameMap[ctESILabel]: ctESILabel,
+ extCommNameMap[ctRouterMAC]: ctRouterMAC,
+ extCommNameMap[ctDefaultGateway]: ctDefaultGateway,
+ extCommNameMap[ctValid]: ctValid,
+ extCommNameMap[ctNotFound]: ctNotFound,
+ extCommNameMap[ctInvalid]: ctInvalid,
+ extCommNameMap[ctColor]: ctColor,
}
func rateLimitParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- exp := regexp.MustCompile(fmt.Sprintf("^(%s|(%s) (\\d+)(\\.(\\d+))?)( as (\\d+))?$", ExtCommNameMap[DISCARD], ExtCommNameMap[RATE]))
+ exp := regexp.MustCompile(fmt.Sprintf("^(%s|(%s) (\\d+)(\\.(\\d+))?)( as (\\d+))?$", extCommNameMap[ctDiscard], extCommNameMap[ctRate]))
elems := exp.FindStringSubmatch(strings.Join(args, " "))
if len(elems) != 8 {
return nil, fmt.Errorf("invalid rate-limit")
}
var rate float32
var as uint64
- if elems[2] == ExtCommNameMap[RATE] {
+ if elems[2] == extCommNameMap[ctRate] {
f, err := strconv.ParseFloat(elems[3]+elems[4], 32)
if err != nil {
return nil, err
@@ -116,7 +116,7 @@ func rateLimitParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func redirectParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 2 || args[0] != ExtCommNameMap[REDIRECT] {
+ if len(args) < 2 || args[0] != extCommNameMap[ctRedirect] {
return nil, fmt.Errorf("invalid redirect")
}
rt, err := bgp.ParseRouteTarget(strings.Join(args[1:], " "))
@@ -141,7 +141,7 @@ func redirectParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func markParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 2 || args[0] != ExtCommNameMap[MARK] {
+ if len(args) < 2 || args[0] != extCommNameMap[ctMark] {
return nil, fmt.Errorf("invalid mark")
}
dscp, err := strconv.ParseUint(args[1], 10, 8)
@@ -152,7 +152,7 @@ func markParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func actionParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 2 || args[0] != ExtCommNameMap[ACTION] {
+ if len(args) < 2 || args[0] != extCommNameMap[ctAction] {
return nil, fmt.Errorf("invalid action")
}
sample := false
@@ -172,7 +172,7 @@ func actionParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func rtParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 2 || args[0] != ExtCommNameMap[RT] {
+ if len(args) < 2 || args[0] != extCommNameMap[ctRT] {
return nil, fmt.Errorf("invalid rt")
}
exts := make([]bgp.ExtendedCommunityInterface, 0, len(args[1:]))
@@ -187,7 +187,7 @@ func rtParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func encapParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 2 || args[0] != ExtCommNameMap[ENCAP] {
+ if len(args) < 2 || args[0] != extCommNameMap[ctEncap] {
return nil, fmt.Errorf("invalid encap")
}
var typ bgp.TunnelType
@@ -215,7 +215,7 @@ func encapParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func esiLabelParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 2 || args[0] != ExtCommNameMap[ESI_LABEL] {
+ if len(args) < 2 || args[0] != extCommNameMap[ctESILabel] {
return nil, fmt.Errorf("invalid esi-label")
}
label, err := strconv.ParseUint(args[1], 10, 32)
@@ -241,7 +241,7 @@ func esiLabelParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func routerMacParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 2 || args[0] != ExtCommNameMap[ROUTER_MAC] {
+ if len(args) < 2 || args[0] != extCommNameMap[ctRouterMAC] {
return nil, fmt.Errorf("invalid router's mac")
}
hw, err := net.ParseMAC(args[1])
@@ -253,7 +253,7 @@ func routerMacParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func defaultGatewayParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) < 1 || args[0] != ExtCommNameMap[DEFAULT_GATEWAY] {
+ if len(args) < 1 || args[0] != extCommNameMap[ctDefaultGateway] {
return nil, fmt.Errorf("invalid default-gateway")
}
return []bgp.ExtendedCommunityInterface{bgp.NewDefaultGatewayExtended()}, nil
@@ -278,7 +278,7 @@ func validationParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
func colorParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
- if len(args) != 2 || args[0] != ExtCommNameMap[COLOR] {
+ if len(args) != 2 || args[0] != extCommNameMap[ctColor] {
return nil, fmt.Errorf("invalid color")
}
color, err := strconv.ParseUint(args[1], 10, 32)
@@ -288,33 +288,33 @@ func colorParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
return []bgp.ExtendedCommunityInterface{bgp.NewColorExtended(uint32(color))}, nil
}
-var ExtCommParserMap = map[ExtCommType]func([]string) ([]bgp.ExtendedCommunityInterface, error){
- ACCEPT: nil,
- DISCARD: rateLimitParser,
- RATE: rateLimitParser,
- REDIRECT: redirectParser,
- MARK: markParser,
- ACTION: actionParser,
- RT: rtParser,
- ENCAP: encapParser,
- ESI_LABEL: esiLabelParser,
- ROUTER_MAC: routerMacParser,
- DEFAULT_GATEWAY: defaultGatewayParser,
- VALID: validationParser,
- NOT_FOUND: validationParser,
- INVALID: validationParser,
- COLOR: colorParser,
+var extCommParserMap = map[extCommType]func([]string) ([]bgp.ExtendedCommunityInterface, error){
+ ctAccept: nil,
+ ctDiscard: rateLimitParser,
+ ctRate: rateLimitParser,
+ ctRedirect: redirectParser,
+ ctMark: markParser,
+ ctAction: actionParser,
+ ctRT: rtParser,
+ ctEncap: encapParser,
+ ctESILabel: esiLabelParser,
+ ctRouterMAC: routerMacParser,
+ ctDefaultGateway: defaultGatewayParser,
+ ctValid: validationParser,
+ ctNotFound: validationParser,
+ ctInvalid: validationParser,
+ ctColor: colorParser,
}
-func ParseExtendedCommunities(args []string) ([]bgp.ExtendedCommunityInterface, error) {
+func parseExtendedCommunities(args []string) ([]bgp.ExtendedCommunityInterface, error) {
idxs := make([]struct {
- t ExtCommType
+ t extCommType
i int
- }, 0, len(ExtCommNameMap))
+ }, 0, len(extCommNameMap))
for idx, v := range args {
- if t, ok := ExtCommValueMap[v]; ok {
+ if t, ok := extCommValueMap[v]; ok {
idxs = append(idxs, struct {
- t ExtCommType
+ t extCommType
i int
}{t, idx})
}
@@ -322,7 +322,7 @@ func ParseExtendedCommunities(args []string) ([]bgp.ExtendedCommunityInterface,
exts := make([]bgp.ExtendedCommunityInterface, 0, len(idxs))
for i, idx := range idxs {
var a []string
- f := ExtCommParserMap[idx.t]
+ f := extCommParserMap[idx.t]
if i < len(idxs)-1 {
a = args[:idxs[i+1].i-idx.i]
args = args[(idxs[i+1].i - idx.i):]
@@ -345,7 +345,7 @@ func ParseExtendedCommunities(args []string) ([]bgp.ExtendedCommunityInterface,
return exts, nil
}
-func ParseFlowSpecArgs(rf bgp.RouteFamily, args []string) (bgp.AddrPrefixInterface, []string, error) {
+func parseFlowSpecArgs(rf bgp.RouteFamily, args []string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// match <rule>... [then <action>...] [rd <rd>] [rt <rt>...]
req := 3 // match <key1> <arg1> [<key2> <arg2>...]
@@ -353,10 +353,10 @@ func ParseFlowSpecArgs(rf bgp.RouteFamily, args []string) (bgp.AddrPrefixInterfa
return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args))
}
m, err := extractReserved(args, map[string]int{
- "match": PARAM_LIST,
- "then": PARAM_LIST,
- "rd": PARAM_SINGLE,
- "rt": PARAM_LIST})
+ "match": paramList,
+ "then": paramList,
+ "rd": paramSingle,
+ "rt": paramList})
if err != nil {
return nil, nil, err
}
@@ -412,7 +412,7 @@ func ParseFlowSpecArgs(rf bgp.RouteFamily, args []string) (bgp.AddrPrefixInterfa
return nlri, extcomms, nil
}
-func ParseEvpnEthernetAutoDiscoveryArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
+func parseEvpnEthernetAutoDiscoveryArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// esi <esi> etag <etag> label <label> rd <rd> [rt <rt>...] [encap <encap type>] [esi-label <esi-label> [single-active | all-active]]
req := 8
@@ -420,13 +420,13 @@ func ParseEvpnEthernetAutoDiscoveryArgs(args []string) (bgp.AddrPrefixInterface,
return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args))
}
m, err := extractReserved(args, map[string]int{
- "esi": PARAM_LIST,
- "etag": PARAM_SINGLE,
- "label": PARAM_SINGLE,
- "rd": PARAM_SINGLE,
- "rt": PARAM_LIST,
- "encap": PARAM_SINGLE,
- "esi-label": PARAM_SINGLE})
+ "esi": paramList,
+ "etag": paramSingle,
+ "label": paramSingle,
+ "rd": paramSingle,
+ "rt": paramList,
+ "encap": paramSingle,
+ "esi-label": paramSingle})
if err != nil {
return nil, nil, err
}
@@ -480,7 +480,7 @@ func ParseEvpnEthernetAutoDiscoveryArgs(args []string) (bgp.AddrPrefixInterface,
return bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_ETHERNET_AUTO_DISCOVERY, r), extcomms, nil
}
-func ParseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
+func parseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <mac address> <ip address> [esi <esi>] etag <etag> label <label> rd <rd> [rt <rt>...] [encap <encap type>] [router-mac <mac address>] [default-gateway]
// or
@@ -492,13 +492,13 @@ func ParseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, erro
return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args))
}
m, err := extractReserved(args, map[string]int{
- "esi": PARAM_LIST,
- "etag": PARAM_SINGLE,
- "label": PARAM_SINGLE,
- "rd": PARAM_SINGLE,
- "rt": PARAM_LIST,
- "encap": PARAM_SINGLE,
- "router-mac": PARAM_SINGLE})
+ "esi": paramList,
+ "etag": paramSingle,
+ "label": paramSingle,
+ "rd": paramSingle,
+ "rt": paramList,
+ "encap": paramSingle,
+ "router-mac": paramSingle})
if err != nil {
return nil, nil, err
}
@@ -607,7 +607,7 @@ func ParseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, erro
return bgp.NewEVPNNLRI(bgp.EVPN_ROUTE_TYPE_MAC_IP_ADVERTISEMENT, r), extcomms, nil
}
-func ParseEvpnMulticastArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
+func parseEvpnMulticastArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <ip address> etag <etag> rd <rd> [rt <rt>...] [encap <encap type>]
// or
@@ -617,10 +617,10 @@ func ParseEvpnMulticastArgs(args []string) (bgp.AddrPrefixInterface, []string, e
return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args))
}
m, err := extractReserved(args, map[string]int{
- "etag": PARAM_SINGLE,
- "rd": PARAM_SINGLE,
- "rt": PARAM_LIST,
- "encap": PARAM_SINGLE})
+ "etag": paramSingle,
+ "rd": paramSingle,
+ "rt": paramList,
+ "encap": paramSingle})
if err != nil {
return nil, nil, err
}
@@ -681,7 +681,7 @@ func ParseEvpnMulticastArgs(args []string) (bgp.AddrPrefixInterface, []string, e
return bgp.NewEVPNNLRI(bgp.EVPN_INCLUSIVE_MULTICAST_ETHERNET_TAG, r), extcomms, nil
}
-func ParseEvpnEthernetSegmentArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
+func parseEvpnEthernetSegmentArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <ip address> esi <esi> rd <rd> [rt <rt>...] [encap <encap type>]
req := 5
@@ -689,10 +689,10 @@ func ParseEvpnEthernetSegmentArgs(args []string) (bgp.AddrPrefixInterface, []str
return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args))
}
m, err := extractReserved(args, map[string]int{
- "esi": PARAM_LIST,
- "rd": PARAM_SINGLE,
- "rt": PARAM_LIST,
- "encap": PARAM_SINGLE})
+ "esi": paramList,
+ "rd": paramSingle,
+ "rt": paramList,
+ "encap": paramSingle})
if err != nil {
return nil, nil, err
}
@@ -745,7 +745,7 @@ func ParseEvpnEthernetSegmentArgs(args []string) (bgp.AddrPrefixInterface, []str
return bgp.NewEVPNNLRI(bgp.EVPN_ETHERNET_SEGMENT_ROUTE, r), extcomms, nil
}
-func ParseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
+func parseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
// Format:
// <ip prefix> [gw <gateway>] [esi <esi>] etag <etag> [label <label>] rd <rd> [rt <rt>...] [encap <encap type>]
req := 5
@@ -753,14 +753,14 @@ func ParseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, er
return nil, nil, fmt.Errorf("%d args required at least, but got %d", req, len(args))
}
m, err := extractReserved(args, map[string]int{
- "gw": PARAM_SINGLE,
- "esi": PARAM_LIST,
- "etag": PARAM_SINGLE,
- "label": PARAM_SINGLE,
- "rd": PARAM_SINGLE,
- "rt": PARAM_LIST,
- "encap": PARAM_SINGLE,
- "router-mac": PARAM_SINGLE})
+ "gw": paramSingle,
+ "esi": paramList,
+ "etag": paramSingle,
+ "label": paramSingle,
+ "rd": paramSingle,
+ "rt": paramList,
+ "encap": paramSingle,
+ "router-mac": paramSingle})
if err != nil {
return nil, nil, err
}
@@ -833,7 +833,7 @@ func ParseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, er
return bgp.NewEVPNNLRI(bgp.EVPN_IP_PREFIX, r), extcomms, nil
}
-func ParseEvpnArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
+func parseEvpnArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
if len(args) < 1 {
return nil, nil, fmt.Errorf("lack of args. need 1 but %d", len(args))
}
@@ -841,15 +841,15 @@ func ParseEvpnArgs(args []string) (bgp.AddrPrefixInterface, []string, error) {
args = args[1:]
switch subtype {
case "a-d":
- return ParseEvpnEthernetAutoDiscoveryArgs(args)
+ return parseEvpnEthernetAutoDiscoveryArgs(args)
case "macadv":
- return ParseEvpnMacAdvArgs(args)
+ return parseEvpnMacAdvArgs(args)
case "multicast":
- return ParseEvpnMulticastArgs(args)
+ return parseEvpnMulticastArgs(args)
case "esi":
- return ParseEvpnEthernetSegmentArgs(args)
+ return parseEvpnEthernetSegmentArgs(args)
case "prefix":
- return ParseEvpnIPPrefixArgs(args)
+ return parseEvpnIPPrefixArgs(args)
}
return nil, nil, fmt.Errorf("invalid subtype. expect [macadv|multicast|prefix] but %s", subtype)
}
@@ -1091,7 +1091,7 @@ func extractAggregator(args []string) ([]string, bgp.PathAttributeInterface, err
return args, nil, nil
}
-func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
+func parsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
var nlri bgp.AddrPrefixInterface
var extcomms []string
var err error
@@ -1222,13 +1222,13 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
nlri = bgp.NewLabeledIPv6AddrPrefix(uint8(ones), ip.String(), *mpls)
}
case bgp.RF_EVPN:
- nlri, extcomms, err = ParseEvpnArgs(args)
+ nlri, extcomms, err = parseEvpnArgs(args)
case bgp.RF_FS_IPv4_UC, bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_UC, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
- nlri, extcomms, err = ParseFlowSpecArgs(rf, args)
+ nlri, extcomms, err = parseFlowSpecArgs(rf, args)
case bgp.RF_OPAQUE:
m, err := extractReserved(args, map[string]int{
- "key": PARAM_SINGLE,
- "value": PARAM_SINGLE})
+ "key": paramSingle,
+ "value": paramSingle})
if err != nil {
return nil, err
}
@@ -1255,7 +1255,7 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
}
if extcomms != nil {
- extcomms, err := ParseExtendedCommunities(extcomms)
+ extcomms, err := parseExtendedCommunities(extcomms)
if err != nil {
return nil, err
}
@@ -1284,19 +1284,19 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
}
func showGlobalRib(args []string) error {
- return showNeighborRib(CMD_GLOBAL, "", args)
+ return showNeighborRib(cmdGlobal, "", args)
}
func modPath(resource string, name, modtype string, args []string) error {
- f, err := checkAddressFamily(IPv4_UC)
+ f, err := checkAddressFamily(ipv4UC)
if err != nil {
return err
}
rf := apiutil.ToRouteFamily(f)
- path, err := ParsePath(rf, args)
+ path, err := parsePath(rf, args)
if err != nil {
cmdstr := "global"
- if resource == CMD_VRF {
+ if resource == cmdVRF {
cmdstr = fmt.Sprintf("vrf %s", name)
}
rdHelpMsgFmt := `
@@ -1357,12 +1357,12 @@ usage: %s rib -a %%s %s%%s match <MATCH> then <THEN>%%s%%s%%s
// "" or " [rt <RT>]"
// <help message for RD>
// <MATCH>
- ExtCommNameMap[ACCEPT],
- ExtCommNameMap[DISCARD],
- ExtCommNameMap[RATE],
- ExtCommNameMap[REDIRECT],
- ExtCommNameMap[MARK],
- ExtCommNameMap[ACTION],
+ extCommNameMap[ctAccept],
+ extCommNameMap[ctDiscard],
+ extCommNameMap[ctRate],
+ extCommNameMap[ctRedirect],
+ extCommNameMap[ctMark],
+ extCommNameMap[ctAction],
)
baseFsMatchExpr := fmt.Sprintf(`
<MATCH> : { %s <PREFIX> [<OFFSET>] |
@@ -1462,11 +1462,11 @@ usage: %s rib %s key <KEY> [value <VALUE>]`,
}
r := api.Resource_GLOBAL
- if resource == CMD_VRF {
+ if resource == cmdVRF {
r = api.Resource_VRF
}
- if modtype == CMD_ADD {
+ if modtype == cmdAdd {
_, err = client.AddPath(ctx, &api.AddPathRequest{
Resource: r,
VrfId: name,
@@ -1506,11 +1506,11 @@ func showGlobalConfig() error {
func modGlobalConfig(args []string) error {
m, err := extractReserved(args, map[string]int{
- "as": PARAM_SINGLE,
- "router-id": PARAM_SINGLE,
- "listen-port": PARAM_SINGLE,
- "listen-addresses": PARAM_LIST,
- "use-multipath": PARAM_FLAG})
+ "as": paramSingle,
+ "router-id": paramSingle,
+ "listen-port": paramSingle,
+ "listen-addresses": paramList,
+ "use-multipath": paramFlag})
if err != nil || len(m["as"]) != 1 || len(m["router-id"]) != 1 {
return fmt.Errorf("usage: gobgp global as <VALUE> router-id <VALUE> [use-multipath] [listen-port <VALUE>] [listen-addresses <VALUE>...]")
}
@@ -1547,9 +1547,9 @@ func modGlobalConfig(args []string) error {
return err
}
-func NewGlobalCmd() *cobra.Command {
+func newGlobalCmd() *cobra.Command {
globalCmd := &cobra.Command{
- Use: CMD_GLOBAL,
+ Use: cmdGlobal,
Run: func(cmd *cobra.Command, args []string) {
var err error
if len(args) != 0 {
@@ -1564,7 +1564,7 @@ func NewGlobalCmd() *cobra.Command {
}
ribCmd := &cobra.Command{
- Use: CMD_RIB,
+ Use: cmdRib,
Run: func(cmd *cobra.Command, args []string) {
if err := showGlobalRib(args); err != nil {
exitWithError(err)
@@ -1574,11 +1574,11 @@ func NewGlobalCmd() *cobra.Command {
ribCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family")
- for _, v := range []string{CMD_ADD, CMD_DEL} {
+ for _, v := range []string{cmdAdd, cmdDel} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {
- err := modPath(CMD_GLOBAL, "", cmd.Use, args)
+ err := modPath(cmdGlobal, "", cmd.Use, args)
if err != nil {
exitWithError(err)
}
@@ -1586,11 +1586,11 @@ func NewGlobalCmd() *cobra.Command {
}
ribCmd.AddCommand(cmd)
- if v == CMD_DEL {
+ if v == cmdDel {
subcmd := &cobra.Command{
- Use: CMD_ALL,
+ Use: cmdAll,
Run: func(cmd *cobra.Command, args []string) {
- family, err := checkAddressFamily(IPv4_UC)
+ family, err := checkAddressFamily(ipv4UC)
if err != nil {
exitWithError(err)
}
@@ -1607,9 +1607,9 @@ func NewGlobalCmd() *cobra.Command {
}
summaryCmd := &cobra.Command{
- Use: CMD_SUMMARY,
+ Use: cmdSummary,
Run: func(cmd *cobra.Command, args []string) {
- if err := showRibInfo(CMD_GLOBAL, ""); err != nil {
+ if err := showRibInfo(cmdGlobal, ""); err != nil {
exitWithError(err)
}
},
@@ -1617,12 +1617,12 @@ func NewGlobalCmd() *cobra.Command {
ribCmd.AddCommand(summaryCmd)
policyCmd := &cobra.Command{
- Use: CMD_POLICY,
+ Use: cmdPolicy,
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
exitWithError(fmt.Errorf("usage: gobgp global policy [{ import | export }]"))
}
- for _, v := range []string{CMD_IMPORT, CMD_EXPORT} {
+ for _, v := range []string{cmdImport, cmdExport} {
if err := showNeighborPolicy("", v, 4); err != nil {
exitWithError(err)
}
@@ -1630,7 +1630,7 @@ func NewGlobalCmd() *cobra.Command {
},
}
- for _, v := range []string{CMD_IMPORT, CMD_EXPORT} {
+ for _, v := range []string{cmdImport, cmdExport} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {
@@ -1640,7 +1640,7 @@ func NewGlobalCmd() *cobra.Command {
},
}
- for _, w := range []string{CMD_ADD, CMD_DEL, CMD_SET} {
+ for _, w := range []string{cmdAdd, cmdDel, cmdSet} {
subcmd := &cobra.Command{
Use: w,
Run: func(subcmd *cobra.Command, args []string) {
@@ -1657,11 +1657,11 @@ func NewGlobalCmd() *cobra.Command {
}
delCmd := &cobra.Command{
- Use: CMD_DEL,
+ Use: cmdDel,
}
allCmd := &cobra.Command{
- Use: CMD_ALL,
+ Use: cmdAll,
Run: func(cmd *cobra.Command, args []string) {
if _, err := client.StopBgp(ctx, &api.StopBgpRequest{}); err != nil {
exitWithError(err)
diff --git a/cmd/gobgp/cmd/global_test.go b/cmd/gobgp/cmd/global_test.go
index c00db1df..468fdc69 100644
--- a/cmd/gobgp/cmd/global_test.go
+++ b/cmd/gobgp/cmd/global_test.go
@@ -28,7 +28,7 @@ func Test_ParsePath(t *testing.T) {
assert := assert.New(t)
buf := "10.0.0.0/24 rt 100:100 med 10 nexthop 10.0.0.1 aigp metric 10 local-pref 100"
- path, err := ParsePath(bgp.RF_IPv4_UC, strings.Split(buf, " "))
+ path, err := parsePath(bgp.RF_IPv4_UC, strings.Split(buf, " "))
assert.Nil(err)
i := 0
attrs, _ := apiutil.GetNativePathAttributes(path)
diff --git a/cmd/gobgp/cmd/monitor.go b/cmd/gobgp/cmd/monitor.go
index 99769679..ebcd2c41 100644
--- a/cmd/gobgp/cmd/monitor.go
+++ b/cmd/gobgp/cmd/monitor.go
@@ -88,7 +88,7 @@ func monitorRoute(pathList []*api.Path, showIdentifier bgp.BGPAddPathMode) {
}
}
-func NewMonitorCmd() *cobra.Command {
+func newMonitorCmd() *cobra.Command {
var current bool
@@ -112,9 +112,9 @@ func NewMonitorCmd() *cobra.Command {
}
ribCmd := &cobra.Command{
- Use: CMD_RIB,
+ Use: cmdRib,
Run: func(cmd *cobra.Command, args []string) {
- family, err := checkAddressFamily(IPv4_UC)
+ family, err := checkAddressFamily(ipv4UC)
if err != nil {
exitWithError(err)
}
@@ -132,12 +132,12 @@ func NewMonitorCmd() *cobra.Command {
ribCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family")
globalCmd := &cobra.Command{
- Use: CMD_GLOBAL,
+ Use: cmdGlobal,
}
globalCmd.AddCommand(ribCmd)
neighborCmd := &cobra.Command{
- Use: fmt.Sprintf("%s [<neighbor address>]", CMD_NEIGHBOR),
+ Use: fmt.Sprintf("%s [<neighbor address>]", cmdNeighbor),
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
name := ""
@@ -174,7 +174,7 @@ func NewMonitorCmd() *cobra.Command {
}
adjInCmd := &cobra.Command{
- Use: CMD_ADJ_IN,
+ Use: cmdAdjIn,
Run: func(cmd *cobra.Command, args []string) {
name := ""
if len(args) > 0 {
@@ -184,7 +184,7 @@ func NewMonitorCmd() *cobra.Command {
}
name = args[0]
}
- family, err := checkAddressFamily(IPv4_UC)
+ family, err := checkAddressFamily(ipv4UC)
if err != nil {
exitWithError(err)
}
@@ -203,7 +203,7 @@ func NewMonitorCmd() *cobra.Command {
adjInCmd.PersistentFlags().StringVarP(&subOpts.AddressFamily, "address-family", "a", "", "address family")
monitorCmd := &cobra.Command{
- Use: CMD_MONITOR,
+ Use: cmdMonitor,
}
monitorCmd.AddCommand(globalCmd)
monitorCmd.AddCommand(neighborCmd)
diff --git a/cmd/gobgp/cmd/mrt.go b/cmd/gobgp/cmd/mrt.go
index 8fd40791..434741ea 100644
--- a/cmd/gobgp/cmd/mrt.go
+++ b/cmd/gobgp/cmd/mrt.go
@@ -188,9 +188,9 @@ func injectMrt() error {
return nil
}
-func NewMrtCmd() *cobra.Command {
+func newMrtCmd() *cobra.Command {
globalInjectCmd := &cobra.Command{
- Use: CMD_GLOBAL,
+ Use: cmdGlobal,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
exitWithError(fmt.Errorf("usage: gobgp mrt inject global <filename> [<count> [<skip>]]"))
@@ -220,12 +220,12 @@ func NewMrtCmd() *cobra.Command {
}
injectCmd := &cobra.Command{
- Use: CMD_INJECT,
+ Use: cmdInject,
}
injectCmd.AddCommand(globalInjectCmd)
mrtCmd := &cobra.Command{
- Use: CMD_MRT,
+ Use: cmdMRT,
}
mrtCmd.AddCommand(injectCmd)
diff --git a/cmd/gobgp/cmd/neighbor.go b/cmd/gobgp/cmd/neighbor.go
index e6126c51..a4d878d6 100644
--- a/cmd/gobgp/cmd/neighbor.go
+++ b/cmd/gobgp/cmd/neighbor.go
@@ -466,8 +466,6 @@ func showNeighbor(args []string) error {
return nil
}
-type AsPathFormat struct{}
-
func getPathSymbolString(p *api.Path, idx int, showBest bool) string {
symbols := ""
if p.Stale {
@@ -699,8 +697,8 @@ func showValidationInfo(p *api.Path, shownAs map[uint32]struct{}) error {
func showRibInfo(r, name string) error {
def := addr2AddressFamily(net.ParseIP(name))
- if r == CMD_GLOBAL {
- def = IPv4_UC
+ if r == cmdGlobal {
+ def = ipv4UC
}
family, err := checkAddressFamily(def)
if err != nil {
@@ -709,13 +707,13 @@ func showRibInfo(r, name string) error {
var t api.Resource
switch r {
- case CMD_GLOBAL:
+ case cmdGlobal:
t = api.Resource_GLOBAL
- case CMD_LOCAL:
+ case cmdLocal:
t = api.Resource_LOCAL
- case CMD_ADJ_IN:
+ case cmdAdjIn:
t = api.Resource_ADJ_IN
- case CMD_ADJ_OUT:
+ case cmdAdjOut:
t = api.Resource_ADJ_OUT
default:
return fmt.Errorf("invalid resource to show RIB info: %s", r)
@@ -761,15 +759,15 @@ func showNeighborRib(r string, name string, args []string) error {
def := addr2AddressFamily(net.ParseIP(name))
switch r {
- case CMD_GLOBAL:
- def = IPv4_UC
+ case cmdGlobal:
+ def = ipv4UC
showBest = true
- case CMD_LOCAL:
+ case cmdLocal:
showBest = true
- case CMD_ADJ_OUT:
+ case cmdAdjOut:
showAge = false
- case CMD_VRF:
- def = IPv4_UC
+ case cmdVRF:
+ def = ipv4UC
showBest = true
}
family, err := checkAddressFamily(def)
@@ -801,7 +799,7 @@ func showNeighborRib(r string, name string, args []string) error {
} else if args[0] == "shorter-prefixes" {
option = api.TableLookupOption_LOOKUP_SHORTER
} else if args[0] == "validation" {
- if r != CMD_ADJ_IN {
+ if r != cmdAdjIn {
return fmt.Errorf("RPKI information is supported for only adj-in.")
}
validationTarget = target
@@ -819,17 +817,17 @@ func showNeighborRib(r string, name string, args []string) error {
var t api.Resource
switch r {
- case CMD_GLOBAL:
+ case cmdGlobal:
t = api.Resource_GLOBAL
- case CMD_LOCAL:
+ case cmdLocal:
t = api.Resource_LOCAL
- case CMD_ADJ_IN, CMD_ACCEPTED, CMD_REJECTED:
+ case cmdAdjIn, cmdAccepted, cmdRejected:
t = api.Resource_ADJ_IN
showIdentifier = bgp.BGP_ADD_PATH_RECEIVE
- case CMD_ADJ_OUT:
+ case cmdAdjOut:
t = api.Resource_ADJ_OUT
showIdentifier = bgp.BGP_ADD_PATH_SEND
- case CMD_VRF:
+ case cmdVRF:
t = api.Resource_VRF
}
@@ -855,7 +853,7 @@ func showNeighborRib(r string, name string, args []string) error {
}
switch r {
- case CMD_LOCAL, CMD_ADJ_IN, CMD_ACCEPTED, CMD_REJECTED, CMD_ADJ_OUT:
+ case cmdLocal, cmdAdjIn, cmdAccepted, cmdRejected, cmdAdjOut:
if len(rib) == 0 {
stream, err := client.ListPeer(ctx, &api.ListPeerRequest{
Address: name,
@@ -935,7 +933,7 @@ func showNeighborRib(r string, name string, args []string) error {
for _, d := range dsts {
switch r {
- case CMD_ACCEPTED:
+ case cmdAccepted:
l := make([]*api.Path, 0, len(d.Paths))
for _, p := range d.GetPaths() {
if !p.Filtered {
@@ -943,7 +941,7 @@ func showNeighborRib(r string, name string, args []string) error {
}
}
d.Paths = l
- case CMD_REJECTED:
+ case cmdRejected:
// always nothing
d.Paths = []*api.Path{}
default:
@@ -966,13 +964,13 @@ func resetNeighbor(cmd string, remoteIP string, args []string) error {
soft := true
dir := api.ResetPeerRequest_BOTH
switch cmd {
- case CMD_RESET:
+ case cmdReset:
soft = false
comm = neighborsOpts.Reason
- case CMD_SOFT_RESET:
- case CMD_SOFT_RESET_IN:
+ case cmdSoftReset:
+ case cmdSoftResetIn:
dir = api.ResetPeerRequest_IN
- case CMD_SOFT_RESET_OUT:
+ case cmdSoftResetOut:
dir = api.ResetPeerRequest_OUT
}
_, err := client.ResetPeer(ctx, &api.ResetPeerRequest{
@@ -989,19 +987,19 @@ func stateChangeNeighbor(cmd string, remoteIP string, args []string) error {
return fmt.Errorf("Too long reason for shutdown communication (max %d bytes)", bgp.BGP_ERROR_ADMINISTRATIVE_COMMUNICATION_MAX)
}
switch cmd {
- case CMD_SHUTDOWN:
- fmt.Printf("WARNING: command `%s` is deprecated. use `%s` instead\n", CMD_SHUTDOWN, CMD_DISABLE)
+ case cmdShutdown:
+ fmt.Printf("WARNING: command `%s` is deprecated. use `%s` instead\n", cmdShutdown, cmdDisable)
_, err := client.ShutdownPeer(ctx, &api.ShutdownPeerRequest{
Address: remoteIP,
Communication: neighborsOpts.Reason,
})
return err
- case CMD_ENABLE:
+ case cmdEnable:
_, err := client.EnablePeer(ctx, &api.EnablePeerRequest{
Address: remoteIP,
})
return err
- case CMD_DISABLE:
+ case cmdDisable:
_, err := client.DisablePeer(ctx, &api.DisablePeerRequest{
Address: remoteIP,
})
@@ -1073,7 +1071,7 @@ func extractDefaultAction(args []string) ([]string, api.RouteAction, error) {
func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) error {
if remoteIP == "" {
- remoteIP = GLOBAL_RIB_NAME
+ remoteIP = globalRIBName
}
assign := &api.PolicyAssignment{
@@ -1094,7 +1092,7 @@ func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) erro
var err error
switch cmdType {
- case CMD_ADD, CMD_SET:
+ case cmdAdd, cmdSet:
if len(args) < 1 {
return fmt.Errorf("%s <policy name>... [default {%s|%s}]", usage, "accept", "reject")
}
@@ -1112,15 +1110,15 @@ func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) erro
}
assign.Policies = ps
switch cmdType {
- case CMD_ADD:
+ case cmdAdd:
_, err = client.AddPolicyAssignment(ctx, &api.AddPolicyAssignmentRequest{
Assignment: assign,
})
- case CMD_SET:
+ case cmdSet:
_, err = client.SetPolicyAssignment(ctx, &api.SetPolicyAssignmentRequest{
Assignment: assign,
})
- case CMD_DEL:
+ case cmdDel:
all := false
if len(args) == 0 {
all = true
@@ -1135,24 +1133,24 @@ func modNeighborPolicy(remoteIP, policyType, cmdType string, args []string) erro
func modNeighbor(cmdType string, args []string) error {
params := map[string]int{
- "interface": PARAM_SINGLE,
+ "interface": paramSingle,
}
usage := fmt.Sprintf("usage: gobgp neighbor %s [ <neighbor-address> | interface <neighbor-interface> ]", cmdType)
- if cmdType == CMD_ADD {
+ if cmdType == cmdAdd {
usage += " as <VALUE>"
- } else if cmdType == CMD_UPDATE {
+ } else if cmdType == cmdUpdate {
usage += " [ as <VALUE> ]"
}
- if cmdType == CMD_ADD || cmdType == CMD_UPDATE {
- params["as"] = PARAM_SINGLE
- params["family"] = PARAM_SINGLE
- params["vrf"] = PARAM_SINGLE
- params["route-reflector-client"] = PARAM_SINGLE
- params["route-server-client"] = PARAM_FLAG
- params["allow-own-as"] = PARAM_SINGLE
- params["remove-private-as"] = PARAM_SINGLE
- params["replace-peer-as"] = PARAM_FLAG
- params["ebgp-multihop-ttl"] = PARAM_SINGLE
+ if cmdType == cmdAdd || cmdType == cmdUpdate {
+ params["as"] = paramSingle
+ params["family"] = paramSingle
+ params["vrf"] = paramSingle
+ params["route-reflector-client"] = paramSingle
+ params["route-server-client"] = paramFlag
+ params["allow-own-as"] = paramSingle
+ params["remove-private-as"] = paramSingle
+ params["replace-peer-as"] = paramFlag
+ params["ebgp-multihop-ttl"] = paramSingle
usage += " [ family <address-families-list> | vrf <vrf-name> | route-reflector-client [<cluster-id>] | route-server-client | allow-own-as <num> | remove-private-as (all|replace) | replace-peer-as | ebgp-multihop-ttl <ttl>]"
}
@@ -1182,7 +1180,7 @@ func modNeighbor(cmdType string, args []string) error {
}
var peer *api.Peer
switch cmdType {
- case CMD_ADD, CMD_DEL:
+ case cmdAdd, cmdDel:
peer = &api.Peer{
Conf: &api.PeerConf{},
State: &api.PeerState{},
@@ -1193,7 +1191,7 @@ func modNeighbor(cmdType string, args []string) error {
peer.Conf.NeighborAddress = addr
}
peer.State.NeighborAddress = addr
- case CMD_UPDATE:
+ case cmdUpdate:
stream, err := client.ListPeer(ctx, &api.ListPeerRequest{
Address: addr,
})
@@ -1220,7 +1218,7 @@ func modNeighbor(cmdType string, args []string) error {
peer.Conf.PeerAs = uint32(as)
}
if len(m["family"]) == 1 {
- peer.AfiSafis = make([]*api.AfiSafi, 0) // for the case of CMD_UPDATE
+ peer.AfiSafis = make([]*api.AfiSafi, 0) // for the case of cmdUpdate
for _, f := range strings.Split(m["family"][0], ",") {
rf, err := bgp.GetRouteFamily(f)
if err != nil {
@@ -1281,19 +1279,19 @@ func modNeighbor(cmdType string, args []string) error {
}
switch cmdType {
- case CMD_ADD:
+ case cmdAdd:
if err = updateNeighborConfig(n); err != nil {
return err
}
_, err = client.AddPeer(ctx, &api.AddPeerRequest{
Peer: n,
})
- case CMD_DEL:
+ case cmdDel:
_, err = client.DeletePeer(ctx, &api.DeletePeerRequest{
Address: n.Conf.NeighborAddress,
Interface: n.Conf.NeighborInterface,
})
- case CMD_UPDATE:
+ case cmdUpdate:
if err = updateNeighborConfig(n); err != nil {
return err
}
@@ -1305,7 +1303,7 @@ func modNeighbor(cmdType string, args []string) error {
return err
}
-func NewNeighborCmd() *cobra.Command {
+func newNeighborCmd() *cobra.Command {
neighborCmdImpl := &cobra.Command{}
@@ -1315,9 +1313,9 @@ func NewNeighborCmd() *cobra.Command {
}
c := make([]cmds, 0, 3)
- c = append(c, cmds{[]string{CMD_LOCAL, CMD_ADJ_IN, CMD_ADJ_OUT, CMD_ACCEPTED, CMD_REJECTED}, showNeighborRib})
- c = append(c, cmds{[]string{CMD_RESET, CMD_SOFT_RESET, CMD_SOFT_RESET_IN, CMD_SOFT_RESET_OUT}, resetNeighbor})
- c = append(c, cmds{[]string{CMD_SHUTDOWN, CMD_ENABLE, CMD_DISABLE}, stateChangeNeighbor})
+ c = append(c, cmds{[]string{cmdLocal, cmdAdjIn, cmdAdjOut, cmdAccepted, cmdRejected}, showNeighborRib})
+ c = append(c, cmds{[]string{cmdReset, cmdSoftReset, cmdSoftResetIn, cmdSoftResetOut}, resetNeighbor})
+ c = append(c, cmds{[]string{cmdShutdown, cmdEnable, cmdDisable}, stateChangeNeighbor})
getPeer := func(addr string) (*api.Peer, error) {
var r *api.ListPeerResponse
@@ -1341,7 +1339,7 @@ func NewNeighborCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
addr := ""
switch name {
- case CMD_RESET, CMD_SOFT_RESET, CMD_SOFT_RESET_IN, CMD_SOFT_RESET_OUT, CMD_SHUTDOWN:
+ case cmdReset, cmdSoftReset, cmdSoftResetIn, cmdSoftResetOut, cmdShutdown:
if args[len(args)-1] == "all" {
addr = "all"
}
@@ -1361,10 +1359,10 @@ func NewNeighborCmd() *cobra.Command {
}
neighborCmdImpl.AddCommand(c)
switch name {
- case CMD_LOCAL, CMD_ADJ_IN, CMD_ADJ_OUT:
+ case cmdLocal, cmdAdjIn, cmdAdjOut:
n := name
c.AddCommand(&cobra.Command{
- Use: CMD_SUMMARY,
+ Use: cmdSummary,
Run: func(cmd *cobra.Command, args []string) {
if err := showRibInfo(n, args[len(args)-1]); err != nil {
exitWithError(err)
@@ -1376,14 +1374,14 @@ func NewNeighborCmd() *cobra.Command {
}
policyCmd := &cobra.Command{
- Use: CMD_POLICY,
+ Use: cmdPolicy,
Run: func(cmd *cobra.Command, args []string) {
peer, err := getPeer(args[0])
if err != nil {
exitWithError(err)
}
remoteIP := peer.State.NeighborAddress
- for _, v := range []string{CMD_IN, CMD_IMPORT, CMD_EXPORT} {
+ for _, v := range []string{cmdIn, cmdImport, cmdExport} {
if err := showNeighborPolicy(remoteIP, v, 4); err != nil {
exitWithError(err)
}
@@ -1391,7 +1389,7 @@ func NewNeighborCmd() *cobra.Command {
},
}
- for _, v := range []string{CMD_IN, CMD_IMPORT, CMD_EXPORT} {
+ for _, v := range []string{cmdIn, cmdImport, cmdExport} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {
@@ -1407,7 +1405,7 @@ func NewNeighborCmd() *cobra.Command {
},
}
- for _, w := range []string{CMD_ADD, CMD_DEL, CMD_SET} {
+ for _, w := range []string{cmdAdd, cmdDel, cmdSet} {
subcmd := &cobra.Command{
Use: w,
Run: func(subcmd *cobra.Command, args []string) {
@@ -1432,7 +1430,7 @@ func NewNeighborCmd() *cobra.Command {
neighborCmdImpl.AddCommand(policyCmd)
neighborCmd := &cobra.Command{
- Use: CMD_NEIGHBOR,
+ Use: cmdNeighbor,
Run: func(cmd *cobra.Command, args []string) {
var err error
if len(args) == 0 {
@@ -1450,7 +1448,7 @@ func NewNeighborCmd() *cobra.Command {
},
}
- for _, v := range []string{CMD_ADD, CMD_DEL, CMD_UPDATE} {
+ for _, v := range []string{cmdAdd, cmdDel, cmdUpdate} {
cmd := &cobra.Command{
Use: v,
Run: func(c *cobra.Command, args []string) {
diff --git a/cmd/gobgp/cmd/policy.go b/cmd/gobgp/cmd/policy.go
index 81a4618e..4f21dffa 100644
--- a/cmd/gobgp/cmd/policy.go
+++ b/cmd/gobgp/cmd/policy.go
@@ -200,17 +200,17 @@ func formatDefinedSet(head bool, typ string, indent int, list []*api.DefinedSet)
func showDefinedSet(v string, args []string) error {
var typ api.DefinedType
switch v {
- case CMD_PREFIX:
+ case cmdPrefix:
typ = api.DefinedType_PREFIX
- case CMD_NEIGHBOR:
+ case cmdNeighbor:
typ = api.DefinedType_NEIGHBOR
- case CMD_ASPATH:
+ case cmdAspath:
typ = api.DefinedType_AS_PATH
- case CMD_COMMUNITY:
+ case cmdCommunity:
typ = api.DefinedType_COMMUNITY
- case CMD_EXTCOMMUNITY:
+ case cmdExtcommunity:
typ = api.DefinedType_EXT_COMMUNITY
- case CMD_LARGECOMMUNITY:
+ case cmdLargecommunity:
typ = api.DefinedType_LARGE_COMMUNITY
default:
return fmt.Errorf("unknown defined type: %s", v)
@@ -254,17 +254,17 @@ func showDefinedSet(v string, args []string) error {
}
var output string
switch v {
- case CMD_PREFIX:
+ case cmdPrefix:
output = formatDefinedSet(true, "PREFIX", 0, m)
- case CMD_NEIGHBOR:
+ case cmdNeighbor:
output = formatDefinedSet(true, "ADDRESS", 0, m)
- case CMD_ASPATH:
+ case cmdAspath:
output = formatDefinedSet(true, "AS-PATH", 0, m)
- case CMD_COMMUNITY:
+ case cmdCommunity:
output = formatDefinedSet(true, "COMMUNITY", 0, m)
- case CMD_EXTCOMMUNITY:
+ case cmdExtcommunity:
output = formatDefinedSet(true, "EXT-COMMUNITY", 0, m)
- case CMD_LARGECOMMUNITY:
+ case cmdLargecommunity:
output = formatDefinedSet(true, "LARGE-COMMUNITY", 0, m)
}
fmt.Print(output)
@@ -407,17 +407,17 @@ func parseDefinedSet(settype string, args []string) (*api.DefinedSet, error) {
}
switch settype {
- case CMD_PREFIX:
+ case cmdPrefix:
return parsePrefixSet(args)
- case CMD_NEIGHBOR:
+ case cmdNeighbor:
return parseNeighborSet(args)
- case CMD_ASPATH:
+ case cmdAspath:
return parseAsPathSet(args)
- case CMD_COMMUNITY:
+ case cmdCommunity:
return parseCommunitySet(args)
- case CMD_EXTCOMMUNITY:
+ case cmdExtcommunity:
return parseExtCommunitySet(args)
- case CMD_LARGECOMMUNITY:
+ case cmdLargecommunity:
return parseLargeCommunitySet(args)
default:
return nil, fmt.Errorf("invalid defined set type: %s", settype)
@@ -425,12 +425,12 @@ func parseDefinedSet(settype string, args []string) (*api.DefinedSet, error) {
}
var modPolicyUsageFormat = map[string]string{
- CMD_PREFIX: "usage: policy prefix %s <name> [<prefix> [<mask range>]]",
- CMD_NEIGHBOR: "usage: policy neighbor %s <name> [<neighbor address>...]",
- CMD_ASPATH: "usage: policy aspath %s <name> [<regexp>...]",
- CMD_COMMUNITY: "usage: policy community %s <name> [<regexp>...]",
- CMD_EXTCOMMUNITY: "usage: policy extcommunity %s <name> [<regexp>...]",
- CMD_LARGECOMMUNITY: "usage: policy large-community %s <name> [<regexp>...]",
+ cmdPrefix: "usage: policy prefix %s <name> [<prefix> [<mask range>]]",
+ cmdNeighbor: "usage: policy neighbor %s <name> [<neighbor address>...]",
+ cmdAspath: "usage: policy aspath %s <name> [<regexp>...]",
+ cmdCommunity: "usage: policy community %s <name> [<regexp>...]",
+ cmdExtcommunity: "usage: policy extcommunity %s <name> [<regexp>...]",
+ cmdLargecommunity: "usage: policy large-community %s <name> [<regexp>...]",
}
func modDefinedSet(settype string, modtype string, args []string) error {
@@ -443,11 +443,11 @@ func modDefinedSet(settype string, modtype string, args []string) error {
return err
}
switch modtype {
- case CMD_ADD:
+ case cmdAdd:
_, err = client.AddDefinedSet(ctx, &api.AddDefinedSetRequest{
DefinedSet: d,
})
- case CMD_DEL:
+ case cmdDel:
all := false
if len(args) < 2 {
all = true
@@ -643,11 +643,11 @@ func modStatement(op string, args []string) error {
}
var err error
switch op {
- case CMD_ADD:
+ case cmdAdd:
_, err = client.AddStatement(ctx, &api.AddStatementRequest{
Statement: stmt,
})
- case CMD_DEL:
+ case cmdDel:
_, err = client.DeleteStatement(ctx, &api.DeleteStatementRequest{
Statement: stmt,
All: true,
@@ -844,11 +844,11 @@ func modCondition(name, op string, args []string) error {
var err error
switch op {
- case CMD_ADD:
+ case cmdAdd:
_, err = client.AddStatement(ctx, &api.AddStatementRequest{
Statement: stmt,
})
- case CMD_DEL:
+ case cmdDel:
_, err = client.DeleteStatement(ctx, &api.DeleteStatementRequest{
Statement: stmt,
})
@@ -974,11 +974,11 @@ func modAction(name, op string, args []string) error {
}
var err error
switch op {
- case CMD_ADD:
+ case cmdAdd:
_, err = client.AddStatement(ctx, &api.AddStatementRequest{
Statement: stmt,
})
- case CMD_DEL:
+ case cmdDel:
_, err = client.DeleteStatement(ctx, &api.DeleteStatementRequest{
Statement: stmt,
})
@@ -1005,12 +1005,12 @@ func modPolicy(modtype string, args []string) error {
var err error
switch modtype {
- case CMD_ADD:
+ case cmdAdd:
_, err = client.AddPolicy(ctx, &api.AddPolicyRequest{
Policy: policy,
ReferExistingStatements: true,
})
- case CMD_DEL:
+ case cmdDel:
all := false
if len(args) < 1 {
all = true
@@ -1024,9 +1024,9 @@ func modPolicy(modtype string, args []string) error {
return err
}
-func NewPolicyCmd() *cobra.Command {
+func newPolicyCmd() *cobra.Command {
policyCmd := &cobra.Command{
- Use: CMD_POLICY,
+ Use: cmdPolicy,
Run: func(cmd *cobra.Command, args []string) {
err := showPolicy(args)
if err != nil {
@@ -1035,7 +1035,7 @@ func NewPolicyCmd() *cobra.Command {
},
}
- for _, v := range []string{CMD_PREFIX, CMD_NEIGHBOR, CMD_ASPATH, CMD_COMMUNITY, CMD_EXTCOMMUNITY, CMD_LARGECOMMUNITY} {
+ for _, v := range []string{cmdPrefix, cmdNeighbor, cmdAspath, cmdCommunity, cmdExtcommunity, cmdLargecommunity} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {
@@ -1044,7 +1044,7 @@ func NewPolicyCmd() *cobra.Command {
}
},
}
- for _, w := range []string{CMD_ADD, CMD_DEL} {
+ for _, w := range []string{cmdAdd, cmdDel} {
subcmd := &cobra.Command{
Use: w,
Run: func(c *cobra.Command, args []string) {
@@ -1059,18 +1059,18 @@ func NewPolicyCmd() *cobra.Command {
}
stmtCmdImpl := &cobra.Command{}
- for _, v := range []string{CMD_ADD, CMD_DEL} {
+ for _, v := range []string{cmdAdd, cmdDel} {
cmd := &cobra.Command{
Use: v,
}
- for _, w := range []string{CMD_CONDITION, CMD_ACTION} {
+ for _, w := range []string{cmdCondition, cmdAction} {
subcmd := &cobra.Command{
Use: w,
Run: func(c *cobra.Command, args []string) {
name := args[len(args)-1]
args = args[:len(args)-1]
var err error
- if c.Use == CMD_CONDITION {
+ if c.Use == cmdCondition {
err = modCondition(name, cmd.Use, args)
} else {
err = modAction(name, cmd.Use, args)
@@ -1086,7 +1086,7 @@ func NewPolicyCmd() *cobra.Command {
}
stmtCmd := &cobra.Command{
- Use: CMD_STATEMENT,
+ Use: cmdStatement,
Run: func(cmd *cobra.Command, args []string) {
var err error
if len(args) < 2 {
@@ -1101,7 +1101,7 @@ func NewPolicyCmd() *cobra.Command {
}
},
}
- for _, v := range []string{CMD_ADD, CMD_DEL} {
+ for _, v := range []string{cmdAdd, cmdDel} {
cmd := &cobra.Command{
Use: v,
Run: func(c *cobra.Command, args []string) {
@@ -1115,7 +1115,7 @@ func NewPolicyCmd() *cobra.Command {
}
policyCmd.AddCommand(stmtCmd)
- for _, v := range []string{CMD_ADD, CMD_DEL} {
+ for _, v := range []string{cmdAdd, cmdDel} {
cmd := &cobra.Command{
Use: v,
Run: func(c *cobra.Command, args []string) {
diff --git a/cmd/gobgp/cmd/root.go b/cmd/gobgp/cmd/root.go
index d8c606e7..3ff5e338 100644
--- a/cmd/gobgp/cmd/root.go
+++ b/cmd/gobgp/cmd/root.go
@@ -92,14 +92,14 @@ func NewRootCmd() *cobra.Command {
rootCmd.PersistentFlags().BoolVarP(&globalOpts.TLS, "tls", "", false, "connection uses TLS if true, else plain TCP")
rootCmd.PersistentFlags().StringVarP(&globalOpts.CaFile, "tls-ca-file", "", "", "The file containing the CA root cert file")
- globalCmd := NewGlobalCmd()
- neighborCmd := NewNeighborCmd()
- vrfCmd := NewVrfCmd()
- policyCmd := NewPolicyCmd()
- monitorCmd := NewMonitorCmd()
- mrtCmd := NewMrtCmd()
- rpkiCmd := NewRPKICmd()
- bmpCmd := NewBmpCmd()
+ globalCmd := newGlobalCmd()
+ neighborCmd := newNeighborCmd()
+ vrfCmd := newVrfCmd()
+ policyCmd := newPolicyCmd()
+ monitorCmd := newMonitorCmd()
+ mrtCmd := newMrtCmd()
+ rpkiCmd := newRPKICmd()
+ bmpCmd := newBmpCmd()
rootCmd.AddCommand(globalCmd, neighborCmd, vrfCmd, policyCmd, monitorCmd, mrtCmd, rpkiCmd, bmpCmd)
return rootCmd
}
diff --git a/cmd/gobgp/cmd/rpki.go b/cmd/gobgp/cmd/rpki.go
index 55aa4b77..1f623f32 100644
--- a/cmd/gobgp/cmd/rpki.go
+++ b/cmd/gobgp/cmd/rpki.go
@@ -85,7 +85,7 @@ func showRPKIServer(args []string) error {
}
func showRPKITable(args []string) error {
- family, err := checkAddressFamily(IPv4_UC)
+ family, err := checkAddressFamily(ipv4UC)
if err != nil {
exitWithError(err)
}
@@ -122,13 +122,13 @@ func showRPKITable(args []string) error {
return nil
}
-func NewRPKICmd() *cobra.Command {
+func newRPKICmd() *cobra.Command {
rpkiCmd := &cobra.Command{
- Use: CMD_RPKI,
+ Use: cmdRPKI,
}
serverCmd := &cobra.Command{
- Use: CMD_RPKI_SERVER,
+ Use: cmdRPKIServer,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 || len(args) == 1 {
showRPKIServer(args)
@@ -173,7 +173,7 @@ func NewRPKICmd() *cobra.Command {
rpkiCmd.AddCommand(serverCmd)
tableCmd := &cobra.Command{
- Use: CMD_RPKI_TABLE,
+ Use: cmdRPKITable,
Run: func(cmd *cobra.Command, args []string) {
showRPKITable(args)
},
diff --git a/cmd/gobgp/cmd/vrf.go b/cmd/gobgp/cmd/vrf.go
index 9af7e11c..8fd25d45 100644
--- a/cmd/gobgp/cmd/vrf.go
+++ b/cmd/gobgp/cmd/vrf.go
@@ -116,16 +116,16 @@ func showVrfs() error {
}
func showVrf(name string) error {
- return showNeighborRib(CMD_VRF, name, nil)
+ return showNeighborRib(cmdVRF, name, nil)
}
func modVrf(typ string, args []string) error {
switch typ {
- case CMD_ADD:
+ case cmdAdd:
a, err := extractReserved(args, map[string]int{
- "rd": PARAM_SINGLE,
- "rt": PARAM_LIST,
- "id": PARAM_SINGLE})
+ "rd": paramSingle,
+ "rt": paramList,
+ "id": paramSingle})
if err != nil || len(a[""]) != 1 || len(a["rd"]) != 1 || len(a["rt"]) < 2 {
return fmt.Errorf("Usage: gobgp vrf add <vrf name> [ id <id> ] rd <rd> rt { import | export | both } <rt>...")
}
@@ -176,7 +176,7 @@ func modVrf(typ string, args []string) error {
},
})
return err
- case CMD_DEL:
+ case cmdDel:
if len(args) != 1 {
return fmt.Errorf("Usage: gobgp vrf del <vrf name>")
}
@@ -188,9 +188,9 @@ func modVrf(typ string, args []string) error {
return nil
}
-func NewVrfCmd() *cobra.Command {
+func newVrfCmd() *cobra.Command {
ribCmd := &cobra.Command{
- Use: CMD_RIB,
+ Use: cmdRib,
Run: func(cmd *cobra.Command, args []string) {
var err error
if len(args) == 1 {
@@ -204,11 +204,11 @@ func NewVrfCmd() *cobra.Command {
},
}
- for _, v := range []string{CMD_ADD, CMD_DEL} {
+ for _, v := range []string{cmdAdd, cmdDel} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {
- err := modPath(CMD_VRF, args[len(args)-1], cmd.Use, args[:len(args)-1])
+ err := modPath(cmdVRF, args[len(args)-1], cmd.Use, args[:len(args)-1])
if err != nil {
exitWithError(err)
}
@@ -218,7 +218,7 @@ func NewVrfCmd() *cobra.Command {
}
neighborCmd := &cobra.Command{
- Use: CMD_NEIGHBOR,
+ Use: cmdNeighbor,
Run: func(cmd *cobra.Command, args []string) {
var err error
if len(args) == 1 {
@@ -252,7 +252,7 @@ func NewVrfCmd() *cobra.Command {
vrfCmdImpl.AddCommand(ribCmd, neighborCmd)
vrfCmd := &cobra.Command{
- Use: CMD_VRF,
+ Use: cmdVRF,
Run: func(cmd *cobra.Command, args []string) {
var err error
if len(args) == 0 {
@@ -269,7 +269,7 @@ func NewVrfCmd() *cobra.Command {
},
}
- for _, v := range []string{CMD_ADD, CMD_DEL} {
+ for _, v := range []string{cmdAdd, cmdDel} {
cmd := &cobra.Command{
Use: v,
Run: func(cmd *cobra.Command, args []string) {