Skip to content

Commit

Permalink
support modification of cnodes
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Jan 1, 2025
1 parent 4fcf930 commit e289ba6
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 36 deletions.
52 changes: 32 additions & 20 deletions pkg/loxinet/dpbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ package loxinet

import (
"fmt"
cmn "github.com/loxilb-io/loxilb/common"
tk "github.com/loxilb-io/loxilib"
"net"
"os"
"runtime/debug"
"sync"
"time"

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

cmn "github.com/loxilb-io/loxilb/common"
)

// man names constants
Expand All @@ -43,6 +41,10 @@ const (
MapNameFw4 = "FW4"
)

const (
UseRPCPeer = false
)

// error codes
const (
DpErrBase = iota - 103000
Expand Down Expand Up @@ -448,6 +450,8 @@ type DpHookInterface interface {
DpCtDel(w *DpCtInfo) int
DpSockVIPAdd(w *SockVIPDpWorkQ) int
DpSockVIPDel(w *SockVIPDpWorkQ) int
DpCnodeAdd(w *PeerDpWorkQ) int
DpCnodeDel(w *PeerDpWorkQ) int
DpTableGC()
DpCtGetAsync()
DpGetLock()
Expand Down Expand Up @@ -770,27 +774,35 @@ func (dp *DpH) DpWorkOnSockVIP(vsWq *SockVIPDpWorkQ) DpRetT {
// DpWorkOnPeerOp - routine to work on a peer request for clustering
func (dp *DpH) DpWorkOnPeerOp(pWq *PeerDpWorkQ) DpRetT {
if pWq.Work == DpCreate {
var newPeer DpPeer
for _, pe := range dp.Peers {
if pe.Peer.Equal(pWq.PeerIP) {
return DpCreateErr
if UseRPCPeer {
var newPeer DpPeer
for _, pe := range dp.Peers {
if pe.Peer.Equal(pWq.PeerIP) {
return DpCreateErr
}
}
newPeer.Peer = pWq.PeerIP
dp.Peers = append(dp.Peers, newPeer)
tk.LogIt(tk.LogInfo, "Added cluster-peer %s\n", newPeer.Peer.String())
return 0
} else {
return dp.DpHooks.DpCnodeAdd(pWq)
}
newPeer.Peer = pWq.PeerIP
dp.Peers = append(dp.Peers, newPeer)
tk.LogIt(tk.LogInfo, "Added cluster-peer %s\n", newPeer.Peer.String())
return 0
} else if pWq.Work == DpRemove {
for idx := range dp.Peers {
pe := &dp.Peers[idx]
if pe.Peer.Equal(pWq.PeerIP) {
if pe.Client != nil {
dp.RPC.RPCHooks.RPCClose(pe)
if UseRPCPeer {
for idx := range dp.Peers {
pe := &dp.Peers[idx]
if pe.Peer.Equal(pWq.PeerIP) {
if pe.Client != nil {
dp.RPC.RPCHooks.RPCClose(pe)
}
dp.Peers = append(dp.Peers[:idx], dp.Peers[idx+1:]...)
tk.LogIt(tk.LogInfo, "Deleted cluster-peer %s\n", pWq.PeerIP.String())
return 0
}
dp.Peers = append(dp.Peers[:idx], dp.Peers[idx+1:]...)
tk.LogIt(tk.LogInfo, "Deleted cluster-peer %s\n", pWq.PeerIP.String())
return 0
}
} else {
return dp.DpHooks.DpCnodeDel(pWq)
}
}

Expand Down
64 changes: 48 additions & 16 deletions pkg/loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,23 @@ func DpEbpfSetLogLevel(logLevel tk.LogLevelT) {
func DpEbpfInit(clusterNodes string, rssEn, egrHooks, localSockPolicy, sockMapEn bool, nodeNum int, disBPF bool, logLevel tk.LogLevelT) *DpEbpfH {
var cfg C.struct_ebpfcfg

cNodes := strings.Split(clusterNodes, ",")
for i, cNode := range cNodes {
addr := net.ParseIP(cNode)
if addr == nil {
continue
}
if utils.IsIPHostAddr(cNode) {
continue
}
if i == 0 {
cfg.cluster1 = C.CString(cNode)
} else if i == 1 {
cfg.cluster2 = C.CString(cNode)
}
}
//cNodes := strings.Split(clusterNodes, ",")
//for i, cNode := range cNodes {
// addr := net.ParseIP(cNode)
// if addr == nil {
// continue
// }
// if utils.IsIPHostAddr(cNode) {
// continue
// }
// if i == 0 {
// cfg.cluster1 = C.CString(cNode)
// } else if i == 1 {
// cfg.cluster2 = C.CString(cNode)
// }
//}

//if clusterEn {
//if len(clusterEn) > 0 {
// cfg.have_mtrace = 1
//} else {
// cfg.have_mtrace = 0
Expand Down Expand Up @@ -1939,6 +1939,38 @@ func (e *DpEbpfH) DpSockVIPDel(w *SockVIPDpWorkQ) int {
return ec
}

// DpCnodeAdd - routine to work on adding a cnode
func (e *DpEbpfH) DpCnodeAdd(w *PeerDpWorkQ) int {
cnode := w.PeerIP.String()

cnodeStr := C.CString(cnode)
defer C.free(unsafe.Pointer(cnodeStr))

ec := int(C.llb_add_cnode(cnodeStr))
if ec != 0 {
*w.Status = DpCreateErr
} else {
*w.Status = 0
}
return ec
}

// DpCnodeDel - routine to work on deleting a cnode
func (e *DpEbpfH) DpCnodeDel(w *PeerDpWorkQ) int {
cnode := w.PeerIP.String()

cnodeStr := C.CString(cnode)
defer C.free(unsafe.Pointer(cnodeStr))

ec := int(C.llb_delete_cnode(cnodeStr))
if ec != 0 {
*w.Status = DpRemoveErr
} else {
*w.Status = 0
}
return ec
}

//export goMapNotiHandler
func goMapNotiHandler(m *mapNoti) {

Expand Down

0 comments on commit e289ba6

Please sign in to comment.