Skip to content

Commit

Permalink
gh-61 gofmt applied
Browse files Browse the repository at this point in the history
  • Loading branch information
PacketCrunch committed Sep 2, 2022
1 parent 2fef032 commit 4fa4cea
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 223 deletions.
2 changes: 1 addition & 1 deletion api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
cmn "github.com/loxilb-io/loxilb/common"
tk "github.com/loxilb-io/loxilib"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down
2 changes: 1 addition & 1 deletion api/restapi/handler/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package handler

import (
"fmt"
"github.com/go-openapi/runtime/middleware"
"github.com/loxilb-io/loxilb/api/restapi/operations"
cmn "github.com/loxilb-io/loxilb/common"
tk "github.com/loxilb-io/loxilib"
"net"
"github.com/go-openapi/runtime/middleware"
)

func ConfigPostRoute(params operations.PostConfigRouteParams) middleware.Responder {
Expand Down
42 changes: 22 additions & 20 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"net"
)

// This file defines the go interface implementation needed to interact with loxinet go module

const (
AU_WORKQ_LEN = 1024
LU_WORKQ_LEN = 1024
Expand Down Expand Up @@ -233,13 +235,13 @@ type SessionUlClMod struct {
}

const (
ROL_TYPE_TRTCM = 0 // Default
ROL_TYPE_TRTCM = 0 // Default
POL_TYPE_SRTCM = 1
)

type PolInfo struct {
PolType int
ColorAware bool
PolType int
ColorAware bool
CommittedInfoRate uint64
PeakInfoRate uint64
CommittedBlkSize uint64
Expand All @@ -252,31 +254,31 @@ const (
POL_ATTACH_PORT PolObjType = 1 << iota
POL_ATTACH_LB_RULE
)

type PolObj struct {
PolObjName string
AttachMent PolObjType
}
PolObjName string
AttachMent PolObjType
}

type PolMod struct {
Ident string
Info PolInfo
Target PolObj
Target PolObj
}

const (
MIRR_TYPE_SPAN = 0 // Default
MIRR_TYPE_SPAN = 0 // Default
MIRR_TYPE_RSPAN = 1
MIRR_TYPE_ERSPAN = 2
)

type MirrInfo struct {
MirrType int
MirrPort string
MirrVlan int
MirrRip net.IP
MirrSip net.IP
MirrTid uint32
MirrType int
MirrPort string
MirrVlan int
MirrRip net.IP
MirrSip net.IP
MirrTid uint32
}

type MirrObjType uint
Expand All @@ -285,16 +287,16 @@ const (
MIRR_ATTACH_PORT MirrObjType = 1 << iota
MIRR_ATTACH_LB_RULE
)

type MirrObj struct {
MirrObjName string
AttachMent MirrObjType
}
MirrObjName string
AttachMent MirrObjType
}

type MirrMod struct {
Ident string
Info MirrInfo
Target MirrObj
Target MirrObj
}

