Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uBPF backend: Support for forwarding #2381

Merged
merged 7 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ubpf_model: specify version of uBPF arch model
  • Loading branch information
osinstom committed May 16, 2020
commit 4be07ca50836f2df0a01d5238a862dd17d2853b9
18 changes: 18 additions & 0 deletions backends/ubpf/p4include/ubpf_model.p4
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ limitations under the License.

#include <core.p4>

#ifndef UBPF_MODEL_VERSION
#define UBPF_MODEL_VERSION 20200304
#endif

/* TODO: handle the uBPF model version in the compiler. */
const bit<32> __ubpf_model_version = UBPF_MODEL_VERSION;

#if UBPF_MODEL_VERSION >= 20200515
enum ubpf_action {
ABORT,
DROP,
Expand All @@ -34,6 +42,7 @@ struct standard_metadata {
bool clone;
bit<32> clone_port;
}
#endif

/*
* The uBPF target can currently pass the packet or drop it.
Expand Down Expand Up @@ -135,8 +144,17 @@ extern bit<16> csum_replace4(in bit<16> csum,
* header, header stack, or header_union.
*/

#if UBPF_MODEL_VERSION >= 20200515
parser parse<H, M>(packet_in packet, out H headers, inout M meta, inout standard_metadata std);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make such changes they will break the user programs that were depending on your prior architecture.
Perhaps you can follow the model of v1model.p4, which has a version and conditional changes?
You should add a version anyway, whether you want to conditionally add this additional argument and handle it in the compiler is your choice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point! I've added version to ubpf_model.p4. However, it seems that make check-p4 does not see macro's definition from test files, for example (e.g. p4_16_samples/tunneling_ubpf.p4):

#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

Is there any specific workaround for v1model.p4 to let tests pass ? I don't observe this issue with make check-ubpf or standalone compilation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler inserts a #define of V1MODEL_VERSION when translating P4_14 to P4_16, but that should not be relevant here. Other than that, there's no special handling of V1MODEL_VERSION needed -- if it is set explicitly in a test file, that will override the default in the header file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that hints at the problem -- the toP4 dumping code will insert a #define V1MODEL_VERSION in the dumped code if it is needed -- you may need something similar for this. See frontends/p4/toP4/toP4.cpp line 172; there's a check when dumping an #include <v1model.p4> line; you may need something similar for #include <ubpf_model.p4>. We should think about a way to make this easier to extend in a backend (a hook to the backend that is called from here, rather than having explicit checks for backend architectures.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a dirty hack to me and it would require to add dependency on uBPF model in the P4 frontend code (what I think we should avoid). I think we can break the backward compatibility for the uBPF programs, but explicitly say users that the old programs must be updated or the old version must be defined by macro definition. I've added the note in the documentation: https://github.com/p4lang/p4c/pull/2381/files#diff-616b1ea3f7f6e6e72e5cb1e8d44899dd. I've also updated examples for uBPF.

Does it sound acceptable to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this, but we should find a portable way to do versioning.

#else
parser parse<H, M>(packet_in packet, out H headers, inout M meta);
#endif

#if UBPF_MODEL_VERSION >= 20200515
control pipeline<H, M>(inout H headers, inout M meta, inout standard_metadata std);
#else
control pipeline<H, M>(inout H headers, inout M meta);
#endif

/*
* The only legal statements in the body of the deparser control are:
Expand Down
1 change: 1 addition & 0 deletions backends/ubpf/tests/testdata/test-ipv4-actions.p4
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>
#include <core.p4>

Expand Down
1 change: 1 addition & 0 deletions backends/ubpf/tests/testdata/test-ipv6-actions.p4
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>
#include <core.p4>

Expand Down
1 change: 1 addition & 0 deletions backends/ubpf/tests/testdata/test-simple-actions.p4
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>
#include <core.p4>

Expand Down
1 change: 1 addition & 0 deletions backends/ubpf/tests/testdata/test-simple-firewall.p4
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>
#include <core.p4>

Expand Down
1 change: 1 addition & 0 deletions backends/ubpf/tests/testdata/test-tunneling.p4
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>
#include <core.p4>

Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/action_call_ubpf.p4
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

struct Headers_t {
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/action_fwd_ubpf.p4
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

struct Headers_t {
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/csum_ubpf.p4
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

header Ethernet {
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/hash_ubpf.p4
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

header test_t {
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/metadata_ubpf.p4
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

@ethernetaddress typedef bit<48> EthernetAddress;
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/ubpf_checksum_extern.p4
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

typedef bit<48> EthernetAddress;
Expand Down
1 change: 1 addition & 0 deletions testdata/p4_16_samples/ubpf_hash_extern.p4
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <core.p4>
#define UBPF_MODEL_VERSION 20200515
#include <ubpf_model.p4>

typedef bit<48> EthernetAddress;
Expand Down