limiter_t limiter;
extern FILE *logfile;
extern uint8_t system_loglevel;
+extern uint8_t do_enforcement;
/* functions */
leaf_t *leaf = NULL;
identity_t *ident = NULL;
- map_reset_iterate(instance->leaf_map);
- while ((leaf = (leaf_t *) map_next(instance->leaf_map))) {
- printf("%x:", leaf->xid);
- ident = leaf->parent;
- while (ident) {
- printf("%d:",ident->id);
- ident = ident->parent;
+ if (system_loglevel == LOG_DEBUG) {
+ map_reset_iterate(instance->leaf_map);
+ while ((leaf = (leaf_t *) map_next(instance->leaf_map))) {
+ printf("%x:", leaf->xid);
+ ident = leaf->parent;
+ while (ident) {
+ printf("%d:",ident->id);
+ ident = ident->parent;
+ }
+ printf("Leaf's parent pointer is %p\n", leaf->parent);
}
- printf("Leaf's parent pointer is %p\n", leaf->parent);
- }
- printf("instance->last_machine is %p\n", instance->last_machine);
+ printf("instance->last_machine is %p\n", instance->last_machine);
+ }
}
static int assign_htb_hierarchy(drl_instance_t *instance) {
} else {
/* Pointerific! */
instance->machines[i]->htb_parent =
- instance->machines[i]->parent->htb_node;
+ instance->machines[i]->parent->htb_node;
}
instance->machines[i]->htb_node = next_node;
/* End delay testing */
#endif
+//#define SFQTEST
+
+#ifdef SFQTEST
+ 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 sfq perturb 20");
+ execute_cmd(cmd);
+#endif
+
return 0;
}
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");
+ printlog(LOG_DEBUG, "GRD: pfifo qdisc wasn't there!\n");
}
/* Add the netem qdisc. */
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");
+ printlog(LOG_DEBUG, "GRD: pfifo qdisc wasn't there!\n");
}
/* Add the netem qdisc. */
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");
+ printlog(LOG_DEBUG, "GRD: pfifo qdisc wasn't there!\n");
}
/* Add the netem qdisc. */
// Seems to take about 85ms / iteration
}
+static int stop_enforcement(drl_instance_t *instance) {
+ char cmd[300];
+ int i;
+
+ for (i = 0; i < instance->machine_count; ++i) {
+ sprintf(cmd, "/sbin/tc class change dev eth0 parent 1:%x classid 1:%x htb rate 8bit ceil 100mbit",
+ instance->machines[i]->htb_parent,
+ instance->machines[i]->htb_node);
+
+ if (execute_cmd(cmd)) {
+ return 1;
+ }
+ }
+
+ for (i = 0; i < instance->set_count; ++i) {
+ sprintf(cmd, "/sbin/tc class change dev eth0 parent 1:%x classid 1:%x htb rate 8bit ceil 100mbit",
+ instance->sets[i]->htb_parent,
+ instance->sets[i]->htb_node);
+
+ if (execute_cmd(cmd)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
static void *signal_thread_func(void *args) {
int sig;
int err;
sigemptyset(&sigs);
sigaddset(&sigs, SIGHUP);
+ sigaddset(&sigs, SIGUSR1);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
while (1) {
sigemptyset(&sigs);
sigaddset(&sigs, SIGHUP);
+ sigaddset(&sigs, SIGUSR1);
err = sigwait(&sigs, &sig);
case SIGHUP:
printlog(LOG_WARN, "Caught SIGHUP - re-reading XML file.\n");
reconfig();
- //time_reconfig(1000); //instrumentation
+ //time_reconfig(1000); /* instrumentation */
flushlog();
break;
+ case SIGUSR1:
+ pthread_rwlock_wrlock(&limiter.limiter_lock);
+ if (do_enforcement) {
+ do_enforcement = 0;
+ stop_enforcement(&limiter.stable_instance);
+ printlog(LOG_CRITICAL, "--Switching enforcement off.--\n");
+ } else {
+ do_enforcement = 1;
+ printlog(LOG_CRITICAL, "--Switching enforcement on.--\n");
+ }
+ pthread_rwlock_unlock(&limiter.limiter_lock);
+ break;
default:
- /* Should be impossible... */
+ /* Intentionally blank. */
break;
}
}
sigemptyset(&signal_mask);
sigaddset(&signal_mask, SIGHUP);
+ sigaddset(&signal_mask, SIGUSR1);
pthread_sigmask(SIG_BLOCK, &signal_mask, NULL);
if (pthread_create(&signal_thread, NULL, &signal_thread_func, NULL) != 0) {
* see estimate.c
*/
if (pthread_create(&estimate_thread, NULL, (void*(*)(void*)) &handle_estimation, &limiter)!=0) {
- ulogd_log(ULOGD_ERROR, "couldn't start estimate thread for 0x%x %s\n",limiter.localaddr,
- limiter.ip);
+ printlog(LOG_CRITICAL, "Couldn't start estimate thread.\n");
fprintf(stderr, "An error has occured starting ulogd_DRL. Refer to your logfile (%s) for additional information.\n", drl_logfile.u.string);
exit(EXIT_FAILURE);
}