From 15b481ffa84a5a6ac7676ac3394e90da76306118 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Mon, 1 Apr 2024 16:04:21 +0900 Subject: [PATCH 1/2] chore: go packages reorganized --- loxilb_test.go | 2 +- main.go | 2 +- {loxinet => pkg/loxinet}/apiclient.go | 0 {loxinet => pkg/loxinet}/cluster.go | 2 +- {loxinet => pkg/loxinet}/dpbroker.go | 0 {loxinet => pkg/loxinet}/dpebpf_linux.go | 6 +++--- {loxinet => pkg/loxinet}/dpebpf_windows.go | 0 {loxinet => pkg/loxinet}/gobgpclient.go | 0 {loxinet => pkg/loxinet}/layer2.go | 0 {loxinet => pkg/loxinet}/layer3.go | 0 {loxinet => pkg/loxinet}/loxinet.go | 0 {loxinet => pkg/loxinet}/loxinet_test.go | 0 {loxinet => pkg/loxinet}/loxinettest.go | 0 {loxinet => pkg/loxinet}/mirror.go | 0 {loxinet => pkg/loxinet}/neighbor.go | 0 {loxinet => pkg/loxinet}/port.go | 0 {loxinet => pkg/loxinet}/qospol.go | 0 {loxinet => pkg/loxinet}/route.go | 0 {loxinet => pkg/loxinet}/rules.go | 0 {loxinet => pkg/loxinet}/session.go | 0 {loxinet => pkg/loxinet}/utils.go | 0 {loxinet => pkg/loxinet}/vlan.go | 0 {loxinet => pkg/loxinet}/xsync.pb.go | 0 {loxinet => pkg/loxinet}/xsync.proto | 0 {loxinet => pkg/loxinet}/xsync_client.go | 0 {loxinet => pkg/loxinet}/xsync_grpc.pb.go | 0 {loxinet => pkg/loxinet}/xsync_server.go | 0 {loxinet => pkg/loxinet}/zones.go | 0 {proto => pkg/proto}/bfd.go | 0 29 files changed, 6 insertions(+), 6 deletions(-) rename {loxinet => pkg/loxinet}/apiclient.go (100%) rename {loxinet => pkg/loxinet}/cluster.go (99%) rename {loxinet => pkg/loxinet}/dpbroker.go (100%) rename {loxinet => pkg/loxinet}/dpebpf_linux.go (99%) rename {loxinet => pkg/loxinet}/dpebpf_windows.go (100%) rename {loxinet => pkg/loxinet}/gobgpclient.go (100%) rename {loxinet => pkg/loxinet}/layer2.go (100%) rename {loxinet => pkg/loxinet}/layer3.go (100%) rename {loxinet => pkg/loxinet}/loxinet.go (100%) rename {loxinet => pkg/loxinet}/loxinet_test.go (100%) rename {loxinet => pkg/loxinet}/loxinettest.go (100%) rename {loxinet => pkg/loxinet}/mirror.go (100%) rename {loxinet => pkg/loxinet}/neighbor.go (100%) rename {loxinet => pkg/loxinet}/port.go (100%) rename {loxinet => pkg/loxinet}/qospol.go (100%) rename {loxinet => pkg/loxinet}/route.go (100%) rename {loxinet => pkg/loxinet}/rules.go (100%) rename {loxinet => pkg/loxinet}/session.go (100%) rename {loxinet => pkg/loxinet}/utils.go (100%) rename {loxinet => pkg/loxinet}/vlan.go (100%) rename {loxinet => pkg/loxinet}/xsync.pb.go (100%) rename {loxinet => pkg/loxinet}/xsync.proto (100%) rename {loxinet => pkg/loxinet}/xsync_client.go (100%) rename {loxinet => pkg/loxinet}/xsync_grpc.pb.go (100%) rename {loxinet => pkg/loxinet}/xsync_server.go (100%) rename {loxinet => pkg/loxinet}/zones.go (100%) rename {proto => pkg/proto}/bfd.go (100%) diff --git a/loxilb_test.go b/loxilb_test.go index d44e331e7..105e60a93 100644 --- a/loxilb_test.go +++ b/loxilb_test.go @@ -17,7 +17,7 @@ package main import ( "fmt" - ln "github.com/loxilb-io/loxilb/loxinet" + ln "github.com/loxilb-io/loxilb/pkg/loxinet" "testing" ) diff --git a/main.go b/main.go index ad0a8e1d0..ca0b9b1fd 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ import ( "time" "github.com/jessevdk/go-flags" - ln "github.com/loxilb-io/loxilb/loxinet" + ln "github.com/loxilb-io/loxilb/pkg/loxinet" opts "github.com/loxilb-io/loxilb/options" ) diff --git a/loxinet/apiclient.go b/pkg/loxinet/apiclient.go similarity index 100% rename from loxinet/apiclient.go rename to pkg/loxinet/apiclient.go diff --git a/loxinet/cluster.go b/pkg/loxinet/cluster.go similarity index 99% rename from loxinet/cluster.go rename to pkg/loxinet/cluster.go index 763365bed..70a1493d7 100644 --- a/loxinet/cluster.go +++ b/pkg/loxinet/cluster.go @@ -26,7 +26,7 @@ import ( cmn "github.com/loxilb-io/loxilb/common" opts "github.com/loxilb-io/loxilb/options" - bfd "github.com/loxilb-io/loxilb/proto" + bfd "github.com/loxilb-io/loxilb/pkg/proto" tk "github.com/loxilb-io/loxilib" ) diff --git a/loxinet/dpbroker.go b/pkg/loxinet/dpbroker.go similarity index 100% rename from loxinet/dpbroker.go rename to pkg/loxinet/dpbroker.go diff --git a/loxinet/dpebpf_linux.go b/pkg/loxinet/dpebpf_linux.go similarity index 99% rename from loxinet/dpebpf_linux.go rename to pkg/loxinet/dpebpf_linux.go index 5bf92d25d..a86be4a09 100644 --- a/loxinet/dpebpf_linux.go +++ b/pkg/loxinet/dpebpf_linux.go @@ -33,13 +33,13 @@ package loxinet #include #include #include -#include "../loxilb-ebpf/kernel/loxilb_libdp.h" +#include "../../loxilb-ebpf/kernel/loxilb_libdp.h" int bpf_map_get_next_key(int fd, const void *key, void *next_key); int bpf_map_lookup_elem(int fd, const void *key, void *value); extern void goMapNotiHandler(struct ll_dp_map_notif *); extern void goLinuxArpResolver(unsigned int); -#cgo CFLAGS: -I./../loxilb-ebpf/libbpf/src/ -I./../loxilb-ebpf/common -#cgo LDFLAGS: -L. -L/lib64 -L./../loxilb-ebpf/kernel -L./../loxilb-ebpf/libbpf/src/build/usr/lib64/ -Wl,-rpath=/lib64/ -lloxilbdp -lbpf -lelf -lz +#cgo CFLAGS: -I./../../loxilb-ebpf/libbpf/src/ -I./../../loxilb-ebpf/common +#cgo LDFLAGS: -L. -L/lib64 -L./../../loxilb-ebpf/kernel -L./../../loxilb-ebpf/libbpf/src/build/usr/lib64/ -Wl,-rpath=/lib64/ -lloxilbdp -lbpf -lelf -lz */ import "C" import ( diff --git a/loxinet/dpebpf_windows.go b/pkg/loxinet/dpebpf_windows.go similarity index 100% rename from loxinet/dpebpf_windows.go rename to pkg/loxinet/dpebpf_windows.go diff --git a/loxinet/gobgpclient.go b/pkg/loxinet/gobgpclient.go similarity index 100% rename from loxinet/gobgpclient.go rename to pkg/loxinet/gobgpclient.go diff --git a/loxinet/layer2.go b/pkg/loxinet/layer2.go similarity index 100% rename from loxinet/layer2.go rename to pkg/loxinet/layer2.go diff --git a/loxinet/layer3.go b/pkg/loxinet/layer3.go similarity index 100% rename from loxinet/layer3.go rename to pkg/loxinet/layer3.go diff --git a/loxinet/loxinet.go b/pkg/loxinet/loxinet.go similarity index 100% rename from loxinet/loxinet.go rename to pkg/loxinet/loxinet.go diff --git a/loxinet/loxinet_test.go b/pkg/loxinet/loxinet_test.go similarity index 100% rename from loxinet/loxinet_test.go rename to pkg/loxinet/loxinet_test.go diff --git a/loxinet/loxinettest.go b/pkg/loxinet/loxinettest.go similarity index 100% rename from loxinet/loxinettest.go rename to pkg/loxinet/loxinettest.go diff --git a/loxinet/mirror.go b/pkg/loxinet/mirror.go similarity index 100% rename from loxinet/mirror.go rename to pkg/loxinet/mirror.go diff --git a/loxinet/neighbor.go b/pkg/loxinet/neighbor.go similarity index 100% rename from loxinet/neighbor.go rename to pkg/loxinet/neighbor.go diff --git a/loxinet/port.go b/pkg/loxinet/port.go similarity index 100% rename from loxinet/port.go rename to pkg/loxinet/port.go diff --git a/loxinet/qospol.go b/pkg/loxinet/qospol.go similarity index 100% rename from loxinet/qospol.go rename to pkg/loxinet/qospol.go diff --git a/loxinet/route.go b/pkg/loxinet/route.go similarity index 100% rename from loxinet/route.go rename to pkg/loxinet/route.go diff --git a/loxinet/rules.go b/pkg/loxinet/rules.go similarity index 100% rename from loxinet/rules.go rename to pkg/loxinet/rules.go diff --git a/loxinet/session.go b/pkg/loxinet/session.go similarity index 100% rename from loxinet/session.go rename to pkg/loxinet/session.go diff --git a/loxinet/utils.go b/pkg/loxinet/utils.go similarity index 100% rename from loxinet/utils.go rename to pkg/loxinet/utils.go diff --git a/loxinet/vlan.go b/pkg/loxinet/vlan.go similarity index 100% rename from loxinet/vlan.go rename to pkg/loxinet/vlan.go diff --git a/loxinet/xsync.pb.go b/pkg/loxinet/xsync.pb.go similarity index 100% rename from loxinet/xsync.pb.go rename to pkg/loxinet/xsync.pb.go diff --git a/loxinet/xsync.proto b/pkg/loxinet/xsync.proto similarity index 100% rename from loxinet/xsync.proto rename to pkg/loxinet/xsync.proto diff --git a/loxinet/xsync_client.go b/pkg/loxinet/xsync_client.go similarity index 100% rename from loxinet/xsync_client.go rename to pkg/loxinet/xsync_client.go diff --git a/loxinet/xsync_grpc.pb.go b/pkg/loxinet/xsync_grpc.pb.go similarity index 100% rename from loxinet/xsync_grpc.pb.go rename to pkg/loxinet/xsync_grpc.pb.go diff --git a/loxinet/xsync_server.go b/pkg/loxinet/xsync_server.go similarity index 100% rename from loxinet/xsync_server.go rename to pkg/loxinet/xsync_server.go diff --git a/loxinet/zones.go b/pkg/loxinet/zones.go similarity index 100% rename from loxinet/zones.go rename to pkg/loxinet/zones.go diff --git a/proto/bfd.go b/pkg/proto/bfd.go similarity index 100% rename from proto/bfd.go rename to pkg/proto/bfd.go From 26a6b5fa2a61e5542433c285bbe95a6853b91380 Mon Sep 17 00:00:00 2001 From: Trekkie Coder Date: Mon, 1 Apr 2024 16:29:18 +0900 Subject: [PATCH 2/2] minor fixes in bfd proto --- main.go | 2 +- pkg/loxinet/cluster.go | 33 +++++++++++++++------------------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/main.go b/main.go index ca0b9b1fd..13c56e828 100644 --- a/main.go +++ b/main.go @@ -22,8 +22,8 @@ import ( "time" "github.com/jessevdk/go-flags" - ln "github.com/loxilb-io/loxilb/pkg/loxinet" opts "github.com/loxilb-io/loxilb/options" + ln "github.com/loxilb-io/loxilb/pkg/loxinet" ) var version string = "0.9.2-beta" diff --git a/pkg/loxinet/cluster.go b/pkg/loxinet/cluster.go index 70a1493d7..9561a0799 100644 --- a/pkg/loxinet/cluster.go +++ b/pkg/loxinet/cluster.go @@ -18,16 +18,13 @@ package loxinet import ( "errors" - "fmt" nlp "github.com/loxilb-io/loxilb/api/loxinlp" - "net" - "os" - "time" - cmn "github.com/loxilb-io/loxilb/common" - opts "github.com/loxilb-io/loxilb/options" bfd "github.com/loxilb-io/loxilb/pkg/proto" tk "github.com/loxilb-io/loxilib" + "net" + "os" + "time" ) // error codes for cluster module @@ -83,13 +80,9 @@ func (ci *CIStateH) BFDSessionNotify(instance string, remote string, ciState str } func (ci *CIStateH) startBFDProto(bfdSessConfigArgs bfd.ConfigArgs) { - url := fmt.Sprintf("http://127.0.0.1:%d/config/params", opts.Opts.Port) - for { - if IsLoxiAPIActive(url) { - break - } - tk.LogIt(tk.LogDebug, "KA - waiting for API server\n") - time.Sleep(1 * time.Second) + + if ci.Bs == nil { + return } mh.dp.WaitXsyncReady("ka") @@ -275,6 +268,10 @@ func (h *CIStateH) ClusterNodeDelete(node cmn.ClusterNodeMod) (int, error) { // CIBFDSessionAdd - routine to add BFD session func (h *CIStateH) CIBFDSessionAdd(bm cmn.BFDMod) (int, error) { + if h.Bs == nil { + return -1, errors.New("bfd not initialized") + } + if bm.Interval != 0 && bm.Interval < bfd.BFDMinSysTXIntervalUs { tk.LogIt(tk.LogError, "[CLUSTER] BFD session Interval value too low\n") return -1, errors.New("bfd interval too low") @@ -308,7 +305,7 @@ func (h *CIStateH) CIBFDSessionAdd(bm cmn.BFDMod) (int, error) { Multi: bm.RetryCount, Instance: bm.Instance} go h.startBFDProto(bfdSessConfigArgs) } else { - bfdSessConfigArgs := bfd.ConfigArgs{RemoteIP: h.RemoteIP.String(), SourceIP: h.SourceIP.String(), + bfdSessConfigArgs := bfd.ConfigArgs{RemoteIP: bm.RemoteIP.String(), SourceIP: bm.SourceIP.String(), Port: cmn.BFDPort, Interval: uint32(bm.Interval), Multi: bm.RetryCount, Instance: bm.Instance} err := h.Bs.BFDAddRemote(bfdSessConfigArgs, h) @@ -316,7 +313,7 @@ func (h *CIStateH) CIBFDSessionAdd(bm cmn.BFDMod) (int, error) { tk.LogIt(tk.LogCritical, "KA - Cant add BFD remote: %s\n", err.Error()) return -1, err } - tk.LogIt(tk.LogInfo, "KA - BFD remote %s:%s:%vus Added\n", h.RemoteIP.String(), h.SourceIP.String(), bm.Interval) + tk.LogIt(tk.LogInfo, "KA - BFD remote %s:%s:%vus Added\n", bm.RemoteIP.String(), bm.SourceIP.String(), bm.Interval) } return 0, nil } @@ -335,20 +332,20 @@ func (h *CIStateH) CIBFDSessionDel(bm cmn.BFDMod) (int, error) { return -1, errors.New("cluster instance not found") } - bfdSessConfigArgs := bfd.ConfigArgs{RemoteIP: h.RemoteIP.String()} + bfdSessConfigArgs := bfd.ConfigArgs{RemoteIP: bm.RemoteIP.String()} err := h.Bs.BFDDeleteRemote(bfdSessConfigArgs) if err != nil { tk.LogIt(tk.LogCritical, "KA - Cant delete BFD remote\n") return -1, err } h.SpawnKa = false - tk.LogIt(tk.LogInfo, "KA - BFD remote %s:%s:%vus deleted\n", h.RemoteIP.String(), h.SourceIP.String(), bm.Interval) + tk.LogIt(tk.LogInfo, "KA - BFD remote %s:%s deleted\n", bm.Instance, bm.RemoteIP.String()) return 0, nil } // CIBFDSessionGet - routine to get BFD session info func (h *CIStateH) CIBFDSessionGet() ([]cmn.BFDMod, error) { - if !h.SpawnKa { + if !h.SpawnKa || h.Bs == nil { tk.LogIt(tk.LogError, "[CLUSTER] BFD sessions not running\n") return nil, errors.New("bfd session not running") }