Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e833481
Applied recent changes of fakeswitch.c
zzxgzgz Oct 18, 2021
c086485
Changed vlan_id and commented out the code that changes the ip and ma…
zzxgzgz Oct 18, 2021
56e2d93
More debug msg for fake switch
zzxgzgz Oct 19, 2021
a583f4b
Try to comment out unwanted function
zzxgzgz Oct 20, 2021
6c85305
Added debug msg in fakeswitch read/write
zzxgzgz Oct 21, 2021
c1c7c4b
Suspect cbench is not able to make connection
zzxgzgz Oct 21, 2021
fb95f05
Added more logs
zzxgzgz Oct 21, 2021
02a9607
Try to change destination_ip for different fake switches, to see if i…
zzxgzgz Oct 21, 2021
354f597
Tried to make different destination IPs for packet_ins
zzxgzgz Oct 25, 2021
6668f41
Added log for destination IPs
zzxgzgz Oct 25, 2021
0be1c5c
Added log
zzxgzgz Oct 25, 2021
ccda506
Modified destination IP generation
zzxgzgz Oct 25, 2021
ce65662
Don't use 0 or 1 as the last octec of destination IPs
zzxgzgz Oct 25, 2021
a89f821
Also not using 10.0.0.10, as it is on the same host, when host 1 has …
zzxgzgz Oct 25, 2021
da2d6e5
Added integration with ACA + Throttling
zzxgzgz Jan 31, 2022
acdf50e
Removed .deps folder
zzxgzgz Jan 31, 2022
1a36e6c
Removed .libs folder
zzxgzgz Jan 31, 2022
8240a63
Removed ./autom4te folder; updated .gitignore
zzxgzgz Jan 31, 2022
d412271
Removed more files
zzxgzgz Jan 31, 2022
0aaf021
Removed a lot of generated files; updated .gitignore
zzxgzgz Jan 31, 2022
46b3761
Removed more files and updated .gitigmore
zzxgzgz Jan 31, 2022
61b0780
Removed more files and updated .gitignore
zzxgzgz Jan 31, 2022
32f4e30
Removed more files and updated .gitignore
zzxgzgz Jan 31, 2022
4c02ec4
Removed more files and updated .gitignore
zzxgzgz Jan 31, 2022
5f858c7
Added back some Makefile s that were already in the repo
zzxgzgz Jan 31, 2022
2c554fe
Delete unwanted local file
zzxgzgz Jan 31, 2022
6f91d71
Added back cbench/Makefile.am; fixed typo in cbench/cbench.c
zzxgzgz Jan 31, 2022
4c05eee
Addressed issues found in PR review
zzxgzgz Jan 31, 2022
48db0c7
Addressed issues found in PR review
zzxgzgz Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
netfpga-packet-generator-c-library
openflow
./netfpga-packet-generator-c-library
./openflow
netfpga-packet-generator-c-library
openflow
cbench/cbench
./.libs
./.deps
./Makefile*
./autom4te.cache
*.o
*.lo
*.la
*.a
./missing
./libtool
./install-sh
./compile
./config.guess
./config.log
./configure
./depcomp
*Makefile
*Makefile.in
./ltmain.sh
./doc/doxygen.conf
./stamp-h1
2 changes: 1 addition & 1 deletion cbench/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ bin_PROGRAMS=cbench
cbench_SOURCES = \
myargs.c myargs.h \
cbench.c cbench.h \
fakeswitch.c fakeswitch.h
fakeswitch.c fakeswitch.h

