-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrouterv4_main.up4
73 lines (62 loc) · 1.71 KB
/
routerv4_main.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
/*
* Author: Hardik Soni
* Email: [email protected]
*/
#include"msa.up4"
#include"../lib-src/common.up4"
struct meta_t { }
header ethernet_h {
bit<48> dmac;
bit<48> smac;
bit<16> ethType;
}
struct hdr_t {
ethernet_h eth;
}
cpackage ModularRouterv4 : implements Unicast<hdr_t, meta_t,
empty_t, empty_t, empty_t> {
parser micro_parser(extractor ex, pkt p, im_t im, out hdr_t hdr, inout meta_t meta,
in empty_t ia, inout empty_t ioa) {
state start {
ex.extract(p, hdr.eth);
transition accept;
}
}
control micro_control(pkt p, im_t im, inout hdr_t hdr, inout meta_t m,
in empty_t ia, out empty_t oa, inout empty_t ioa) {
bit<16> nh;
bit<32> qv;
IPv4() ipv4_i;
action forward(bit<48> dmac, bit<48> smac, PortId_t port) {
hdr.eth.dmac = dmac;
hdr.eth.smac = smac;
im.set_out_port(port);
}
table forward_tbl {
key = { nh : exact; }
actions = { forward; }
const entries = {
(16w1) : forward(0x000000000001, 0x000000000002, 9w1);
(16w2) : forward(0x000000000002, 0x000000000001, 9w2);
(16w22) : forward(0x3cfdfec3e540, 0x3cfdfec3e428, 9w44);
(16w23) : forward(0x3cfdfec3e428, 0x3cfdfec3e540, 9w52);
}
}
apply {
if (hdr.eth.ethType == 0x0800) {
ipv4_i.apply(p, im, ia, nh, ioa);
forward_tbl.apply();
}
qv = im.get_value(metadata_fields_t.QUEUE_DEPTH_AT_DEQUEUE);
if (qv == (bit<32>)64) {
im.drop();
}
}
}
control micro_deparser(emitter em, pkt p, in hdr_t hdr) {
apply {
em.emit(p, hdr.eth);
}
}
}
ModularRouterv4() main;