diff --git a/cmd/create/create_bfd.go b/cmd/create/create_bfd.go index 70924df..9d551c2 100644 --- a/cmd/create/create_bfd.go +++ b/cmd/create/create_bfd.go @@ -17,13 +17,13 @@ package create import ( "context" + "errors" "fmt" "loxicmd/pkg/api" "net" "net/http" "os" "time" - "errors" "github.com/spf13/cobra" ) @@ -45,7 +45,7 @@ ex) loxicmd create bfd 32.32.32.2 --instance=default --sourceIP=32.32.32.1 --int } }, Run: func(cmd *cobra.Command, args []string) { - + // Make EndPointMod if len(args) <= 0 { fmt.Printf("create bfd needs remoteIP args\n") @@ -62,7 +62,6 @@ ex) loxicmd create bfd 32.32.32.2 --instance=default --sourceIP=32.32.32.1 --int fmt.Printf("Error: %s\n", err.Error()) return } - //fmt.Printf("Debug: response.StatusCode: %d\n", resp.StatusCode) if resp.StatusCode == http.StatusOK { diff --git a/cmd/create/create_file.go b/cmd/create/create_file.go index 1641093..b1611aa 100644 --- a/cmd/create/create_file.go +++ b/cmd/create/create_file.go @@ -203,4 +203,4 @@ func BFDCreateWithFile(restOptions *api.RESTOptions, byteBuf []byte) error { return err } return nil -} \ No newline at end of file +} diff --git a/cmd/delete/delete_bfd.go b/cmd/delete/delete_bfd.go index 442a356..c7ae3ff 100644 --- a/cmd/delete/delete_bfd.go +++ b/cmd/delete/delete_bfd.go @@ -72,7 +72,7 @@ ex) loxicmd delete bfd 32.32.32.2 --instance=default" return } defer resp.Body.Close() - + fmt.Printf("Debug: response.StatusCode: %d\n", resp.StatusCode) if resp.StatusCode == http.StatusOK { PrintDeleteResult(resp, *restOptions) @@ -81,6 +81,6 @@ ex) loxicmd delete bfd 32.32.32.2 --instance=default" }, } deleteBFDCmd.Flags().StringVarP(&o.Instance, "instance", "", "default", "Specify the cluster instance name") - + return deleteBFDCmd } diff --git a/cmd/dump/apply.go b/cmd/dump/apply.go index f0600cb..5f772ef 100644 --- a/cmd/dump/apply.go +++ b/cmd/dump/apply.go @@ -710,4 +710,4 @@ func ApplyBFDConfig(file string, restOptions *api.RESTOptions) { } defer resp.Body.Close() } -} \ No newline at end of file +} diff --git a/cmd/dump/save.go b/cmd/dump/save.go index 307145a..dc00400 100644 --- a/cmd/dump/save.go +++ b/cmd/dump/save.go @@ -46,14 +46,14 @@ func SaveCmd(saveOpts *SaveOptions, restOptions *api.RESTOptions) *cobra.Command _ = cmd _ = args dpath := "/etc/loxilb/" - if (!saveOpts.SaveIpConfig && !saveOpts.SaveAllConfig && + if !saveOpts.SaveIpConfig && !saveOpts.SaveAllConfig && !saveOpts.SaveLBConfig && !saveOpts.SaveSessionConfig && - !saveOpts.SaveUlClConfig && !saveOpts.SaveFWConfig && - !saveOpts.SaveEPConfig && !saveOpts.SaveBFDConfig) { - fmt.Println("Provide valid options") - cmd.Help() - return - } + !saveOpts.SaveUlClConfig && !saveOpts.SaveFWConfig && + !saveOpts.SaveEPConfig && !saveOpts.SaveBFDConfig { + fmt.Println("Provide valid options") + cmd.Help() + return + } if _, err := os.Stat(dpath); errors.Is(err, os.ErrNotExist) { err := os.Mkdir(dpath, os.ModePerm) if err != nil { diff --git a/cmd/get/get_bfd.go b/cmd/get/get_bfd.go index dbcff39..9caa8f0 100644 --- a/cmd/get/get_bfd.go +++ b/cmd/get/get_bfd.go @@ -18,24 +18,24 @@ package get import ( "context" "encoding/json" + "errors" "fmt" "io" "loxicmd/pkg/api" "net/http" - "time" - "strings" "os" "os/exec" - "errors" + "strings" + "time" "github.com/spf13/cobra" ) func NewGetBFDCmd(restOptions *api.RESTOptions) *cobra.Command { var GetBFDCmd = &cobra.Command{ - Use: "bfd", - Short: "Get all BFD sessions", - Long: `It shows BFD Sessions in the LoxiLB`, + Use: "bfd", + Short: "Get all BFD sessions", + Long: `It shows BFD Sessions in the LoxiLB`, Run: func(cmd *cobra.Command, args []string) { client := api.NewLoxiClient(restOptions) @@ -90,7 +90,7 @@ func PrintGetBFDResult(resp *http.Response, o api.RESTOptions) { if o.PrintOption == "wide" { table.SetHeader(BFD_WIDE_TITLE) data = append(data, []string{bfd.Instance, bfd.RemoteIP, bfd.SourceIP, - fmt.Sprintf("%d",bfd.Port), fmt.Sprintf("%d us",bfd.Interval), fmt.Sprintf("%d",bfd.RetryCount), bfd.State}) + fmt.Sprintf("%d", bfd.Port), fmt.Sprintf("%d us", bfd.Interval), fmt.Sprintf("%d", bfd.RetryCount), bfd.State}) } else { table.SetHeader(BFD_TITLE) data = append(data, []string{bfd.Instance, bfd.RemoteIP, bfd.State}) @@ -138,10 +138,10 @@ func BFDdump(restOptions *api.RESTOptions, path string) (string, error) { fmt.Printf("Error: Failed to unmarshal HTTP response: (%s)\n", err.Error()) return "", err } - + bfds := api.BFDSessionGet{} bfds.BFDSessionAttr = BFDresp.BFDSessionAttr - + cfgResultByte, err := json.Marshal(bfds) if err != nil { fmt.Printf("Error: Failed to marshal BFD Cfg: (%s)\n", err.Error()) diff --git a/cmd/get/get_firewall.go b/cmd/get/get_firewall.go index 4090e8a..edd9a42 100644 --- a/cmd/get/get_firewall.go +++ b/cmd/get/get_firewall.go @@ -94,7 +94,7 @@ func PrintGetFWResult(resp *http.Response, o api.RESTOptions) { table.SetHeader(FIREWALL_TITLE) data = append(data, []string{fwrule.Rule.SrcIP, fwrule.Rule.DstIP, fmt.Sprintf("%d", fwrule.Rule.SrcPortMin), fmt.Sprintf("%d", fwrule.Rule.SrcPortMax), fmt.Sprintf("%d", fwrule.Rule.DstPortMin), fmt.Sprintf("%d", fwrule.Rule.DstPortMax), fmt.Sprintf("%d", fwrule.Rule.Proto), - fwrule.Rule.InPort, fmt.Sprintf("%d", fwrule.Rule.Pref), MakeFirewallOptionToString(fwrule.Opts)}) + fwrule.Rule.InPort, fmt.Sprintf("%d", fwrule.Rule.Pref), MakeFirewallOptionToString(fwrule.Opts), fmt.Sprintf("%s", fwrule.Opts.Counter)}) } diff --git a/cmd/get/get_hastate.go b/cmd/get/get_hastate.go index a78b4b8..ee3b45d 100644 --- a/cmd/get/get_hastate.go +++ b/cmd/get/get_hastate.go @@ -88,4 +88,4 @@ func PrintGetHAStateResult(resp *http.Response, o api.RESTOptions) { } // Rendering the load balance data to table TableShow(data, table) -} \ No newline at end of file +} diff --git a/cmd/get/type.go b/cmd/get/type.go index edfaeed..1ffada5 100644 --- a/cmd/get/type.go +++ b/cmd/get/type.go @@ -40,11 +40,11 @@ var ( FILESYSTEM_TITLE = []string{"fileSystem", "type", "size", "used", "avail", "usePercent", "mountedOn"} MIRROR_TITLE = []string{"Mirror Name", "Mirror info", "Target\nAttachment", "target\nName"} MIRROR_WIDE_TITLE = []string{"Mirror Name", "Mirror info", "Target\nAttachment", "target\nName", "Sync"} - FIREWALL_TITLE = []string{"Source IP", "destination IP", "min SPort", "max SPort", "min DPort", "max DPort", "protocol", "port Name", "preference", "Option"} + FIREWALL_TITLE = []string{"Source IP", "destination IP", "min SPort", "max SPort", "min DPort", "max DPort", "protocol", "port Name", "preference", "Option", "Counters"} ENDPOINT_TITLE = []string{"Host", "Name", "ptype", "port", "duration", "retries", "minDelay", "avgDelay", "maxDelay", "State"} PARAM_TITLE = []string{"Param Name", "Value"} BGPNEIGHBOR_TITLE = []string{"Peer", "AS", "UP/Down", "State"} HASTATE_TITLE = []string{"Instance", "HAState"} BFD_TITLE = []string{"Instance", "RemoteIP", "State"} - BFD_WIDE_TITLE = []string{"Instance", "RemoteIP", "SourceIP", "Port", "Interval","Retry Count", "State"} + BFD_WIDE_TITLE = []string{"Instance", "RemoteIP", "SourceIP", "Port", "Interval", "Retry Count", "State"} ) diff --git a/cmd/set/set_bfd.go b/cmd/set/set_bfd.go index 19510de..fa56ab6 100644 --- a/cmd/set/set_bfd.go +++ b/cmd/set/set_bfd.go @@ -20,9 +20,9 @@ import ( "errors" "fmt" "loxicmd/pkg/api" + "net" "net/http" "time" - "net" "github.com/spf13/cobra" ) @@ -31,9 +31,9 @@ import ( func NewSetBFDCmd(restOptions *api.RESTOptions) *cobra.Command { o := api.BFDSessionInfo{} SetBFDCmd := &cobra.Command{ - Use: "bfd remoteIP [--instance=] [--interval=] [--retryCount=]", - Short: "bfd session configuration", - Long: `bfd session congfigration + Use: "bfd remoteIP [--instance=] [--interval=] [--retryCount=]", + Short: "bfd session configuration", + Long: `bfd session congfigration --instance - Cluster Instance name --interval - BFD packet Tx interval value in microseconds --retryCount - Maximum number of retry to detect failure`, diff --git a/pkg/api/bfd.go b/pkg/api/bfd.go index 0a40454..908df0f 100644 --- a/pkg/api/bfd.go +++ b/pkg/api/bfd.go @@ -35,10 +35,10 @@ type BFDSessionInfo struct { // Interval - Tx Interval between BFD packets SourceIP string `json:"sourceIp" yaml:"sourceIp"` - + // Port - BFD session port Port uint16 `json:"port" yaml:"port"` - + // Interval - Tx Interval between BFD packets Interval uint64 `json:"interval" yaml:"interval"` diff --git a/pkg/api/client.go b/pkg/api/client.go index ef6af34..3d069a2 100644 --- a/pkg/api/client.go +++ b/pkg/api/client.go @@ -42,7 +42,7 @@ const ( loxiParamResource = "config/params" loxiBGPNeighResource = "config/bgp/neigh" loxiStatusResource = "status" - loxiBFDSessionResource = "config/bfd" + loxiBFDSessionResource = "config/bfd" ) type LoxiClient struct { @@ -318,4 +318,4 @@ func (l *LoxiClient) BFDSession() *BFDSession { }, }, } -} \ No newline at end of file +} diff --git a/pkg/api/firewall.go b/pkg/api/firewall.go index 012c0e2..39372c9 100644 --- a/pkg/api/firewall.go +++ b/pkg/api/firewall.go @@ -42,6 +42,9 @@ type FwOptArg struct { Mark int `json:"fwMark" yaml:"fwMark"` // Record - Record packets matching rule Record bool `json:"record" yaml:"record"` + + // Counter - Traffic counter + Counter string `json:"counter"` } // FwRuleArg - Information related to firewall rule diff --git a/pkg/api/hastate.go b/pkg/api/hastate.go index eb55016..745f336 100644 --- a/pkg/api/hastate.go +++ b/pkg/api/hastate.go @@ -40,4 +40,3 @@ type HAStateInfo struct { // Instance Virtual IP address Vip string `json:"vip,omitempty"` } -