[P4-dev] P4Runtime with bmv2 support

cs.lev cs.lev at gmx.com
Thu Jul 26 06:20:32 EDT 2018


Dear Antontin,

Thanks for the quick response.
I have checked what you have said, and it seems to be OK from my
perspective.
I found out that maybe some versioning issue could be the main cause (I
am experimenting with ubuntu:16.04), and the grpcio module from the pip
repository might be too old, but the the grpc repository, (as said
before) failed to be compiled properly.

I have restarted the whole process on an ubuntu:18.04, but now I have
encountered to have too new packages (that's my luck :D), and ran into
this issue:
https://github.com/p4lang/tutorials/issues/114

Just for letting everyone to know about this, doing the following steps
after the steps in my previous email (compiling, modifying python
source codes with p4 ->p4.v1, etc.) solved the issue (at least for now
- read table and insert functions are working):

I have manually copied the related p4*_grpc.py files from
/PI/proto/py_out/p4/ to the related /usr/local/lib/python2.7/dist-
packages/p4/.

$ sudo cp <yourPI>/proto/py_out/p4/config/v1/*_grpc.py
/usr/local/lib/python2.7/dist-packages/p4/config/v1/

$ sudo cp <yourPI>/proto/py_out/p4/v1/*_grpc.py
/usr/local/lib/python2.7/dist-packages/p4/v1/

Then, modify the switch.py in the controller's p4runtime_lib as follows
(only the relevant part is included):
from p4.v1 import p4runtime_pb2_grpc as p4runtime_pb2_grpc
from p4.v1 import p4runtime_pb2

from p4.tmp import p4config_pb2

class SwitchConnection(object):
    def __init__(self, name, address='127.0.0.1:50051', device_id=0):
        self.name = name
        self.address = address
        self.device_id = device_id
        self.p4info = None
        self.channel = grpc.insecure_channel(self.address)
        self.client_stub =
p4runtime_pb2_grpc.P4RuntimeStub(self.channel)

If you completely replace p4runtime_pb2 with its _grpc counterpart, it
still won't work. The main issue only happened (again, for now - e.g.
helper.py did not needed such a change) in the connection function, so
the rest could have remained the same.


Best,
cslev






On Wed, 2018-07-25 at 12:05 -0700, Antonin Bas wrote:
> As per the P4Runtime spec, a controller must become master by doing
> the appropriate handshake on the P4Runtime StreamChannel before it
> can do a Write or SetForwardingPipelineConfig RPC.
> It looks like this code is performing the handshake: https://github.c
> om/p4lang/tutorials/blob/master/utils/p4runtime_lib/switch.py#L58
> I recommend making sure that the handshake is done correctly and
> checking that the election_id advertised on the StreamChannel matches
> the one in the RPC which errors.
> 
> On Wed, Jul 25, 2018 at 7:19 AM, cs.lev <cs.lev at gmx.com> wrote:
> > Dear Antonin,
> > 
> > I have spent again several days of putting all pieces together, and
> > I
> > believe I am very close to a working solution.
> > I have followed your instructions and recompiled everything
> > accordingly.
> > 
> > For just a python based p4runtime controller, I have install
> > protobuf,
> > and grpc, then PI.
> > Everything went fine.
> > 
> > Python controller code from the p4lang/tutorial repository has been
> > adopted, and the concerned 'v1' issue before was address by putting
> > it
> > in the right place:
> > in switch.py:
> > from p4 import p4runtime_pb2 -> from p4.v1 import p4runtime_pb2
> > 
> > in bmv2.py:
> > nothing was needed to be changed
> > 
> > in helper.py
> > from p4 import p4runtime_pb2
> > from p4.config import p4info_pb2 
> >             |
> >            \ /
> > from p4.v1 import p4runtime_pb2
> > from p4.config.v1 import p4info_pb2
> > 
> > Then, the python controller application was only compiled about
> > missing
> > grpc, grpcio, and protobuf python package.
> > Since the corresponding python packages installable from grpc and
> > protobuf repository were not working (complaining about missing
> > argument grpc.UnaryUnaryClientInterceptor), I have let 'pip' do the
> > job, which indeed did.
> > pip install grpc
> > pip install grpcio
> > pip install protobuf
> > 
> > I have checked, and pip was installing the right version of the
> > libraries (1.3.2, 3.2, respectively).
> > 
> > Then, all modules were found, I still got this error:
> >     if match_type == p4info_pb2.MatchField.VALID:
> > AttributeError: type object 'MatchField' has no attribute 'VALID'
> > 
> > I have realized that it is just the part of the helper.py source,
> > and
> > among matchin types LPM, EXACT, etc. I have just commented the
> > corresponding lines matching on VALID type.
> > 
> > This error also disappeared, but now I got this:
> > 
> > File "/usr/local/lib/python2.7/dist-packages/grpc/_channel.py",
> > line
> > 448, in _end_unary_response_blocking
> >     raise _Rendezvous(state, None, None, deadline)
> > grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated
> > with:
> >         status = StatusCode.PERMISSION_DENIED
> >         details = "Not master"
> >         debug_error_string =
> > "{"created":"@1532528239.124242815","description":"Error received
> > from
> > peer","file":"src/core/lib/surface/call.cc","file_line":1083,"grpc_
> > mess
> > age":"Not master","grpc_status":7}"
> > 
> > I have also tried to compile and run the controller libraries on
> > the
> > same machine where the switch is running to avoid any firewall-ish
> > problem, but the case is still there.
> > 
> > Any thoughts on how to resolve this?
> > 
> > Thank you,
> > cslev
> > 
> > 
> > 
> > On Wed, 2018-07-18 at 13:47 -0700, Antonin Bas wrote:
> > > 1) I think the instructions in the simple_switch_grpc are pretty
> > > comprehensive regarding how to install everything.
> > > 
> > > 2) If you want to use P4Runtime, you probably want to use
> > > simple_switch_grpc and not simple_switch.  You definitely do not
> > need
> > > to compile PI with --with-bmv2.
> > > 
> > > 3) The fact that all Python packages are installed under a v1/
> > > directory has nothing to do with bmv1 vs bmv2. We decided to add
> > the
> > > major semantic version number to the P4Runtime Protobuf package
> > path
> > > in accordance with best practices for deploying cloud APIs. We
> > are
> > > working on P4Runtime v1.0.0, so the major version number is 1 and
> > the
> > > Protobuf package therefore includes v1.
> > > 
> > > 4) You should be able to look at the tutorial code for directions
> > on
> > > how to use P4Runtime (of course you should probably also read the
> > > specification). Apart from the package name (p4 -> p4.v1 and
> > > p4.config -> p4.config.v1), things should be pretty much the
> > same.
> > > 
> > > On Wed, Jul 18, 2018 at 5:16 AM, cs.lev <cs.lev at gmx.com> wrote:
> > > > Regarding to developing own control-plane code, I used the
> > latest
> > > > version of PI (only grpc and protobufs are not up-to-dates as
> > the
> > > > installation instructions sticked to certain tags, e.g., 3.2),
> > bmv2
> > > > and
> > > > p4c.
> > > > 
> > > > On the other hand, what I want is to control bmv2 softswitch
> > via
> > > > P4runtime (from a Python application if possible), so I guess I
> > > > would
> > > > need bmv2 support (without it, the python bindings will
> > definitely
> > > > be
> > > > only for v1 (located under /usr/lib/...dist-packages/.../v1 as
> > in
> > > > my
> > > > previous mail).
> > > > 
> > > > Thus, I should compile PI with --with-bmv2 configuration, which
> > > > requires nanosmg, thrift, etc.
> > > > After doing so, and PI has found all libraries, I still find
> > python
> > > > bindings under directory /usr/local/lib/python2.7/dist-
> > > > packages/p4/config/v1/.
> > > > 
> > > > Maybe this version would be OK to control the bmv2, but if it
> > is
> > > > not
> > > > the same (and working) version that the tutorial VM image has
> > used,
> > > > then is there any API documentation on how to build a Python-
> > based
> > > > P4runtime controller?
> > > > 
> > > > Or is there any other tutorial in any kind of language showing
> > > > examples
> > > > of basic API calls to control the bmv2 with P4runtime?
> > > >  - I have only found some youtube videos about ONOS and its
> > > > p4runtime
> > > > support but nothing else that would really help :S
> > > > 
> > > > Thank you,
> > > > cslev
> > > > 
> > > > 
> > > > On Tue, 2018-07-17 at 10:09 -0700, Antonin Bas wrote:
> > > > > If you want to use simple_switch_grpc, you need to follow the
> > > > steps
> > > > > in the README (https://github.com/p4lang/behavioral-model/tre
> > e/ma
> > > > ster
> > > > > /targets/simple_switch_grpc) and install PI without bmv2
> > support
> > > > (I
> > > > > believe --without-bmv2 is the default actually so the flag
> > could
> > > > > simply be omitted).
> > > > > 
> > > > > All of your problems seem to come from the fact that you want
> > to
> > > > use
> > > > > the tutorials repo with the latest versions of PI & bmv2 &
> > p4c.
> > > > When
> > > > > we release a new version of the tutorials, we use a "frozen"
> > > > version
> > > > > of the dependencies. So if you want to use the tutorials you
> > have
> > > > to
> > > > > use the appropriate versions, as advertised here: https://git
> > hub.
> > > > com/
> > > > > p4lang/tutorials/blob/master/vm/user-bootstrap.sh#L8
> > > > > If you want to develop your own control-plane code, feel free
> > to
> > > > use
> > > > > the latest version of PI & bmv2 & p4c as they should work
> > fine
> > > > > together, but don't expect the tutorial exercises to work
> > with
> > > > these.
> > > > > 
> > > > > On Tue, Jul 17, 2018 at 8:21 AM, cs.lev <cs.lev at gmx.com>
> > wrote:
> > > > > > Dear all,
> > > > > > 
> > > > > > I would like to have proper P4Runtime support on a bare-
> > metal
> > > > > > server, with all its python bindings to write my own
> > > > controllers.
> > > > > > 
> > > > > > I have run into the following issue during configuring and
> > > > > > compiling related libraries.
> > > > > > 
> > > > > > First of all, I found there is a cyclic dependency between
> > bmv2
> > > > and
> > > > > > PI (but correct me if I am wrong), as bmv2 can be compiled
> > with
> > > > PI
> > > > > > support (--with-pi) which needs the PI libraries to be
> > > > installed in
> > > > > > order to compile afterwards the simple_switch_grpc binary.
> > > > > > However, to support bmv2 in PI, during its installation, it
> > > > > > requires bmv2 and its libraries.
> > > > > > 
> > > > > > As a workaround, first I compiled PI without bmv2 support,
> > then
> > > > > > compiled bmv2 with PI support, and finally I recompiled PI
> > with
> > > > > > bmv2 support.
> > > > > > Everything seemed to be OK, as compilation ended without
> > errors
> > > > and
> > > > > > simple_switch_grpc could have been run.
> > > > > > 
> > > > > > After trying to test (a modified version of the) p4runtime
> > > > example
> > > > > > (originally tailored to the mininet environment) from
> > > > > > p4lang/tutorial,
> > > > > > the python based controller has complained about missing
> > > > modules.
> > > > > > After a lot of googling, debugging, and comparing ENV
> > variables
> > > > of
> > > > > > the p4tutorial’s VM and my bare metal installation, I have
> > > > found
> > > > > > that the libraries the python modules are looking for
> > should be
> > > > in
> > > > > > /usr/local/lib/python2.7/dist-packages/p4/.
> > > > > > 
> > > > > > However, the PI installation on the bare metal put all
> > > > libraries
> > > > > > into /usr/local/lib/python2.7/dist-packages/p4/v1, 
> > > > > > even though the configure parameter --with-bmv2 should have
> > > > > > indicated to the compilation process to not put the
> > > > corresponding
> > > > > > libraries in such a subdirectory (v1).
> > > > > > 
> > > > > > In the beginning, it seemed a good idea to do the
> > following:
> > > > > > 
> > > > > > $ cp /usr/local/lib/python2.7/dist-packages/p4/v1/*
> > > > > > /usr/local/lib/python2.7/dist-packages/p4/
> > > > > > 
> > > > > > $ cp  /usr/local/lib/python2.7/dist-packages/p4/config/v1/*
> > > > > > /usr/local/lib/python2.7/dist-packages/p4/config/
> > > > > > Then, the controller application was now complaining about
> > > > missing
> > > > > > modules.
> > > > > > So, it indeed seemed to be a good workaround...
> > > > > > 
> > > > > > 
> > > > > > BUT, (if you are still with me :)), the interesting parts
> > > > started
> > > > > > to show up.
> > > > > > The controller could connect to the switch and even the
> > > > > > readTableRules(p4info_helper,switch) function could have
> > been
> > > > > > called and returned without errors.
> > > > > > 
> > > > > > At this point, I still believed that everything is working,
> > > > however
> > > > > > when I tried to insert flow rules into my switch, the
> > > > controller
> > > > > > raised the following error:
> > > > > >   File "controller.py", line 86, in main
> > > > > >     output_port='0')
> > > > > >   File "controller.py", line 23, in addIPforwardRule
> > > > > >     "port": 1,
> > > > > >   File
> > > > > >
> > > >
> > "/home/csikor/p4/p4_vlan/p4runtime_controller/p4runtime_lib/helper.
> > > > > > py", line 173, in buildTableEntry
> > > > > >     for match_field_name, value in match_fields.iteritems()
> > > > > >   File
> > > > > >
> > > >
> > "/home/csikor/p4/p4_vlan/p4runtime_controller/p4runtime_lib/helper.
> > > > > > py", line 100, in get_match_field_pb
> > > > > >     if match_type == p4info_pb2.MatchField.VALID:
> > > > > > AttributeError: type object 'MatchField' has no attribute
> > > > 'VALID'
> > > > > > 
> > > > > > 
> > > > > > The rule inserting source code had no issues in the mininet
> > > > > > environment, but for a comprehensive view I include the
> > > > relevant
> > > > > > part of it below:
> > > > > > def addIPforwardRule(p4info_helper, sw):
> > > > > > table_entry = p4info_helper.buildTableEntry(
> > > > > > table_name="MyIngress.ipv4_lpm",
> > > > > > match_fields={
> > > > > > "hdr.ipv4.dstAddr": ("10.0.0.1", 32)
> > > > > > },
> > > > > > action_name="MyIngress.ipv4_forward",
> > > > > > action_params={
> > > > > > "port": 1
> > > > > > })
> > > > > > sw.WriteTableEntry(table_entry)
> > > > > > 
> > > > > > 
> > > > > > Later on, I have found out that in contrast to other python
> > > > > > modules, the p4info_pb2 library that I have used (copied
> > from
> > > > > > /usr/local/lib/python2.7/dist-packages/p4/config/v1) is not
> > the
> > > > > > same as it was in the p4lang/tutorial's VM's python
> > modules,
> > > > which
> > > > > > of course is somewhat expected.
> > > > > > 
> > > > > > In order to do a workaround again, as a last resort I have
> > > > copied
> > > > > > all the python libraries for P4runtime from the VM's
> > > > > > /usr/local/lib/python2.7/dist-packages/p4/ directory to the
> > > > same
> > > > > > place at my bare metal server, but now I get a
> > UNIMPLEMENTED
> > > > error
> > > > > > :)
> > > > > > 
> > > > > >   File "controller.py", line 95, in
> > > > > >
> > > >
> > main    s.SetForwardingPipelineConfig(p4info=p4info_helper.p4info,
> > > > > > bmv2_json_file_path=bmv2_file_path)  
> > > > > >   File
> > > > > >
> > > >
> > "/home/csikor/p4/p4_vlan/p4runtime_controller/p4runtime_lib/switch.
> > > > > > py", line 45, in
> > > > > >
> > > >
> > SetForwardingPipelineConfig    self.client_stub.SetForwardingPipeli
> > > > > > neConfig(request)  
> > > > > >   File "/usr/local/lib/python2.7/dist-
> > > > packages/grpc/_channel.py",
> > > > > > line 492, in __call__    return
> > > > _end_unary_response_blocking(state,
> > > > > > call, False, deadline)  
> > > > > >   File "/usr/local/lib/python2.7/dist-
> > > > packages/grpc/_channel.py",
> > > > > > line 440, in _end_unary_response_blocking    
> > > > > > 
> > > > > >   raise _Rendezvous(state, None, None,
> > > > > > deadline)grpc._channel._Rendezvous: <_Rendezvous of RPC
> > that
> > > > > > terminated with (StatusCode.UNIMPLEMENTED, )>
> > > > > > 
> > > > > > I guess some of the installation steps should be revisited,
> > but
> > > > can
> > > > > > someone explain me in which order and how should I proceed
> > with
> > > > the
> > > > > > installation of the libraries to have the same environment
> > as
> > > > the
> > > > > > VM has?
> > > > > > Or what else can I do?
> > > > > > 
> > > > > > Thank you for considering my request.
> > > > > > 
> > > > > > BR,
> > > > > > Levi
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > _______________________________________________
> > > > > > P4-dev mailing list
> > > > > > P4-dev at lists.p4.org
> > > > > > http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org
> > > > > > 
> > > > > 
> > > > > 
> > > > > 
> > > > > -- 
> > > > > Antonin
> > > > 
> > > 
> > > 
> > > 
> > > -- 
> > > Antonin
> > 
> 
> 
> 
> -- 
> Antonin



More information about the P4-dev mailing list