p4lang / tutorials

P4 language tutorials
Apache License 2.0
1.33k stars 878 forks source link

The thrift server did not start in the basic.p4 exercise even when configuring simple_switch_grpc with the "--with-thrift" option. #536

Closed castilhorosa closed 9 months ago

castilhorosa commented 9 months ago

Hi,

I'm using the P4 tutorial image (version 2023-11-01) to run the basic.p4 exercise. I would like to invoke the command set_queue_depth using the thrift server since, as far as I know, it's not possible to do it in P4Runtime. I tried to connect to thrift server on port 9090 after the mininet CLI showed up, but it seems that thrift server is not running at all. I've configured (./configure) both bmv2 and simple_switch_grpc with the "--with-thrift" option as @antoninbas mentioned here https://github.com/p4lang/PI/issues/333#issuecomment-377981446 but the netstat command did not show any service on port 9090. What else should I do to enable thrift server to set the queue's depth using the simple_switch_CLI? Do I need to include some other parameters somewhere?

jafingerhut commented 9 months ago

I just downloaded the 2023-11-01 version of the Development version of the P4 Tutorials pre-built VM image from this page: https://github.com/jafingerhut/p4-guide/blob/master/bin/README-install-troubleshooting.md

I started it up and ran these commands in a terminal from the user account p4:

cd tutorials/exercises/basic
cp solution/basic.p4 .
make run

I am omitting the many lines of output that appear after that, but soon afterwards it stops with a prompt mininet>

Then I created a separate terminal window to try out some other commands. For example:

ps axguwww | grep simple_switch_grpc

This shows there were 3 simple_switch_grpc processes running. In the example of one of those lines of output pasted below, you can see that it has the command line option --thrift-port 9090:

root        2470  0.3  2.5 1230352 51740 pts/5   Sl+  03:24   0:01 simple_switch_grpc -i 1@s1-eth1 -i 2@s1-eth2 -i 3@s1-eth3 -i 4@s1-eth4 --pcap /home/p4/tutorials/exercises/basic/pcaps --nanolog ipc:///tmp/bm-0-log.ipc --device-id 0 build/basic.json --log-console --thrift-port 9090 -- --grpc-server-addr 0.0.0.0:50051

If I run the following netstat -a command and pipe its output through grep, it finds a line of output mentioning TCP port 9090:

$ netstat -a | grep 9090
tcp6       0      0 [::]:9090               [::]:*                  LISTEN   

There are other simple_switch_grpc processes running that are listening on other TCP ports like 9091 and 9092, and they also show up in the output of similar commands to grep for those numbers in the (long) output of netstat -a.

Do you see different output from similar commands run on your system?

castilhorosa commented 9 months ago

After the mininet prompt shows up, I type ps axguwww | grep simple_switch_grpc in another terminal as you mention and I got this:

root 58998 0.0 0.1 9684 4632 pts/0 S+ 13:14 0:00 sudo python3 ../../utils/run_exercise.py -t pod-topo/topology.json -j build/basic.json -b simple_switch_grpc root 58999 0.6 0.8 405752 33888 pts/0 Sl+ 13:14 0:00 python3 ../../utils/run_exercise.py -t pod-topo/topology.json -j build/basic.json -b simple_switch_grpc root 59191 0.3 1.2 1206744 49064 pts/6 Sl+ 13:14 0:00 simple_switch_grpc -i 1@s1-eth1 -i 2@s1-eth2 -i 3@s1-eth3 -i 4@s1-eth4 --pcap /home/p4/tutorials/exercises/basic/pcaps --nanolog ipc:///tmp/bm-0-log.ipc --device-id 0 build/basic.json --thrift-port 9090 -- --grpc-server-addr 0.0.0.0:50051 root 59206 0.3 1.2 1206744 48636 pts/7 Sl+ 13:14 0:00 simple_switch_grpc -i 1@s2-eth1 -i 2@s2-eth2 -i 4@s2-eth4 -i 3@s2-eth3 --pcap /home/p4/tutorials/exercises/basic/pcaps --nanolog ipc:///tmp/bm-1-log.ipc --device-id 1 build/basic.json --thrift-port 9091 -- --grpc-server-addr 0.0.0.0:50052 root 59221 0.2 1.0 1198032 40516 pts/8 Sl+ 13:14 0:00 simple_switch_grpc -i 1@s3-eth1 -i 2@s3-eth2 --pcap /home/p4/tutorials/exercises/basic/pcaps --nanolog ipc:///tmp/bm-2-log.ipc --device-id 2 build/basic.json --thrift-port 9092 -- --grpc-server-addr 0.0.0.0:50053 root 59236 0.2 1.0 1198032 40800 pts/9 Sl+ 13:14 0:00 simple_switch_grpc -i 2@s4-eth2 -i 1@s4-eth1 --pcap /home/p4/tutorials/exercises/basic/pcaps --nanolog ipc:///tmp/bm-3-log.ipc --device-id 3 build/basic.json --thrift-port 9093 -- --grpc-server-addr 0.0.0.0:50054 p4 59309 0.0 0.0 6436 656 pts/1 S+ 13:14 0:00 grep --color=auto simple_switch_grpc

