[PATCH 1/3] route/qdisc: added more attributes to netem dump

Steffen Vogel post at steffenvogel.de
Thu Jul 23 23:42:26 PDT 2015


I added all the netem attributes (except for limit) to the NL_DUMP_DETAILS section.

---
 lib/route/qdisc/netem.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 61 insertions(+), 2 deletions(-)

diff --git a/lib/route/qdisc/netem.c b/lib/route/qdisc/netem.c
index 06d9fe8..36095fa 100644
--- a/lib/route/qdisc/netem.c
+++ b/lib/route/qdisc/netem.c
@@ -141,8 +141,66 @@ static void netem_dump_line(struct rtnl_tc *tc, void *data,
 {
 	struct rtnl_netem *netem = data;
 
-	if (netem)
-		nl_dump(p, "limit %d", netem->qnm_limit);
+	if (netem) {
+		if (netem->qnm_mask & SCH_NETEM_ATTR_LIMIT && netem->qnm_limit > 0)
+			nl_dump(p, " limit %dpkts", netem->qnm_limit);
+		else
+			nl_dump(p, " no limit");
+	}
+}
+
+static void netem_dump_details(struct rtnl_tc *tc, void *data,
+			    struct nl_dump_params *p)
+{
+	struct rtnl_netem *netem = data;
+	char buf[32];
+
+	if (netem) {		
+		if (netem->qnm_mask & SCH_NETEM_ATTR_LATENCY && netem->qnm_latency > 0) {
+			nl_msec2str(nl_ticks2us(netem->qnm_latency) / 1000, buf, sizeof(buf));
+			nl_dump(p, " latency %s", buf);
+			
+			if (netem->qnm_mask & SCH_NETEM_ATTR_JITTER && netem->qnm_jitter > 0) {
+				nl_msec2str(nl_ticks2us(netem->qnm_jitter) / 1000, buf, sizeof(buf));
+				nl_dump(p, " jitter %s", buf);
+
+				if (netem->qnm_mask & SCH_NETEM_ATTR_DELAY_CORR && netem->qnm_corr.nmc_delay > 0)
+					nl_dump(p, " %d%", netem->qnm_corr.nmc_delay);
+			}
+		}
+
+		if (netem->qnm_mask & SCH_NETEM_ATTR_LOSS && netem->qnm_loss > 0) {
+			nl_dump(p, " loss %d%", netem->qnm_loss);
+		
+			if (netem->qnm_mask & SCH_NETEM_ATTR_LOSS_CORR && netem->qnm_corr.nmc_loss > 0)
+				nl_dump(p, " %d%", netem->qnm_corr.nmc_loss);
+		}
+
+		if (netem->qnm_mask & SCH_NETEM_ATTR_DUPLICATE && netem->qnm_duplicate > 0) {
+			nl_dump(p, " duplicate %d%", netem->qnm_duplicate);
+		
+			if (netem->qnm_mask & SCH_NETEM_ATTR_DUP_CORR && netem->qnm_corr.nmc_duplicate > 0)
+				nl_dump(p, " %d%", netem->qnm_corr.nmc_duplicate);
+		}
+
+		if (netem->qnm_mask & SCH_NETEM_ATTR_RO_PROB && netem->qnm_ro.nmro_probability > 0) {
+			nl_dump(p, " reorder %d%", netem->qnm_ro.nmro_probability);
+			
+			if (netem->qnm_mask & SCH_NETEM_ATTR_RO_CORR && netem->qnm_ro.nmro_correlation > 0)
+				nl_dump(p, " %d%", netem->qnm_ro.nmro_correlation);
+		
+			if (netem->qnm_mask & SCH_NETEM_ATTR_GAP && netem->qnm_gap > 0)
+				nl_dump(p, " gap %d", netem->qnm_gap);
+		}
+
+		if (netem->qnm_mask & SCH_NETEM_ATTR_CORRUPT_PROB && netem->qnm_crpt.nmcr_probability > 0) {
+			nl_dump(p, " reorder %d%", netem->qnm_crpt.nmcr_probability);
+			
+			if (netem->qnm_mask & SCH_NETEM_ATTR_CORRUPT_CORR && netem->qnm_crpt.nmcr_correlation > 0)
+				nl_dump(p, " %d%", netem->qnm_crpt.nmcr_correlation);
+
+		}
+	}
 }
 
 static int netem_msg_fill_raw(struct rtnl_tc *tc, void *data,
@@ -892,6 +950,7 @@ static struct rtnl_tc_ops netem_ops = {
 	.to_msg_parser		= netem_msg_parser,
 	.to_free_data		= netem_free_data,
 	.to_dump[NL_DUMP_LINE]	= netem_dump_line,
+	.to_dump[NL_DUMP_DETAILS] = netem_dump_details,
 	.to_msg_fill_raw	= netem_msg_fill_raw,
 };
 
-- 
2.3.0




More information about the libnl mailing list