[P4-dev] What happens during table miss?

Antonin Bas antonin at barefootnetworks.com
Tue Jul 21 21:00:28 EDT 2015


Hi Archie,

I just wanted to complete Antoine's answer.
The CLI is the highest level way of populating match-action tables. The CLI
itself uses Python code which calls into the C PD library through RPC. The
PD library then calls target-specific APIs to populate the tables. And
because a chart is better than a long sentence:

CLI ---> Python RPC client code ---> C++ RPC server code ---> C PD library
---> behavioral model

We use Thrift to build the RPC client / server code:
https://thrift.apache.org/
In a nutshell, the p4c-behavioral compiler generates the PD library as well
as the Thrift IDL. We then run the Thrift compiler on this IDL to produce
the C++ server code and the client code. The CLI uses the generated Python
client code and Python's reflection abilities to provide a high-level way
of programming the data plane.

Note that the CLI, the RPC interface and the C PD API are supposed to be
target independent (to some extent), unlike the behavioral-model's APIs, so
you should use these.

A few use cases:
- we use the Python RPC client code in our unit tests:
https://github.com/p4lang/p4factory/blob/master/targets/l2_switch/of-tests/tests/l2_switch.py.
For example, you will see a call to mcast_src_pruning_table_add_with__drop,
which adds an entry to the mcast_src_pruning table with action _drop.
- as mentioned above, the CLI uses the Python RPC client code
- our switchapi high-level application (https://github.com/p4lang/switchapi),
which supports most L2/L3 networking features, uses the C PD library
directly.
- Thrift lets you generate client bindings in a large number of different
languages. One person at the P4 workshop had Thrift generate Haskell
binding to integrate with his controller.

If you are interested in using the C PD library directly, run 'make' in one
of the p4factory targets and take a look at the generated header file:
build/inc/p4_sim/pd.h. Using the PD library directly means linking your
application directly with the behavioral-model binary to run them as one
process. It may be easier to use the Thrift generated client code. Look at
of-tests/pd_thrift/ for the generate code and at our unit test to see how
we use this code.

It is a very broad topic, so let me know of you have specific questions on
how to achieve something.

Antonin

On Mon, Jul 20, 2015 at 5:10 PM, Antoine Kaufmann <
antoinek at cs.washington.edu> wrote:

> Unfortunately I don't know the switch implemented in p4factory in
> detail. Depending on what you want to do, you could use p4c-behavioral
> directly (that contains the part that generates C code from a P4 program
> to execute the packet processing pipeline. The generated C code then has
> functions you can call to hand it packets, and callbacks you need to set
> for sending out packets. There are also functions to manage the table
> entries. This gets fairly close to what you would have running on a
> switch CPU for managing a switch chip.
>
> If you are interested I have some code laying around for some simple
> P4 examples that takes the p4c-behavioral output, attaches it to
> ethernet devices using PCAP and adds some table entries on
> initialization and in response to packets that the packet processing
> pipeline forwards to "the CPU".
>
> Hope this helps.
>
> Cheers
> Antoine
>
> On Thu, Jul 16 19:02, Archie wrote:
> > Thanks for the reply. I have one more question. In openflow, the packet
> > specific rule, i.e. rules with values are installed in switches by the
> > controller. From the example given here
> > <https://github.com/p4lang/p4factory> under "Integration with Mininet" ,
> > the way actual entries are added to the table is using commands like the
> > following
> >
> > python ../../cli/pd_cli.py -p simple_router -i p4_pd_rpc.simple_router -s
> > $PWD/of-tests/pd_thrift:$PWD/../../submodules/oft-infra -m "add_entry
> > send_frame 1 rewrite_mac 00:aa:bb:00:00:00" -c localhost:22222
> > Is this the only way to put table entries? Or are there other ways to
> fill
> > the table
> >
> > Thanks again,
> > Archie
> >
> > On Wed, Jul 15, 2015 at 7:32 PM, Antoine Kaufmann <
> > antoinek at cs.washington.edu> wrote:
> >
> > >  [image: Boxbe] <https://www.boxbe.com/overview> Antoine Kaufmann (
> > > antoinek at cs.washington.edu) added themselves to your Guest List
> > > <
> https://www.boxbe.com/approved-list?tc_serial=21984698592&tc_rand=1956447171&utm_source=stf&utm_medium=email&utm_campaign=ANNO_TEST&utm_content=001&token=KoehR8YgfXD5NEHKSTVhZMnTzJkqy3Gol98B8KMsw2qEpQeNZ%2FQH6mkRnl1NQiay&key=jmIWxZTGsw6jU6dmbN%2BkMpxbWEffPerO%2BGhR5aTN9Qo%3D
> >
> > > | Remove them
> > > <
> https://www.boxbe.com/anno?action=remove&tc_serial=21984698592&tc_rand=1956447171&utm_source=stf&utm_medium=email&utm_campaign=ANNO_TEST&utm_content=001&token=KoehR8YgfXD5NEHKSTVhZMnTzJkqy3Gol98B8KMsw2qEpQeNZ%2FQH6mkRnl1NQiay&key=jmIWxZTGsw6jU6dmbN%2BkMpxbWEffPerO%2BGhR5aTN9Qo%3D
> >
> > > | Block them
> > > <
> https://www.boxbe.com/anno?action=add&disp=b&tc_serial=21984698592&tc_rand=1956447171&utm_source=stf&utm_medium=email&utm_campaign=ANNO_TEST&utm_content=001&token=KoehR8YgfXD5NEHKSTVhZMnTzJkqy3Gol98B8KMsw2qEpQeNZ%2FQH6mkRnl1NQiay&key=jmIWxZTGsw6jU6dmbN%2BkMpxbWEffPerO%2BGhR5aTN9Qo%3D
> >
> > >
> > > Hi Archie,
> > >
> > > what happens with a P4 switch on a table miss is entirely controlled by
> > > the P4 program (plus runtime configuration). If the table has a default
> > > action that was added at runtime from the CPU, then that action will be
> > > executed. Regardless of whether there is a default action, you the
> > > control program can also branch on whether the lookup hit and missed.
> > >
> > > If you want the open flow behavior, you can implement this in P4, by
> > > either encapsulating and forwarding the packet to a remote controller,
> > > or locally forwarding it to the CPU.
> > >
> > > I hope that helps!
> > >
> > > Cheers,
> > > Antoine
> > >
> > > On Wed, Jul 15 18:41, Archie wrote:
> > > > Hi,
> > > >      I know in openflow, when a switch can't find a rule-match for a
> > > > packet, it forwards the packet to the controller. Does the same thing
> > > > happen in P4? Or is a table-miss handled in some other way in P4?
> > > >
> > > >
> > > > Thanks,
> > > > Archie
> > >
> > > --
> > > Antoine Kaufmann
> > > <antoinek at cs.washington.edu>
> > >
> > >
>
> --
> Antoine Kaufmann
> <antoinek at cs.washington.edu>
>
> _______________________________________________
> P4-dev mailing list
> P4-dev at p4.org
> Listinfo - http://mail.p4.org/mailman/listinfo/p4-dev_p4.org
> Archives - http://mail.p4.org/pipermail/p4-dev_p4.org/
>



-- 
Antonin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20150721/32ffe833/attachment-0001.html>


More information about the P4-dev mailing list