Skip to content

Commit

Permalink
Merge pull request #422 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR - Per end-point counters
  • Loading branch information
UltraInstinct14 authored Oct 24, 2023
2 parents c7d5923 + c072264 commit 9e2edc1
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ loxilb is an open source hyper-scale software load-balancer for cloud-native wor
* Support for TCP, UDP, SCTP (w/ multi-homing), QUIC, FTP, TFTP etc
* High-availability support with hitless/maglev/cgnat clustering
* Full compliance for K8s loadbalancer Spec
* Multi-cluster support
* Multi-cluster, in-cluster or ext-cluster deployment support
- Extensive and scalable liveness probes for cloud-native environments
- High-perf replacement for the *aging* iptables/ipvs
- L7 proxy support - HTTP1.0, 1.1, 2.0 etc
Expand Down
23 changes: 11 additions & 12 deletions api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func NlpRegister(hook cmn.NetHookInterface) {
hooks = hook
}

func iSBlackListedIntf(name string, masterIdx int) bool {
filter := nNl.BLRgx.MatchString(name)
return filter
}

func applyAllConfig(name string) bool {
command := "loxicmd apply --per-intf " + name + " -c /etc/loxilb/ipconfig/"
cmd := exec.Command("bash", "-c", command)
Expand Down Expand Up @@ -1196,8 +1201,7 @@ func DelRoute(route nlp.Route) int {
func LUWorkSingle(m nlp.LinkUpdate) int {
var ret int

filter := nNl.BLRgx.MatchString(m.Link.Attrs().Name)
if filter {
if iSBlackListedIntf(m.Link.Attrs().Name, m.Link.Attrs().MasterIndex) {
return -1
}

Expand All @@ -1213,8 +1217,7 @@ func AUWorkSingle(m nlp.AddrUpdate) int {
return -1
}

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
return -1
}

Expand Down Expand Up @@ -1251,8 +1254,7 @@ func NUWorkSingle(m nlp.NeighUpdate) int {
return -1
}

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
return -1
}

Expand All @@ -1276,8 +1278,7 @@ func RUWorkSingle(m nlp.RouteUpdate) int {
return -1
}

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
return -1
}

Expand Down Expand Up @@ -1362,8 +1363,7 @@ func GetBridges() {
return
}
for _, link := range links {
filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
continue
}
switch link.(type) {
Expand All @@ -1389,8 +1389,7 @@ func NlpGet(ch chan bool) int {

for _, link := range links {

filter := nNl.BLRgx.MatchString(link.Attrs().Name)
if filter {
if iSBlackListedIntf(link.Attrs().Name, link.Attrs().MasterIndex) {
continue
}

Expand Down
3 changes: 3 additions & 0 deletions api/models/loadbalance_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions api/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/restapi/handler/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func ConfigGetLoadbalancer(params operations.GetConfigLoadbalancerAllParams) mid
tmpEp.TargetPort = int64(ep.EpPort)
tmpEp.Weight = int64(ep.Weight)
tmpEp.State = ep.State
tmpEp.Counter = ep.Counters
tmpLB.Endpoints = append(tmpLB.Endpoints, tmpEp)
}

Expand Down
3 changes: 3 additions & 0 deletions api/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2349,6 +2349,9 @@ definitions:
state:
type: string
description: state of the endpoint
counter:
type: string
description: traffic counters of the endpoint

secondaryIPs:
type: array
Expand Down
2 changes: 2 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ type LbEndPointArg struct {
Weight uint8 `json:"weight"`
// State - current state of the end-point
State string `json:"state"`
// Counters - traffic counters of the end-point
Counters string `json:"counters"`
}

// LbSecIPArg - Secondary IP
Expand Down
2 changes: 1 addition & 1 deletion loxilb-ebpf
77 changes: 54 additions & 23 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ type ruleNatEp struct {
inActTries int
inActive bool
noService bool
mark bool
chkVal bool
stat ruleStat
}

type ruleNatSIP struct {
Expand Down Expand Up @@ -759,11 +760,14 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) {
continue
}

counterStr := fmt.Sprintf("%v:%v", ep.stat.packets, ep.stat.bytes)

ret.Eps = append(ret.Eps, cmn.LbEndPointArg{
EpIP: ep.xIP.String(),
EpPort: ep.xPort,
Weight: ep.weight,
State: state,
EpIP: ep.xIP.String(),
EpPort: ep.xPort,
Weight: ep.weight,
State: state,
Counters: counterStr,
})
}
// Make LB rule
Expand Down Expand Up @@ -1157,7 +1161,7 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg,
if natActs.mode == cmn.LBModeDSR && k.EpPort != serv.ServPort {
return RuleUnknownServiceErr, errors.New("malformed-service dsr-port error")
}
ep := ruleNatEp{pNetAddr, xNetAddr, k.EpPort, k.Weight, 0, false, false, false}
ep := ruleNatEp{pNetAddr, xNetAddr, k.EpPort, k.Weight, 0, false, false, false, ruleStat{0, 0}}
natActs.endPoints = append(natActs.endPoints, ep)
}

Expand Down Expand Up @@ -1194,29 +1198,29 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servSecIPs []cmn.LbSecIPArg,
ruleChg = true
e.inActive = false
}
e.mark = true
n.mark = true
e.chkVal = true
n.chkVal = true
break
}
}
}

