Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/drop.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#include "common.h"
#define NAME "drop"

static Ihandle *inboundCheckbox, *outboundCheckbox, *chanceInput;
static Ihandle *inboundCheckbox, *outboundCheckbox, *chanceInput, *burstLossInput;

static volatile short dropEnabled = 0,
dropInbound = 1, dropOutbound = 1,
chance = 1000; // [0-10000]
chance = 1000, // [0-10000]
consecutiveDropCount = 0,
bulkLossChance = 0;


static Ihandle* dropSetupUI() {
Expand All @@ -18,13 +20,19 @@ static Ihandle* dropSetupUI() {
outboundCheckbox = IupToggle("Outbound", NULL),
IupLabel("Chance(%):"),
chanceInput = IupText(NULL),
IupLabel("Burst(%):"),
burstLossInput = IupText(NULL),
NULL
);

IupSetAttribute(chanceInput, "VISIBLECOLUMNS", "4");
IupSetAttribute(chanceInput, "VALUE", "10.0");
IupSetCallback(chanceInput, "VALUECHANGED_CB", uiSyncChance);
IupSetAttribute(chanceInput, SYNCED_VALUE, (char*)&chance);
IupSetAttribute(burstLossInput, "VISIBLECOLUMNS", "6");
IupSetAttribute(burstLossInput, "VALUE", "0.0");
IupSetCallback(burstLossInput, "VALUECHANGED_CB", uiSyncChance);
IupSetAttribute(burstLossInput, SYNCED_VALUE, (char*)&bulkLossChance);
IupSetCallback(inboundCheckbox, "ACTION", (Icallback)uiSyncToggle);
IupSetAttribute(inboundCheckbox, SYNCED_VALUE, (char*)&dropInbound);
IupSetCallback(outboundCheckbox, "ACTION", (Icallback)uiSyncToggle);
Expand Down Expand Up @@ -58,15 +66,20 @@ static short dropProcess(PacketNode *head, PacketNode* tail) {
while (head->next != tail) {
PacketNode *pac = head->next;
// chance in range of [0, 10000]
if (checkDirection(pac->addr.Direction, dropInbound, dropOutbound)
&& calcChance(chance)) {
LOG("dropped with chance %.1f%%, direction %s",
chance/100.0, BOUND_TEXT(pac->addr.Direction));
freeNode(popNode(pac));
++dropped;
} else {
head = head->next;
if (checkDirection(pac->addr.Direction, dropInbound, dropOutbound)) {
if ((consecutiveDropCount > 0 && calcChance(bulkLossChance)) || calcChance(chance)) {
LOG("dropped with chance %.1f%%, direction %s",
chance / 100.0, BOUND_TEXT(pac->addr.Direction));
freeNode(popNode(pac));
++dropped;
++consecutiveDropCount;
continue;
}
else {
consecutiveDropCount = 0;
}
}
head = head->next;
}

return dropped > 0;
Expand Down