type NetHookInterface interface {
Expand Down
24 changes: 12 additions & 12 deletions loxinet/dpbroker.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ const (
)

type MirrDpWorkQ struct {
Work DpWorkT
Name string
HwMark int
MiPortNum int
MiBD int
Status *DpStatusT
Work DpWorkT
Name string
HwMark int
MiPortNum int
MiBD int
Status *DpStatusT
}

type PortDpWorkQ struct {
Expand Down Expand Up @@ -145,12 +145,12 @@ type RouteDpWorkQ struct {
}

type StatDpWorkQ struct {
Work DpWorkT
Name string
HwMark uint32
Packets *uint64
Bytes *uint64
DropPackets *uint64
Work DpWorkT
Name string
HwMark uint32
Packets *uint64
Bytes *uint64
DropPackets *uint64
}

type TableDpWorkQ struct {
Expand Down
35 changes: 17 additions & 18 deletions loxinet/dpebpf_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (
"unsafe"
)

// This file implements the interface DpHookInterface
// The implementation is specific to loxilb ebpf datapath for linux
// This file implements the interface DpHookInterface
// The implementation is specific to loxilb ebpf datapath for linux

const (
EBPF_ERR_BASE = iota - 50000
Expand Down Expand Up @@ -138,7 +138,7 @@ func dpEbpfTicker() {
tk.LogIt(-1, "DP Tick at for selector %v:%d\n", t, sel)

// For every tick collect stats for an eBPF map
// This routine caches stats in a local statsDB
// This routine caches stats in a local statsDB
// which can be collected from a separate gothread
C.llb_collect_map_stats(C.int(tbls[sel]))

Expand Down Expand Up @@ -250,7 +250,7 @@ func DpPortPropMod(w *PortDpWorkQ) int {

// This is a special case
if w.LoadEbpf == "llb0" {
w.PortNum = C.LLB_INTERFACES-1
w.PortNum = C.LLB_INTERFACES - 1
}

key := new(intfMapKey)
Expand All @@ -264,7 +264,7 @@ func DpPortPropMod(w *PortDpWorkQ) int {
if w.LoadEbpf != "" && w.LoadEbpf != "lo" && w.LoadEbpf != "llb0" {
lRet := loadEbpfPgm(w.LoadEbpf)
if lRet != 0 {
tk.LogIt(tk.LOG_ERROR, "ebpf load - %d error\n", w.PortNum,)
tk.LogIt(tk.LOG_ERROR, "ebpf load - %d error\n", w.PortNum)
return EBPF_ERR_EBFP_LOAD
}
}
Expand Down Expand Up @@ -310,7 +310,7 @@ func DpPortPropMod(w *PortDpWorkQ) int {
txV = C.uint(0)
C.llb_add_map_elem(C.LL_DP_TX_INTF_MAP, unsafe.Pointer(&txK), unsafe.Pointer(&txV))
C.llb_del_map_elem(C.LL_DP_TX_INTF_MAP, unsafe.Pointer(&txK))

C.llb_del_map_elem(C.LL_DP_INTF_MAP, unsafe.Pointer(key))

if w.LoadEbpf != "" {
Expand Down Expand Up @@ -696,7 +696,7 @@ func (e *DpEbpfH) DpNatLbRuleDel(w *NatDpWorkQ) int {
func (e *DpEbpfH) DpStat(w *StatDpWorkQ) int {
var packets, bytes, dropPackets uint64
var tbl []int
var polTbl[] int
var polTbl []int
sync := 0
switch {
case w.Name == MAP_NAME_NAT4:
Expand Down Expand Up @@ -738,7 +738,6 @@ func (e *DpEbpfH) DpStat(w *StatDpWorkQ) int {
bytes += uint64(b)
}


for _, t := range polTbl {

ret := C.llb_fetch_pol_map_stats(C.int(t), C.uint(w.HwMark), (unsafe.Pointer(&p)), unsafe.Pointer(&b))
Expand Down Expand Up @@ -922,7 +921,7 @@ func (e *DpEbpfH) DpTableGet(w *TableDpWorkQ) (error, DpRetT) {
var b, p uint64
goCt4Ent := convDPCt2GoObj(ctKey, act)
ret := C.llb_fetch_map_stats_cached(C.int(C.LL_DP_ACLV4_STATS_MAP), C.uint(tact.ca.cidx), C.int(1),
(unsafe.Pointer(&b)), unsafe.Pointer(&p))
(unsafe.Pointer(&b)), unsafe.Pointer(&p))
if ret == 0 {
goCt4Ent.bytes += b
goCt4Ent.packets += p
Expand Down Expand Up @@ -997,7 +996,7 @@ func (e *DpEbpfH) DpPolMod(w *PolDpWorkQ) int {
dat.ca.act_type = C.DP_SET_DO_POLICER
// For finding pa, we need to account for padding of 4
pa := (*polAct)(getPtrOffset(unsafe.Pointer(dat),
C.sizeof_struct_dp_cmn_act + C.sizeof_struct_bpf_spin_lock + 4))
C.sizeof_struct_dp_cmn_act+C.sizeof_struct_bpf_spin_lock+4))

if w.Srt == false {
pa.trtcm = 1
Expand All @@ -1011,8 +1010,8 @@ func (e *DpEbpfH) DpPolMod(w *PolDpWorkQ) int {
pa.color_aware = 1
}

pa.toksc_pus = C.ulonglong(w.Cir/(8000000))
pa.tokse_pus = C.ulonglong(w.Pir/(8000000))
pa.toksc_pus = C.ulonglong(w.Cir / (8000000))
pa.tokse_pus = C.ulonglong(w.Pir / (8000000))
pa.cbs = C.uint(w.Cbs)
pa.ebs = C.uint(w.Ebs)
pa.tok_c = pa.cbs
Expand Down Expand Up @@ -1041,15 +1040,15 @@ func (e *DpEbpfH) DpPolMod(w *PolDpWorkQ) int {
C.llb_del_map_elem(C.LL_DP_POL_MAP, unsafe.Pointer(&key))
return 0
}
return 0;
return 0
}

func (e *DpEbpfH) DpPolAdd(w *PolDpWorkQ) int {
return e.DpPolMod(w);
return e.DpPolMod(w)
}

func (e *DpEbpfH) DpPolDel(w *PolDpWorkQ) int {
return e.DpPolMod(w);
return e.DpPolMod(w)
}

func (e *DpEbpfH) DpMirrMod(w *MirrDpWorkQ) int {
Expand Down Expand Up @@ -1087,13 +1086,13 @@ func (e *DpEbpfH) DpMirrMod(w *MirrDpWorkQ) int {
C.llb_del_map_elem(C.LL_DP_MIRROR_MAP, unsafe.Pointer(&key))
return 0
}
return 0;
return 0
}

func (e *DpEbpfH) DpMirrAdd(w *MirrDpWorkQ) int {
return e.DpMirrMod(w);
return e.DpMirrMod(w)
}

func (e *DpEbpfH) DpMirrDel(w *MirrDpWorkQ) int {
return e.DpMirrMod(w);
return e.DpMirrMod(w)
}
2 changes: 1 addition & 1 deletion loxinet/gobgpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"context"
"errors"
"fmt"
"io"
cmn "github.com/loxilb-io/loxilb/common"
tk "github.com/loxilb-io/loxilib"
"io"
"net"
"os"
"os/exec"
Expand Down
2 changes: 1 addition & 1 deletion loxinet/layer2.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func l2FdbAttrCopy(dst *FdbAttr, src *FdbAttr) {
dst.Dst = src.Dst
}

// For TunFDB, try to associate with appropriate neighbor
// For TunFDB, try to associate with appropriate neighbor
func (f *FdbEnt) L2FdbResolveNh() (bool, int, error) {
p := f.Port
attr := f.FdbAttr
Expand Down
2 changes: 1 addition & 1 deletion loxinet/layer3.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (l3 *L3H) IfaAdd(Obj string, Cidr string) (int, error) {
return L3_ADDR_ERR, errors.New("ip address exists")
}

// if network part of an added ifa is equal to previously
// if network part of an added ifa is equal to previously
// existing ifa, then it is considered a secondary ifa
if ifaEnt.IfaNet.IP.Equal(network.IP) {
pfxSz1, _ := ifaEnt.IfaNet.Mask.Size()
Expand Down
11 changes: 6 additions & 5 deletions loxinet/loxinet.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ package loxinet

import (
"fmt"
"os"
"sync"
"time"
apiserver "github.com/loxilb-io/loxilb/api"
tk "github.com/loxilb-io/loxilib"
nlp "github.com/loxilb-io/loxilb/api/loxinlp"
cmn "github.com/loxilb-io/loxilb/common"
opts "github.com/loxilb-io/loxilb/options"
tk "github.com/loxilb-io/loxilib"
"os"
"sync"
"time"
)

const (
Expand Down Expand Up @@ -96,7 +97,7 @@ func loxiNetInit() {
// Initialize the security zone subsystem
mh.zn = ZoneInit()

// Add a root zone by default
// Add a root zone by default
mh.zn.ZoneAdd(ROOT_ZONE)
mh.zr, _ = mh.zn.Zonefind(ROOT_ZONE)
if mh.zr == nil {
Expand Down
2 changes: 2 additions & 0 deletions loxinet/loxinet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"testing"
)

// This file implements loxilb's go unit-test framework

func TestMain(t *testing.T) {
TestLoxinet(t)
}
8 changes: 4 additions & 4 deletions loxinet/loxinettest.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ func TestLoxinet(t *testing.T) {
t.Errorf("Failed to delete session for user1\n")
}

pInfo := cmn.PolInfo { PolType: 0, ColorAware: false, CommittedInfoRate: 100, PeakInfoRate: 100 }
polObj := cmn.PolObj { PolObjName: "hs0", AttachMent: cmn.POL_ATTACH_PORT}
pInfo := cmn.PolInfo{PolType: 0, ColorAware: false, CommittedInfoRate: 100, PeakInfoRate: 100}
polObj := cmn.PolObj{PolObjName: "hs0", AttachMent: cmn.POL_ATTACH_PORT}
_, err = mh.zr.Pols.PolAdd("pol-hs0", pInfo, polObj)
if err != nil {
t.Errorf("Failed to add policer pol-hs0\n")
Expand All @@ -344,8 +344,8 @@ func TestLoxinet(t *testing.T) {
t.Errorf("Failed to delete policer pol-hs0\n")
}

mInfo := cmn.MirrInfo { MirrType: cmn.MIRR_TYPE_SPAN, MirrPort: "hs0" }
mObj := cmn.MirrObj { MirrObjName: "hs1", AttachMent: cmn.MIRR_ATTACH_PORT}
mInfo := cmn.MirrInfo{MirrType: cmn.MIRR_TYPE_SPAN, MirrPort: "hs0"}
mObj := cmn.MirrObj{MirrObjName: "hs1", AttachMent: cmn.MIRR_ATTACH_PORT}
_, err = mh.zr.Mirrs.MirrAdd("mirr-1", mInfo, mObj)
if err != nil {
t.Errorf("Failed to add mirror mirr-1\n")
Expand Down
Loading

0 comments on commit 4fa4cea

Please sign in to comment.