Validation of field parameter

19 views
Skip to first unread message

Amith GSPN

unread,
Jul 23, 2023, 7:52:04 PM7/23/23
to p4-dev
Hi,

In the given P4 code, we need to validate the "next_hop_id" field parameter to ascertain whether it contains a "NULL" value or not. Objective is to execute the action block conditionally based on the presence or absence of a "NULL" value in the "next_hop_id" field.

action set_nhop(bit<9> next_hop_id) {
#ifdef TARGET_BMV2_V1MODEL
        standard_metadata.egress_spec = next_hop_id;
#endif // TARGET_BMV2_V1MODEL 
}

Thanks,
Amith

Amith GSPN

unread,
Jul 23, 2023, 10:38:32 PM7/23/23
to p4-dev, Amith GSPN
Hi,

Sorry, The above message doesn't address my question correctly.
 
In the below given P4 code, I need to validate the "next_hop_id" field parameter to ascertain whether it contains a "NULL" value or not. If it is a "NULL" value drop the packet, if not forward the packet to given next_hop_id.  Question is how do you validate the field "next_hop_id" to implement the functionality? 

Note: "next_hop_id" contains the port_number

action set_nhop(bit<9> next_hop_id) {

// If next_hop_id is "NULL" drop the packet
drop();

// If next_hop_id is not "NULL" execute below lines

#ifdef TARGET_BMV2_V1MODEL
        standard_metadata.egress_spec = next_hop_id;
#endif // TARGET_BMV2_V1MODEL 
}

Thanks,
Amith

Mihai Budiu

unread,
Jul 23, 2023, 10:41:15 PM7/23/23
to Amith GSPN, p4-dev, Amith GSPN
There are no null values in p4.

From: p4-...@lists.p4.org <p4-...@lists.p4.org> on behalf of Amith GSPN <amith...@gmail.com>
Sent: Sunday, July 23, 2023 7:38:32 PM
To: p4-dev <p4-...@lists.p4.org>
Cc: Amith GSPN <amith...@gmail.com>
Subject: [P4-dev] Re: Validation of field parameter
 
--
You received this message because you are subscribed to the Google Groups "p4-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to p4-dev+un...@lists.p4.org.
To view this discussion on the web visit https://groups.google.com/a/lists.p4.org/d/msgid/p4-dev/05b1803b-7d7a-481c-bc22-7d65be0c60dcn%40lists.p4.org.

Andy Fingerhut

unread,
Jul 24, 2023, 1:09:36 PM7/24/23
to Mihai Budiu, Amith GSPN, p4-dev
There _might_ be NULL values in the control plane API one uses, used to represent values of some parameters.  However, in the data plane such values are typically represented by some numeric value of a parameter that is most often defined as something like bit<9> or bit<11> or bit<16>.  You should check with your control plane API to see what it transforms NULL values in the control plane API into as a bit<W> value, probably 0.

Andy


Reply all
Reply to author
Forward
0 new messages