However, when I type netstat -a | grep 9090, I see nothing in the screen. It seems there is no process running in on port 9090. Therefore, when I try to connect to thrift server using the command ./simple_switch_CLI --thrift-port 9090 in /usr/local/bin I got:

Could not connect to any of [('127.0.0.1', 9090)] Could not connect to thrift client on port 9090 Make sure the switch is running and that you have the right port

When I type netstat -a | more I got this:

p4@p4:/usr/local/bin$ netstat -a | more Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:domain 0.0.0.0: LISTEN
tcp 0 0 0.0.0.0:ssh 0.0.0.0:
LISTEN
tcp 0 0 localhost:ipp 0.0.0.0: LISTEN
tcp6 0 0 [::]:50051 [::]:
LISTEN
tcp6 0 0 [::]:50052 [::]: LISTEN
tcp6 0 0 [::]:50053 [::]:
LISTEN
tcp6 0 0 [::]:50054 [::]: LISTEN
tcp6 0 0 [::]:ssh [::]:
LISTEN
tcp6 0 0 ip6-localhost:ipp [::]: LISTEN
tcp6 0 0 127.0.0.1:50054 127.0.0.1:38696 ESTABLISHED tcp6 0 0 127.0.0.1:37448 127.0.0.1:50051 ESTABLISHED tcp6 0 0 127.0.0.1:50053 127.0.0.1:33346 ESTABLISHED tcp6 0 0 127.0.0.1:50051 127.0.0.1:37448 ESTABLISHED tcp6 0 0 127.0.0.1:47578 127.0.0.1:50052 ESTABLISHED tcp6 0 0 127.0.0.1:50052 127.0.0.1:47578 ESTABLISHED tcp6 0 0 127.0.0.1:33346 127.0.0.1:50053 ESTABLISHED tcp6 0 0 127.0.0.1:38696 127.0.0.1:50054 ESTABLISHED udp 0 0 localhost:domain 0.0.0.0:

udp 0 0 p4:bootpc 0.0.0.0:
raw6 0 0 [::]:ipv6-icmp [::]:
7

jafingerhut commented 9 months ago

I do not know why we are seeing different behavior, but when I run that pre-built VM that I publish, I get the behavior that I showed.

castilhorosa commented 9 months ago

@jafingerhut, maybe it's because you used the pre-built VM image without any modifications. In my case, I had to recompile the bmv2 to get better throughput using the commands below.

cd /home/vagrant/behavioral-model/ ./autogen.sh ./configure 'CXXFLAGS=-g -O3' 'CFLAGS=-g -O3' --with-thrift --with-pi --disable-logging-macros --disable-elogger make sudo make install sudo ldconfig cd targets/ cd simple_switch_grpc/ ./configure --with-thrift make sudo make install

I included the option --with-thrift in ./configure of bmv2, different from what is recommended here https://github.com/p4lang/tutorials/issues/303#issuecomment-551174766 Maybe I should not do that.

Another observation is that I can not type ./autogen.sh inside the simple_switch_grpc directory as recommended because, for some reason, the file does not exist in such a directory. I'm not sure if these nuances is causing the problem.

I tested it in the P4 Tutorial Release 2023-08-23 and it worked. However, in such a version I don't have the source code available to rebuild bmv2 to optimize throughput.

jafingerhut commented 9 months ago

Here is the part of the script that is used to build behavioral-model from source code, included as part of the P4 Tutorials Development VM images: https://github.com/p4lang/p4c/issues/2310

./autogen.sh
./configure --enable-debugger --with-pi --with-thrift
make -j${NUM_CORES}
sudo make install-strip
sudo ldconfig

Note that there is no need to run any commands inside of a simple_switch_grpc directory, since about a year or so ago.

antoninbas commented 9 months ago

Andy is correct, you no longer need to run configure manually in targets/simple_switch_grpc.

Additionally, when running configure with a new set of flags, you may need to run make clean before running make.

castilhorosa commented 9 months ago

It worked. I run make clean before running make. Thanks @jafingerhut and @antoninbas.

jafingerhut commented 9 months ago

Closing this issue, as perhaps the questions have been answered. Feel free to reopen if not, create a new issue, and/or to post questions to https://forum.p4.org