P4RUNTIME GRPC experiment

Posted by ramblix on Tue, 15 Oct 2019 16:25:51 +0200

Read the test documents:

PI/proto/demo_grpc/README.md

Environmental configuration

In this experiment, grpc server opened a web service on port 8888, while my experiment was run in a container on the server, so I couldn't use the browser. So add a port mapping to the container, mapping 18888 to 8888.

#Stop our container
docker stop p4-rt
#Building our new image
docker commit p4-rt p4-rt1
#Add port mapping, using mirror p4-rt1
docker run -it --privileged --name p4-rt1 -p 18888:8888 -v /home/admin/p4-rt:/p4-rt -w /p4-rt p4-rt1 bash 

Compiling our experimental program

#Install lightweight http server Library
apt-get install libmicrohttpd-dev
cd PI/proto/demo_grpc/
./configure --with-proto --with-bmv2
make
make install
#After compilation, four executable files will be generated in this directory.
controller         #grpc client, running a web server with 8888 bit port.
pi_grpc_server     #grpc server of bmv2 target
pi_server_dummy    #grpc server of dummy target
test_perf

By viewing the Makefile.am file, you can know the functions of these files:

ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4

AM_CPPFLAGS = \
-I$(top_srcdir)/../include \
-I$(top_srcdir)/frontend \
-I$(top_srcdir)/server \
-I$(top_builddir)/cpp_out \
-I$(top_builddir)/grpc_out \
-I$(top_srcdir)/p4info

AM_CXXFLAGS = -Wall -Werror -Wno-unused-command-line-argument

noinst_PROGRAMS = controller pi_server_dummy test_perf
#grpc server whose Pi? Server? Dummy is dummy target
pi_server_dummy_SOURCES = pi_server_main.cpp

test_perf_SOURCES = test_perf.cpp
#The controller executable contains the code for the web server and the code for the grpc client
controller_SOURCES = \
simple_router_mgr.cpp \
simple_router_mgr.h \
web_server.cpp \
web_server.h \
app.cpp

COMMON_SERVER_LIBS = \
$(top_builddir)/server/libpigrpcserver.la \
$(top_builddir)/frontend/libpifeproto.la \
$(top_builddir)/libpiprotogrpc.la \
$(top_builddir)/libpiprotobuf.la \
$(top_builddir)/../src/libpiall.la

#grpc server whose Pi is bmv2 target
if WITH_BMV2
bin_PROGRAMS = pi_grpc_server

pi_grpc_server_SOURCES = pi_server_main.cpp

pi_grpc_server_LDADD = \
$(COMMON_SERVER_LIBS) \
$(top_builddir)/../targets/bmv2/libpi_bmv2.la \
-lthrift -lruntimestubs -lsimpleswitch_thrift
endif  # WITH_BMV2

pi_server_dummy_LDADD = \
$(COMMON_SERVER_LIBS) \
$(top_builddir)/../targets/dummy/libpi_dummy.la

test_perf_LDADD = \
$(top_builddir)/../src/libpip4info.la \
$(top_builddir)/libpiprotogrpc.la \
$(top_builddir)/libpiprotobuf.la \
$(top_builddir)/p4info/libpiconvertproto.la \
$(PROTOBUF_LIBS) $(GRPC_LIBS)

controller_LDADD = \
$(top_builddir)/../src/libpip4info.la \
$(top_builddir)/libpiprotogrpc.la \
$(top_builddir)/libpiprotobuf.la \
$(top_builddir)/p4info/libpiconvertproto.la \
-lmicrohttpd $(BOOST_SYSTEM_LIB) \
$(PROTOBUF_LIBS) $(GRPC_LIBS)

Running test cases

Run the test example in the directory pi / proto / demo ﹣ grpc /.

#Follow the instructions of the md file in the directory to execute the following command:
ip link add name veth250 type veth peer name veth251
ip link set dev veth250 up
ip link set dev veth251 up
python 1sw_demo.py --cpu-port veth250
./pi_grpc_server
./controller -c simple_router.json -p simple_router.p4info.txt

controller failed to start, error reported. There is a bug in bmv2 model, and google does not get the desired solution. Instead, it needs to run dummy model next.

dummy model

#Running on a console
./pi_server_dummy
#Running on another console
./controller -c simple_router.json -p simple_router.p4info.txt
#Success

Using web to replace forwarding data surface

Open the browser on a device that can access the physical server and visit our web server: 192.168.1.1:18888. Get the following page:

Select the data face file to be replaced and execute submit.

You can see the following output on the console:

P4Runtime SetForwardingPipelineConfig
[P4Runtime] [warn] p4::tmp::P4DeviceConfig is deprecated
P4Runtime Write
updates {
  type: INSERT
  entity {
    table_entry {
      table_id: 33589124
      match {
        field_id: 1
        exact {
          value: "\000\000\000\000"
        }
      }
      action {
        action {
          action_id: 16784184
        }
      }
    }
  }
}
P4Runtime Write
updates {
  type: INSERT
  entity {
    table_entry {
      table_id: 33581985
      match {
        field_id: 1
        lpm {
          value: "\n\000\000\n"
          prefix_len: 32
        }
      }
      action {
        action {
          action_id: 16812204
          params {
            param_id: 1
            value: "\n\000\000\n"
          }
          params {
            param_id: 2
            value: "\000\001"
          }
        }
      }
    }
  }
}
P4Runtime Write
updates {
  type: INSERT
  entity {
    table_entry {
      table_id: 33581985
      match {
        field_id: 1
        lpm {
          value: "\n\000\001\n"
          prefix_len: 32
        }
      }
      action {
        action {
          action_id: 16812204
          params {
            param_id: 1
            value: "\n\000\001\n"
          }
          params {
            param_id: 2
            value: "\000\002"
          }
        }
      }
    }
  }
}
P4Runtime Write
updates {
  type: INSERT
  entity {
    table_entry {
      table_id: 33562826
      match {
        field_id: 1
        exact {
          value: "\000\001"
        }
      }
      action {
        action {
          action_id: 16813016
          params {
            param_id: 1
            value: "\000\252\273\000\000\000"
          }
        }
      }
    }
  }
}
P4Runtime Write
updates {
  type: INSERT
  entity {
    table_entry {
      table_id: 33562826
      match {
        field_id: 1
        exact {
          value: "\000\002"
        }
      }
      action {
        action {
          action_id: 16813016
          params {
            param_id: 1
            value: "\000\252\273\000\000\001"
          }
        }
      }
    }
  }
}
P4Runtime SetForwardingPipelineConfig
[P4Runtime] [warn] p4::tmp::P4DeviceConfig is deprecated

Topics: Linux P4 Docker Web Server JSON