Commit bb92b0d9 authored by Maciej Lipinski's avatar Maciej Lipinski Committed by Benoit Rat

SW: adding networkTool by Maciej. This is a crappa-code which enables to…

SW: adding networkTool by Maciej. This is a crappa-code which enables to stress-test a bit the switch with heavy traffic, checks frame loss and frame latency
parent 8cf2d196
This diff is collapsed.
CC = g++
CFLAGS = -g3 -O0 -lm -w -Wall
TESTER = test
DECODER = networkTool
OBJS = networkTool.o
OUTPUT= $(DECODER)
all : $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(OUTPUT)
clean:
rm -f $(OBJS) $(TESTER) $(DECODER)
The networkTool is my private and crappy code that I created to test reliability mechanims
in a White Rabbit network. I did it in a rush, looking at codes of the others (Alessandro
Rubini and Bartosz Bielawski) and creating something suited to my reqirements based on
ptp-noposix network functions.
DISCLAIMER:
The code is by no means an example of programming practices -- it is crap.
The code is by no means working perfectly -- it has many bugs (known and unknown)
This code is able to make a Gigabit Ethernet Card worth 1000 euro to loose frames, therefore
the results of it should be taken with loads of thoughts and wits and knowing what one is
doing. It is not always the Device Under Test (be it WR Switch) that is the cause of frame
loss.
I provide no support and no warranty for this code. I make it public because it seems to
be useful for people out there. However, anyone who uses this code should be aware what he/she
is doing and she/he shall not complain the code is crap... it is crap and by using this code
you agree that you have no room for complaints, on contrary, you are most welcome to improve
and debug it and submit your modifications to a separate branch. If I consider the changes
useful, I'll merge it to the master.
Short description:
This application can do the following:
- send raw Ethernet frames (single/burst) of different size and with different gap between
them (if burst):
* Transmission time of each frame is timestamped in the S/W and the timestamp included in
the frame,
* Each frame in a burst has a subsequent ID
- receive raw Ethernet frames (single/burst) of expected size :
* Reception time of each frame is tiemstamped
* ID of subsequent frames in a burst is verified to check whether we lost some frames
* latency and reception gap (frequency) is calculated based on measured/received timestamps
* if receiving burst, a report on the number of received/lost frames and average latency/gap
is provided.
If you want to measure latency, it is recommended to use the same PC to transmit and receive
(to have the same timebase).
In order to start:
- make
- ./networkTool -h
In order to send/receive frames you need to run it with superuser rights (sudo)
\ No newline at end of file
This diff is collapsed.
#ifndef _fec_decoder_h
#define _fec_decoder_h
#include <stdio.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#include <linux/if_arp.h>
#include <linux/errqueue.h>
#include <linux/sockios.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <asm/types.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <math.h>
#define DEMO__
//#define DEMO__ // makes a binary for the demo
#include <asm/socket.h>
#define PTPD_SOCK_RAW_ETHERNET 1
#define PTPD_SOCK_UDP 2
#define PACKET_SIZE 1518
#define IFACE_NAME_LEN 16
#define ETHER_MTU 1518
#define PACKED __attribute__((packed))
#define DEBUG_DETAIL 2
#define DEBUG_LIGHT 1
#define DEBUG_NO 0
// FECed frame header size [bytes]
#define FEC_HEADE_SIZE 8
#define ETHER_TYPE 0xDEED
#define MAX_BURST 10000000
typedef uint32_t ipv4_addr_t;
typedef char Octet;
typedef uint8_t mac_addr_t[6];
const mac_addr_t FEC_ADDR = {0x76, 0x54, 0xba, 0x98 , 0xfe, 0xdc};
const mac_addr_t DEFAULT_UNICAST_MAC = {0x00,0x01,0x02,0x03,004,0x05 };
const mac_addr_t UNICAST_MAC_ETH_5 = {0x00,0x1b,0x21,0x8e,0xd7,0x44 };
const mac_addr_t UNICAST_MAC_ETH_4_RENAME = {0x00,0x1b,0x21,0x8e,0xd7,0x45 };
const mac_addr_t DEFAULT_MULTICAST_MAC= {0x01,0x01,0x02,0x03,004,0x05 };
const mac_addr_t BROADCAST_MAC = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF };
PACKED struct etherpacket {
struct ethhdr ether;
char data[ETHER_MTU];
};
PACKED struct bench_pkt {
uint32_t burst_id;
uint32_t seq;
uint16_t size, size2;
struct timeval tx;
struct timeval xx;
struct timeval rx;
char payload[0];
};
enum rxfrom_mode {
RETURN_SEQ_NUM,
RETURN_DATA};
typedef struct timeval timeval_t;
typedef void *wr_socket_t;
typedef struct{
int rx_seq_id;
timeval_t rx; //reception timestamp
timeval_t tx; //transmision timestamp
timeval_t xx; //latency time tx-to-rx
} rx_data_t;
typedef struct {
// Network interface name (eth0, ...)
char if_name[IFACE_NAME_LEN];
// Socket family (RAW ethernet/UDP)
int family;
// MAC address
mac_addr_t mac;
// Destination MASC address, filled by recvfrom() function on interfaces bound to multiple addresses
mac_addr_t mac_dest;
// IP address
ipv4_addr_t ip;
// UDP port
uint16_t port;
// RAW ethertype
uint16_t ethertype;
// physical port to bind socket to
uint16_t physical_port;
} wr_sockaddr_t;
struct my_socket {
int fd;
wr_sockaddr_t bind_addr;
mac_addr_t local_mac;
int if_index;
} ;
typedef struct my_socket my_socket_t;
typedef struct {
char rx_if_name[IFACE_NAME_LEN];
char tx_if_name[IFACE_NAME_LEN];
int rx_do;
int rx_burst_do;
int tx_burst_do;
int tx_do;
uint16_t ethertype;
mac_addr_t dst_mac;
int pkt_time_interval;
int pkt_number_in_burst;
size_t pkt_payload_size;
int show_rxtx_data;
} RunTimeOpts;
#endif
\ No newline at end of file
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