-
Notifications
You must be signed in to change notification settings - Fork 6
/
ipv4.up4
90 lines (77 loc) · 1.96 KB
/
ipv4.up4
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
/*
* Author: Hardik Soni
* Email: [email protected]
*/
#include"msa.up4"
#include"common.up4"
header ipv4_h {
// bit<4> version;
// bit<4> ihl;
bit<8> ihl_version;
bit<8> diffserv;
bit<16> totalLen;
bit<16> identification;
bit<3> flags;
bit<13> fragOffset;
bit<8> ttl;
bit<8> protocol;
bit<16> hdrChecksum;
bit<32> srcAddr;
bit<32> dstAddr;
}
struct ipv4_hdr_t {
ipv4_h ipv4;
}
cpackage IPv4 : implements Unicast<ipv4_hdr_t, empty_t, empty_t, bit<16>, empty_t> {
parser micro_parser(extractor ex, pkt p, im_t im, out ipv4_hdr_t hdr,
inout empty_t meta, in empty_t ia, inout empty_t ioa) {
state start {
ex.extract(p, hdr.ipv4);
transition accept;
}
}
control micro_control(pkt p, im_t im, inout ipv4_hdr_t hdr, inout empty_t m,
in empty_t e, out bit<16> nexthop,
inout empty_t ioa) { // nexthop out arg
action process(bit<16> nh) {
// disabling for pings
// hdr.ipv4.ttl = hdr.ipv4.ttl - 1;
nexthop = nh; // setting out param
}
action default_act() {
nexthop = 0;
}
table ipv4_lpm_tbl {
key = {
// Why not lpm? because can't specify prefix length in const entries
hdr.ipv4.dstAddr : exact;
hdr.ipv4.diffserv : ternary;
}
actions = {
process;
default_act;
}
const entries = {
// v1model mininet suitable entries
// 10.0.1.1, _
(32w167772417, _) : process(16w1);
// 10.0.2.1, _
(32w167772673, _): process(16w2);
// for tofino setup at cornell-netlab
// 10.0.0.22
(32w167772182, _) : process(16w22);
// 10.0.0.23
(32w167772183, _) : process(16w23);
}
default_action = default_act;
}
apply {
ipv4_lpm_tbl.apply();
}
}
control micro_deparser(emitter em, pkt p, in ipv4_hdr_t h) {
apply {
em.emit(p, h.ipv4);
}
}
}