commit 12c045aa7f8c3017548d5795035aaa89c40a6a08
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Fri May 22 14:13:24 2015 +0200
Add Slave methods for NetEm value parsing from interface config
This patch provides Slave methods for parsing values from NetEm
tag in config dict.
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Acked-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Slave/NetConfigCommon.py | 77 +++++++++++++++++++++++++++++++++++++++++
1 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Slave/NetConfigCommon.py b/lnst/Slave/NetConfigCommon.py
index c60419b..ffcb0b4 100644
--- a/lnst/Slave/NetConfigCommon.py
+++ b/lnst/Slave/NetConfigCommon.py
@@ -35,3 +35,80 @@ def get_slave_option(netdev, slave_id, opt_name):
if option == opt_name:
return value
return None
+
+def get_netem_option(netem_tag, netem_name, opt_name):
+ try:
+ options = netem_tag[netem_name]
+ except KeyError:
+ return None
+ for opt in options:
+ if opt["name"] == opt_name:
+ return opt["value"]
+
+def parse_delay(config):
+ time = get_netem_option(config, "delay", "time")
+ jitter= get_netem_option(config, "delay", "jitter")
+ correlation = get_netem_option(config, "delay", "correlation")
+ distribution = get_netem_option(config, "delay", "distribution")
+ rv = "delay %s " % time
+ if jitter is not None:
+ rv = rv + "%s " % jitter
+ if correlation is not None:
+ rv = rv + "%s " % correlation
+ if distribution is not None:
+ rv = rv + "distribution %s " % distribution
+ return rv
+
+def parse_loss(config):
+ percent = get_netem_option(config, "loss", "percent")
+ correlation = get_netem_option(config, "loss", "correlation")
+ rv = "loss %s " % percent
+ if correlation is not None:
+ rv = rv + "%s " % correlation
+ return rv
+
+def parse_corrupt(config):
+ percent = get_netem_option(config, "corrupt", "percent")
+ correlation = get_netem_option(config, "corrupt", "correlation")
+ rv = "corrupt %s " % percent
+ if correlation is not None:
+ rv = rv + "%s " % correlation
+ return rv
+
+def parse_duplication(config):
+ percent = get_netem_option(config, "duplication", "percent")
+ correlation = get_netem_option(config, "duplication",
"correlation")
+ rv = "duplicate %s " % percent
+ if correlation is not None:
+ rv = rv + "%s " % correlation
+ return rv
+
+def parse_reordering(config):
+ percent = get_netem_option(config, "reordering", "percent")
+ correlation = get_netem_option(config, "reordering",
"correlation")
+ gap_distance = get_netem_option(config, "reordering",
"gap_distance")
+ rv = "reorder %s " % percent
+ if correlation is not None:
+ rv = rv + "%s " % correlation
+ if gap_distance is not None:
+ rv = rv + "gap %s " % gap_distance
+ return rv
+
+def parse_netem(config):
+ rv = ""
+ # delay parsing
+ if "delay" in config:
+ rv = rv + parse_delay(config)
+ # loss parsing
+ if "loss" in config:
+ rv = rv + parse_loss(config)
+ # corrupt
+ if "corrupt" in config:
+ rv = rv + parse_corrupt(config)
+ # duplication
+ if "duplication" in config:
+ rv = rv + parse_duplication(config)
+ # reordering
+ if "reordering" in config:
+ rv = rv + parse_reordering(config)
+ return rv
Show replies by date