Skip to content

Commit

Permalink
added a new method to check whether a given interface has a Westport …
Browse files Browse the repository at this point in the history
…Channel NIC (#17)

Signed-off-by: Nishant Parekh <[email protected]>
  • Loading branch information
nishant-parekh authored Aug 14, 2024
1 parent b0c0dda commit c6d3010
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.6

require (
github.com/redhat-best-practices-for-k8s/graphsolver-exports v0.0.2
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.4
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.5
github.com/sirupsen/logrus v1.9.3
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redhat-best-practices-for-k8s/graphsolver-exports v0.0.2 h1:SJnXD40jEFBCWT8ZjmJOFJdIzMwWPbrIUCAQu1oXfYQ=
github.com/redhat-best-practices-for-k8s/graphsolver-exports v0.0.2/go.mod h1:Vl268nAHQKEnIw7GIYehp3Lx4qYP8+rOlwGsWxD/aO4=
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.4 h1:66qE0Vj/8vWvt8yaVq1yJK5+OOELGZdlCwzHkXRxFr4=
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.4/go.mod h1:NO9mpaj5neVKarRGcsL5SHVFb+uYUoCC8uVbuT419xs=
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.5 h1:0X6pIv4tMsSquGS4m+xgmzFGIm16Snj2ErmnpoYqLog=
github.com/redhat-best-practices-for-k8s/l2discovery-exports v0.0.5/go.mod h1:NO9mpaj5neVKarRGcsL5SHVFb+uYUoCC8uVbuT419xs=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
19 changes: 17 additions & 2 deletions lib.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package lib

import (
"strings"

export "github.com/redhat-best-practices-for-k8s/graphsolver-exports"
l2lib "github.com/redhat-best-practices-for-k8s/l2discovery-exports"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -91,6 +93,7 @@ type AlgoFunction1 int
const (
// same node
StepIsPTP AlgoFunction1 = iota
StepIsWPCNic
)

// list of Algorithm function with 2 params
Expand All @@ -105,6 +108,8 @@ const (
StepDifferentNic
)

const WPCNICSubsystemID = "E810-XXV-4T"

// list of Algorithm function with 3 params
type AlgoFunction3 int

Expand Down Expand Up @@ -281,6 +286,16 @@ func SameNicWrapper(config export.L2Info, if1, if2 int) bool {
return SameNic(config.GetPtpIfList()[if1], config.GetPtpIfList()[if2])
}

// Determines if the NIC is intel WPC NIC
func isWpcNic(ifaceName1 *l2lib.PtpIf) bool {
return strings.Contains(ifaceName1.IfPci.Subsystem, WPCNICSubsystemID)
}

// wrapper for isWpcNic
func isWPCNicWrapper(config export.L2Info, if1 int) bool {
return isWpcNic(config.GetPtpIfList()[if1])
}

// wrapper for nil algo function
func NilWrapper() bool {
return true
Expand All @@ -304,8 +319,9 @@ func applyStep(config export.L2Info, step [][]int, combinations []int) bool {
var AlgoCode0 [1]ConfigFunc0
AlgoCode0[StepNil] = NilWrapper

var AlgoCode1 [1]ConfigFunc1
var AlgoCode1 [2]ConfigFunc1
AlgoCode1[StepIsPTP] = IsPTPWrapper
AlgoCode1[StepIsWPCNic] = isWPCNicWrapper

var AlgoCode2 [5]ConfigFunc2
AlgoCode2[StepSameLan2] = SameLan2Wrapper
Expand All @@ -316,7 +332,6 @@ func applyStep(config export.L2Info, step [][]int, combinations []int) bool {

var AlgoCode3 [1]ConfigFunc3
AlgoCode3[StepSameLan3] = SameLan3Wrapper

result := true
for _, test := range step {
switch test[1] {
Expand Down

0 comments on commit c6d3010

Please sign in to comment.