From c6d30109fa83f0c3df003621360a8bf6411e226d Mon Sep 17 00:00:00 2001 From: Nishant Parekh Date: Wed, 14 Aug 2024 17:16:41 -0400 Subject: [PATCH] added a new method to check whether a given interface has a Westport Channel NIC (#17) Signed-off-by: Nishant Parekh --- go.mod | 2 +- go.sum | 4 ++-- lib.go | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 51b8e1e..baa8449 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 1088d35..f0a26c9 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/lib.go b/lib.go index ba68d3d..f71a207 100644 --- a/lib.go +++ b/lib.go @@ -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" @@ -91,6 +93,7 @@ type AlgoFunction1 int const ( // same node StepIsPTP AlgoFunction1 = iota + StepIsWPCNic ) // list of Algorithm function with 2 params @@ -105,6 +108,8 @@ const ( StepDifferentNic ) +const WPCNICSubsystemID = "E810-XXV-4T" + // list of Algorithm function with 3 params type AlgoFunction3 int @@ -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 @@ -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 @@ -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] {