Skip to content

Commit

Permalink
Merge pull request #526 from TrekkieCoder/main
Browse files Browse the repository at this point in the history
PR -  BFD : configurable tx interval
  • Loading branch information
UltraInstinct14 authored Feb 9, 2024
2 parents 700f8ee + 596e816 commit 2ee2529
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
19 changes: 15 additions & 4 deletions loxinet/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package loxinet
import (
"errors"
"fmt"
"net"
"os"
"time"

cmn "github.com/loxilb-io/loxilb/common"
opts "github.com/loxilb-io/loxilb/options"
bfd "github.com/loxilb-io/loxilb/proto"
tk "github.com/loxilb-io/loxilib"
"net"
"time"
)

// error codes for cluster module
Expand Down Expand Up @@ -58,6 +60,7 @@ type ClusterNode struct {
type CIStateH struct {
SpawnKa bool
RemoteIP net.IP
KaArgsVal int64
ClusterMap map[string]*ClusterInstance
StateMap map[string]int
NodeMap map[string]*ClusterNode
Expand Down Expand Up @@ -89,11 +92,18 @@ func (ci *CIStateH) startBFDProto() {
// We need some cool-off period for loxilb to self sync-up in the cluster
time.Sleep(KAInitTiVal * time.Second)

txInterval := uint32(bfd.BFDDflSysTXIntervalUs)
if ci.KaArgsVal != 0 && ci.KaArgsVal >= bfd.BFDMinSysTXIntervalUs {
txInterval = uint32(ci.KaArgsVal)
}

bs := bfd.StructNew(3784)
err := bs.BFDAddRemote(ci.RemoteIP.String(), 3784, bfd.BFDMinSysTXIntervalUs, 3, cmn.CIDefault, ci)
err := bs.BFDAddRemote(ci.RemoteIP.String(), 3784, txInterval, 3, cmn.CIDefault, ci)
if err != nil {
tk.LogIt(tk.LogCritical, "KA - Cant add BFD remote\n")
os.Exit(1)
}
tk.LogIt(tk.LogInfo, "KA - Added BFD remote %s:%vus\n", ci.RemoteIP.String(), txInterval)
}

// CITicker - Periodic ticker for Cluster module
Expand All @@ -109,7 +119,7 @@ func (ci *CIStateH) CISpawn() {
}

// CIInit - routine to initialize Cluster context
func CIInit(spawnKa bool, remoteIP net.IP) *CIStateH {
func CIInit(spawnKa bool, remoteIP net.IP, extArgs int64) *CIStateH {
var nCIh = new(CIStateH)
nCIh.StateMap = make(map[string]int)
nCIh.StateMap["MASTER"] = cmn.CIStateMaster
Expand All @@ -119,6 +129,7 @@ func CIInit(spawnKa bool, remoteIP net.IP) *CIStateH {
nCIh.StateMap["NOT_DEFINED"] = cmn.CIStateNotDefined
nCIh.SpawnKa = spawnKa
nCIh.RemoteIP = remoteIP
nCIh.KaArgsVal = extArgs
nCIh.ClusterMap = make(map[string]*ClusterInstance)

if _, ok := nCIh.ClusterMap[cmn.CIDefault]; !ok {
Expand Down
4 changes: 2 additions & 2 deletions loxinet/loxinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var mh loxiNetH
func loxiNetInit() {
var rpcMode int

spawnKa, kaMode := KAString2Mode(opts.Opts.Ka)
spawnKa, kaMode, kaExtArgs := KAString2Mode(opts.Opts.Ka)
clusterMode := false
if opts.Opts.ClusterNodes != "none" {
clusterMode = true
Expand Down Expand Up @@ -249,7 +249,7 @@ func loxiNetInit() {
}

// Initialize the clustering subsystem
mh.has = CIInit(spawnKa, kaMode)
mh.has = CIInit(spawnKa, kaMode, kaExtArgs)
if clusterMode {
if opts.Opts.Bgp {
tk.LogIt(tk.LogInfo, "init-wait cluster mode\n")
Expand Down
18 changes: 13 additions & 5 deletions loxinet/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"os"
"os/exec"
"strconv"
"strings"
"syscall"
"time"
)
Expand Down Expand Up @@ -138,19 +139,26 @@ func LogString2Level(logStr string) tk.LogLevelT {
}

// KAString2Mode - Convert ka mode in string opts to spawn/KAMode
func KAString2Mode(kaStr string) (bool, net.IP) {
func KAString2Mode(kaStr string) (bool, net.IP, int64) {
spawnKa := false
kaExtraArgs := int64(0)

if kaStr == "none" {
return spawnKa, nil
return spawnKa, nil, kaExtraArgs
}

remote := net.ParseIP(kaStr)
kaArgs := strings.Split(kaStr, ":")

remote := net.ParseIP(kaArgs[0])
if remote == nil {
return spawnKa, remote
return spawnKa, remote, kaExtraArgs
}

if len(kaArgs) > 1 {
kaExtraArgs, _ = strconv.ParseInt(kaArgs[1], 10, 32)
}
spawnKa = true
return spawnKa, remote
return spawnKa, remote, kaExtraArgs
}

// HTTPSProber - Do a https probe for given url
Expand Down
6 changes: 4 additions & 2 deletions proto/bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"encoding/binary"
"errors"
"fmt"
tk "github.com/loxilb-io/loxilib"
"net"
"sync"
"time"

tk "github.com/loxilb-io/loxilib"
)

type SessionState uint8
Expand All @@ -36,7 +37,8 @@ const (
)

const (
BFDMinSysTXIntervalUs = 200000
BFDMinSysTXIntervalUs = 100000
BFDDflSysTXIntervalUs = 200000
BFDMinSysRXIntervalUs = 200000
)

Expand Down

0 comments on commit 2ee2529

Please sign in to comment.