diff --git a/loxinet/cluster.go b/loxinet/cluster.go index 995cf85d9..6190939ad 100644 --- a/loxinet/cluster.go +++ b/loxinet/cluster.go @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 { diff --git a/loxinet/loxinet.go b/loxinet/loxinet.go index ed90c938e..388733e59 100644 --- a/loxinet/loxinet.go +++ b/loxinet/loxinet.go @@ -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 @@ -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") diff --git a/loxinet/utils.go b/loxinet/utils.go index 6e5e8e3ad..d9ad9ee75 100644 --- a/loxinet/utils.go +++ b/loxinet/utils.go @@ -31,6 +31,7 @@ import ( "os" "os/exec" "strconv" + "strings" "syscall" "time" ) @@ -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 diff --git a/proto/bfd.go b/proto/bfd.go index c60570267..a64090856 100644 --- a/proto/bfd.go +++ b/proto/bfd.go @@ -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 @@ -36,7 +37,8 @@ const ( ) const ( - BFDMinSysTXIntervalUs = 200000 + BFDMinSysTXIntervalUs = 100000 + BFDDflSysTXIntervalUs = 200000 BFDMinSysRXIntervalUs = 200000 )