-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathheaders.p4
103 lines (92 loc) · 3.67 KB
/
headers.p4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//----------------------------------------------------------------------------
// This file is owned and controlled by Xilinx and must be used solely //
// for design, simulation, implementation and creation of design files //
// limited to Xilinx devices or technologies. Use with non-Xilinx //
// devices or technologies is expressly prohibited and immediately //
// terminates your license. //
// //
// XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" SOLELY //
// FOR USE IN DEVELOPING PROGRAMS AND SOLUTIONS FOR XILINX DEVICES. BY //
// PROVIDING THIS DESIGN, CODE, OR INFORMATION AS ONE POSSIBLE //
// IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD, XILINX IS //
// MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE FROM ANY //
// CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING ANY //
// RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION. XILINX EXPRESSLY //
// DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO THE ADEQUACY OF THE //
// IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OR //
// REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM CLAIMS OF //
// INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A //
// PARTICULAR PURPOSE. //
// //
// Xilinx products are not intended for use in life support appliances, //
// devices, or systems. Use in such applications are expressly //
// prohibited. //
// //
// (c) Copyright 1995-2016 Xilinx, Inc. //
// All rights reserved. //
//----------------------------------------------------------------------------
#include "xilinx.p4"
typedef bit<48> MacAddress;
typedef bit<32> IPv4Address;
header ethernet_h {
MacAddress dst;
MacAddress src;
bit<16> type;
}
header ipv4_h {
bit<4> version;
bit<4> ihl;
bit<8> tos;
bit<16> len;
bit<16> id;
bit<3> flags;
bit<13> frag;
bit<8> ttl;
bit<8> proto;
bit<16> chksum;
IPv4Address src;
IPv4Address dst;
}
header udp_h {
bit<16> sport;
bit<16> dport;
bit<16> len;
bit<16> chksum;
}
struct headers_t {
ethernet_h ethernet;
ipv4_h ipv4;
udp_h udp;
}
struct metadata_t {
bit<1> dropped;
}
@Xilinx_MaxPacketRegion(1518*8) // in bits
parser Parser(packet_in pkt, out headers_t hdr) {
state start {
pkt.extract(hdr.ethernet);
transition select(hdr.ethernet.type) {
0x0800 : parse_ipv4;
default : accept;
}
}
state parse_ipv4 {
pkt.extract(hdr.ipv4);
transition select(hdr.ipv4.proto) {
17 : parse_udp;
default : accept;
}
}
state parse_udp {
pkt.extract(hdr.udp);
transition accept;
}
}
@Xilinx_MaxPacketRegion(1518*8) // in bits
control Deparser(in headers_t hdr, packet_out pkt) {
apply {
pkt.emit(hdr.ethernet);
pkt.emit(hdr.ipv4);
pkt.emit(hdr.udp);
}
}