Commit ea947e56 authored by Pramod R Sanaga's avatar Pramod R Sanaga

1) Removed a bug in handling reordered packets.

2) Removed a double-long causing warning messages in RttSensor.
3) Added NullSensor as a dependency to UdpPacketSensor.
parent 3587f3ea
......@@ -104,11 +104,14 @@ void NullSensor::localAck(PacketInfo * packet)
logWrite(SENSOR, "----------------------------------------");
logWrite(SENSOR, "Stream ID: %s", packet->elab.toString().c_str());
logWrite(SENSOR, "Ack received: Time: %f", packet->packetTime.toDouble());
list<Option>::iterator pos = packet->tcpOptions->begin();
list<Option>::iterator limit = packet->tcpOptions->end();
for (; pos != limit; ++pos)
if(packet->transport == TCP_CONNECTION)
{
logWrite(SENSOR, "TCP Option: %d", pos->type);
list<Option>::iterator pos = packet->tcpOptions->begin();
list<Option>::iterator limit = packet->tcpOptions->end();
for (; pos != limit; ++pos)
{
logWrite(SENSOR, "TCP Option: %d", pos->type);
}
}
if (packet->packetTime < lastPacketTime) {
logWrite(EXCEPTION,"Reordered packets! Old %f New %f",lastPacketTime.toDouble(),
......
......@@ -341,6 +341,8 @@ void SensorList::pushAverageThroughputSensor(void)
void SensorList::pushUdpPacketSensor()
{
pushNullSensor();
// Example dependency check
if (depUdpPacketSensor == NULL)
{
......
......@@ -304,6 +304,8 @@ void handleUDP_Version_2(struct pcap_pkthdr const *pcap_info, struct udphdr cons
// we saw, then send an acknowledgement for it. Otherwise, ignore the
// packet - it arrived out of order.
// printf("Received seqNum = %d\n", packetSeqNum);
// printf("Packet loss = %d\n", clientIter->second.packetLoss);
// TODO:Take wrap around into account.
{
if(packetSeqNum > (clientIter->second.curSeqNum + 1))
......@@ -323,7 +325,7 @@ void handleUDP_Version_2(struct pcap_pkthdr const *pcap_info, struct udphdr cons
// Echo the sender timestamp received in the original packet.
memcpy(&appAck[1 + 2*globalConsts::USHORT_INT_SIZE + globalConsts::ULONG_LONG_SIZE], &senderTimestamp, globalConsts::ULONG_LONG_SIZE);
outFile<<"TIME="<<packetLibpcapTimestamp<<",SIZE=udpLen + overhead"<<std::endl;
outFile<<"TIME="<<packetLibpcapTimestamp<<",SIZE="<<udpLen + overhead<<std::endl;
// Include the sequence numbers, and ACK times of at least the last
// seen three packets - more than 3 if the packet size allows.
......@@ -386,20 +388,23 @@ void handleUDP_Version_2(struct pcap_pkthdr const *pcap_info, struct udphdr cons
// This indicates where the redundant ACKs start in the packet.
int redunAckStart = 1 + 2*globalConsts::USHORT_INT_SIZE + 2*globalConsts::ULONG_LONG_SIZE;
int index = (clientIter->second.queueEndPtr + 1 - numAcks + ackQueueSize)%ackQueueSize;
// Copy the redundant ACKs.
for(int i = 0;i < numAcks; i++)
{
// Copy the seq. number this redun ACK is acking.
memcpy(&appAck[redunAckStart + i*ackSize], &clientIter->second.ackQueue[(clientIter->second.queueStartPtr + i)%ackQueueSize].seqNo, globalConsts::USHORT_INT_SIZE);
memcpy(&appAck[redunAckStart + i*ackSize], &clientIter->second.ackQueue[index].seqNo, globalConsts::USHORT_INT_SIZE);
// Copy the size of the packet being acked.
memcpy(&appAck[redunAckStart + i*ackSize + globalConsts::USHORT_INT_SIZE], &clientIter->second.ackQueue[(clientIter->second.queueStartPtr + i)%ackQueueSize].packetSize, globalConsts::USHORT_INT_SIZE);
memcpy(&appAck[redunAckStart + i*ackSize + globalConsts::USHORT_INT_SIZE], &clientIter->second.ackQueue[index].packetSize, globalConsts::USHORT_INT_SIZE);
timeDiff = packetLibpcapTimestamp - clientIter->second.ackQueue[(clientIter->second.queueStartPtr + i)%ackQueueSize].ackTime;
timeDiff = packetLibpcapTimestamp - clientIter->second.ackQueue[index].ackTime;
// Copy the time diffrence between when this packet was received
// and when the latest packet being ACKed was received here.
memcpy(&appAck[redunAckStart + i*ackSize + 2*globalConsts::USHORT_INT_SIZE], &timeDiff, globalConsts::ULONG_LONG_SIZE);
index = (index + 1)%ackQueueSize;
}
// Always maintain the sequence numbers and ack send times
......@@ -428,8 +433,6 @@ void handleUDP_Version_2(struct pcap_pkthdr const *pcap_info, struct udphdr cons
// Send the ACK off to the host we received the data packet from.
sendto(sd,appAck,ackLength,flags,(struct sockaddr *)&cliAddr,cliLen), errno;
}
}
int getLinkLayer(struct pcap_pkthdr const *pcap_info, const u_char *pkt_data)
......
......@@ -39,7 +39,6 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
memcpy(&numRedunAcksChar, &packet->payload[0], global::UCHAR_SIZE);
int numRedunAcks = static_cast<int>(numRedunAcksChar);
int numThroughputAcks = 1;
double avgThroughput = 0;
// This is the timestamp at the receiver, when the original packet was received.
......@@ -90,8 +89,6 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
if(ackTimeDiff - timeDiff == 0)
continue;
numThroughputAcks++;
tmpUdpAck.timeTaken = ackTimeDiff - timeDiff;
tmpUdpAck.isRedun = true;
tmpUdpAck.seqNum = redunSeqNum;
......@@ -109,11 +106,6 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
avgThroughput += 8000000.0*( static_cast<double> ( (*vecIterator).packetSize )) / ( static_cast<double>(ackTimeDiff - timeDiff)*1024.0 );
tmpUdpAck.packetSize = (*vecIterator).packetSize;
}
if(tmpUdpAck.packetSize < 0)
{
printf("Packetsize negative for redunAck = %d, isFake = %d\n", redunSeqNum,packetHistory->isAckFake());
}
ackList[queuePtr] = tmpUdpAck;
queuePtr = (queuePtr + 1)%MAX_SAMPLES;
......
......@@ -25,13 +25,12 @@ void UdpMaxDelaySensor::localAck(PacketInfo *packet)
{
// This is a re-ordered ACK or a corrupted packet - don't do anything
// with it - just return.
if( packetHistory->isAckValid() == false )
// If this packet is ACKing a packet that we lost due to libpcap send loss,
// dont use this packet timestamp for RTT calculations.
if( packetHistory->isAckValid() == false || packetHistory->isAckFake() == true)
return;
int overheadLen = 14 + 4 + 8 + packet->ip->ip_hl*4;
unsigned short int seqNum = *(unsigned short int *)(packet->payload + 1);
unsigned short int echoedPacketSize = *(unsigned short int *)(packet->payload + 1 + global::USHORT_INT_SIZE);
unsigned long long echoedTimestamp = *(unsigned long long *)(packet->payload + 1 + 2*global::USHORT_INT_SIZE + global::ULONG_LONG_SIZE);
unsigned long long oneWayQueueDelay;
bool eventFlag = false;
......@@ -39,15 +38,11 @@ void UdpMaxDelaySensor::localAck(PacketInfo *packet)
vector<UdpPacketInfo> ackedPackets = packetHistory->getAckedPackets();
vecIterator = find_if(ackedPackets.begin(), ackedPackets.end(), bind2nd(equalSeqNum(), seqNum));
// Find the one way RTT for this packet.
unsigned long long timeStamp = packet->packetTime.toMicroseconds();
// We lost this packet send time due to loss in libpcap, use the
// time echoed in the ACK packet.
if(packetHistory->isAckFake() == true)
oneWayQueueDelay = (timeStamp - echoedTimestamp)/2;
else
oneWayQueueDelay = (timeStamp - (*vecIterator).timeStamp)/2;
// Find the one way RTT for this packet.
oneWayQueueDelay = (timeStamp - (*vecIterator).timeStamp)/2;
// Scale the value of one way RTT, so that it is correct for a transmission
// size of 1518 bytes.
......@@ -56,15 +51,15 @@ void UdpMaxDelaySensor::localAck(PacketInfo *packet)
// size echoed in the ACK packet - this does not included the header
// overhead for the packet - we assume that the packet on the reverse path
// has the same overhead length as the original packet.
if(packetHistory->isAckFake() == true)
oneWayQueueDelay = ( oneWayQueueDelay )*1518 / (overheadLen + echoedPacketSize);
else
oneWayQueueDelay = ( oneWayQueueDelay )*1518 / ((*vecIterator).packetSize);
oneWayQueueDelay = ( oneWayQueueDelay )*1518 / ((*vecIterator).packetSize);
// Find the queuing delay for this packet, by subtracting the
// one way minimum delay from the above value.
oneWayQueueDelay = oneWayQueueDelay - minDelaySensor->getMinDelay();
if(oneWayQueueDelay > 9000000)
logWrite(ERROR,"Incorrect oneWayQueueDelay value = %llu, minDelay = %llu", oneWayQueueDelay, minDelaySensor->getMinDelay());
// Set this as the new maximum one way queuing delay.
if(oneWayQueueDelay > maxDelay)
{
......
......@@ -30,18 +30,11 @@ void UdpMinDelaySensor::localSend(PacketInfo *packet)
void UdpMinDelaySensor::localAck(PacketInfo *packet)
{
if( ( ntohs(packet->udp->len) - 8 ) < global::udpMinAckPacketSize )
{
logWrite(ERROR, "UDP packet data sent to UdpMinDelaySensor::localAck was less than the "
" required minimum %d bytes",global::udpMinAckPacketSize);
ackValid = false;
sendValid = false;
return;
}
// This is a re-ordered ACK or an incorrect packet - don't do anything
// with it - just return.
if( packetHistory->isAckValid() == false )
// If this packet is ACKing a packet that we lost due to libpcap send loss,
// dont use this packet timestamp for RTT calculations.
if( packetHistory->isAckValid() == false || packetHistory->isAckFake() == true )
{
ackValid = false;
sendValid = false;
......@@ -51,8 +44,6 @@ void UdpMinDelaySensor::localAck(PacketInfo *packet)
sendValid = false;
unsigned short int seqNum = *(unsigned short int *)(packet->payload + 1);
unsigned short int echoedPacketSize = *(unsigned short int *)(packet->payload + 1 + global::USHORT_INT_SIZE);
unsigned long long echoedTimestamp = *(unsigned long long *)(packet->payload + 1 + 2*global::USHORT_INT_SIZE + global::ULONG_LONG_SIZE);
unsigned long long oneWayDelay;
bool eventFlag = false;
......@@ -61,24 +52,13 @@ void UdpMinDelaySensor::localAck(PacketInfo *packet)
vector<UdpPacketInfo > ackedPackets = packetHistory->getAckedPackets();
vecIterator = find_if(ackedPackets.begin(), ackedPackets.end(), bind2nd(equalSeqNum(), seqNum));
// Calculate the one way delay as half of RTT.
unsigned long long timeStamp = packet->packetTime.toMicroseconds();
// We lost this packet send time due to loss in libpcap, use the
// time echoed in the ACK packet.
if(packetHistory->isAckFake() == true)
oneWayDelay = (timeStamp - echoedTimestamp)/2;
else
oneWayDelay = (timeStamp - (*vecIterator).timeStamp)/2;
oneWayDelay = (timeStamp - (*vecIterator).timeStamp)/2;
// Calculate the delay for the maximum sized packet.
// We lost this packet size details due to loss in libpcap, use the
// size echoed in the ACK packet
if(packetHistory->isAckFake() == true)
oneWayDelay = ( oneWayDelay ) * 1518 / (echoedPacketSize);
else
oneWayDelay = ( oneWayDelay ) * 1518 / ( (*vecIterator).packetSize);
oneWayDelay = ( oneWayDelay ) * 1518 / ( (*vecIterator).packetSize);
// Set this as the new minimum one way delay.
if(oneWayDelay < minDelay)
......
......@@ -54,7 +54,6 @@ void UdpPacketSensor::localSend(PacketInfo *packet)
sendValid = true;
ackValid = false;
// CHANGE:
unsigned short int seqNum = ntohs(*(unsigned short int *)(packet->payload + 1));
unsigned short int packetSize = (*(unsigned short int *)(packet->payload + 1 + global::USHORT_INT_SIZE)) + overheadLen;
UdpPacketInfo tmpPacketInfo;
......@@ -74,6 +73,8 @@ void UdpPacketSensor::localSend(PacketInfo *packet)
sentPacketList.push_back(tmpPacketInfo);
}
libpcapSendLoss += (seqNum - lastSeenSeqNum - 1);
logWrite(SENSOR,"STAT: libpcap send loss = %d", libpcapSendLoss);
}
}
......@@ -106,9 +107,10 @@ void UdpPacketSensor::localAck(PacketInfo *packet)
listIterator = find_if(sentPacketList.begin(), sentPacketList.end(), bind2nd(equalSeqNum(), seqNum));
bool isReordered = false;
if(listIterator == sentPacketList.end())
{
bool isReordered = handleReorderedAck(packet);
isReordered = handleReorderedAck(packet);
if(isReordered == false)
{
......@@ -119,10 +121,15 @@ void UdpPacketSensor::localAck(PacketInfo *packet)
return;
}
else
{
ackValid = true;
listIterator = find_if(unAckedPacketList.begin(), unAckedPacketList.end(), bind2nd(equalSeqNum(), seqNum));
}
}
else
{
ackValid = true;
}
// We received an ACK correctly(without reordering), but we dont have any record of ever
// sending the original packet(Actually, we have a fake packet inserted into our send list)
......@@ -151,6 +158,7 @@ void UdpPacketSensor::localAck(PacketInfo *packet)
// Look at the redundant ACKs first.
UdpPacketInfo tmpPacketInfo;
std::vector<int> redunAckVector;
if(numRedunAcks > 0)
{
......@@ -164,11 +172,16 @@ void UdpPacketSensor::localAck(PacketInfo *packet)
// Check whether the packet that this redundant ACK refers to exists
// in our list of sent ( but unacked ) packets. It might not exist
// if its ACK was not lost earlier.
listIterator = find_if(sentPacketList.begin(), curPacketIterator, bind2nd(equalSeqNum(), redunSeqNum));
if(isReordered == false)
listIterator = find_if(sentPacketList.begin(), curPacketIterator, bind2nd(equalSeqNum(), redunSeqNum));
else
listIterator = find_if(sentPacketList.begin(), sentPacketList.end(), bind2nd(equalSeqNum(), redunSeqNum));
redunAckVector.push_back(redunSeqNum);
// An unacked packet exists with this sequence number, delete it
// from the list and consider it acked.
if(listIterator != curPacketIterator && listIterator != sentPacketList.end())
if((isReordered == false && listIterator != curPacketIterator) ||(isReordered == true && listIterator != sentPacketList.end()) )
{
tmpPacketInfo.seqNum = (*listIterator).seqNum;
tmpPacketInfo.packetSize = (*listIterator).packetSize;
......@@ -224,14 +237,21 @@ void UdpPacketSensor::localAck(PacketInfo *packet)
comparePacket.seqNum = seqNum;
comparePacket.timeStamp = (*curPacketIterator).timeStamp;
listIterator = find_if(sentPacketList.begin(), curPacketIterator, bind2nd(lessSeqNum(), &comparePacket));
if(isReordered == false)
{
listIterator = find_if(sentPacketList.begin(), curPacketIterator, bind2nd(lessSeqNum(), &comparePacket));
}
else
{
listIterator = find_if(sentPacketList.begin(), sentPacketList.end(), bind2nd(lessSeqNum(), &comparePacket));
}
if( (listIterator != sentPacketList.end()) && (listIterator != curPacketIterator ))
if( ( isReordered == true && listIterator != sentPacketList.end()) || (isReordered == false && listIterator != curPacketIterator ))
{
logWrite(SENSOR, "STAT::Packet being ACKed = %d",seqNum);
do{
logWrite(SENSOR, "STAT::Lost packet seqnum = %d",(*listIterator).seqNum);
logWrite(SENSOR, "STAT::Lost packet seqnum = %d, curTimestamp = %llu, lost packet Timestamp = %llu",(*listIterator).seqNum, (*curPacketIterator).timeStamp, (*listIterator).timeStamp);
// This packet might have been lost - but store it as UnAcked
// to account for reordering on the forward path.
......@@ -248,14 +268,21 @@ void UdpPacketSensor::localAck(PacketInfo *packet)
packetLoss++;
totalPacketLoss++;
listIterator = find_if(sentPacketList.begin(), curPacketIterator, bind2nd(lessSeqNum(), &comparePacket ));
if(isReordered == false)
listIterator = find_if(sentPacketList.begin(), curPacketIterator, bind2nd(lessSeqNum(), &comparePacket ));
else
listIterator = find_if(sentPacketList.begin(), sentPacketList.end(), bind2nd(lessSeqNum(), &comparePacket ));
}
while( (listIterator != sentPacketList.end()) && (listIterator != curPacketIterator) );
logWrite(SENSOR,"STAT::Total packet loss = %d",totalPacketLoss);
while( (isReordered == true && listIterator != sentPacketList.end()) || (isReordered == false && listIterator != curPacketIterator) );
logWrite(SENSOR,"STAT::UdpPacketSensor:Total packet loss = %d",totalPacketLoss);
}
sentPacketList.erase(curPacketIterator);
if(isReordered == false)
sentPacketList.erase(curPacketIterator);
else
unAckedPacketList.erase(curPacketIterator);
}
bool UdpPacketSensor::handleReorderedAck(PacketInfo *packet)
......
......@@ -57,7 +57,9 @@ void UdpRttSensor::localAck(PacketInfo *packet)
// has the same overhead length as the original packet.
currentRtt = ( currentRtt )*1518 / ((*vecIterator).packetSize);
double alpha = 0.25, beta = 0.125;
// Avoid conversion to double and back to long long.
//double alpha = 0.25, beta = 0.125;
if(ewmaRtt == 0)
{
ewmaRtt = currentRtt;
......@@ -74,12 +76,22 @@ void UdpRttSensor::localAck(PacketInfo *packet)
else
{
if(currentRtt > ewmaRtt)
ewmaDevRtt = ewmaDevRtt*(1 - beta) + beta*(currentRtt - ewmaRtt);
{
// Avoid conversion to double and back to long long.
//ewmaDevRtt = ewmaDevRtt*(1 - beta) + beta*(currentRtt - ewmaRtt);
ewmaDevRtt = ewmaDevRtt*7/8 + (currentRtt - ewmaRtt)/8;
}
else
ewmaDevRtt = ewmaDevRtt*(1 - beta) + beta*(ewmaRtt - currentRtt );
{
// Avoid conversion to double and back to long long.
//ewmaDevRtt = ewmaDevRtt*(1 - beta) + beta*(ewmaRtt - currentRtt );
ewmaDevRtt = ewmaDevRtt*7/8 + (ewmaRtt - currentRtt )/8;
}
}
ewmaRtt = ewmaRtt*(1 - alpha) + currentRtt*alpha;
// Avoid conversion to double and back to long long.
//ewmaRtt = ewmaRtt*(1 - alpha) + currentRtt*alpha;
ewmaRtt = ewmaRtt*3/4 + currentRtt/4;
}
}
......
......@@ -52,8 +52,6 @@ extern char * optarg;
#include <iomanip>
// Udp-CHANGES-Begin
#include <iostream>
#include <fstream>
#include <functional>
#include <climits>
#include <limits.h>
......
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