Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate service name with LB rule and connection entries #14

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Associate service name with LB rule and connection entries
  • Loading branch information
nik-netlox committed Nov 3, 2023
commit 620bb173bec876a638f8619b0d94809432ac7084
6 changes: 5 additions & 1 deletion cmd/create/create_loadbalancer.go
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ type CreateLoadBalancerOptions struct {
Endpoints []string
SecIPs []string
Select string
Name string
}

type CreateLoadBalancerResult struct {
@@ -104,7 +105,7 @@ func NewCreateLoadBalancerCmd(restOptions *api.RESTOptions) *cobra.Command {
o := CreateLoadBalancerOptions{}

var createLbCmd = &cobra.Command{
Use: "lb IP [--select=<rr|hash|priority>] [--tcp=<port>:<targetPort>] [--udp=<port>:<targetPort>] [--sctp=<port>:<targetPort>] [--icmp] [--mark=<val>] [--secips=<ip>,][--endpoints=<ip>:<weight>,] [--mode=<onearm|fullnat>] [--bgp] [--monitor] [--inatimeout=<to>]",
Use: "lb IP [--select=<rr|hash|priority>] [--tcp=<port>:<targetPort>] [--udp=<port>:<targetPort>] [--sctp=<port>:<targetPort>] [--icmp] [--mark=<val>] [--secips=<ip>,][--endpoints=<ip>:<weight>,] [--mode=<onearm|fullnat>] [--bgp] [--monitor] [--inatimeout=<to>] [--name=<service-name>]",
Short: "Create a LoadBalancer",
Long: `Create a LoadBalancer

@@ -117,6 +118,7 @@ func NewCreateLoadBalancerCmd(restOptions *api.RESTOptions) *cobra.Command {
fullnat - LB put Service IP as scrIP

ex) loxicmd create lb 192.168.0.200 --tcp=80:32015 --endpoints=10.212.0.1:1,10.212.0.2:1,10.212.0.3:1
loxicmd create lb 192.168.0.200 --tcp=80:32015 --name="http-service" --endpoints=10.212.0.1:1,10.212.0.2:1,10.212.0.3:1
loxicmd create lb 192.168.0.200 --udp=80:32015 --endpoints=10.212.0.1:1,10.212.0.2:1,10.212.0.3:1 --mark=10
loxicmd create lb 192.168.0.200 --tcp=80:32015 --udp=80:32015 --endpoints=10.212.0.1:1,10.212.0.2:1,10.212.0.3:1
loxicmd create lb 192.168.0.200 --select=hash --tcp=80:32015 --endpoints=10.212.0.1:1,10.212.0.2:1,10.212.0.3:1
@@ -185,6 +187,7 @@ ex) loxicmd create lb 192.168.0.200 --tcp=80:32015 --endpoints=10.212.0.1:1,10.2
Mode: api.LbMode(ModeToNum(o.Mode)),
Timeout: o.Timeout,
Block: o.Mark,
Name: o.Name,
}

if o.Mode == "dsr" && targetPort != port {
@@ -240,6 +243,7 @@ ex) loxicmd create lb 192.168.0.200 --tcp=80:32015 --endpoints=10.212.0.1:1,10.2
createLbCmd.Flags().Uint32VarP(&o.Timeout, "inatimeout", "", 0, "Specify the timeout (in seconds) after which a LB session will be reset for inactivity")
createLbCmd.Flags().Uint16VarP(&o.Mark, "mark", "", 0, "Specify the mark num to segregate a load-balancer VIP service")
createLbCmd.Flags().StringSliceVar(&o.Endpoints, "endpoints", o.Endpoints, "Endpoints is pairs that can be specified as '<endpointIP>:<Weight>'")
createLbCmd.Flags().StringVarP(&o.Name, "name", "", o.Name, "Name for load balancer rule")

return createLbCmd
}
12 changes: 8 additions & 4 deletions cmd/get/get_conntrack.go
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ func NewGetConntrackCmd(restOptions *api.RESTOptions) *cobra.Command {

},
}

GetctCmd.Flags().StringVarP(&restOptions.ServiceName, "servName", "", restOptions.ServiceName, "Name for load balancer rule")
return GetctCmd
}

@@ -84,17 +84,21 @@ func PrintGetCTResult(resp *http.Response, o api.RESTOptions) {

// Table Init
table := TableInit()
table.SetHeader([]string{"destIP", "srcIP", "dport", "sport", "proto", "state", "act", "packets", "bytes"})
table.SetHeader([]string{"Service Name","destIP", "srcIP", "dport", "sport", "proto", "state", "act", "packets", "bytes"})
// Making load balance data
data = makeConntrackData(ctresp)
data = makeConntrackData(o, ctresp)

// Rendering the load balance data to table
TableShow(data, table)
}

func makeConntrackData(ctresp api.CtInformationGet) (data [][]string) {
func makeConntrackData(o api.RESTOptions,ctresp api.CtInformationGet) (data [][]string) {
for _, conntrack := range ctresp.CtInfo {
if o.ServiceName != "" && o.ServiceName != conntrack.ServName {
continue
}
data = append(data, []string{
conntrack.ServName,
conntrack.Dip,
conntrack.Sip,
fmt.Sprintf("%d", conntrack.Dport),
15 changes: 9 additions & 6 deletions cmd/get/get_loadbalancer.go
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ func NewGetLoadBalancerCmd(restOptions *api.RESTOptions) *cobra.Command {

},
}

GetLbCmd.Flags().StringVarP(&restOptions.ServiceName, "servName", "", restOptions.ServiceName, "Name for load balancer rule")
return GetLbCmd
}

@@ -133,6 +133,9 @@ func PrintGetLbResult(resp *http.Response, o api.RESTOptions) {

// Making load balance data
for _, lbrule := range lbresp.LbRules {
if o.ServiceName != "" && o.ServiceName != lbrule.Service.Name {
continue
}
if o.PrintOption == "wide" {
table.SetHeader(LOADBALANCER_WIDE_TITLE)
secIPs = ""
@@ -146,25 +149,25 @@ func PrintGetLbResult(resp *http.Response, o api.RESTOptions) {
if lbrule.Service.Monitor {
for i, eps := range lbrule.Endpoints {
if i == 0 {
data = append(data, []string{lbrule.Service.ExternalIP, secIPs, fmt.Sprintf("%d", lbrule.Service.Port), lbrule.Service.Protocol, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)),
data = append(data, []string{lbrule.Service.ExternalIP, secIPs, fmt.Sprintf("%d", lbrule.Service.Port), lbrule.Service.Protocol, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)),
eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), eps.State, eps.Counter})
} else {
data = append(data, []string{"", "", "", "", "", "", "", eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), eps.State, eps.Counter})
data = append(data, []string{"", "", "", "", "", "", "", "", eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), eps.State, eps.Counter})
}
}
} else {
for i, eps := range lbrule.Endpoints {
if i == 0 {
data = append(data, []string{lbrule.Service.ExternalIP, secIPs, fmt.Sprintf("%d", lbrule.Service.Port), lbrule.Service.Protocol, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)),
data = append(data, []string{lbrule.Service.ExternalIP, secIPs, fmt.Sprintf("%d", lbrule.Service.Port), lbrule.Service.Protocol, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)),
eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), "-", eps.Counter})
} else {
data = append(data, []string{"", "", "", "", "", "", "", eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), "-", eps.Counter})
data = append(data, []string{"", "", "", "", "", "", "", "", eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), "-", eps.Counter})
}
}
}
} else {
table.SetHeader(LOADBALANCER_TITLE)
data = append(data, []string{lbrule.Service.ExternalIP, fmt.Sprintf("%d", lbrule.Service.Port), lbrule.Service.Protocol, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)), fmt.Sprintf("%d", len(lbrule.Endpoints)), BoolToMon(lbrule.Service.Monitor)})
data = append(data, []string{lbrule.Service.ExternalIP, fmt.Sprintf("%d", lbrule.Service.Port), lbrule.Service.Protocol, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)), fmt.Sprintf("%d", len(lbrule.Endpoints)), BoolToMon(lbrule.Service.Monitor)})
}
}

4 changes: 2 additions & 2 deletions cmd/get/type.go
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ package get

var (
CONNTRACK_TITLE = []string{"destIP", "srcIP", "dPort", "sPort", "proto", "state", "act", "packets", "bytes"}
LOADBALANCER_TITLE = []string{"Ext IP", "Port", "Proto", "Mark", "Sel", "Mode", "# of Endpoints", "Monitor"}
LOADBALANCER_WIDE_TITLE = []string{"Ext IP", "Sec IPs", "Port", "Proto", "Mark", "Sel", "Mode", "Endpoint", "EPort", "Weight", "State", "Counters"}
LOADBALANCER_TITLE = []string{"Ext IP", "Port", "Proto", "Name", "Mark", "Sel", "Mode", "# of Endpoints", "Monitor"}
LOADBALANCER_WIDE_TITLE = []string{"Ext IP", "Sec IPs", "Port", "Proto", "Name", "Mark", "Sel", "Mode", "Endpoint", "EPort", "Weight", "State", "Counters"}
SESSION_TITLE = []string{"ident", "session IP"}
SESSION_WIDE_TITLE = []string{"ident", "session IP", "access Network Tunnel", "core Network Tunnel"}
PORT_WIDE_TITLE = []string{"index", "portname", "MAC", "link/state", "mtu", "isActive/bpf\nPort type", "Statistics", "L3Info", "L2Info", "Sync"}
1 change: 1 addition & 0 deletions pkg/api/conntrack.go
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ type ConntrackInformation struct {
CAct string `json:"conntrackAct"`
Pkts uint64 `json:"packets"`
Bytes uint64 `json:"bytes"`
ServName string `json:"servName"`
}

func (ct ConntrackInformation) Key() string {
1 change: 1 addition & 0 deletions pkg/api/loadBalancer.go
Original file line number Diff line number Diff line change
@@ -47,6 +47,7 @@ type LoadBalancerService struct {
Timeout uint32 `json:"inactiveTimeOut" yaml:"inactiveTimeOut"`
Block uint16 `json:"block" yaml:"block"`
Managed bool `json:"managed,omitempty" yaml:"managed"`
Name string `json:"name,omitempty" yaml:"name"`
}

type LoadBalancerEndpoint struct {
1 change: 1 addition & 0 deletions pkg/api/rest.go
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ type RESTOptions struct {
ServerIP string
ServerPort int16
Timeout int16
ServiceName string
}

type RESTClient struct {