M.Sc. course at the Reichman University
Lecturers and guides of the course:
Prof. Bremler-Barr Anat
Dr. Harchol Yotam
In this assignment, I had to develop a P4 application – a memcached load balancer.
I was supposed to use the Mininet virtual network to simulate a network that contains
two memcached servers and a client host.
The network is presented in the following figure:
Performing load balancing between the two memcached servers.
The client h1 (10.0.1.1) sends memcached UDP requests to its default gateway s1 (10.0.0.1).
The switch flow table should contain rules that direct the memcached requests to one of the
memcached servers h2, h3 (10.0.2.2, 10.0.3.3), each one contains a different set of keys and values.
In this assignment I had to write a P4 code to direct the incoming memcached requests packets
to one of the servers based on the requested key in the UDP packet.
Specifically, I had to apply the following load balancing policy:
Given a key (that we define to always be of length 5 bytes), check the last character of the key.
If it is an even digit, send the request to h2. If it is an odd digit, send it to h3.
If it is not a digit, send it to h2.
So, for example, a request from h1 to 10.0.0.1, with the key “key01” will go to h3,
while requests with the keys “key02” or “other” will go to h2.
We assume that all the requests have keys of length of exactly 5 bytes and we should not
expect or handle other types of requests.
p4c is a reference compiler for the P4 programming language.
It supports both P4-14 and P4-16. My project is in the P4-16 language.
Please follow the instructions at the p4lang/p4c
repository at the followd link:
https://github.com/p4lang/p4c
- In your shell, go to the directory
/home/p4/tutorials/exercises/memcached
, and then run:
Thatmake
make
script should start the mininet environment and open the mininet shell.
- Run h1-h3 nodes with
xterm
command:
Now, you will notice 3 new terminal windows, named h1 to h3.xterm h1 h2 h3
- In the terminal window of h2, type:
That will start the memcached server on h2 and add some entries../start_h2_server.sh
- In the terminal window of h3, do the same thing:
That will also start the memcached server on h3 and add some entries../start_h3_server.sh
- Before we start sending the UDP packets, open a new terminal window and open
wireshark
sudo wireshark
- After the
wireshark
window will open, start capturing packets from s1-eth1, and a new window will open
- Now, in the terminal window of h1, type:
And the result is expected to be the value of key01 in h3../send_memcached_get.sh 10.0.0.1 key01
- If you go back to the
wireshark
s1-eth1 sniffing window, you will notice the packets you've just sent in the window of h1:
- Now stop capturing s1-eth1, and start capturing s1-eth3.
Repeat step 7, with any odd key you like "xxxx1-xxxx9" and now you should see the packets in s1-eth3 as well:
- Likewise, requests for other (existing) keys should yield the corresponding values from the corresponding server,
based on the policy above.
Repeat steps 7 && 9 with new terms: - In order to stop the Mininet, follow the following steps:
For your convinience, I have created simple bash script to run those 2 commands together:
make stop make clean
If you would like to./juststopit.sh
make
again aftermake stop && make clean
, you can just ran another simple bash script I have created for you:
./makeagain.sh
- More info about Memcached:
A. https://memcached.org/
B. http://www.deepness-lab.org/pubs/networking17_loadbalancing.pdf - Mininet:
A. http://mininet.org/walkthrough/ - P4lang:
A. https://github.com/p4lang/tutorials/
B. http://conferences.sigcomm.org/sigcomm/2018/files/slides/hda/paper_2.2.pdf
C. https://opennetworking.org/wp-content/uploads/2020/12/P4_tutorial_01_basics.gslide.pdf
D. https://p4.org/p4-spec/docs/P4-16-v1.0.0-spec.pdf
E. https://p4.org/p4-spec/docs/P4-16-v1.0.0-spec.html