Reputation: 122
I'm doing packet forwarding through the use of a UDP socket. The setup is based on a traffic generator which sends packets to the UDP socket, the UDP socket then simply switches the source and destination addresses and sends the packet back to the where the packet came from (the traffic generator) where some networking metrics are then recorded. I'm using XL710 for 40GbE and the environment is on a computer and where it is sending data over an internal virtual network
I have tried to create the simplest application for doing this, which is able to send back about 350 000
packets/second to the traffic generator while the traffic generator is sending about 5 000 000
packets/second to the UDP socket. Therefore, it seems like there should be some room for improvement.
Here is the code for the UDP socket for echoing the packet back.
#define PORT 12345
#define IP_ADDR "192.168.0.32"
int main(int argc, char *argv[]){
int socket_fd;
struct sockaddr_in address, send_address;
char packet_buffert[2000] = {0};
if ((socket_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
exit(EXIT_FAILURE);
}
address.sin_family = AF_INET;
address.sin_port = htons(PORT);
address.sin_addr.s_addr = inet_addr(IP_ADDR);
if(bind(socket_fd, (struct sockaddr*)&address, sizeof(address))<0){
return -1;
}
socklen_t s = sizeof(send_address);
while(1){
if ((n = recvfrom (socket_fd, packet_buffert, sizeof packet_buffert, 0,(struct sockaddr*)&traffic_gen_addr, (socklen_t*)&s)) < 0)
{
printf(" %s\n ", strerror(errno));
return EXIT_FAILURE;
}
if (sendto (socket_fd, packet_buffert, n, 0, (struct sockaddr*)&traffic_gen_addr, (socklen_t)sizeof(traffic_gen_addr)) < 0)
{
printf("%s \n", strerror(errno));
return EXIT_FAILURE;
}
}
}
Thoughts I have had so far has been if and how batching packets could be done, but I have not been able to implement correctly as of yet.
What changes to the UDP socket could be made to improve or optimize the throughput, so that it may achieve higher packets/second? Is there some important concepts that this implementation is missing out on that could improve networking performance?
Upvotes: 0
Views: 105
Reputation: 1
in order to make your program send more packets per second you want to use smaller packet sizes. if you're sending packets with >500 length for example, you'd be generating more volumetric traffic than packets per second.
the example below show packets with being sent with 0 data length.
also, you can try using pthreads to make your CPU threads fork the function that generate packets. this will use a lot of your processor!
Upvotes: 0