Skip to content

Commit

Permalink
gh-61 Continuing to add comments where necessary and helpful
Browse files Browse the repository at this point in the history
  • Loading branch information
PacketCrunch committed Sep 3, 2022
1 parent 7d93467 commit 34232a5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 58 deletions.
8 changes: 4 additions & 4 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ const (
type PolInfo struct {
PolType int
ColorAware bool
CommittedInfoRate uint64
PeakInfoRate uint64
CommittedBlkSize uint64
ExcessBlkSize uint64
CommittedInfoRate uint64 // CIR in Mbps
PeakInfoRate uint64 // PIR in Mbps
CommittedBlkSize uint64 // CBS in bytes
ExcessBlkSize uint64 // EBS in bytes
}

type PolObjType uint
Expand Down
53 changes: 3 additions & 50 deletions loxinet/dpebpf_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,16 @@ import (
"fmt"
)

// This file implements the interface DpHookInterface
// The implementation is specific to loxilb ebpf datapath for windows (in-progress)

const (
EBPF_ERR_BASE = iota - DP_ERR_BASE - 1000
)

type DpEbpfH struct {
}

func (e *DpEbpfH) DpPortPropAdd(w *portDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpPortPropDel(w *portDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpL2AddrAdd(w *l2AddrDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpL2AddrDel(w *l2AddrDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpRouterMacAdd(w *routerMacDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpRouterMacDel(w *routerMacDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpNextHopAdd(w *nextHopDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpNextHopDel(w *nextHopDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpRouteAdd(w *RouteDpWorkQ) int {
fmt.Println(*w)
return 0
}

func (e *DpEbpfH) DpRouteDel(w *RouteDpWorkQ) int {
fmt.Println(*w)
return 0
}

func DpEbpfInit() *DpEbpfH {
ne := new(DpEbpfH)
return ne
Expand Down
21 changes: 18 additions & 3 deletions loxinet/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ const (
RT_MAX_LB = (2 * 1024)
)

// Tunable parameters related to inactive rules
type RuleCfg struct {
RuleInactTries int
RuleInactChkTime int
Expand All @@ -200,6 +201,7 @@ type RuleH struct {
Tables [RT_MAX]ruleTable
}

// Initialize the Rules subsystem
func RulesInit(zone *Zone) *RuleH {
var nRh = new(RuleH)
nRh.Zone = zone
Expand Down Expand Up @@ -479,6 +481,7 @@ func (a *ruleAct) String() string {
return ks
}

// Output all rules into json and write to the byte array
func (R *RuleH) Rules2Json() ([]byte, error) {
var t cmn.LbServiceArg
var eps []cmn.LbEndPointArg
Expand Down Expand Up @@ -526,6 +529,7 @@ func (R *RuleH) Rules2Json() ([]byte, error) {
return bret, nil
}

// Get all rules and pack them into a cmn.LbRuleMod slice
func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) {
var res []cmn.LbRuleMod

Expand Down Expand Up @@ -564,20 +568,26 @@ func (R *RuleH) GetNatLbRule() ([]cmn.LbRuleMod, error) {
return res, nil
}

// Add a service LB nat rule. The service details are passed in serv argument,
// and end-point information is passed in the slice servEntdPoints. On success,
// it will return 0 and nil error, else appropriate return code and error string will be set
func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servEndPoints []cmn.LbEndPointArg) (int, error) {
var natActs ruleNatActs
var ipProto uint8

// Vaildate service args
service := serv.ServIP + "/32"
_, sNetAddr, err := net.ParseCIDR(service)
if err != nil {
return RULE_UNK_SERV_ERR, errors.New("malformed-service error")
}

// Currently support a maximum of MAX_NAT_EPS
if len(servEndPoints) <= 0 || len(servEndPoints) > MAX_NAT_EPS {
return RULE_EP_COUNT_ERR, errors.New("endpoints-range error")
}

// For ICMP service, non-zero port can't be specified
if serv.Proto == "icmp" && serv.ServPort != 0 {
return RULE_UNK_SERV_ERR, errors.New("malformed-service error")
}
Expand Down Expand Up @@ -666,6 +676,7 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servEndPoints []cmn.LbEndPoi
return RULE_EXISTS_ERR, errors.New("lbrule-exists error")
}

// Update the rule
eRule.act.action.(*ruleNatActs).sel = natActs.sel
eRule.act.action.(*ruleNatActs).endPoints = eEps
eRule.sT = time.Now()
Expand Down Expand Up @@ -700,6 +711,9 @@ func (R *RuleH) AddNatLbRule(serv cmn.LbServiceArg, servEndPoints []cmn.LbEndPoi
return 0, nil
}

// Delete a service LB nat rule. The service details are passed in serv argument.
// On success, it will return 0 and nil error, else appropriate return code and
// error string will be set
func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) {
var ipProto uint8

Expand Down Expand Up @@ -742,7 +756,7 @@ func (R *RuleH) DeleteNatLbRule(serv cmn.LbServiceArg) (int, error) {
return 0, nil
}

// This is periodic routine which does two main things :
// This is periodic ticker routine which does two main things :
// 1. Syncs rule statistics counts
// 2. Check health of lb-rule end-points
func (R *RuleH) RulesSync() {
Expand Down Expand Up @@ -816,6 +830,7 @@ func (R *RuleH) RulesTicker() {
R.RulesSync()
}

// Destructor routine for all rules
func (R *RuleH) RuleDestructAll() {
var lbs cmn.LbServiceArg
for _, r := range R.Tables[RT_LB].eMap {
Expand All @@ -839,7 +854,7 @@ func (R *RuleH) RuleDestructAll() {
return
}

// Sync state of nat-rule entities to data-path
// Sync state of nat-rule entity to data-path
func (r *ruleEnt) Nat2DP(work DpWorkT) int {

nWork := new(NatDpWorkQ)
Expand Down Expand Up @@ -890,7 +905,7 @@ func (r *ruleEnt) Nat2DP(work DpWorkT) int {
return 0
}

// Sync state of rule entities to data-path
// Sync state of rule entity to data-path
func (r *ruleEnt) DP(work DpWorkT) int {

if work == DP_TABLE_GET {
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

const (
MKFS_SCRIPT = "/usr/local/sbin/mkllb_bpffs"
RUNNING_FLAG_FILE = "/var/run/loxilb"
BPF_FS_CHK_FILE = "/opt/loxilb/dp/bpf/intf_map"
)

Expand All @@ -53,6 +52,7 @@ var buildInfo string = ""
func main() {
fmt.Printf("loxilb start\n")

// Parse command-line arguments
_, err := flags.Parse(&opts.Opts)
if err != nil {
fmt.Println(err)
Expand All @@ -64,6 +64,8 @@ func main() {
os.Exit(0)
}

// It is important to make sure loxilb's eBPF filesystem
// is in place and mounted to make sure maps are pinned properly
if fileExists(BPF_FS_CHK_FILE) == false {
if fileExists(MKFS_SCRIPT) {
_, err := exec.Command("/bin/bash", MKFS_SCRIPT).Output()
Expand Down

0 comments on commit 34232a5

Please sign in to comment.