Programming Multi-Core Processors based Embedded Systems A Hands-On Experience on Cavium Octeon based Platforms Lab Exercises
Lab # 3: Network Packet Sniffing 3-2
Lab Goals Objective Packet capture / filter / analyze - A case study Learning parallel programming using threads Utilizing many core systems efficiently Performance measurement Packet capture / filter / analyze - A case study We will use series of labs to achieve our objectives. Today's lab is about packet sniffing 3-3
Prerequisites Sniffing Mechanism Capturing of network packets arriving or departing from a network interface Mechanism We use raw sockets as follows rawSock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)) This system call picks every packet going out or coming in on an Ethernet interface 3-4
Prerequisites Testing You can use loop back device as a network interface Use Netperf or MPAC for traffic generation on the network interface 3-5
Lab Setup System 1 System 2 1 GigE Link 3-6 Sender Receiver 2 4 6 1 3 5 7 Sender Receiver Packet Sniffer 1 GigE Link System 1 System 2 Data Packets Core Packet Mapping to Cores 3-6
Sniffing Labs Framework One thread, called the dispatcher, sniffs the packets from the interface and puts it in one of the workers’ queues Filtering / Analysis Any kind of processing on a packet is the responsibility of the workers Each worker has its own queue or shared queue depending on sniffer application architecture Dispatcher assigns packets to worker queues 3-7
Sniffer Application Architecture MPAC packet sniffer version 1 Single queue Dispatcher can access whole queue Each worker thread can access only dedicated locations In-site sniffing No copying from dispatcher to worker space Each location access is mutually exclusive Controlled by a flag per location No locking overhead Get packet, if flag = 1 (workers) Location Access Function = Put packet, if flag = 0 (Dispatcher) 3-8
MPAC Packet Sniffer (Version 1) T1 T0 TN-1 Dispatcher putting space TN Dispatcher putting direction Workers getting direction TN Worker Threads 3-9
Lab 3 – Packet Sniffing Sniff a frame Objective This lab captures Ethernet packets which are destined to or departing from a specific interface Objective Can a dispatcher sniff at the line rate Hands on experience of plain sniffing Observing the base case performance of the dispatcher – worker model 3-10
Lab 3 - Sniffing Observations Observe the throughput performance with increasing number of threads Use core affinity and observe throughput 3-11
Cross Compile for Target System Cross Compile on Host System Go to Cavium SDK directory and run the command host$ source env-setup <OCTEON-MODEL> (where <OCTEON-MODEL> is the model of your target board. E.g. OCTEON_CN56XX) host$ cd /<path-to-mpac>/mpac_1.2 host$ ./configure --host=i386-redhat-linux-gnu --target=mips64-octeon-linux-gnu export CC=mips64-octeon-linux-gnu-gcc host$ make clean host$ make CC=mips64-octeon-linux-gnu-gcc 3-12
Run on target system Copy executable “mpac_net_bm” and “mpac_sniffer_app” from the directory mpac_1.2/apps/sniffer/sniffer_MQ_optimized/ on target system target$ ./mpac_net_bm –c <Receiver> –d <duration> –l <# of threads> target$ ./mpac_net_bm –c <Sender> –d <duration> –l <# of threads> -i <IP of Receiver> target$ ./mpac_sniffer_app –n<# of Threads> –d<duration> -f<interface to sniff> -e 3 3-13
Lab 3 – Sniffing (MPAC sniffer version 3) $ ./mpac_sniffer_app -f eth0 -d 30 -e 3 -q 1000 -n <# of Threads> $ ./mpac_sniffer_app -f lo -d 30 -e 3 -q 1000 -n <# of Threads> 3-14