Add Heavy Hitter to examples master (#10)
Add Heavy Hitter to SIGCOMM 2016 in master
This commit is contained in:
134
SIGCOMM_2016/heavy_hitter/p4src/heavy_hitter.p4
Normal file
134
SIGCOMM_2016/heavy_hitter/p4src/heavy_hitter.p4
Normal file
@@ -0,0 +1,134 @@
|
||||
/* Copyright 2013-present Barefoot Networks, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "includes/headers.p4"
|
||||
#include "includes/parser.p4"
|
||||
|
||||
field_list ipv4_checksum_list {
|
||||
ipv4.version;
|
||||
ipv4.ihl;
|
||||
ipv4.diffserv;
|
||||
ipv4.totalLen;
|
||||
ipv4.identification;
|
||||
ipv4.flags;
|
||||
ipv4.fragOffset;
|
||||
ipv4.ttl;
|
||||
ipv4.protocol;
|
||||
ipv4.srcAddr;
|
||||
ipv4.dstAddr;
|
||||
}
|
||||
|
||||
field_list_calculation ipv4_checksum {
|
||||
input {
|
||||
ipv4_checksum_list;
|
||||
}
|
||||
algorithm : csum16;
|
||||
output_width : 16;
|
||||
}
|
||||
|
||||
calculated_field ipv4.hdrChecksum {
|
||||
verify ipv4_checksum;
|
||||
update ipv4_checksum;
|
||||
}
|
||||
|
||||
action _drop() {
|
||||
drop();
|
||||
}
|
||||
|
||||
header_type custom_metadata_t {
|
||||
fields {
|
||||
nhop_ipv4: 32;
|
||||
}
|
||||
}
|
||||
|
||||
metadata custom_metadata_t custom_metadata;
|
||||
|
||||
action set_nhop(nhop_ipv4, port) {
|
||||
modify_field(custom_metadata.nhop_ipv4, nhop_ipv4);
|
||||
modify_field(standard_metadata.egress_spec, port);
|
||||
add_to_field(ipv4.ttl, -1);
|
||||
}
|
||||
|
||||
action set_dmac(dmac) {
|
||||
modify_field(ethernet.dstAddr, dmac);
|
||||
}
|
||||
|
||||
counter ip_src_counter {
|
||||
type: packets;
|
||||
static: count_table;
|
||||
instance_count: 1024;
|
||||
}
|
||||
|
||||
action count_action(idx) {
|
||||
count(ip_src_counter, idx);
|
||||
}
|
||||
|
||||
table count_table {
|
||||
reads {
|
||||
ipv4.srcAddr : lpm;
|
||||
}
|
||||
actions {
|
||||
count_action;
|
||||
_drop;
|
||||
}
|
||||
size : 1024;
|
||||
}
|
||||
|
||||
table ipv4_lpm {
|
||||
reads {
|
||||
ipv4.dstAddr : lpm;
|
||||
}
|
||||
actions {
|
||||
set_nhop;
|
||||
_drop;
|
||||
}
|
||||
size: 1024;
|
||||
}
|
||||
|
||||
table forward {
|
||||
reads {
|
||||
custom_metadata.nhop_ipv4 : exact;
|
||||
}
|
||||
actions {
|
||||
set_dmac;
|
||||
_drop;
|
||||
}
|
||||
size: 512;
|
||||
}
|
||||
|
||||
action rewrite_mac(smac) {
|
||||
modify_field(ethernet.srcAddr, smac);
|
||||
}
|
||||
|
||||
table send_frame {
|
||||
reads {
|
||||
standard_metadata.egress_port: exact;
|
||||
}
|
||||
actions {
|
||||
rewrite_mac;
|
||||
_drop;
|
||||
}
|
||||
size: 256;
|
||||
}
|
||||
|
||||
control ingress {
|
||||
apply(count_table);
|
||||
apply(ipv4_lpm);
|
||||
apply(forward);
|
||||
}
|
||||
|
||||
control egress {
|
||||
apply(send_frame);
|
||||
}
|
||||
139
SIGCOMM_2016/heavy_hitter/p4src/heavy_hitter_template.p4
Normal file
139
SIGCOMM_2016/heavy_hitter/p4src/heavy_hitter_template.p4
Normal file
@@ -0,0 +1,139 @@
|
||||
/* Copyright 2013-present Barefoot Networks, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "includes/headers.p4"
|
||||
#include "includes/parser.p4"
|
||||
|
||||
// TODO: Define the threshold value
|
||||
|
||||
field_list ipv4_checksum_list {
|
||||
ipv4.version;
|
||||
ipv4.ihl;
|
||||
ipv4.diffserv;
|
||||
ipv4.totalLen;
|
||||
ipv4.identification;
|
||||
ipv4.flags;
|
||||
ipv4.fragOffset;
|
||||
ipv4.ttl;
|
||||
ipv4.protocol;
|
||||
ipv4.srcAddr;
|
||||
ipv4.dstAddr;
|
||||
}
|
||||
|
||||
field_list_calculation ipv4_checksum {
|
||||
input {
|
||||
ipv4_checksum_list;
|
||||
}
|
||||
algorithm : csum16;
|
||||
output_width : 16;
|
||||
}
|
||||
|
||||
calculated_field ipv4.hdrChecksum {
|
||||
verify ipv4_checksum;
|
||||
update ipv4_checksum;
|
||||
}
|
||||
|
||||
action _drop() {
|
||||
drop();
|
||||
}
|
||||
|
||||
header_type custom_metadata_t {
|
||||
fields {
|
||||
nhop_ipv4: 32;
|
||||
// TODO: Add the metadata for hash indices and count values
|
||||
}
|
||||
}
|
||||
|
||||
metadata custom_metadata_t custom_metadata;
|
||||
|
||||
action set_nhop(nhop_ipv4, port) {
|
||||
modify_field(custom_metadata.nhop_ipv4, nhop_ipv4);
|
||||
modify_field(standard_metadata.egress_spec, port);
|
||||
add_to_field(ipv4.ttl, -1);
|
||||
}
|
||||
|
||||
action set_dmac(dmac) {
|
||||
modify_field(ethernet.dstAddr, dmac);
|
||||
}
|
||||
|
||||
// TODO: Define the field list to compute the hash on
|
||||
// Use the 5 tuple of
|
||||
// (src ip, dst ip, src port, dst port, ip protocol)
|
||||
|
||||
// TODO: Define two different hash functions to store the counts
|
||||
// Note: Please use csum16 and crc16 for the hash functions
|
||||
|
||||
// TODO: Define the registers to store the counts
|
||||
|
||||
|
||||
// TODO: Actions to set heavy hitter filter
|
||||
|
||||
|
||||
// TODO: Define the tables to run actions
|
||||
|
||||
|
||||
// TODO: Define table to drop the heavy hitter traffic
|
||||
|
||||
|
||||
table ipv4_lpm {
|
||||
reads {
|
||||
ipv4.dstAddr : lpm;
|
||||
}
|
||||
actions {
|
||||
set_nhop;
|
||||
_drop;
|
||||
}
|
||||
size: 1024;
|
||||
}
|
||||
|
||||
table forward {
|
||||
reads {
|
||||
custom_metadata.nhop_ipv4 : exact;
|
||||
}
|
||||
actions {
|
||||
set_dmac;
|
||||
_drop;
|
||||
}
|
||||
size: 512;
|
||||
}
|
||||
|
||||
action rewrite_mac(smac) {
|
||||
modify_field(ethernet.srcAddr, smac);
|
||||
}
|
||||
|
||||
table send_frame {
|
||||
reads {
|
||||
standard_metadata.egress_port: exact;
|
||||
}
|
||||
actions {
|
||||
rewrite_mac;
|
||||
_drop;
|
||||
}
|
||||
size: 256;
|
||||
}
|
||||
|
||||
control ingress {
|
||||
// TODO: Add table control here
|
||||
if (// TODO: Add conditional here) {
|
||||
// TODO: apply table here
|
||||
} else {
|
||||
apply(ipv4_lpm);
|
||||
apply(forward);
|
||||
}
|
||||
}
|
||||
|
||||
control egress {
|
||||
apply(send_frame);
|
||||
}
|
||||
57
SIGCOMM_2016/heavy_hitter/p4src/includes/headers.p4
Normal file
57
SIGCOMM_2016/heavy_hitter/p4src/includes/headers.p4
Normal file
@@ -0,0 +1,57 @@
|
||||
/* Copyright 2013-present Barefoot Networks, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
header_type ethernet_t {
|
||||
fields {
|
||||
dstAddr : 48;
|
||||
srcAddr : 48;
|
||||
etherType : 16;
|
||||
}
|
||||
}
|
||||
|
||||
header_type ipv4_t {
|
||||
fields {
|
||||
version : 4;
|
||||
ihl : 4;
|
||||
diffserv : 8;
|
||||
totalLen : 16;
|
||||
identification : 16;
|
||||
flags : 3;
|
||||
fragOffset : 13;
|
||||
ttl : 8;
|
||||
protocol : 8;
|
||||
hdrChecksum : 16;
|
||||
srcAddr : 32;
|
||||
dstAddr: 32;
|
||||
}
|
||||
}
|
||||
|
||||
header_type tcp_t {
|
||||
fields {
|
||||
srcPort : 16;
|
||||
dstPort : 16;
|
||||
seqNo : 32;
|
||||
ackNo : 32;
|
||||
dataOffset : 4;
|
||||
res : 3;
|
||||
ecn : 3;
|
||||
ctrl : 6;
|
||||
window : 16;
|
||||
checksum : 16;
|
||||
urgentPtr : 16;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
49
SIGCOMM_2016/heavy_hitter/p4src/includes/parser.p4
Normal file
49
SIGCOMM_2016/heavy_hitter/p4src/includes/parser.p4
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Copyright 2013-present Barefoot Networks, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
parser start {
|
||||
return parse_ethernet;
|
||||
}
|
||||
|
||||
#define ETHERTYPE_IPV4 0x0800
|
||||
|
||||
header ethernet_t ethernet;
|
||||
|
||||
parser parse_ethernet {
|
||||
extract(ethernet);
|
||||
return select(latest.etherType) {
|
||||
ETHERTYPE_IPV4 : parse_ipv4;
|
||||
default: ingress;
|
||||
}
|
||||
}
|
||||
|
||||
header ipv4_t ipv4;
|
||||
|
||||
#define IP_PROTOCOLS_TCP 6
|
||||
|
||||
parser parse_ipv4 {
|
||||
extract(ipv4);
|
||||
return select(latest.protocol) {
|
||||
IP_PROTOCOLS_TCP : parse_tcp;
|
||||
default: ingress;
|
||||
}
|
||||
}
|
||||
|
||||
header tcp_t tcp;
|
||||
|
||||
parser parse_tcp {
|
||||
extract(tcp);
|
||||
return ingress;
|
||||
}
|
||||
Reference in New Issue
Block a user