GlaiChen / p4lang_memcached_load_balancer

Assignment at "Advanced Topics in Networks" course

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Advanced Topics in IP Networks"

M.Sc. course at the Reichman University

Lecturers and guides of the course:
Prof. Bremler-Barr Anat
Dr. Harchol Yotam

p4lang_memcached_load_balancer

Introduction

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:


The Goal

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.

Installing p4c compiler

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

Running the project

  1. In your shell, go to the directory /home/p4/tutorials/exercises/memcached, and then run:

    make
    That make script should start the mininet environment and open the mininet shell.



  2. Run h1-h3 nodes with xterm command:

    xterm h1 h2 h3
    Now, you will notice 3 new terminal windows, named h1 to h3.



  3. In the terminal window of h2, type:

    ./start_h2_server.sh
    That will start the memcached server on h2 and add some entries.



  4. In the terminal window of h3, do the same thing:

    ./start_h3_server.sh
    That will also start the memcached server on h3 and add some entries.

  5. Before we start sending the UDP packets, open a new terminal window and open wireshark

    sudo wireshark
  6. After the wireshark window will open, start capturing packets from s1-eth1, and a new window will open



  7. Now, in the terminal window of h1, type:

    ./send_memcached_get.sh 10.0.0.1 key01
    And the result is expected to be the value of key01 in h3.



  8. 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:



  9. 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:



  10. 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:
    • Start capturing s1-eth2
    • Send even keys (xxxx0-xxxx8) / other keys which aren't odd keys.
      You should see in your wireshark sniffing window the following results:



  11. In order to stop the Mininet, follow the following steps:
    make stop
    make clean
    For your convinience, I have created simple bash script to run those 2 commands together:
    ./juststopit.sh
    If you would like to make again after make stop && make clean , you can just ran another simple bash script I have created for you:
    ./makeagain.sh

References

  1. More info about Memcached:
    A. https://memcached.org/
    B. http://www.deepness-lab.org/pubs/networking17_loadbalancing.pdf
  2. Mininet:
    A. http://mininet.org/walkthrough/
  3. 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

About

Assignment at "Advanced Topics in Networks" course


Languages

Language:P4 86.3%Language:Shell 13.7%