-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add json
output format for tools netem show
#2454
Conversation
@FloSch62 would you find some juice to add a robot test for this? Or I can do it later, both is fine |
Sure |
@hellt Done |
agreeing to all point of @vista-
|
IMO it should be an empty string instead of "N/A" |
Agree with @kaelemc, let the formatter handle nil values (and represent those in the proper data format). In this case, maybe representing the values as |
Agree, if someone wants to change it, feel free to do so. I would need to find some time |
if qdisc.Netem.Latency64 != nil && *qdisc.Netem.Latency64 != 0 { | ||
delay = (time.Duration(*qdisc.Netem.Latency64) * time.Nanosecond).String() | ||
} | ||
if qdisc.Netem.Jitter64 != nil && *qdisc.Netem.Jitter64 != 0 { | ||
jitter = (time.Duration(*qdisc.Netem.Jitter64) * time.Nanosecond).String() | ||
} | ||
if qdisc.Netem.Rate != nil && int(qdisc.Netem.Rate.Rate) != 0 { | ||
rate = int(qdisc.Netem.Rate.Rate * 8 / 1000) | ||
} | ||
if qdisc.Netem.Corrupt != nil && qdisc.Netem.Corrupt.Probability != 0 { | ||
// round to 2 decimal places | ||
corruption = math.Round((float64(qdisc.Netem.Corrupt.Probability)/ | ||
float64(math.MaxUint32)*100)*100) / 100 | ||
} | ||
if qdisc.Netem.Qopt.Loss != 0 { | ||
// round to 2 decimal places | ||
loss = math.Round((float64(qdisc.Netem.Qopt.Loss)/float64(math.MaxUint32)*100)*100) / 100 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the output types to be float/int/string for the respecting netem values, with empty values represented by go types.
here is the output they produce.
{
"interface": "mgmt0",
"delay": "1s",
"jitter": "5ms",
"packet_loss": 0.1,
"rate": 0,
"corruption": 0.2
},
Everyone OK with the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, looks good.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2454 +/- ##
==========================================
+ Coverage 52.48% 52.60% +0.11%
==========================================
Files 172 172
Lines 17614 17677 +63
==========================================
+ Hits 9245 9299 +54
- Misses 7398 7404 +6
- Partials 971 974 +3
|
@@ -83,6 +88,11 @@ var netemShowCmd = &cobra.Command{ | |||
} | |||
|
|||
func netemSetFn(_ *cobra.Command, _ []string) error { | |||
// Ensure that the sch_netem kernel module is loaded (for Fedora/RHEL compatibility) | |||
if err := exec.Command("modprobe", "sch_netem").Run(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR brings
-format json
tocontainerlab tools netem show --node clab-vlan-srl1 --format json
And we do a modprobe sch_netem first before setting an impairment to ensure rhel/fedora can directly use it.
closes #1848