19 changes: 18 additions & 1 deletion cbench/cbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct myargs my_options[] = {
/*******************************************************************/
double run_test(int n_fakeswitches, struct fakeswitch * fakeswitches, int mstestlen, int delay)
{
printf("Test started\n");
struct timeval now, then, diff;
struct pollfd * pollfds;
int i;
Expand All @@ -77,11 +78,18 @@ double run_test(int n_fakeswitches, struct fakeswitch * fakeswitches, int mstest

for(i = 0; i< n_fakeswitches; i++)
fakeswitch_handle_io(&fakeswitches[i], &pollfds[i]);
/*
This is the throttling part.
The program sleeps 5000 microsecond(5ms) at the end of each iteration.
This sleep time gave us a cbench send packet_in speed at about 500,000 requests/second
Please feel free to adjust the number to suit your need.
*/
usleep(5000);
}
tNow = now.tv_sec;
tmNow = localtime(&tNow);
printf("%02d:%02d:%02d.%03d %-3d switches: flows/sec: ", tmNow->tm_hour, tmNow->tm_min, tmNow->tm_sec, (int)(now.tv_usec/1000), n_fakeswitches);
usleep(100000); // sleep for 100 ms, to let packets queue
usleep(5000); // sleep for 5 ms, to let packets queue
for( i = 0 ; i < n_fakeswitches; i++)
{
count = fakeswitch_get_count(&fakeswitches[i]);
Expand All @@ -93,6 +101,7 @@ double run_test(int n_fakeswitches, struct fakeswitch * fakeswitches, int mstest
sum /= passed; // is now per ms
printf(" total = %lf per ms \n", sum);
free(pollfds);
printf("Test Ended\n");
return sum;
}

Expand Down Expand Up @@ -177,18 +186,21 @@ int timeout_connect(int fd, const char * hostname, int port, int mstimeout) {
int make_tcp_connection_from_port(const char * hostname, unsigned short port, unsigned short sport,
int mstimeout, int nodelay)
{
printf("Making connection to host at port: %ld\n", port);
struct sockaddr_in local;
int s;
int err;
int zero = 0;

s = socket(AF_INET,SOCK_STREAM,0);
if(s<0){
printf("make_tcp_connection: socket: %ld\n", port);
perror("make_tcp_connection: socket");
exit(1); // bad socket
}
if(nodelay && (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, &zero, sizeof(zero)) < 0))
{
printf("setsockopt %ld\n", port);
perror("setsockopt");
fprintf(stderr,"make_tcp_connection::Unable to disable Nagle's algorithm\n");
exit(1);
Expand All @@ -200,6 +212,7 @@ int make_tcp_connection_from_port(const char * hostname, unsigned short port, un
err=bind(s,(struct sockaddr *)&local, sizeof(local));
if(err)
{
printf("make_tcp_connection_from_port::bind %ld\n", port);
perror("make_tcp_connection_from_port::bind");
return -4;
}
Expand All @@ -208,6 +221,7 @@ int make_tcp_connection_from_port(const char * hostname, unsigned short port, un

if(err)
{
printf("make_tcp_connection: connect %ld\n", port);
perror("make_tcp_connection: connect");
close(s);
return err; // bad connect
Expand Down Expand Up @@ -372,6 +386,7 @@ int main(int argc, char * argv[])

for( i = 0; i < n_fakeswitches; i++)
{
printf("Inside n_fakeswitches for loop, i = %ld\n", i);
int sock;
double sum = 0;
if (connect_delay != 0 && i != 0 && (i % connect_group_size == 0)) {
Expand All @@ -385,6 +400,7 @@ int main(int argc, char * argv[])
fprintf(stderr, "make_nonblock_tcp_connection :: returned %d", sock);
exit(1);
}
printf("Connnection established, i = %ld\n", i);
if(debug)
fprintf(stderr,"Initializing switch %d ... ", i+1);
fflush(stderr);
Expand All @@ -397,6 +413,7 @@ int main(int argc, char * argv[])
if(!should_test_range && ((i+1) != n_fakeswitches)) // only if testing range or this is last
continue;
for( j = 0; j < tests_per_loop; j ++) {
printf("Inside tests per loop, i = %ld, j = %ld\n", i, j);
if ( j > 0 )
delay = 0; // only delay on the first run
v = 1000.0 * run_test(i+1, fakeswitches, mstestlen, delay);
Expand Down
52 changes: 38 additions & 14 deletions cbench/fakeswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,22 @@ void fakeswitch_learn_dstmac(struct fakeswitch *fs)
{
// thanks wireshark
char gratuitous_arp_reply [] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0c,
0x29, 0x1a, 0x29, 0x1a, 0x08, 0x06, 0x00, 0x01,
0x08, 0x00, 0x06, 0x04, 0x00, 0x02, 0x00, 0x0c,
0x29, 0x1a, 0x29, 0x1a, 0x7f, 0x00, 0x00, 0x01,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0c, // 8 octects per line
// Ethernet Type: 802.1Q VLAN tagging (0x8100)
0x29, 0x1a, 0x29, 0x1a, 0x81, 0x00, 0x00, 0x01, //<- this 0x00, 0x01 (which is 1) is the vlan_id
// Ethernet Type: ARP (0x0806)
0x08, 0x06, 0x06, 0x04, 0x00, 0x02, 0x00, 0x0c,
// ARP OP Code: 1 is request, 2 is reply
0x00, 0x01, 0x29, 0x1a, 0x7f, 0x00, 0x00, 0x01,
0x00, 0x0c, 0x29, 0x1a, 0x29, 0x1a, 0x7f, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};

char mac_address_to_learn[] = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
char ip_address_to_learn[] = { 192, 168 , 1, 40 };
char ip_address_to_learn[] = { 10, 0, 0, 2 };
char destination_ip_address[] = {10, 0, 0, 3};

char buf [512];
int len = sizeof( struct ofp_packet_in ) + sizeof(gratuitous_arp_reply);
Expand All @@ -123,19 +127,30 @@ void fakeswitch_learn_dstmac(struct fakeswitch *fs)
memcpy(pkt_in->data, gratuitous_arp_reply, sizeof(gratuitous_arp_reply));

mac_address_to_learn[5] = fs->id;
ip_address_to_learn[2] = fs->id;
// second octet
ip_address_to_learn[1] = (fs->current_mac_address) / 10000;
// third octet
ip_address_to_learn[2] = ((fs->current_mac_address)%10000) / 100;
// fourth octet
ip_address_to_learn[3] = (fs->current_mac_address)%100;

// we don't want the last digit of IP address to be 0 or 1, 1 is reserved.
// also ignoring .10, as it is used on the same host when host 1 has only 1 port
if (ip_address_to_learn[3] == 1 || ip_address_to_learn[3] == 0 || ip_address_to_learn[3] == 10){
ip_address_to_learn[3] = 2;
}

eth = (struct ether_header * ) pkt_in->data;
memcpy (eth->ether_shost, mac_address_to_learn, 6);

arp_reply = ((void *) eth) + sizeof (struct ether_header);
memcpy ( arp_reply + 8, mac_address_to_learn, 6);
memcpy ( arp_reply + 14, ip_address_to_learn, 4);
memcpy ( arp_reply + 18, mac_address_to_learn, 6);
memcpy ( arp_reply + 24, ip_address_to_learn, 4);
memcpy ( arp_reply + 8 + 4, mac_address_to_learn, 6);
memcpy ( arp_reply + 14 + 4, destination_ip_address, 4);
memcpy ( arp_reply + 18 + 4, mac_address_to_learn, 6);
memcpy ( arp_reply + 24 + 4, ip_address_to_learn, 4);

msgbuf_push(fs->outbuf,(char * ) pkt_in, len);
debug_msg(fs, " sent gratuitous ARP reply to learn about mac address: version %d length %d type %d eth: %x arp: %x ", pkt_in->header.version, len, buf[1], eth, arp_reply);
debug_msg(fs, "current_mac_address: %d sent packet in with destination IP: %ld.%ld.%ld.%ld \n", fs->current_mac_address, ip_address_to_learn[0],ip_address_to_learn[1],ip_address_to_learn[2],ip_address_to_learn[3]);
}


Expand Down Expand Up @@ -347,6 +362,7 @@ void fakeswitch_change_status(struct fakeswitch *fs, int new_status) {
/***********************************************************************/
void fakeswitch_handle_read(struct fakeswitch *fs)
{
debug_msg(fs, "Handle read called.");
int count;
struct ofp_header * ofph;
struct ofp_header echo;
Expand Down Expand Up @@ -376,14 +392,20 @@ void fakeswitch_handle_read(struct fakeswitch *fs)
struct ofp_stats_request * stats_req;
case OFPT_PACKET_OUT:
po = (struct ofp_packet_out *) ofph;
debug_msg(fs, "Got OFPT_PACKET_OUT, switch_status: %ld", fs->switch_status);

if ( fs->switch_status == READY_TO_SEND && ! packet_out_is_lldp(po)) {
// assume this is in response to what we sent
debug_msg(fs, "Increment count for OFPT_PACKET_OUT");
fs->count++; // got response to what we went
fs->probe_state--;
}else{
debug_msg(fs, "Got OFPT_PACKET_OUT but it doesn't count");
}
break;
case OFPT_FLOW_MOD:
fm = (struct ofp_flow_mod *) ofph;
debug_msg(fs, "Got OFPT_FLOW_MOD");
if(fs->switch_status == READY_TO_SEND && (fm->command == htons(OFPFC_ADD) ||
fm->command == htons(OFPFC_MODIFY_STRICT)))
{
Expand Down Expand Up @@ -424,6 +446,7 @@ void fakeswitch_handle_read(struct fakeswitch *fs)
msgbuf_push(fs->outbuf, buf, count);
debug_msg(fs, "sent vendor");
// apply nox hack; nox ignores packet_in until this msg is sent
fs->count++;
fs->probe_state=0;
break;
case OFPT_HELLO:
Expand Down Expand Up @@ -476,6 +499,7 @@ void fakeswitch_handle_read(struct fakeswitch *fs)
/***********************************************************************/
static void fakeswitch_handle_write(struct fakeswitch *fs)
{
debug_msg(fs, "Handle write.");
char buf[BUFLEN];
int count ;
int send_count = 0 ;
Expand All @@ -491,13 +515,13 @@ static void fakeswitch_handle_write(struct fakeswitch *fs)
for (i = 0; i < send_count; i++)
{
// queue up packet

fakeswitch_learn_dstmac(fs);
fs->probe_state++;
// TODO come back and remove this copy
count = make_packet_in(fs->id, fs->xid++, fs->current_buffer_id, buf, BUFLEN, fs->current_mac_address);
fs->current_mac_address = ( fs->current_mac_address + 1 ) % fs->total_mac_addresses;
fs->current_buffer_id = ( fs->current_buffer_id + 1 ) % NUM_BUFFER_IDS;
msgbuf_push(fs->outbuf, buf, count);
// msgbuf_push(fs->outbuf, buf, count);
debug_msg(fs, "send message %d", i);
}
} else if( fs->switch_status == WAITING)
Expand All @@ -512,7 +536,7 @@ static void fakeswitch_handle_write(struct fakeswitch *fs)
} else if ( fs->switch_status == LEARN_DSTMAC)
{
// we should learn the dst mac addresses
fakeswitch_learn_dstmac(fs);
// fakeswitch_learn_dstmac(fs);
fakeswitch_change_status(fs, READY_TO_SEND);
}
// send any data if it's queued
Expand Down
1 change: 1 addition & 0 deletions openflow
Submodule openflow added at 82ad07
2 changes: 1 addition & 1 deletion pkt_gen/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ common/nf2util.o: common/nf2.h common/nf2util.c common/nf2util.h common/reg_defi
make -C common/

clean:
rm -rf *.o pkt_gen *~
rm -rf *.o pkt_gen *~