Skip to content

Commit

Permalink
added statistics method in TestbedARAClient (see also #126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Frey committed Sep 27, 2014
1 parent 470487f commit 389c241
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
2 changes: 2 additions & 0 deletions include/testbed/TestbedARAClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class TestbedARAClient : public AbstractARAClient {

std::string toString();

std::string getStatistics();

/**
* Sends the packet to the packets destination.
*
Expand Down
3 changes: 3 additions & 0 deletions include/testbed/TestbedNetworkInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TestbedNetworkInterface : public ReliableNetworkInterface {
bool equals(NetworkInterface* otherInterface);

std::string getStatistics();
std::string getInterfaceName();

protected:
void doSend(const Packet* packet, std::shared_ptr<Address> recipient);
Expand All @@ -45,6 +46,8 @@ class TestbedNetworkInterface : public ReliableNetworkInterface {
std::map<std::string, unsigned long> receiveStatistics;
/// we store the number of sent packets per packet type in a map
std::map<std::string, unsigned long> sentStatistics;

std::string interfaceName;
};

TESTBED_NAMESPACE_END
Expand Down
58 changes: 38 additions & 20 deletions testbed/TestbedARAClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ TestbedARAClient::TestbedARAClient(Configuration& configuration) : AbstractARACl
// set the clock to the standard clock (if it is not pre-set to the dummy clock, the tests fail)
Environment::setClock(new StandardClock());
//TODO Make configurable
//Logger* logger = new SimpleLoggerExtended("ara");
Logger* logger = new SimpleLogger("ara");
setLogger(logger);
logDebug("Initialized testbedARAClient");
// DEBUG: logDebug("Initialized testbedARAClient");
initializeNetworkInterfaces();
logDebug("Initialized testbedARAClient network Interfaces");
// DEBUG: logDebug("Initialized testbedARAClient network Interfaces");
}

TestbedARAClient::~TestbedARAClient() { }
Expand All @@ -40,9 +39,24 @@ std::string TestbedARAClient::toString() {
return result.str();
}

std::string TestbedARAClient::getStatistics() {
std::ostringstream result;

// print network interface statistics
for (auto& interface: interfaces) {
TestbedNetworkInterface* testbedInterface = dynamic_cast<TestbedNetworkInterface*>(interface);

if (testbedInterface) {
result << "Network Interface Statistics [" << testbedInterface->getInterfaceName() << "]" << std::endl;
result << testbedInterface->getStatistics();
}
}

return result.str();
}

void TestbedARAClient::sendPacket(Packet* packet) {
// DEBUG:
std::cerr << "[TestbedARAClient::sendPacket] pass packet to client" << std::endl;
// DEBUG: std::cerr << "[TestbedARAClient::sendPacket] pass packet to client" << std::endl;
AbstractARAClient::sendPacket(packet);
}

Expand All @@ -53,16 +67,19 @@ void TestbedARAClient::receivePacket(Packet* packet, ARA::NetworkInterface* inte
}

void TestbedARAClient::deliverToSystem(const Packet* packet) {
logDebug("sending packet # %u to System via TAP", packet->getSequenceNumber());

int payloadLength = packet->getPayloadLength();
const void *payload = packet->getPayload();
logDebug("attempting to send packet # %u to System via TAP", packet->getSequenceNumber());

/// deliver the packet to the system
if (dessert_syssend(payload, payloadLength) == DESSERT_OK){
std::cerr << "[TestbedARAClient::deliverToSystem] sending packet to system was successful" << std::endl;
} else {
std::cerr << "[TestbedARAClient::deliverToSystem] sending packet to system failed" << std::endl;
struct ether_header* payload;
const TestbedPacket* testbedPacket = dynamic_cast<const TestbedPacket*>(packet);
int payloadLength = dessert_msg_ethdecap(testbedPacket->toDessertMessage(), &payload);

if (payloadLength != -1) {
/// send the payload to the system
if (dessert_syssend(payload, payloadLength) != DESSERT_OK){
logFatal("sending packet to system failed");
}
/// since the data was allocated using malloc indessert_msg_ethdecap()
free(payload);
}
}

Expand Down Expand Up @@ -105,14 +122,14 @@ std::string TestbedARAClient::routingTableToString() {
void TestbedARAClient::handleExpiredRouteDiscoveryTimer(std::weak_ptr<Timer> routeDiscoveryTimer){
std::lock_guard<std::recursive_mutex> routeDiscoveryTimerLock(routeDiscoveryTimerMutex);
AbstractARAClient::handleExpiredRouteDiscoveryTimer(routeDiscoveryTimer);

// should come up with our own handling
}

void TestbedARAClient::handleExpiredDeliveryTimer(std::weak_ptr<Timer> deliveryTimer){
std::shared_ptr<Timer> timer = deliveryTimer.lock();

if (timer) {
// DEBUG:
std::cerr << "[TestbedARAClient::handleExpiredDeliveryTimer] "<< std::endl;
TestbedTimerAddressInfo* timerInfo = (TestbedTimerAddressInfo*) timer->getContextObject();
AddressPtr destination = timerInfo->getDestination();

Expand All @@ -126,7 +143,10 @@ void TestbedARAClient::handleExpiredDeliveryTimer(std::weak_ptr<Timer> deliveryT
discovery = runningRouteDiscoveries.find(destination);

if (discovery != runningRouteDiscoveries.end()) {
// its important to delete the discovery info first or else the client will always think the route discovery is still running and never send any packets
/**
* We delete the route discovery info first or else the client will
* always think the route discovery is still running and never send any packets
*/
runningRouteDiscoveries.erase(discovery);

std::lock_guard<std::mutex> lock(deliveryTimerMutex);
Expand All @@ -151,15 +171,13 @@ void TestbedARAClient::handleExpiredPANTTimer(std::weak_ptr<Timer> pantTimer){
}

void TestbedARAClient::startRouteDiscoveryTimer(const Packet* packet){
std::cerr << "[TBA] start route discovery timer" << std::endl;
std::cerr << "[TestbedARAClient::startRouteDiscoveryTimer] start route discovery timer" << std::endl;

TestbedRouteDiscoveryInfo* discoveryInfo = new TestbedRouteDiscoveryInfo(packet);
TimerPtr timer = getNewTimer(TimerType::ROUTE_DISCOVERY_TIMER, discoveryInfo);
timer->addTimeoutListener(this);
timer->run(routeDiscoveryTimeoutInMilliSeconds * 1001);

std::cerr << "[TBA] type is " << discoveryInfo->toString() << std::endl;

AddressPtr destination = packet->getDestination();

std::lock_guard<std::recursive_mutex> lock(routeDiscoveryTimerMutex);
Expand Down
5 changes: 5 additions & 0 deletions testbed/TestbedNetworkInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ TESTBED_NAMESPACE_BEGIN
TestbedNetworkInterface::TestbedNetworkInterface(dessert_meshif_t* dessertPointer, AbstractNetworkClient* client, PacketFactory* packetFactory, int ackTimeoutInMicroSeconds)
: ReliableNetworkInterface(client, ackTimeoutInMicroSeconds, std::make_shared<TestbedAddress>(dessertPointer->hwaddr), std::make_shared<TestbedAddress>(DESSERT_BROADCAST_ADDRESS)) {
numberOfReceivedPackets = numberOfSentPackets = 0;
interfaceName = std::string(dessertPointer->if_name);
// DEBUG: std::cerr << "[TestbedNetworkInterface] address: " << *localAddress << " broadcast address: " << *broadcastAddress << std::endl;
}

Expand All @@ -24,6 +25,10 @@ bool TestbedNetworkInterface::equals(NetworkInterface* otherInterface) {
return false;
}

std::string TestbedNetworkInterface::getInterfaceName(){
return interfaceName;
}

std::string TestbedNetworkInterface::getStatistics(){
std::ostringstream result;

Expand Down

0 comments on commit 389c241

Please sign in to comment.