for i, nEp := range natActs.endPoints {
n := &natActs.endPoints[i]
if nEp.mark == false {
if nEp.chkVal == false {
ruleChg = true
n.mark = true
n.chkVal = true
eEps = append(eEps, *n)
}
}

for i, eEp := range eEps {
e := &eEps[i]
if eEp.mark == false {
if eEp.chkVal == false {
ruleChg = true
e.inActive = true
}
e.mark = false
e.chkVal = false
}

if eRule.hChk.prbType != serv.ProbeType || eRule.hChk.prbPort != serv.ProbePort ||
Expand Down Expand Up @@ -1987,12 +1991,27 @@ func (R *RuleH) RulesSync() {
if rule.sync != 0 || rChg {
rule.DP(DpCreate)
}
rule.DP(DpStatsGet)

bytes := uint64(0)
packets := uint64(0)
switch at := rule.act.action.(type) {
case *ruleNatActs:
for _, natActs := range at.endPoints {
bytes += natActs.stat.bytes
packets += natActs.stat.packets
}
}

rule.stat.bytes = bytes
rule.stat.packets = packets

tk.LogIt(-1, "%d:%s,%s pc %v bc %v \n",
rule.ruleNum, ruleKeys, ruleActs,
rule.stat.packets, rule.stat.bytes)

if rule.hChk.actChk == false {
rule.DP(DpStatsGet)

if !rule.hChk.actChk {
continue
}

Expand Down Expand Up @@ -2303,18 +2322,30 @@ func (r *ruleEnt) DP(work DpWorkT) int {
}

if work == DpStatsGet {
nStat := new(StatDpWorkQ)
nStat.Work = work
nStat.Mark = uint32(r.ruleNum)
if isNat == true {
nStat.Name = MapNameNat4
if isNat {
switch at := r.act.action.(type) {
case *ruleNatActs:
for i := range at.endPoints {
nEP := &at.endPoints[i]
nStat := new(StatDpWorkQ)
nStat.Work = work
nStat.Mark = (((uint32(r.ruleNum)) & 0xfff) << 4) | (uint32(i) & 0xf)
nStat.Name = MapNameNat4
nStat.Bytes = &nEP.stat.bytes
nStat.Packets = &nEP.stat.packets
mh.dp.ToDpCh <- nStat
}
}
} else {
nStat := new(StatDpWorkQ)
nStat.Work = work
nStat.Mark = uint32(r.ruleNum)
nStat.Name = MapNameFw4
}
nStat.Bytes = &r.stat.bytes
nStat.Packets = &r.stat.packets
nStat.Bytes = &r.stat.bytes
nStat.Packets = &r.stat.packets

mh.dp.ToDpCh <- nStat
mh.dp.ToDpCh <- nStat
}
return 0
}

Expand Down

0 comments on commit 9e2edc1

Please sign in to comment.