Skip to content

Commit

Permalink
Merge pull request #29 from celestiaorg/mojtaba/fix-include-specific-…
Browse files Browse the repository at this point in the history
…tc-error-msg

fix: Include Specific 'tc' Error message
  • Loading branch information
mojtaba-esk authored Nov 30, 2023
2 parents a64cd89 + 2ba0793 commit cf5b5ab
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions xdp/latency/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,25 @@ func (l *Latency) deleteTc() error {
if !l.isThereTcNetEmRule() {
return nil
}
return exec.Command(l.TcBinPath, "qdisc", "del", "dev", l.NetworkInterface.Name, "root").Run()
out, err := exec.Command(l.TcBinPath, "qdisc", "del", "dev", l.NetworkInterface.Name, "root").CombinedOutput()
if err != nil {
return fmt.Errorf("failed to delete tc rule: %w, output: `%s`", err, string(out))
}
return nil
}

func (l *Latency) addTc() error {
latencyStr := fmt.Sprintf("%dms", l.Latency.Milliseconds())
jitterStr := fmt.Sprintf("%dms", l.Jitter.Milliseconds())
return exec.Command(l.TcBinPath, "qdisc", "add", "dev", l.NetworkInterface.Name, "root", "netem", "delay", latencyStr, jitterStr).Run()
out, err := exec.Command(l.TcBinPath, "qdisc", "add", "dev", l.NetworkInterface.Name, "root", "netem", "delay", latencyStr, jitterStr).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to add tc rule: %w, output: `%s`", err, string(out))
}
return nil
}

func (l *Latency) isThereTcNetEmRule() bool {
out, err := exec.Command(l.TcBinPath, "qdisc", "show", "dev", l.NetworkInterface.Name).Output()
out, err := exec.Command(l.TcBinPath, "qdisc", "show", "dev", l.NetworkInterface.Name).CombinedOutput()
if err != nil {
return false
}
Expand Down

0 comments on commit cf5b5ab

Please sign in to comment.