| // Copyright (c) 2017, Google Inc. |
| // |
| // Common header definitions. |
| // Note: This code has not been tested and is expected to contain bugs. |
| |
| #ifndef P4_SPEC_HEADERS_P4_ |
| #define P4_SPEC_HEADERS_P4_ |
| |
| //------------------------------------------------------------------------------ |
| // Field type definitions |
| //------------------------------------------------------------------------------ |
| |
| typedef bit<48> EthernetAddress; |
| typedef bit<32> IPv4Address; |
| typedef bit<128> IPv6Address; |
| typedef bit<9> PortNum; |
| |
| //------------------------------------------------------------------------------ |
| // Protocol header definitions |
| //------------------------------------------------------------------------------ |
| |
| header ethernet_t { |
| EthernetAddress dst_addr; |
| EthernetAddress src_addr; |
| bit<16> ether_type; |
| } |
| |
| header ipv4_base_t { |
| bit<4> version; |
| bit<4> ihl; |
| bit<8> diffserv; |
| bit<16> total_len; |
| bit<16> identification; |
| bit<3> flags; |
| bit<13> frag_offset; |
| bit<8> ttl; |
| bit<8> protocol; |
| bit<16> hdr_checksum; |
| IPv4Address src_addr; |
| IPv4Address dst_addr; |
| } |
| |
| // Fixed ipv6 header |
| header ipv6_base_t { |
| bit<4> version; |
| bit<8> traffic_class; |
| bit<20> flow_label; |
| bit<16> payload_length; |
| bit<8> next_header; |
| bit<8> hop_limit; |
| IPv6Address src_addr; |
| IPv6Address dst_addr; |
| } |
| |
| header udp_t { |
| bit<16> src_port; |
| bit<16> dst_port; |
| bit<16> hdr_length; |
| bit<16> checksum; |
| } |
| |
| header tcp_t { |
| bit<16> src_port; |
| bit<16> dst_port; |
| bit<32> seq_no; |
| bit<32> ack_no; |
| bit<4> data_offset; |
| bit<4> res; |
| bit<8> flags; |
| bit<16> window; |
| bit<16> checksum; |
| bit<16> urgent_ptr; |
| } |
| |
| // Same for both ip v4 and v6 |
| header icmp_header_t { |
| bit<8> icmp_type; |
| bit<8> code; |
| bit<16> checksum; |
| } |
| |
| header vlan_tag_t { |
| bit<3> pcp; |
| bit cfi; |
| bit<12> vid; |
| bit<16> ether_type; |
| } |
| |
| header arp_t { |
| bit<16> hw_type; |
| bit<16> proto_type; |
| bit<8> hw_addr_len; |
| bit<8> proto_addr_len; |
| bit<16> opcode; |
| bit<48> sender_hw_addr; |
| bit<32> sender_proto_addr; |
| bit<48> target_hw_addr; |
| bit<32> target_proto_addr; |
| } |
| |
| //------------------------------------------------------------------------------ |
| // Controller header definitions |
| //------------------------------------------------------------------------------ |
| |
| @controller_header("packet_in") |
| header packet_in_header_t { |
| // TODO(samarabdi) Change once we move from 9 to 32 bits |
| @proto_tag(1) bit<9> ingress_physical_port; |
| @proto_tag(4) bit<7> padding1; |
| @proto_tag(2) bit<32> ingress_logical_port; |
| // The initial intended egress port decided for the packet by the pipeline. |
| // This is standard metadata.egress_spec at the time the punt-rule was hit. |
| // TODO(samarabdi) Change once we move from 9 to 32 bits |
| @proto_tag(3) bit<9> target_egress_port; |
| @proto_tag(5) bit<7> padding2; |
| } |
| |
| @not_extracted_in_egress |
| @controller_header("packet_out") |
| header packet_out_header_t { |
| // TODO(samarabdi) Change once we move from 9 to 32 bits |
| @proto_tag(1) bit<9> egress_physical_port; |
| @proto_tag(2) bit<1> submit_to_ingress; |
| @proto_tag(3) bit<6> padding; |
| } |
| |
| //------------------------------------------------------------------------------ |
| // Metadata definition |
| //------------------------------------------------------------------------------ |
| |
| // Local meta-data for each packet being processed. |
| // TODO(samarabdi): Evaluate if this should be role-based. |
| struct local_metadata_t { |
| bit<32> vrf_id; |
| bit<8> class_id; // Dst traffic class ID (IPSP) |
| bit<5> cpu_cos_queue_id; |
| bit<1> skip_egress; |
| // TODO(samarabdi) Change once we move from 9 to 32 bits |
| bit<9> egress_spec_at_punt_match; |
| bit<2> color; |
| bit<16> l4_src_port; |
| bit<16> l4_dst_port; |
| bit<8> icmp_code; |
| } |
| #endif // P4_SPEC_HEADERS_P4_ |