Skip to content

Commit

Permalink
Merge pull request #23 from loxilb-io/fw-count
Browse files Browse the repository at this point in the history
PR: support for fw-counters
  • Loading branch information
TrekkieCoder authored Mar 14, 2024
2 parents 79712bf + 7cd57e5 commit 43ca77f
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 36 deletions.
5 changes: 2 additions & 3 deletions cmd/create/create_bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package create

import (
"context"
"errors"
"fmt"
"loxicmd/pkg/api"
"net"
"net/http"
"os"
"time"
"errors"

"github.com/spf13/cobra"
)
Expand All @@ -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")
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/create/create_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,4 @@ func BFDCreateWithFile(restOptions *api.RESTOptions, byteBuf []byte) error {
return err
}
return nil
}
}
4 changes: 2 additions & 2 deletions cmd/delete/delete_bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cmd/dump/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,4 +710,4 @@ func ApplyBFDConfig(file string, restOptions *api.RESTOptions) {
}
defer resp.Body.Close()
}
}
}
14 changes: 7 additions & 7 deletions cmd/dump/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions cmd/get/get_bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion cmd/get/get_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)})

}

Expand Down
2 changes: 1 addition & 1 deletion cmd/get/get_hastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ func PrintGetHAStateResult(resp *http.Response, o api.RESTOptions) {
}
// Rendering the load balance data to table
TableShow(data, table)
}
}
4 changes: 2 additions & 2 deletions cmd/get/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
)
8 changes: 4 additions & 4 deletions cmd/set/set_bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"errors"
"fmt"
"loxicmd/pkg/api"
"net"
"net/http"
"time"
"net"

"github.com/spf13/cobra"
)
Expand All @@ -31,9 +31,9 @@ import (
func NewSetBFDCmd(restOptions *api.RESTOptions) *cobra.Command {
o := api.BFDSessionInfo{}
SetBFDCmd := &cobra.Command{
Use: "bfd remoteIP [--instance=<instance>] [--interval=<interval>] [--retryCount=<count>]",
Short: "bfd session configuration",
Long: `bfd session congfigration
Use: "bfd remoteIP [--instance=<instance>] [--interval=<interval>] [--retryCount=<count>]",
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`,
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const (
loxiParamResource = "config/params"
loxiBGPNeighResource = "config/bgp/neigh"
loxiStatusResource = "status"
loxiBFDSessionResource = "config/bfd"
loxiBFDSessionResource = "config/bfd"
)

type LoxiClient struct {
Expand Down Expand Up @@ -318,4 +318,4 @@ func (l *LoxiClient) BFDSession() *BFDSession {
},
},
}
}
}
3 changes: 3 additions & 0 deletions pkg/api/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/api/hastate.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ type HAStateInfo struct {
// Instance Virtual IP address
Vip string `json:"vip,omitempty"`
}

0 comments on commit 43ca77f

Please sign in to comment.