Commit eaa24dfc authored by David Johnson's avatar David Johnson

Daemonise, log, do plr (of course still broken on Linux, probably the

kernel patch's problem), adjust param units on Linux.
parent 4d3a10cc
......@@ -111,7 +111,7 @@ void DummynetPipe::updateParameter(struct dn_pipe* pipe, Parameter const & newPa
pipe->delay = newParameter.getValue();
break;
case Parameter::LOSS:
// TODO: Loss
pipe->fs.plr = newParameter.getValue();
break;
case Parameter::NOTHING:
break;
......
......@@ -5,7 +5,7 @@ all: delay-agent
SRCS := $(wildcard *.cc)
LIBS = -lcrypto -lpubsub
CXXFLAGS = -DELVIN_COMPAT -Wall -I../../lib/ -I../../../../
CXXFLAGS = -DELVIN_COMPAT -Wall -I../../lib/ -I../../../../ -I../../../lib/libtb/
LDFLAGS = -L../../../../pubsub
OS = $(shell uname -s)
......@@ -16,7 +16,7 @@ endif
ifeq ($(OS), Linux)
CXXFLAGS += -DLINUX -I../../../../libnl/include
LDFLAGS += -L../../../../libnl/lib -lnl
#LDFLAGS += -L../../../../libnl/lib -lnl
endif
OBJS := $(SRCS:%.cc=%.o)
......@@ -26,9 +26,12 @@ CFLAGS = $(CXXFLAGS)
%.o: %.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
delay-agent: $(OBJS) libevent.a
delay-agent: $(OBJS) libevent.a ../../../../libnl/lib/libnl.a ../../../../obj/lib/libtb/log.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
../../../../obj/lib/libtb/log.o:
@echo "build testbed tree first to get log.o!"
clean:
rm -f *.a delay-agent $(OBJS)
......
......@@ -142,8 +142,8 @@ void NetlinkPipe::updateParameter(Parameter const & newParameter)
cerr << "Couldn't find htb class " << htbClassHandle << endl;
return;
}
rtnl_htb_set_rate(htbClass, newParameter.getValue());
rtnl_htb_set_ceil(htbClass, newParameter.getValue());
rtnl_htb_set_rate(htbClass, newParameter.getValue() * 1000);
rtnl_htb_set_ceil(htbClass, newParameter.getValue() * 1000);
rtnl_class_change(nl_handle, htbClass, NULL);
rtnl_class_put(htbClass);
break;
......@@ -153,7 +153,7 @@ void NetlinkPipe::updateParameter(Parameter const & newParameter)
cerr << "Couldn't find delay qdisc " << delayHandle << endl;
return;
}
rtnl_delay_set_delay(qdisc, newParameter.getValue());
rtnl_delay_set_delay(qdisc, newParameter.getValue() * 1000);
rtnl_qdisc_change(nl_handle, qdisc, NULL);
rtnl_qdisc_put(qdisc);
break;
......
......@@ -12,6 +12,7 @@ public:
{
NOTHING,
BANDWIDTH,
// This is the delay in milliseconds
DELAY,
// This is the loss rate in thousandths. 1000 is 100% loss. 1 is 0.1% loss. Etc.
LOSS,
......
......@@ -7,6 +7,8 @@
#include <netlink/route/link.h>
#endif
#include <stdlib.h>
using namespace std;
namespace g
......@@ -28,6 +30,11 @@ int stringToInt(std::string const & val)
return result;
}
double stringToDouble(std::string const & val)
{
return strtod(val.c_str(),NULL);
}
int hexStringToInt(std::string const & val)
{
int result = 0;
......
......@@ -14,6 +14,7 @@
#include <fstream>
#include "event.h"
#include "log.h"
#define TBDB_OBJECTTYPE_LINK "LINK"
#define TBDB_EVENTTYPE_UP "UP"
......@@ -25,6 +26,7 @@
enum { EVENT_BUFFER_SIZE = 50 };
int stringToInt(std::string const & val);
double stringToDouble(std::string const & val);
int hexStringToInt(std::string const & val);
std::string intToString(int val);
......
......@@ -104,6 +104,7 @@ Parameter parseArg(string const & arg)
}
std::string key = arg.substr(0, equalsPos);
std::string valueString = arg.substr(equalsPos + 1);
if (key == "BANDWIDTH" || key == "bandwidth")
{
int value = stringToInt(valueString);
......@@ -116,8 +117,8 @@ Parameter parseArg(string const & arg)
}
else if (key == "PLR" || key == "plr")
{
// TODO: Implement PLR
cerr << "EVENT: PLR is not yet implmented" << endl;
double value = stringToDouble(valueString);
result = Parameter(Parameter::DELAY, (int)(value*0x7fffffff));
}
else
{
......
......@@ -10,7 +10,6 @@ using namespace std;
void setupDefaultParameters(void);
void readArgs(int argc, char * argv[]);
void usage(char * name);
void initLogging(string const & logFile);
// Reads the map file, initializes the pipe and pipeVault data
// structure, and sets up the two subscription strings for events.
void readMapFile(string const & mapFile, string & linkSubscribe, string & resetSubscribe);
......@@ -51,7 +50,8 @@ void readArgs(int argc, char * argv[])
string mapFile;
string logFile;
string pidFile;
string pidFile("/var/run/delayagent.pid");
int pid;
// Prevent getopt from printing an error message.
opterr = 0;
......@@ -102,9 +102,18 @@ void readArgs(int argc, char * argv[])
if(server == "" || mapFile == "" || g::experimentName == "")
usage(argv[0]);
initLogging(logFile);
readMapFile(mapFile, linkSubscribe, resetSubscribe);
if (g::debug) {
loginit(0, 0);
}
else {
/* Become a daemon */
daemon(0, 0);
loginit(0, (char *)logFile.c_str());
}
writePidFile(pidFile);
readMapFile(mapFile, linkSubscribe, resetSubscribe);
initEvents(server, port, keyFile, linkSubscribe, resetSubscribe);
}
......@@ -115,10 +124,6 @@ void usage(char * name)
exit(-1);
}
void initLogging(string const & /*logFile*/)
{
}
void readMapFile(string const & mapFile, string & linkSubscribe, string & resetSubscribe)
{
cerr << "Reading map file" << endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment