-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackets_firewall.p4
104 lines (93 loc) · 1.19 KB
/
packets_firewall.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
104
header_type ethernet_t
{
fields
{
bit<48>dst;
}
}
header_type recorder_t
{
fields
{
bit<6>cnt;
}
}
metadata recorder_t recorder;
header ethernet_t ethernet;
parser start
{
return parse_ethernet;
}
parser parse_ethernet
{
extract(ethernet);
return ingress;
}
register drop_triger
{
width : 6;
instance_count : 1;
}
action _drop()
{
drop();
}
action forward_h2_h1()
{
modify_field(standard_metadata.egress_spec, 1);
}
action get_value()
{
modify_field(recorder.cnt, drop_triger[0]);
}
action forward_h1_h2()
{
modify_field(standard_metadata.egress_spec, 2);
drop_triger[0] = drop_triger[0] + 1;
}
table h1_h2
{
actions
{
forward_h1_h2;
}
size : 2;
}
table h2_h1
{
actions
{
forward_h2_h1;
}
size : 2;
}
table drop_table
{
actions
{
_drop;
}
size : 2;
}
control ingress
{
get_value();
if(recorder.cnt >= 50)
{
apply(drop_table);
}
else
{
if(standard_metadata.ingress_port == 1)
{
apply(h1_h2);
}
else
{
apply(h2_h1);
}
}
}
control egress
{
}