Commit fd4a999c authored by Jonathon Duerig's avatar Jonathon Duerig

Minor updates to bw-bottleneck which hadn't been checked in.

parent 04f6583d
#include <stdlib.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
......@@ -7,8 +7,8 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/time.h>
#include <string.h>
#include <sys/time.h>
#include <pcap.h>
#include <errno.h>
#include <netinet/in.h>
......@@ -25,7 +25,7 @@
#include <map>
#include <sstream>
#define REMOTE_SERVER_PORT 19655
#define REMOTE_SERVER_PORT 19835
#define MAX_MSG 100
......@@ -173,7 +173,7 @@ void pcapCallback(u_char *user, const struct pcap_pkthdr *pcap_info, const u_cha
// Ignore the IP options for now - but count their length.
/////////////////////////////////////////////////////////
u_char *udpPacketStart = (u_char *)(pkt_data + sizeof(struct ether_header) + ipHeaderLength*4);
u_char *udpPacketStart = (u_char *)(pkt_data + sizeof(struct ether_header) + ipHeaderLength*4);
struct udphdr const *udpPacket;
......@@ -190,9 +190,10 @@ void pcapCallback(u_char *user, const struct pcap_pkthdr *pcap_info, const u_cha
handleUDP(pcap_info,udpPacket,udpPacketStart, ipPacket);
}
void init_pcap( char *ipAddress)
void init_pcap( char *ipAddress, char * iface)
{
char interface[20] = "vnet";
char * interface = iface;
// char interface[20] = "vnet";
struct bpf_program bpfProg;
char errBuf[PCAP_ERRBUF_SIZE];
char filter[128] = " udp ";
......@@ -209,8 +210,8 @@ void init_pcap( char *ipAddress)
pcap_lookupnet(interface, &netp, &maskp, errBuf);
pcapDescriptor = pcap_open_live(interface, BUFSIZ, 0, 0, errBuf);
localAddress.s_addr = netp;
printf("IP addr = %s, Interface = %s\n", ipAddress, interface);
sprintf(filter," udp and ( (src host %s and dst port 19655 ) or (dst host %s and src port 19655 )) ", ipAddress, ipAddress);
printf("IP addr = %s, Interface = %s, Port = %d\n", ipAddress, interface, REMOTE_SERVER_PORT);
sprintf(filter," udp and ( (src host %s and dst port %d ) or (dst host %s and src port %d )) ", ipAddress, REMOTE_SERVER_PORT, ipAddress, REMOTE_SERVER_PORT);
if(pcapDescriptor == NULL)
{
......@@ -218,7 +219,7 @@ void init_pcap( char *ipAddress)
exit(1);
}
pcap_compile(pcapDescriptor, &bpfProg, filter, 1, netp);
pcap_compile(pcapDescriptor, &bpfProg, filter, 1, netp);
pcap_setfilter(pcapDescriptor, &bpfProg);
pcap_setnonblock(pcapDescriptor, 1, errBuf);
......@@ -245,9 +246,9 @@ int main(int argc, char **argv)
ifstream inputFileHandle;
localhostEnt = gethostbyname(argv[3]);
memcpy((char *) &localHostAddr.sin_addr.s_addr,
memcpy((char *) &localHostAddr.sin_addr.s_addr,
localhostEnt->h_addr_list[0], localhostEnt->h_length);
init_pcap(inet_ntoa(localHostAddr.sin_addr));
init_pcap(inet_ntoa(localHostAddr.sin_addr), argv[4]);
int pcapfd = pcap_get_selectable_fd(pcapDescriptor);
// Create the output directory.
......@@ -264,7 +265,7 @@ int main(int argc, char **argv)
while(!inputFileHandle.eof())
{
inputFileHandle.getline(tmpStr, 80);
inputFileHandle.getline(tmpStr, 80);
tmpString = tmpStr;
if(tmpString.size() < 3)
......@@ -289,10 +290,11 @@ int main(int argc, char **argv)
for(int i = 0;i < numHosts; i++)
{
host1 = NULL;
cout << "Host: " << hostList[i] << endl;
host1 = gethostbyname(hostList[i].c_str());
remoteServAddresses[i].sin_family = host1->h_addrtype;
memcpy((char *) &remoteServAddresses[i].sin_addr.s_addr,
memcpy((char *) &remoteServAddresses[i].sin_addr.s_addr,
host1->h_addr_list[0], host1->h_length);
remoteServAddresses[i].sin_port = htons(REMOTE_SERVER_PORT);
}
......@@ -408,9 +410,9 @@ int main(int argc, char **argv)
memcpy(&messageString[1], &hostIndex, sizeof(short int));
memcpy(&messageString[1 + sizeof(short int)], &sendTime, sizeof(unsigned long long));
rc = sendto(clientSocket, messageString, 1 + sizeof(short int) + sizeof(unsigned long long), flags,
rc = sendto(clientSocket, messageString, 1 + sizeof(short int) + sizeof(unsigned long long), flags,
(struct sockaddr *) &remoteServAddresses[i], sizeof(remoteServAddresses[i]));
if(rc < 0)
printf("ERROR sending %dth udp message, packetCounter = %d\n", i, packetCounter);
......@@ -464,7 +466,7 @@ int main(int argc, char **argv)
}
}
// Find the common sequence of delay indices present for
// Find the common sequence of delay indices present for
// all the probed destinations.
int minSequenceLength = 128;
int maxFirstSeenIndex = -999999, minLastSeenIndex = 9999999;
......@@ -480,7 +482,7 @@ int main(int argc, char **argv)
for (int k = 0; k < delaySeqLen; k++)
{
if (delaySequenceArray[i][k] != -9999)
if (delaySequenceArray[i][k] != -9999)
{
lastSeenIndex = k;
if (firstSeenIndex == -1)
......@@ -523,7 +525,7 @@ int main(int argc, char **argv)
if(delaySequenceSize[l] < minSequenceLength)
continue;
if (delaySequenceArray[l][k] == -9999)
if (delaySequenceArray[l][k] == -9999)
{
missingSampleFlag = true;
}
......@@ -552,7 +554,7 @@ int main(int argc, char **argv)
for(int k = 0; k < delaySequenceArray[i].size(); k++)
{
tmpFileHandle << delaySequenceArray[i][k] << "\n";
tmpFileHandle << delaySequenceArray[i][k] << "\n";
}
tmpFileHandle.close();
......@@ -578,7 +580,7 @@ int main(int argc, char **argv)
/*
for (int k = 0; k < delaySeqLen; k++)
{
if (delaySequenceArray[i][k] != -9999)
if (delaySequenceArray[i][k] != -9999)
{
lastSeenIndex = k;
if (firstSeenIndex == -1)
......@@ -626,7 +628,7 @@ int main(int argc, char **argv)
{
for (int k = firstSeenIndex; k < lastSeenIndex + 1; k++)
{
outputFileHandle << delaySequenceArray[i][k] << " "<< sendTimesArray[i][k] << "\n";
outputFileHandle << delaySequenceArray[i][k] << " "<< sendTimesArray[i][k] << "\n";
}
}
outputFileHandle.close();
......
......@@ -6,13 +6,13 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>
#include <pcap.h>
#include <errno.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
#include <netinet/if_ether.h>
#include <net/ethernet.h>
......@@ -38,13 +38,13 @@ using namespace std;
unsigned long long getTimeMilli()
{
struct timeval tp;
gettimeofday(&tp, NULL);
struct timeval tp;
gettimeofday(&tp, NULL);
long long tmpSecVal = tp.tv_sec;
long long tmpUsecVal = tp.tv_usec;
long long tmpSecVal = tp.tv_sec;
long long tmpUsecVal = tp.tv_usec;
return (tmpSecVal*1000 + tmpUsecVal/1000);
return (tmpSecVal*1000 + tmpUsecVal/1000);
}
void handleUDP(struct pcap_pkthdr const *pcap_info, struct udphdr const *udpHdr, u_char *const udpPacketStart, struct ip const *ipPacket)
......@@ -70,19 +70,19 @@ void handleUDP(struct pcap_pkthdr const *pcap_info, struct udphdr const *udpHdr,
memcpy((char *) &returnAddr.sin_addr, (char *)&(ipPacket->ip_src), sizeof(struct in_addr));
returnAddr.sin_port = udpHdr->source;
appAck[0] = '1';
appAck[0] = '1';
memcpy(&appAck[1] ,(dataPtr + 1), sizeof(short int));
memcpy(&appAck[1 + sizeof(short int)], &sendTimestamp, sizeof(unsigned long long));
memcpy(&appAck[1 + + sizeof(short int) + sizeof(unsigned long long)], &oneWayDelay, sizeof(long long));
memcpy(&appAck[1 + sizeof(short int)], &sendTimestamp, sizeof(unsigned long long));
memcpy(&appAck[1 + + sizeof(short int) + sizeof(unsigned long long)], &oneWayDelay, sizeof(long long));
cout << "Sending app level ack to "<< inet_ntoa(returnAddr.sin_addr) << ",at " << sendTimestamp << " , recvtimestamp = "<<recvTimestamp<< ", delay = "<< oneWayDelay << endl;
sendto(sd,appAck,1 + + sizeof(short int) + 2*sizeof(long long),flags,(struct sockaddr *)&returnAddr,cliLen);
}
else if(packetType == '1') // TODO:This is an udp ACK packet. If it is being sent
// out from this host, do nothing.
{
sendto(sd,appAck,1 + + sizeof(short int) + 2*sizeof(long long),flags,(struct sockaddr *)&returnAddr,cliLen);
}
else if(packetType == '1') // TODO:This is an udp ACK packet. If it is being sent
// out from this host, do nothing.
{
}
}
else
{
printf("ERROR: Unknown UDP packet received from remote agent\n");
......@@ -170,9 +170,10 @@ void pcapCallback(u_char *user, const struct pcap_pkthdr *pcap_info, const u_cha
}
void init_pcap( char *ipAddress)
void init_pcap( char *ipAddress, char * iface)
{
char interface[] = "eth1";
char * interface = iface;
/* char interface[] = "any";*/
struct bpf_program bpfProg;
char errBuf[PCAP_ERRBUF_SIZE];
char filter[128] = " udp ";
......@@ -200,7 +201,7 @@ void init_pcap( char *ipAddress)
int main(int argc, char *argv[]) {
char msg[MAX_MSG];
struct hostent *localHost;
......@@ -214,7 +215,7 @@ int main(int argc, char *argv[]) {
localHost = gethostbyname(argv[1]);
if(localHost == NULL)
if(localHost == NULL)
{
printf("ERROR: Unknown host %s\n", argv[1]);
exit(1);
......@@ -228,16 +229,16 @@ int main(int argc, char *argv[]) {
servAddr.sin_port = htons(LOCAL_SERVER_PORT);
rc = bind (sd, (struct sockaddr *) &servAddr,sizeof(servAddr));
if(rc<0) {
printf("%s: cannot bind port number %d \n",
argv[0], LOCAL_SERVER_PORT);
printf("%s: cannot bind port number %d \n",
argv[0], LOCAL_SERVER_PORT);
exit(1);
}
printf("%s: waiting for data on port UDP %u\n",
printf("%s: waiting for data on port UDP %u\n",
argv[0],LOCAL_SERVER_PORT);
init_pcap(inet_ntoa(servAddr.sin_addr));
init_pcap(inet_ntoa(servAddr.sin_addr), argv[2]);
int pcapfd = pcap_get_selectable_fd(pcapDescriptor);
flags = 0;
......
......@@ -47,7 +47,7 @@ inputFileHandle.close()
numHosts = len(hostList)
targetSleepTime = float ((1000.0/float(probeRate))/1000.0 ) - 0.001
targetSleepTime = float ((1000.0/float(probeRate)) ) - 0.001
clientSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
fcntl.fcntl(clientSocket, fcntl.F_SETFL, os.O_NONBLOCK)
......@@ -72,24 +72,24 @@ for i in range(0, numHosts-1):
#{
secondHostAddr = (hostList[j] + ".flex-plab2.tbres.emulab.net", portNum)
startTime = int(time.time()*1000)
startTime = int(time.time())
lastSentTime = startTime
endProbesFlag = 0
readTimeoutFlag = 0
# For each combination(pair), send a train of UDP packets.
while (( lastSentTime - startTime)/1000 < probeDuration) or \
while (( lastSentTime - startTime) < probeDuration) or \
not(readTimeoutFlag):
#{
# Stop waiting for probe replies after a timeout - calculated from the
# time the last probe was sent out.
if endProbesFlag and ( (time.time()*1000 - lastSentTime)/1000.0 > timeout):
if endProbesFlag and ( (time.time() - lastSentTime) > timeout):
readTimeoutFlag = 1
# Stop sending probes after the given probe duration.
if not(endProbesFlag) and (lastSentTime - startTime)/1000.0 > probeDuration:
if not(endProbesFlag) and (lastSentTime - startTime) > probeDuration:
endProbesFlag = 1
if endProbesFlag:
......@@ -133,14 +133,14 @@ for i in range(0, numHosts-1):
if clientSocket in writeSet:
#{
# Send the probe packets.
sendTime = int(time.time()*1000)
sendTime = int(time.time())
messageString = "0 "
messageString = messageString + str(sendTime)
clientSocket.sendto(messageString, firstHostAddr)
packetTimeMaps[0][str(sendTime)] = packetCounter
delaySequenceArray[0].append(-9999)
sendTime = int(time.time()*1000)
sendTime = int(time.time())
messageString = "1 "
messageString = messageString + str(sendTime)
clientSocket.sendto(messageString, secondHostAddr)
......@@ -148,15 +148,15 @@ for i in range(0, numHosts-1):
delaySequenceArray[1].append(-9999)
# Sleep for 99 msec for a 10Hz target probing rate.
lastSentTime = time.time()*1000
lastSentTime = time.time()
time.sleep(targetSleepTime)
packetCounter += 1
#}
else:
#{
if not(time.time()*1000 - lastSentTime > targetSleepTime*1000):
time.sleep( float( ( targetSleepTime*1000 - (time.time()*1000 - lastSentTime) )/1000.0) )
if not(time.time() - lastSentTime > targetSleepTime):
time.sleep( float( ( targetSleepTime - (time.time() - lastSentTime) )) )
#}
#}
#}
......
......@@ -25,7 +25,8 @@
#include <map>
#include <sstream>
#define REMOTE_SERVER_PORT 9831
#define REMOTE_SERVER_PORT 19835
/*9831*/
#define MAX_MSG 100
......@@ -153,10 +154,9 @@ void pcapCallback(u_char *user, const struct pcap_pkthdr *pcap_info, const u_cha
int ipHeaderLength = ipPacket->ip_hl;
int ipVersion = ipPacket->ip_v;
if(ipVersion != 4)
{
printf("Captured IP packet is not IPV4.\n");
printf("Captured IP packet is not IPV4: %d\n", ipVersion);
return;
}
......@@ -191,9 +191,10 @@ void pcapCallback(u_char *user, const struct pcap_pkthdr *pcap_info, const u_cha
handleUDP(pcap_info,udpPacket,udpPacketStart, ipPacket);
}
void init_pcap( char *ipAddress)
void init_pcap( char *ipAddress, char * iface)
{
char interface[] = "eth0";
char * interface = iface;
/* char interface[] = "any"; */
struct bpf_program bpfProg;
char errBuf[PCAP_ERRBUF_SIZE];
char filter[128] = " udp ";
......@@ -206,7 +207,8 @@ void init_pcap( char *ipAddress)
pcapDescriptor = pcap_open_live(interface, BUFSIZ, 0, 0, errBuf);
localAddress.s_addr = netp;
printf("IP addr = %s\n", ipAddress);
sprintf(filter," udp and ( (src host %s and dst port 9831 ) or (dst host %s and src port 9831 )) ", ipAddress, ipAddress);
sprintf(filter," udp and ( (src host %s and dst port %d ) or (dst host %s and src port %d )) ", ipAddress, REMOTE_SERVER_PORT,
ipAddress, REMOTE_SERVER_PORT);
if(pcapDescriptor == NULL)
{
......@@ -242,7 +244,7 @@ int main(int argc, char **argv)
localhostEnt = gethostbyname(argv[3]);
memcpy((char *) &localHostAddr.sin_addr.s_addr,
localhostEnt->h_addr_list[0], localhostEnt->h_length);
init_pcap(inet_ntoa(localHostAddr.sin_addr));
init_pcap(inet_ntoa(localHostAddr.sin_addr), argv[4]);
int pcapfd = pcap_get_selectable_fd(pcapDescriptor);
// Create the output directory.
......
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