当前位置: 首页 > Linux

P4RUNTIMEGRPC实验

时间:2023-04-06 06:41:31 Linux

参考文档:PI/proto/demo_grpc/README.md环境配置由于本次实验grpc服务器在8888端口开启了web服务,而我的实验运行在服务器上的容器中,无法使用浏览器.所以这里给容器添加一个端口映射,把18888映射到8888。--privileged--namep4-rt1-p18888:8888-v/home/admin/p4-rt:/p4-rt-w/p4-rtp4-rt1bash编译我们的实验程序#安装轻量级http服务器库apt-getinstalllibmicrohttpd-devcdPI/proto/demo_grpc/./configure--with-proto--with-bmv2makemakeinstall#编译后会在该目录下生成四个可执行文件。controller#grpc客户端运行一个端口为8888的Web服务器。pi_grpc_server#bmv2target的grpcserverpi_server_dummy#dummytarget的grpcservertest_perf查看Makefile.am文件可以知道这几个文件的作用:ACLOCAL_AMFLAGS=${ACLOCAL_FLAGS}-Im4AM_CPPFLAGS=\-I$(top_srcdir)/../包括\-I$(top_srcdir)/frontend\-I$(top_srcdir)/server\-I$(top_builddir)/cpp_out\-I$(top_builddir)/grpc_out\-I$(top_srcdir)/p4infoAM_CXXFLAGS=-Wall-Werror-Wno-unused-command-line-argumentnoinst_PROGRAMS=controllerpi_server_dummytest_perf#pi_server_dummyisthegrpcserverfordummytargetpi_server_dummy_SOURCES=pi_server_main.cpptest_perf_SOURCES=test_perf.cpp#controller可执行文件包含web服务器代码和grpc客户端代码controller_SOURCES=\simple_router_mgr.cpp\simple_router_mgr.h\web_server.cpp\web_server.h\app.cppCOMMON_SERVER_LIBS=\$(top_builddir)/server/libpigrpcserver.la\$(top_builddir)/frontend/libpifeproto.la\$(top_bu)/libpiprotogrpc.la\$(top_builddir)/libpiprotobuf.la\$(top_builddir)/../src/libpiall.la#pi_grpc_server是bmv2target的grpcserverifWITH_BMV2bin_PROGRAMS=pi_grpc_serverpi_grpc_server_SOURCES=pi_server_main.cpppi_grpc_server_LDADD=\$(COMMON_SERVER_LIBS)\$(top_builddir)/../targets/bmv2/libpi_bmv2.la\-lthrift-lruntimestubs-lsimpleswitch_thriftendif#WITH_BMV2pi_server_dummy_LDADD=\$(COMMON_SERVER_LIBS)\$(top_builddir)/../targets/dummy/libpi_dummy.latest_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)运行测试用例运行PI/proto/demo_grpc/目录下的测试用例:#按照md文件的说明操作在该目录下执行以下命令:iplinkaddnameveth250typevethpeernameveth251iplinksetdevveth250upiplinksetdevveth251uppython1sw_demo.py--cpu-portveth250./pi_grpc_server./controller-csimple_router.json-psimple_router.p4info.txtcontroller无法启动,bmv2模型有bug,谷歌没有得到想要的解决方案,退而求其次是运行dummy模型。dummymodel#在一个控制台上运行。/pi_server_dummy#在另一个控制台上运行。/controller-csimple_router.json-psimple_router.p4info.txt#在可以访问物理服务器的服务器上成功使用web转发数据平面更换打开设备上的浏览器并访问我们的网络服务器:192.168.1.1:18888。得到如下页面:选择需要替换的数据平面文件,执行提交,在控制台看到如下输出:table_entry{table_id:33589124match{field_id:1exact{value:"\000\000\000\000"}}action{action{action_id:16784184}}}}}P4RuntimeWriteupdates{type:INSERTentity{table_entry{table_id:33581985mfield_id:1lpm{value:"\n\000\000\n"prefix_len:32}}action{action{action_id:16812204params{param_id:1value:"\n\000\000\n"}params{param_id:2value:"\000\001"}}}}}}P4RuntimeWriteupdates{type:INSERTentity{table_entry{table_id:33581985match{field_id:1lpm{value:"\n\000\001\n"prefix_len:32}}action{action{action_id:16812204params{param_id:1value:"\n\000\001\n"}params{param_id:2value:"\000\002"}}}}}}P4RuntimeWriteupdates{type:INSERTentity{table_entry{table_id:33562826match{field_id:1exact{value:"\000\001"}}action{action{action_id:16813016params{param_id:1value:"\000\252\273\000\000\000"}}}}}}P4RuntimeWriteupdates{type:INSERTentity{table_entry{table_id:33562826match{field_id:1确切{值:“\000\002”}}动作{动作{action_id:16813016params{param_id:1value:"\000\252\273\000\000\001"}}}}}P4RuntimeSetForwardingPipelineConfig[P4Runtime][警告]p4::tmp::P4DeviceConfig已弃用