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

1) Corrected libpcap filter strings in KernelTcp & UdpServer - udp packets

will be captured correctly now.
2) SensorList - initialized all udp dependent sensors to NULL in constructor.
3) fixed a small bug in throughput calculation using redundant ACKs.
parent 76bf1d5e
......@@ -457,11 +457,15 @@ void KernelTcp::init(void)
bpf_u_int32 maskp; /* subnet mask */
bpf_u_int32 netp; /* ip */
ostringstream filter;
struct in_addr tempAddr;
/* ask pcap for the network address and mask of the device */
pcap_lookupnet(global::interface.c_str(), &netp, &maskp, errbuf);
tempAddr.s_addr = netp;
char *localIPAddr = inet_ntoa(tempAddr);
filter << "(port " << global::peerServerPort << " and tcp)"
" or (port " << global::peerUdpServerPort << " and udp )";
" or ( udp and ( (src port " << global::peerUdpServerPort << " and dst host " << localIPAddr<< " ) or (dst port " << global::peerUdpServerPort << " and src host "<<localIPAddr<<" ) ) )";
/* open device for reading.
* NOTE: We use non-promiscuous */
......@@ -830,6 +834,7 @@ namespace
pos = global::planetMap.find(key);
if (pos != global::planetMap.end()) {
outgoing = false;
logWrite(PCAP, "Captured an Incoming UDP packet");
} else {
logWrite(ERROR,"Unable to find packet in planetMap");
return;
......@@ -885,6 +890,7 @@ namespace
// packets that are incoming. All other separation can be done
// inside the sensors themselves. We call these 'Send' and 'Ack'
// packets because my thinking was originally muddied about this.
logWrite(PCAP, "Before Capturing an Incoming UDP packet with UDP sensors");
if (outgoing) {
/*
* Outgoing packets
......@@ -895,6 +901,7 @@ namespace
/*
* Incoming packets
*/
logWrite(PCAP, "Capturing an Incoming UDP packet with UDP sensors");
packet.packetType = PACKET_INFO_ACK_COMMAND;
pos->second->capturePacket(&packet);
}
......
......@@ -139,8 +139,20 @@ void SensorList::reset(void)
depThroughputSensor = NULL;
depTSThroughputSensor = NULL;
depMinDelaySensor = NULL;
depUdpPacketSensor = NULL;
depUdpThroughputSensor = NULL;
depUdpMinDelaySensor = NULL;
depUdpMaxDelaySensor = NULL;
depUdpRttSensor = NULL;
depUdpLossSensor = NULL;
depUdpAvgThroughputSensor = NULL;
}
void SensorList::pushSensor(std::auto_ptr<Sensor> newSensor)
{
if (tail != NULL)
......
......@@ -310,7 +310,7 @@ 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("Received seqNum = %d, from IP = %s, port = %d\n", packetSeqNum, inet_ntoa(ipPacket->ip_src),sourcePort );
// printf("Packet loss = %d\n", clientIter->second.packetLoss);
// TODO:Take wrap around into account.
{
......@@ -527,12 +527,15 @@ void init_pcap(char *interface)
char errBuf[PCAP_ERRBUF_SIZE];
char filter[32] = "";
sprintf(filter," udp and dst port %d", ( localServerPort ) );
// IP Address and sub net mask.
bpf_u_int32 maskp, netp;
struct in_addr tempAddr;
pcap_lookupnet(interface, &netp, &maskp, errBuf);
tempAddr.s_addr = netp;
printf("Server address = %s\n", inet_ntoa(tempAddr));
sprintf(filter," udp and dst port %d and dst host %s", localServerPort, inet_ntoa(tempAddr));
pcapDescriptor = pcap_open_live(interface, SNAPLEN, 0, 0, errBuf);
if(pcapDescriptor == NULL)
......
......@@ -19,4 +19,4 @@
# The server runs in an infinite while loop - it can be terminated after the session
# is determined to be done at the client - kill using Ctrl-C.
sudo ./UdpServer eth1 3492
sudo ./UdpServer vnet 3492
......@@ -79,8 +79,8 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
for(i = 0;i < numRedunAcks; i++)
{
redunSeqNum = *(unsigned short int *)(packet->payload + 1 + global::udpMinAckPacketSize + i*global::udpRedunAckSize);
redunPacketSize = *(unsigned short int *)(packet->payload + 1 + global::udpMinAckPacketSize + i*global::udpRedunAckSize + global::USHORT_INT_SIZE);
redunSeqNum = *(unsigned short int *)(packet->payload + global::udpMinAckPacketSize + i*global::udpRedunAckSize);
redunPacketSize = *(unsigned short int *)(packet->payload + global::udpMinAckPacketSize + i*global::udpRedunAckSize + global::USHORT_INT_SIZE);
// Find if this redundant ACK is useful - or it was acked before.
vecIterator = find_if(ackedPackets.begin(), ackedPackets.end(), bind2nd(equalSeqNum(), redunSeqNum));
......@@ -90,10 +90,13 @@ void UdpAvgThroughputSensor::localAck(PacketInfo *packet)
// Calculate throughput for the packet being acked by
// the redundant ACK.
timeDiff = *(unsigned long long *)(packet->payload + 1 + global::udpMinAckPacketSize + i*global::udpRedunAckSize + global::udpSeqNumSize);
timeDiff = *(unsigned long long *)(packet->payload + global::udpMinAckPacketSize + i*global::udpRedunAckSize + 2*global::USHORT_INT_SIZE);
if(ackTimeDiff - timeDiff == 0)
if((timeDiff > ackTimeDiff) || (ackTimeDiff - timeDiff == 0))
{
logWrite(EXCEPTION, "Error using UDP redun Seqnum = %d, for seqNum = %d, time taken = %llu,ackTimeDiff = %llu, timeDiff = %llu, i = %d, numAcks = %d",redunSeqNum,seqNum, ackTimeDiff - timeDiff,ackTimeDiff,timeDiff, i, numRedunAcks);
continue;
}
tmpUdpAck.timeTaken = ackTimeDiff - timeDiff;
tmpUdpAck.isRedun = true;
......
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