+#ifdef DELAY40MS
+ /* Only for artificial delay testing. */
+ sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:1000 handle 1000 pfifo");
+ execute_cmd(cmd);
+
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1000 handle 1000 netem loss 0 delay 40ms");
+ execute_cmd(cmd);
+ sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:11f9 handle 11f9 pfifo");
+ execute_cmd(cmd);
+
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:11f9 handle 11f9 netem loss 0 delay 40ms");
+ execute_cmd(cmd);
+ sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:11fa handle 11fa pfifo");
+ execute_cmd(cmd);
+
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:11fa handle 11fa netem loss 0 delay 40ms");
+ execute_cmd(cmd);
+ /* End delay testing */
+#endif
+
+ return 0;
+}
+
+static int setup_tc_grd(drl_instance_t *instance) {
+ int i;
+ char cmd[300];
+
+ for (i = 0; i < instance->leaf_count; ++i) {
+ /* Delete the old pfifo qdisc that might have been there before. */
+ sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:1%x handle 1%x pfifo",
+ instance->leaves[i].xid, instance->leaves[i].xid);
+
+ if (execute_cmd(cmd)) {
+ //FIXME: remove this print and do a log.
+ printf("GRD: pfifo qdisc wasn't there!\n");
+ }
+
+ /* Add the netem qdisc. */
+#ifdef DELAY40MS
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1%x handle 1%x netem loss 0 delay 40ms",
+ instance->leaves[i].xid, instance->leaves[i].xid);
+#else
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1%x handle 1%x netem loss 0 delay 0ms",
+ instance->leaves[i].xid, instance->leaves[i].xid);
+#endif
+
+ if (execute_cmd(cmd)) {
+ return 1;
+ }
+ }
+
+ /* Do the same for 1000 and 1fff. */
+ sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:1000 handle 1000 pfifo");
+
+ if (execute_cmd(cmd)) {
+ //FIXME: remove this print and do a log.
+ printf("GRD: pfifo qdisc wasn't there!\n");
+ }
+
+ /* Add the netem qdisc. */
+#ifdef DELAY40MS
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1000 handle 1000 netem loss 0 delay 40ms");
+#else
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1000 handle 1000 netem loss 0 delay 0ms");
+#endif
+
+ if (execute_cmd(cmd)) {
+ return 1;
+ }
+
+ sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:1fff handle 1fff pfifo");
+
+ if (execute_cmd(cmd)) {
+ //FIXME: remove this print and do a log.
+ printf("GRD: pfifo qdisc wasn't there!\n");
+ }
+
+ /* Add the netem qdisc. */
+#ifdef DELAY40MS
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1fff handle 1fff netem loss 0 delay 40ms");
+#else
+ sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1fff handle 1fff netem loss 0 delay 0ms");
+#endif
+
+ if (execute_cmd(cmd)) {
+ return 1;
+ }
+