Hi,
I have been also trying to get egress mac timestamp on P4_16 and have similar problems. David's code is working but my P4_16 version is not. I have enabled mac registers and added the egress command header. I have attached the p4 file I have written, along with the commands I use to compile and load the program.
```
/* -*- P4_16 -*- */
#include <core.p4>
#include <v1model.p4>
/*************************************************************************
*********************** H E A D E R S ***********************************
*************************************************************************/
typedef bit<16> egressSpec_t;
typedef bit<48> macAddr_t;
header ethernet_t {
macAddr_t dstAddr;
macAddr_t srcAddr;
bit<16> etherType;
}
header nfp_mac_eg_ts_t{
bit<24> zero;
bit<8> eg_off_byte;
}
struct intrinsic_metadata_t {
bit<64> ingress_global_timestamp;
bit<64> current_global_timestamp;
}
header nfp_ts_hdr_t {
bit<64>ig_ts;
bit<64>eg_ts;
}
struct metadata {
intrinsic_metadata_t intrinsic_metadata;
}
struct headers {
nfp_mac_eg_ts_t nfp_mac_eg_ts;
ethernet_t ethernet;
nfp_ts_hdr_t nfp_ts_hdr;
}
/*************************************************************************
*********************** P A R S E R ***********************************
*************************************************************************/
parser MyParser(packet_in packet,
out headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
state start {
transition parse_ethernet;
}
state parse_ethernet {
packet.extract(hdr.ethernet);
transition accept;
}
}
/*************************************************************************
************ C H E C K S U M V E R I F I C A T I O N *************
*************************************************************************/
control MyVerifyChecksum(inout headers hdr, inout metadata meta) {
apply { }
}
/*************************************************************************
************** I N G R E S S P R O C E S S I N G *******************
*************************************************************************/
control MyIngress(inout headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
action drop() {
mark_to_drop();
}
action all_packets_fwd_action(egressSpec_t port) {
standard_metadata.egress_spec = port;
}
table all_packets_fwd {
key = {
standard_metadata.ingress_port: exact;
}
actions = {
all_packets_fwd_action;
drop;
NoAction;
}
size = 1024;
default_action = NoAction;
}
apply {
hdr.nfp_ts_hdr.setValid();
hdr.nfp_ts_hdr.ig_ts = meta.intrinsic_metadata.ingress_global_timestamp;
hdr.nfp_ts_hdr.eg_ts = 0xffffffffffffffff; //meta.intrinsic_metadata.current_global_timestamp;
hdr.nfp_mac_eg_ts.setValid();
hdr.nfp_mac_eg_ts.zero = 0;
hdr.nfp_mac_eg_ts.eg_off_byte = 18;
all_packets_fwd.apply();
}
}
/*************************************************************************
**************** E G R E S S P R O C E S S I N G *******************
*************************************************************************/
control MyEgress(inout headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata) {
apply { }
}
/*************************************************************************
************* C H E C K S U M C O M P U T A T I O N **************
*************************************************************************/
control MyComputeChecksum(inout headers hdr, inout metadata meta) {
apply { }
}
/*************************************************************************
*********************** D E P A R S E R *******************************
*************************************************************************/
control MyDeparser(packet_out packet, in headers hdr) {
apply {
packet.emit(hdr.nfp_mac_eg_ts);
packet.emit(hdr.ethernet);
packet.emit(hdr.nfp_ts_hdr);
}
}
/*************************************************************************
*********************** S W I T C H *******************************
*************************************************************************/
V1Switch(
MyParser(),
MyVerifyChecksum(),
MyIngress(),
MyEgress(),
MyComputeChecksum(),
MyDeparser()
) main;
```
Commands to build and upload:
```
sudo modprobe -r -v nfp && sudo modprobe nfp nfp_pf_netdev=0 nfp_dev_cpp=1
sudo /opt/netronome/p4/bin/nfp4build -o basic.nffw -p out -4 basic.p4 -l lithium --nfp4c_p4_version 16 --nfp4c_I /opt/netronome/p4/include/16/p4include/ --nfirc_mac_ingress_timestamp
sudo systemctl start nfp-sdk6-rte.service
sudo systemctl status nfp-sdk6-rte.service
sudo /opt/netronome/p4/bin/rtecli design-unload
sudo /opt/netronome/bin/nfp-nffw unload
sudo /opt/netronome/p4/bin/rtecli design-load -f basic.nffw -p out/pif_design.json
sudo /opt/netronome/p4/bin/rtecli config-reload -c user_config.json
```
user_config.json :
```
{
"tables": {
"ingress::all_packets_fwd": {
"rules": [
{
"action": {
"data": {
"port": {
"value": "p0"
}
},
"type": "ingress::all_packets_fwd_action"
},
"name": "p1 to p0",
"match": {
"standard_metadata.ingress_port": {
"value": "p1"
}
}
},
{
"action": {
"data": {
"port": {
"value": "p1"
}
},
"type": "ingress::all_packets_fwd_action"
},
"name": "p0 to p1",
"match": {
"standard_metadata.ingress_port": {
"value": "p0"
}
}
}
]
}
}
}
```