Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 14 additions & 74 deletions addons/intel/e810.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

type E810Opts struct {
EnableDefaultConfig bool `json:"enableDefaultConfig"`
UblxCmds []E810UblxCmds `json:"ublxCmds"`
UblxCmds UblxCmdList `json:"ublxCmds"`
DevicePins map[string]map[string]string `json:"pins"`
DpllSettings map[string]uint64 `json:"settings"`
PhaseOffsetPins map[string]map[string]string `json:"phaseOffsetPins"`
Expand Down Expand Up @@ -57,63 +57,14 @@ done
echo "Disabled all SMA and U.FL Connections"
`

var unitTest bool
var clockChain = &ClockChain{}
var (
unitTest bool
clockChain = &ClockChain{}
)

// For mocking DPLL pin info
var DpllPins = []*dpll_netlink.PinInfo{}

func getDefaultUblxCmds() []E810UblxCmds {
// Ublx command to output NAV-CLOCK every second
cfgMsgNavClock := E810UblxCmds{
ReportOutput: false,
Args: []string{"-p", "CFG-MSG,1,34,1"},
}
// Ublx command to output NAV-STATUS every second
cfgMsgNavStatus := E810UblxCmds{
ReportOutput: false,
Args: []string{"-p", "CFG-MSG,1,3,1"},
}

// Ublx command to disable SA messages
cfgMsgDisableSA := E810UblxCmds{
ReportOutput: false,
Args: []string{"-p", "CFG-MSG,0xf0,0x02,0"},
}
// Ublx command to disable SV messages
cfgMsgDisableSV := E810UblxCmds{
ReportOutput: false,
Args: []string{"-p", "CFG-MSG,0xf0,0x03,0"},
}
// Ublx command to disable VTG messages
cfgMsgDisableVTG := E810UblxCmds{
ReportOutput: false,
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_VTG_I2C,0"},
}
// Ublx command to disable GST messages
cfgMsgDisableGST := E810UblxCmds{
ReportOutput: false,
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_GST_I2C,0"},
}
// Ublx command to disable ZDA messages
cfgMsgDisableZDA := E810UblxCmds{
ReportOutput: false,
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_ZDA_I2C,0"},
}
// Ublx command to disable GBS messages
cfgMsgDisableGBS := E810UblxCmds{
ReportOutput: false,
Args: []string{"-z", "CFG-MSGOUT-NMEA_ID_GBS_I2C,0"},
}
// Ublx command to save configuration to storage
cfgSave := E810UblxCmds{
ReportOutput: false,
Args: []string{"-p", "SAVE"},
}
return []E810UblxCmds{cfgMsgNavClock, cfgMsgNavStatus, cfgMsgDisableSA, cfgMsgDisableSV,
cfgMsgDisableVTG, cfgMsgDisableGST, cfgMsgDisableZDA, cfgMsgDisableGBS, cfgSave}
}

func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) error {
glog.Info("calling onPTPConfigChange for e810 plugin")
var e810Opts E810Opts
Expand Down Expand Up @@ -159,7 +110,7 @@ func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
for _, phc := range phcs {
pinPath = fmt.Sprintf("/sys/class/net/%s/device/ptp/%s/pins/%s", device, phc.Name(), pin)
glog.Infof("echo %s > %s", value, pinPath)
err = os.WriteFile(pinPath, []byte(value), 0666)
err = os.WriteFile(pinPath, []byte(value), 0o666)
if err != nil {
glog.Error("e810 failed to write " + value + " to " + pinPath + ": " + err.Error())
}
Expand Down Expand Up @@ -211,11 +162,11 @@ func OnPTPConfigChangeE810(data *interface{}, nodeProfile *ptpv1.PtpProfile) err
}

func AfterRunPTPCommandE810(data *interface{}, nodeProfile *ptpv1.PtpProfile, command string) error {
pluginData := (*data).(*E810PluginData)
glog.Info("calling AfterRunPTPCommandE810 for e810 plugin")
var e810Opts E810Opts
var err error
var optsByteArray []byte
var stdout []byte

e810Opts.EnableDefaultConfig = false

Expand All @@ -229,22 +180,10 @@ func AfterRunPTPCommandE810(data *interface{}, nodeProfile *ptpv1.PtpProfile, co
switch command {
case "gpspipe":
glog.Infof("AfterRunPTPCommandE810 doing ublx config for command: %s", command)
for _, ublxOpt := range append(e810Opts.UblxCmds, getDefaultUblxCmds()...) {
ublxArgs := ublxOpt.Args
glog.Infof("Running /usr/bin/ubxtool with args %s", strings.Join(ublxArgs, ", "))
stdout, _ = exec.Command("/usr/local/bin/ubxtool", ublxArgs...).CombinedOutput()
//stdout, err = exec.Command("/usr/local/bin/ubxtool", "-p", "STATUS").CombinedOutput()
if data != nil && ublxOpt.ReportOutput {
_data := *data
glog.Infof("Saving status to hwconfig: %s", string(stdout))
var pluginData = _data.(*E810PluginData)
_pluginData := *pluginData
statusString := fmt.Sprintf("ublx data: %s", string(stdout))
*_pluginData.hwplugins = append(*_pluginData.hwplugins, statusString)
} else {
glog.Infof("Not saving status to hwconfig: %s", string(stdout))
}
}
// Execute user-supplied UblxCmds first:
*pluginData.hwplugins = append(*pluginData.hwplugins, e810Opts.UblxCmds.runAll()...)
// Finish with the default commands:
*pluginData.hwplugins = append(*pluginData.hwplugins, defaultUblxCmds().runAll()...)
case "tbc-ho-exit":
_, err = clockChain.EnterNormalTBC()
if err != nil {
Expand Down Expand Up @@ -277,7 +216,7 @@ func PopulateHwConfigE810(data *interface{}, hwconfigs *[]ptpv1.HwConfig) error
//*hwconfigs = append(*hwconfigs, hwConfig)
if data != nil {
_data := *data
var pluginData = _data.(*E810PluginData)
pluginData := _data.(*E810PluginData)
_pluginData := *pluginData
if _pluginData.hwplugins != nil {
for _, _hwconfig := range *_pluginData.hwplugins {
Expand All @@ -299,7 +238,8 @@ func E810(name string) (*plugin.Plugin, *interface{}) {
glog.Infof("registering e810 plugin")
hwplugins := []string{}
pluginData := E810PluginData{hwplugins: &hwplugins}
_plugin := plugin.Plugin{Name: "e810",
_plugin := plugin.Plugin{
Name: "e810",
OnPTPConfigChange: OnPTPConfigChangeE810,
AfterRunPTPCommand: AfterRunPTPCommandE810,
PopulateHwConfig: PopulateHwConfigE810,
Expand Down
90 changes: 90 additions & 0 deletions addons/intel/e810_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package intel

import (
"slices"
"testing"

ptpv1 "github.com/k8snetworkplumbingwg/ptp-operator/api/v1"
"github.com/stretchr/testify/assert"
)

func Test_E810(t *testing.T) {
p, d := E810("e810")
assert.NotNil(t, p)
assert.NotNil(t, d)

p, d = E810("not_e810")
assert.Nil(t, p)
assert.Nil(t, d)
}

func Test_AfterRunPTPCommandE810(t *testing.T) {
unitTest = true
profile, err := loadProfile("./testdata/profile-tgm.yaml")
assert.NoError(t, err)
p, d := E810("e810")
data := (*d).(*E810PluginData)

err = p.AfterRunPTPCommand(d, profile, "bad command")
assert.NoError(t, err)

mockExec, execRestore := setupExecMock()
defer execRestore()
mockExec.setDefaults("output", nil)
err = p.AfterRunPTPCommand(d, profile, "gpspipe")
assert.NoError(t, err)
// Ensure all 9 required calls are the last 9:
requiredUblxCmds := []string{
"CFG-MSG,1,34,1",
"CFG-MSG,1,3,1",
"CFG-MSG,0xf0,0x02,0",
"CFG-MSG,0xf0,0x03,0",
"CFG-MSGOUT-NMEA_ID_VTG_I2C,0",
"CFG-MSGOUT-NMEA_ID_GST_I2C,0",
"CFG-MSGOUT-NMEA_ID_ZDA_I2C,0",
"CFG-MSGOUT-NMEA_ID_GBS_I2C,0",
"SAVE",
}
found := make([]string, 0, len(requiredUblxCmds))
for _, call := range mockExec.actualCalls {
for _, arg := range call.args {
if slices.Contains(requiredUblxCmds, arg) {
found = append(found, arg)
}
}
}
assert.Equal(t, requiredUblxCmds, found)
// And expect 3 of them to have produced output (as specified in the profile)
assert.Equal(t, 3, len(*data.hwplugins))
}

func Test_PopulateHwConfdigE810(t *testing.T) {
p, d := E810("e810")
data := (*d).(*E810PluginData)
err := p.PopulateHwConfig(d, nil)
assert.NoError(t, err)

output := []ptpv1.HwConfig{}
err = p.PopulateHwConfig(d, &output)
assert.NoError(t, err)
assert.Equal(t, 0, len(output))

data.hwplugins = &[]string{"A", "B", "C"}
err = p.PopulateHwConfig(d, &output)
assert.NoError(t, err)
assert.Equal(t, []ptpv1.HwConfig{
{
DeviceID: "e810",
Status: "A",
},
{
DeviceID: "e810",
Status: "B",
},
{
DeviceID: "e810",
Status: "C",
},
},
output)
}
33 changes: 11 additions & 22 deletions addons/intel/e825.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var pluginNameE825 = "e825"
// E825Opts is the options structure for e825 plugin
type E825Opts struct {
EnableDefaultConfig bool `json:"enableDefaultConfig"`
UblxCmds []E810UblxCmds `json:"ublxCmds"`
UblxCmds UblxCmdList `json:"ublxCmds"`
DevicePins map[string]map[string]string `json:"pins"`
DpllSettings map[string]uint64 `json:"settings"`
PhaseOffsetPins map[string]map[string]string `json:"phaseOffsetPins"`
Expand Down Expand Up @@ -96,7 +96,7 @@ func OnPTPConfigChangeE825(_ *interface{}, nodeProfile *ptpv1.PtpProfile) error
for _, phc := range phcs {
pinPath := fmt.Sprintf("/sys/class/net/%s/device/ptp/%s/pins/%s", device, phc.Name(), pin)
glog.Infof("echo %s > %s", value, pinPath)
err = os.WriteFile(pinPath, []byte(value), 0666)
err = os.WriteFile(pinPath, []byte(value), 0o666)
if err != nil {
glog.Error("e825 failed to write " + value + " to " + pinPath + ": " + err.Error())
}
Expand Down Expand Up @@ -155,11 +155,11 @@ func OnPTPConfigChangeE825(_ *interface{}, nodeProfile *ptpv1.PtpProfile) error

// AfterRunPTPCommandE825 performs actions after certain PTP commands for e825 plugin
func AfterRunPTPCommandE825(data *interface{}, nodeProfile *ptpv1.PtpProfile, command string) error {
pluginData := (*data).(*E825PluginData)
glog.Info("calling AfterRunPTPCommandE825 for e825 plugin")
var e825Opts E825Opts
var err error
var optsByteArray []byte
var stdout []byte

e825Opts.EnableDefaultConfig = false

Expand All @@ -172,23 +172,11 @@ func AfterRunPTPCommandE825(data *interface{}, nodeProfile *ptpv1.PtpProfile, co
}
switch command {
case "gpspipe":
glog.Infof("AfterRunPTPCommandE825 doing ublx config for command: %s", command)
for _, ublxOpt := range append(e825Opts.UblxCmds, getDefaultUblxCmds()...) {
ublxArgs := ublxOpt.Args
glog.Infof("Running /usr/bin/ubxtool with args %s", strings.Join(ublxArgs, ", "))
stdout, _ = exec.Command("/usr/local/bin/ubxtool", ublxArgs...).CombinedOutput()
//stdout, err = exec.Command("/usr/local/bin/ubxtool", "-p", "STATUS").CombinedOutput()
if data != nil && ublxOpt.ReportOutput {
_data := *data
glog.Infof("Saving status to hwconfig: %s", string(stdout))
var pluginData = _data.(*E825PluginData)
_pluginData := *pluginData
statusString := fmt.Sprintf("ublx data: %s", string(stdout))
*_pluginData.hwplugins = append(*_pluginData.hwplugins, statusString)
} else {
glog.Infof("Not saving status to hwconfig: %s", string(stdout))
}
}
glog.Infof("AfterRunPTPCommandE810 doing ublx config for command: %s", command)
// Execute user-supplied UblxCmds first:
*pluginData.hwplugins = append(*pluginData.hwplugins, e825Opts.UblxCmds.runAll()...)
// Finish with the default commands:
*pluginData.hwplugins = append(*pluginData.hwplugins, defaultUblxCmds().runAll()...)
case "tbc-ho-exit":
_, err = clockChain.EnterNormalTBC()
if err != nil {
Expand Down Expand Up @@ -222,7 +210,7 @@ func PopulateHwConfigE825(data *interface{}, hwconfigs *[]ptpv1.HwConfig) error
//*hwconfigs = append(*hwconfigs, hwConfig)
if data != nil {
_data := *data
var pluginData = _data.(*E825PluginData)
pluginData := _data.(*E825PluginData)
_pluginData := *pluginData
if _pluginData.hwplugins != nil {
for _, _hwconfig := range *_pluginData.hwplugins {
Expand All @@ -245,7 +233,8 @@ func E825(name string) (*plugin.Plugin, *interface{}) {
glog.Infof("registering e825 plugin")
hwplugins := []string{}
pluginData := E825PluginData{hwplugins: &hwplugins}
_plugin := plugin.Plugin{Name: "e825",
_plugin := plugin.Plugin{
Name: "e825",
OnPTPConfigChange: OnPTPConfigChangeE825,
AfterRunPTPCommand: AfterRunPTPCommandE825,
PopulateHwConfig: PopulateHwConfigE825,
Expand Down
Loading
Loading