Skip to content

Commit

Permalink
compute clockType from ptp4lConfig
Browse files Browse the repository at this point in the history
  GM = No Slave interface
  BC = Multiple interfaces with atleast one slave
  OC = Single slave interface

  review fixes:

    - moved logic and modified to include global interface entry
    - added `serverOnly` and `clientOnly` alternatives
    - renamed `hasSlaveInterfaceDefined` => hasSlaveConfigDefined

Signed-off-by: Nishant Parekh <[email protected]>
  • Loading branch information
nishant-parekh authored and josephdrichard committed Jun 9, 2024
1 parent afdb057 commit 61585e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions pkg/daemon/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/openshift/linuxptp-daemon/pkg/event"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -32,6 +33,7 @@ type ptp4lConf struct {
sections []ptp4lConfSection
mapping []string
profile_name string
clock_type event.ClockType
}

func NewLinuxPTPConfUpdate() (*LinuxPTPConfUpdate, error) {
Expand Down Expand Up @@ -112,6 +114,7 @@ func (output *ptp4lConf) populatePtp4lConf(config *string) error {
var currentSection ptp4lConfSection
output.sections = make([]ptp4lConfSection, 0)
globalIsDefined := false
hasSlaveConfigDefined := false

if config != nil {
for _, line := range strings.Split(*config, "\n") {
Expand All @@ -137,6 +140,12 @@ func (output *ptp4lConf) populatePtp4lConf(config *string) error {
split := strings.IndexByte(line, ' ')
if split > 0 {
currentSection.options[line[:split]] = line[split:]
if (line[:split] == "masterOnly" && line[split:] == "0") ||
(line[:split] == "serverOnly" && line[split:] == "0") ||
(line[:split] == "slaveOnly" && line[split:] == "1") ||
(line[:split] == "clientOnly" && line[split:] == "1") {
hasSlaveConfigDefined = true
}
}
} else {
return errors.New("Config option not in section: " + line)
Expand All @@ -146,9 +155,21 @@ func (output *ptp4lConf) populatePtp4lConf(config *string) error {
output.sections = append(output.sections, currentSection)
}
}

if !globalIsDefined {
output.sections = append(output.sections, ptp4lConfSection{options: map[string]string{}, sectionName: "[global]"})
}

if !hasSlaveConfigDefined {
// No Slave Interfaces defined
output.clock_type = event.GM
} else if len(output.sections) > 2 {
// Multiple interfaces with at least one slave Interface defined
output.clock_type = event.BC
} else {
// Single slave Interface defined
output.clock_type = event.OC
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/daemon/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func (dn *Daemon) applyNodePtpProfile(runID int, nodeProfile *ptpv1.PtpProfile)
return err
}

clockType = output.clock_type
output.profile_name = *nodeProfile.Name

if nodeProfile.Interface != nil && *nodeProfile.Interface != "" {
Expand Down Expand Up @@ -564,7 +565,7 @@ func (p *ptpProcess) cmdRun() {
Values: map[event.ValueType]int64{
event.OFFSET: int64(ts2phcsOffset),
},
ClockType: "GM", //TODO: add actual defined
ClockType: clockType,
Time: time.Now().Unix(),
WriteToLog: true,
Reset: false,
Expand Down

0 comments on commit 61585e9

Please sign in to comment.