blob: 7284a3f5f1ce65069ebe9e4812c0c5ea4f0f09fa [file] [log] [blame]
Carmelo Cascone9ab40612017-09-19 16:31:55 +09001// Copyright (c) 2017, Google Inc.
2//
3// Common header definitions.
4// Note: This code has not been tested and is expected to contain bugs.
5
6#ifndef P4_SPEC_HEADERS_P4_
7#define P4_SPEC_HEADERS_P4_
8
9//------------------------------------------------------------------------------
10// Field type definitions
11//------------------------------------------------------------------------------
12
13typedef bit<48> EthernetAddress;
14typedef bit<32> IPv4Address;
15typedef bit<128> IPv6Address;
16typedef bit<9> PortNum;
17
18//------------------------------------------------------------------------------
19// Protocol header definitions
20//------------------------------------------------------------------------------
21
22header ethernet_t {
23 EthernetAddress dst_addr;
24 EthernetAddress src_addr;
25 bit<16> ether_type;
26}
27
28header ipv4_base_t {
29 bit<4> version;
30 bit<4> ihl;
31 bit<8> diffserv;
32 bit<16> total_len;
33 bit<16> identification;
34 bit<3> flags;
35 bit<13> frag_offset;
36 bit<8> ttl;
37 bit<8> protocol;
38 bit<16> hdr_checksum;
39 IPv4Address src_addr;
40 IPv4Address dst_addr;
41}
42
43// Fixed ipv6 header
44header ipv6_base_t {
45 bit<4> version;
46 bit<8> traffic_class;
47 bit<20> flow_label;
48 bit<16> payload_length;
49 bit<8> next_header;
50 bit<8> hop_limit;
51 IPv6Address src_addr;
52 IPv6Address dst_addr;
53}
54
55header udp_t {
56 bit<16> src_port;
57 bit<16> dst_port;
58 bit<16> hdr_length;
59 bit<16> checksum;
60}
61
62header tcp_t {
63 bit<16> src_port;
64 bit<16> dst_port;
65 bit<32> seq_no;
66 bit<32> ack_no;
67 bit<4> data_offset;
68 bit<4> res;
69 bit<8> flags;
70 bit<16> window;
71 bit<16> checksum;
72 bit<16> urgent_ptr;
73}
74
75// Same for both ip v4 and v6
76header icmp_header_t {
77 bit<8> icmp_type;
78 bit<8> code;
79 bit<16> checksum;
80}
81
82header vlan_tag_t {
83 bit<3> pcp;
84 bit cfi;
85 bit<12> vid;
86 bit<16> ether_type;
87}
88
89header arp_t {
90 bit<16> hw_type;
91 bit<16> proto_type;
92 bit<8> hw_addr_len;
93 bit<8> proto_addr_len;
94 bit<16> opcode;
95 bit<48> sender_hw_addr;
96 bit<32> sender_proto_addr;
97 bit<48> target_hw_addr;
98 bit<32> target_proto_addr;
99}
100
101//------------------------------------------------------------------------------
102// Controller header definitions
103//------------------------------------------------------------------------------
104
105@controller_header("packet_in")
106header packet_in_header_t {
107 // TODO(samarabdi) Change once we move from 9 to 32 bits
108 @proto_tag(1) bit<9> ingress_physical_port;
109 @proto_tag(4) bit<7> padding1;
110 @proto_tag(2) bit<32> ingress_logical_port;
111 // The initial intended egress port decided for the packet by the pipeline.
112 // This is standard metadata.egress_spec at the time the punt-rule was hit.
113 // TODO(samarabdi) Change once we move from 9 to 32 bits
114 @proto_tag(3) bit<9> target_egress_port;
115 @proto_tag(5) bit<7> padding2;
116}
117
118@not_extracted_in_egress
119@controller_header("packet_out")
120header packet_out_header_t {
121 // TODO(samarabdi) Change once we move from 9 to 32 bits
122 @proto_tag(1) bit<9> egress_physical_port;
123 @proto_tag(2) bit<1> submit_to_ingress;
124 @proto_tag(3) bit<6> padding;
125}
126
127//------------------------------------------------------------------------------
128// Metadata definition
129//------------------------------------------------------------------------------
130
131// Local meta-data for each packet being processed.
132// TODO(samarabdi): Evaluate if this should be role-based.
133struct local_metadata_t {
134 bit<32> vrf_id;
135 bit<8> class_id; // Dst traffic class ID (IPSP)
136 bit<5> cpu_cos_queue_id;
137 bit<1> skip_egress;
138 // TODO(samarabdi) Change once we move from 9 to 32 bits
139 bit<9> egress_spec_at_punt_match;
140 bit<2> color;
141 bit<16> l4_src_port;
142 bit<16> l4_dst_port;
143 bit<8> icmp_code;
144}
145#endif // P4_SPEC_HEADERS_P4_