Giter Club home page Giter Club logo

Comments (8)

mihaibudiu avatar mihaibudiu commented on September 25, 2024

v1model is not documented properly, but the expectation is that the hdr struct (called h in this program) would only contain headers or stacks. It's equivalent to the P4-14 collection of all possible headers. We should provide a better error message, though.

from p4c.

jnfoster avatar jnfoster commented on September 25, 2024

I see. Is the right solution to restrict v1model? Or could one improve the compiler so it supports all types?

from p4c.

mihaibudiu avatar mihaibudiu commented on September 25, 2024

v1model was written to allow P4-14 programs to be translated to P4-16. The converter should never generate programs that crash the compiler. However, today v1model is the only model which can be executed by the behavioral model simulator, for both P4-14 and P4-16 programs, so we also use it for testing the compiler using P4-16 programs.

If we want to program v1model directly we have to document it better and make the behavioral model back-end p4c-bm-ss more robust. The long term plan is to have a new standard architecture model and back-end, which would make v1model obsolete. How much we invest in the v1model and p4c-bm-ss back-end depends on how quickly we expect to have the standard architecture model, a corresponding back-end, and support for these in the behavioral model simulator.

from p4c.

jnfoster avatar jnfoster commented on September 25, 2024

Ahh. I misunderstood. Sorry. I thought v1model was the proto-standard architecture. If it's just a shim to allow P4-14 models to import their programs into the P4-16 workchain then these kind of restrictions make total sense.

Thanks for clarifying!

from p4c.

smolkaj avatar smolkaj commented on September 25, 2024

The following similar program causes the compiler to crash with Segmentation fault (core dumped). The problem seems to be that I try to extract a struct in my parser, which the specification of extract forbids.

Maybe an error message would be more graceful than a segmentation fault? Then again, if you don't expect users to write programs against this target manually, it probably does not matter.

#include <core.p4>
#include <v1model.p4>

struct H { };
struct M { };

parser ParserI(packet_in b, out H parsedHdr, inout M meta,
              inout standard_metadata_t standard_metadata)
{
    state start {
                // here I am trying to extract a struct -> segmentation fault
        b.extract(parsedHdr);
        transition accept;
    }
}


control VerifyChecksumI(in H hdr,
                        inout M meta,
                        inout standard_metadata_t standard_metadata)
{
    apply { }
}


control IngressI(inout H hdr,
                 inout M meta,
                 inout standard_metadata_t standard_metadata)
{
    apply { }
}


control EgressI(inout H hdr,
                inout M meta,
                inout standard_metadata_t standard_metadata)
{
    apply { }

}


control ComputeChecksumI(inout H hdr,
                         inout M meta,
                         inout standard_metadata_t standard_metadata)
{
    apply { }
}


control DeparserI(packet_out b, in H hdr)
{
    apply { }
}


V1Switch(ParserI(),
         VerifyChecksumI(),
         IngressI(),
         EgressI(),
         ComputeChecksumI(),
         DeparserI()) main;

from p4c.

mihaibudiu avatar mihaibudiu commented on September 25, 2024

I have sent a pull request which fixes these; it includes these examples as tests in p4_16_errors
(Our testing framework does not check the outputs produced by the p4c-bm2-ss compiler - I will file a separate issue with that.)
The compiler should never BUG or segfault.

from p4c.

smolkaj avatar smolkaj commented on September 25, 2024

A segmentation fault can likewise be provoked in the deparser by emitting something that is not a header.

from p4c.

mihaibudiu avatar mihaibudiu commented on September 25, 2024

There is a new folder with negative tests for p4c-bm-ss, called testdata/p4_16_bmv_errors. There are three tests for these cases checked-in. (The testing script still does not save reference outputs - so the test would succeed even if the compiler crashes, but I filed issue #96 for this problem.)

from p4c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.