Commit aa642dab authored by Pramod R Sanaga's avatar Pramod R Sanaga
Browse files

All the changes from the last couple of days' bug fixes:

1) Fix max delay event to include the forward path min delay
2) Fix time conversion problem to ulonglong in packet sensor.
3) Fix averaging sensor to better average in case of heavy packet loss.
4) made the buffer used to fill in junk udp packet data is a static member - takes up less memory - and allows up 65k sized udp segments to be sent.
parent fcd835cf
......@@ -39,6 +39,7 @@ namespace
pcap_t * KernelTcp::pcapDescriptor = NULL;
int KernelTcp::pcapfd = -1;
char KernelTcp::udpPacketBuffer[66000] = "";
KernelTcp::KernelTcp()
: state(DISCONNECTED)
......@@ -345,11 +346,11 @@ int KernelTcp::writeUdpMessage(int size, WriteResult & result)
// Indicate to the server the version of the format in which our data packets are.
unsigned char serverVersion = 2;
memcpy(&udpPacketBuffer[0], &serverVersion, sizeof(unsigned char));
memcpy(&KernelTcp::udpPacketBuffer[0], &serverVersion, sizeof(unsigned char));
// Put the sequence number of the packet.
unsigned short networkOrder_udpCurSeqNum = htons(udpCurSeqNum);
memcpy(&udpPacketBuffer[1],&networkOrder_udpCurSeqNum, global::USHORT_INT_SIZE);
unsigned short int networkOrder_udpCurSeqNum = htons(udpCurSeqNum);
memcpy(&KernelTcp::udpPacketBuffer[1],&networkOrder_udpCurSeqNum, global::USHORT_INT_SIZE);
// Copy the size of the packet.. This can be used
// by the sensors in case they miss this packet
......@@ -358,7 +359,7 @@ int KernelTcp::writeUdpMessage(int size, WriteResult & result)
// sender are echoed in the ACKs.
unsigned short networkOrder_size = (size);
memcpy(&udpPacketBuffer[1 + global::USHORT_INT_SIZE],&networkOrder_size, global::USHORT_INT_SIZE);
memcpy(&KernelTcp::udpPacketBuffer[1 + global::USHORT_INT_SIZE],&networkOrder_size, global::USHORT_INT_SIZE);
// Copy the timestamp of when this packet is being sent.
......@@ -368,7 +369,7 @@ int KernelTcp::writeUdpMessage(int size, WriteResult & result)
// this packet because of a libpcap buffer overflow.
unsigned long long curTime = getCurrentTime().toMicroseconds();
curTime = (curTime);
memcpy(&udpPacketBuffer[1 + 2*global::USHORT_INT_SIZE], &curTime, global::ULONG_LONG_SIZE);
memcpy(&KernelTcp::udpPacketBuffer[1 + 2*global::USHORT_INT_SIZE], &curTime, global::ULONG_LONG_SIZE);
bool socketConnectedFlag = true;
......@@ -394,7 +395,7 @@ int KernelTcp::writeUdpMessage(int size, WriteResult & result)
remoteServAddr.sin_port = htons(result.planet.remotePort);
int flags = 0;
int bytesWritten = sendto(peersock, udpPacketBuffer, size, flags,
int bytesWritten = sendto(peersock, KernelTcp::udpPacketBuffer, size, flags,
(struct sockaddr *) &remoteServAddr,
sizeof(remoteServAddr));
......
......@@ -37,7 +37,6 @@ private:
ConnectionState state;
// Udp - CHANGES - Begin
unsigned short udpCurSeqNum;
char udpPacketBuffer[1530];
struct sockaddr_in udpLocalAddr;
// Udp - CHANGES - End
int peersock;
......@@ -51,6 +50,7 @@ private:
public:
static pcap_t * pcapDescriptor;
static int pcapfd;
static char udpPacketBuffer[66000];
static void init(void);
static void addNewPeer(fd_set * readable);
static void readFromPeers(fd_set * readable);
......
......@@ -409,12 +409,13 @@ void SensorList::pushUdpMaxDelaySensor()
{
pushUdpPacketSensor();
pushUdpMinDelaySensor();
pushUdpLossSensor();
// Example dependency check
if (depUdpMaxDelaySensor == NULL)
{
logWrite(SENSOR, "Adding UdpMaxDelaySensor");
UdpMaxDelaySensor * newSensor = new UdpMaxDelaySensor(depUdpPacketSensor, depUdpMinDelaySensor);
UdpMaxDelaySensor * newSensor = new UdpMaxDelaySensor(depUdpPacketSensor, depUdpMinDelaySensor, depUdpLossSensor);
std::auto_ptr<Sensor> current(newSensor);
pushSensor(current);
......
......@@ -31,7 +31,9 @@ long long Time::toMilliseconds(void) const
// Udp - CHANGES - Begin
unsigned long long Time::toMicroseconds(void) const
{
unsigned long long result = data.tv_sec * 1000 * 1000 + data.tv_usec;
unsigned long long result_sec = data.tv_sec;
unsigned long long result_usec = data.tv_usec;
unsigned long long result = result_sec*1000000 + result_usec;
return result;
}
// Udp - CHANGES - End
......
......@@ -47,8 +47,6 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
memcpy(&numRedunAcksChar, &packet->payload[0], global::UCHAR_SIZE);
int numRedunAcks = static_cast<int>(numRedunAcksChar);
double avgThroughput = 0;
// This is the timestamp at the receiver, when the original packet was received.
unsigned long long currentAckTimeStamp = *(unsigned long long *)(packet->payload + 1 + 2*global::USHORT_INT_SIZE );
unsigned long long timeStamp = packet->packetTime.toMicroseconds();
......@@ -103,18 +101,17 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
tmpUdpAck.timeTaken = ackTimeDiff - timeDiff;
tmpUdpAck.isRedun = true;
tmpUdpAck.seqNum = redunSeqNum;
tmpUdpAck.numPackets = 1;
// We lost the record of the size of this packet due to libpcap
// loss, use the length echoed back in the ACK.
if((*vecIterator).isFake == true)
{
avgThroughput += 8000000.0*( static_cast<double> ( redunPacketSize )) / ( static_cast<double>(ackTimeDiff - timeDiff)*1024.0 );
tmpUdpAck.packetSize = redunPacketSize;
}
else
{
avgThroughput += 8000000.0*( static_cast<double> ( (*vecIterator).packetSize )) / ( static_cast<double>(ackTimeDiff - timeDiff)*1024.0 );
tmpUdpAck.packetSize = (*vecIterator).packetSize;
}
......@@ -133,6 +130,7 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
{
calculateTput(timeStamp, packet);
lastAckTime = currentAckTimeStamp;
logWrite(ERROR,"Error - Two UDP ACKs report the same receive time, for seqNum = %d",seqNum);
return;
}
......@@ -149,18 +147,18 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
// loss, use the length echoed back in the ACK.
if(packetHistory->isAckFake() == true)
{
avgThroughput += 8000000.0*( static_cast<double> (echoedPacketSize )) / ( static_cast<double>(ackTimeDiff)*1024.0 );
tmpUdpAck.packetSize = echoedPacketSize;
}
else
{
avgThroughput += 8000000.0*( static_cast<double> ((*vecIterator).packetSize )) / ( static_cast<double>(ackTimeDiff)*1024.0 );
tmpUdpAck.packetSize = (*vecIterator).packetSize;
}
tmpUdpAck.timeTaken = ackTimeDiff - timeDiff;
//tmpUdpAck.timeTaken = ackTimeDiff - timeDiff;
tmpUdpAck.timeTaken = ackTimeDiff;
tmpUdpAck.isRedun = false;
tmpUdpAck.seqNum = seqNum;
tmpUdpAck.numPackets = lossSensor->getPacketLoss() + 1;
ackList[queuePtr] = tmpUdpAck;
queuePtr = (queuePtr + 1)%MAX_SAMPLES;
......@@ -185,23 +183,46 @@ void UdpAvgThroughputSensor::calculateTput(unsigned long long timeStamp, PacketI
int i, index;
unsigned long long timePeriod = 0;
long packetSizeSum = 0;
int packetCount = 0;
int firstPacketIndex = (queuePtr -1 + MAX_SAMPLES)%MAX_SAMPLES;
bool heavyLossFlag = false;
for(i = 0;(i < sampleCount && timePeriod < MAX_TIME_PERIOD); i++)
if(ackList[firstPacketIndex].numPackets >= MAX_SAMPLES)
{
logWrite(SENSOR,"Setting heavy loss flag");
heavyLossFlag = true;
}
//for(i = 0;(i < sampleCount && timePeriod < MAX_TIME_PERIOD); i++)
for(i = 0;i < sampleCount; i = i + packetCount)
{
index = (queuePtr -1 - i + MAX_SAMPLES)%MAX_SAMPLES;
if(i + ackList[index].numPackets >= MAX_SAMPLES)
{
if(heavyLossFlag == false)
{
logWrite(SENSOR,"Breaking out of Tput loop");
break;
}
else
heavyLossFlag = false;
}
timePeriod += ackList[index].timeTaken;
packetSizeSum += ackList[index].packetSize;
packetCount = ackList[index].numPackets;
}
// Avoid dividing by zero.
if(timePeriod == 0)
{
logWrite(ERROR, "Timeperiod is zero in UdpAvgThroughput calculation");
logWrite(ERROR, "Timeperiod is zero in UdpAvgThroughput calculation, i = %d, index = %d, seqNum = %d", i, index, ackList[index].seqNum);
return;
}
if(timePeriod > 5000000)
if(timePeriod > 50000000)
{
logWrite(ERROR, " Incorrect UdpAvgThroughput timePeriod = %llu, bytes = %d, i = %d, numSamples = %d, sampleCount = %d queuePtr = %d", timePeriod, packetSizeSum, i,numSamples,sampleCount, queuePtr);
int k;
......
......@@ -21,6 +21,7 @@ struct UdpAck {
long packetSize;
unsigned short seqNum;
bool isRedun;
int numPackets;
};
......@@ -46,7 +47,7 @@ class UdpAvgThroughputSensor:public Sensor{
double throughputKbps;
int lastSeenThroughput;
UdpAck ackList[100];
UdpAck ackList[MAX_SAMPLES];
int numSamples;
int queuePtr;
};
......
......@@ -9,10 +9,11 @@
using namespace std;
UdpMaxDelaySensor::UdpMaxDelaySensor(UdpPacketSensor const *udpPacketSensorVal, UdpMinDelaySensor const *minDelaySensorVal)
UdpMaxDelaySensor::UdpMaxDelaySensor(UdpPacketSensor const *udpPacketSensorVal, UdpMinDelaySensor const *minDelaySensorVal, UdpLossSensor const *lossSensorVal)
: maxDelay(0),
packetHistory(udpPacketSensorVal),
minDelaySensor(minDelaySensorVal)
minDelaySensor(minDelaySensorVal),
lossSensor(lossSensorVal)
{
}
......@@ -77,8 +78,11 @@ void UdpMaxDelaySensor::localAck(PacketInfo *packet)
oneWayQueueDelay = oneWayQueueDelay - minDelaySensor->getMinDelay();
if(oneWayQueueDelay > 9000000)
if(oneWayQueueDelay > 90000000)
{
logWrite(ERROR,"Incorrect oneWayQueueDelay value = %llu, minDelay = %llu, seqNum=%d, SENDTS=%llu,RECVTS=%llu", oneWayQueueDelay, minDelaySensor->getMinDelay(),seqNum, (*vecIterator).timeStamp, timeStamp);
return;
}
// Set this as the new maximum one way queuing delay.
if(oneWayQueueDelay > maxDelay)
......@@ -92,8 +96,9 @@ void UdpMaxDelaySensor::localAck(PacketInfo *packet)
{
// Report the maximum delay
ostringstream messageBuffer;
messageBuffer<<"MAXINQ="<<(maxDelay)/1000;
global::output->eventMessage(messageBuffer.str(), packet->elab);
messageBuffer<<"MAXINQ="<<(maxDelay+minDelaySensor->getMinDelay())/1000;
if(lossSensor->getPacketLoss() > 0)
global::output->eventMessage(messageBuffer.str(), packet->elab);
logWrite(SENSOR,"VALUE::New Max Delay = %llu",maxDelay);
}
......
......@@ -10,17 +10,19 @@
#include "lib.h"
#include "UdpPacketSensor.h"
#include "UdpMinDelaySensor.h"
#include "UdpLossSensor.h"
#include "Sensor.h"
class Sensor;
class UdpPacketSensor;
class UdpMinDelaySensor;
class UdpLossSensor;
struct UdpPacketInfo;
class UdpMaxDelaySensor:public Sensor{
public:
explicit UdpMaxDelaySensor(UdpPacketSensor const *udpPacketSensorVal, UdpMinDelaySensor const *minDelaySensorVal);
explicit UdpMaxDelaySensor(UdpPacketSensor const *udpPacketSensorVal, UdpMinDelaySensor const *minDelaySensorVal, UdpLossSensor const *lossSensorVal);
~UdpMaxDelaySensor();
......@@ -31,6 +33,7 @@ class UdpMaxDelaySensor:public Sensor{
unsigned long long maxDelay;
UdpPacketSensor const *packetHistory;
UdpMinDelaySensor const *minDelaySensor;
UdpLossSensor const *lossSensor;
};
#endif
......@@ -5,6 +5,7 @@
*/
#include "UdpPacketSensor.h"
#include "CommandOutput.h"
using namespace std;
......
Supports Markdown
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