Run P4 without P4factory - A Simple Example In Tutorials. -2 附 simple_router源码
/*
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"
#include "includes/intrinsic.p4"
#define FLOWLET_MAP_SIZE 13 // 8K
#define FLOWLET_INACTIVE_TOUT 50000 // usec -> 50ms
header_type ingress_metadata_t {
fields {
flow_ipg : 32; // inter-packet gap
flowlet_map_index : FLOWLET_MAP_SIZE; // flowlet map index
flowlet_id : 16; // flowlet id
flowlet_lasttime : 32; // flowlet's last reference time
ecmp_offset : 14; // offset into the ecmp table
nhop_ipv4 : 32;
}
}
metadata ingress_metadata_t ingress_metadata;
action _drop() {
drop();
}
field_list l3_hash_fields {
ipv4.srcAddr;
ipv4.dstAddr;
ipv4.protocol;
tcp.srcPort;
tcp.dstPort;
}
field_list_calculation flowlet_map_hash {
input {
l3_hash_fields;
}
algorithm : crc16;
output_width : FLOWLET_MAP_SIZE;
}
register flowlet_lasttime {
width : 32;
instance_count : 8192;
}
register flowlet_id {
width : 16;
instance_count : 8192;
}
action set_nhop(nhop_ipv4, port) {
modify_field(ingress_metadata.nhop_ipv4, nhop_ipv4);
modify_field(standard_metadata.egress_spec, port);
add_to_field(ipv4.ttl, -1);
}
action lookup_flowlet_map() {
modify_field_with_hash_based_offset(ingress_metadata.flowlet_map_index, 0,
flowlet_map_hash, FLOWLET_MAP_SIZE);
register_read(ingress_metadata.flowlet_id,
flowlet_id, ingress_metadata.flowlet_map_index);
modify_field(ingress_metadata.flow_ipg,
intrinsic_metadata.ingress_global_timestamp);
register_read(ingress_metadata.flowlet_lasttime,
flowlet_lasttime, ingress_metadata.flowlet_map_index);
subtract_from_field(ingress_metadata.flow_ipg,
ingress_metadata.flowlet_lasttime);
register_write(flowlet_lasttime, ingress_metadata.flowlet_map_index,
intrinsic_metadata.ingress_global_timestamp);
}
table flowlet {
actions { lookup_flowlet_map; }
}
action update_flowlet_id() {
add_to_field(ingress_metadata.flowlet_id, 1);
register_write(flowlet_id, ingress_metadata.flowlet_map_index,
ingress_metadata.flowlet_id);
}
table new_flowlet {
actions { update_flowlet_id; }
}
field_list flowlet_l3_hash_fields {
ipv4.srcAddr;
ipv4.dstAddr;
ipv4.protocol;
tcp.srcPort;
tcp.dstPort;
ingress_metadata.flowlet_id;
}
#define ECMP_BIT_WIDTH 10
#define ECMP_GROUP_TABLE_SIZE 1024
#define ECMP_NHOP_TABLE_SIZE 16384
field_list_calculation flowlet_ecmp_hash {
input {
flowlet_l3_hash_fields;
}
algorithm : crc16;
output_width : ECMP_BIT_WIDTH;
}
action set_ecmp_select(ecmp_base, ecmp_count) {
modify_field_with_hash_based_offset(ingress_metadata.ecmp_offset, ecmp_base,
flowlet_ecmp_hash, ecmp_count);
}
table ecmp_group {
reads {
ipv4.dstAddr : lpm;
}
actions {
_drop;
set_ecmp_select;
}
size : ECMP_GROUP_TABLE_SIZE;
}
table ecmp_nhop {
reads {
ingress_metadata.ecmp_offset : exact;
}
actions {
_drop;
set_nhop;
}
size : ECMP_NHOP_TABLE_SIZE;
}
action set_dmac(dmac) {
modify_field(ethernet.dstAddr, dmac);
}
table forward {
reads {
ingress_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(flowlet);
if (ingress_metadata.flow_ipg > FLOWLET_INACTIVE_TOUT) {
apply(new_flowlet);
}
apply(ecmp_group);
apply(ecmp_nhop);
apply(forward);
}
control egress {
apply(send_frame);
}
Run P4 without P4factory - A Simple Example In Tutorials. -2 附 simple_router源码的更多相关文章
- Run P4 without P4factory - A Simple Example In Tutorials. -2
Reference:Github-Tutorial Exercise 2: Implementing TCP flowlet switching 实验准备: 参考之前的博客:Run P4 withou ...
- Run P4 without P4factory - A Simple Example In Tutorials.
前言 本文是我运行P4社区于Github开源教程Tutorials中的P4 SIGCOMM 2015 Tutorial一些实战小结,Github链接: Github. 测试的例子:P4 SIGCOMM ...
- flask 源码专题(一):app.run()的背后
当我们用Flask写好一个app后, 运行app.run()表示监听指定的端口, 对收到的request运行app生成response并返回. 现在分析一下, 运行app.run()后具体发生了什么事 ...
- Quartz源码——QuartzSchedulerThread.run() 源码分析(三)
QuartzSchedulerThread.run()是主要处理任务的方法!下面进行分析,方便自己查看! 我都是分析的jobStore 方式为jdbc的SimpleTrigger!RAM的方式类似分析 ...
- spring-boot-2.0.3启动源码篇四 - run方法(三)之createApplicationContext
前言 此系列是针对springboot的启动,旨在于和大家一起来看看springboot启动的过程中到底做了一些什么事.如果大家对springboot的源码有所研究,可以挑些自己感兴趣或者对自己有帮助 ...
- Spring boot 源码分析(一)SpringApplication.run(上)
SpringApplication.run(Main.class, args); 从这个方法开始讲吧: public static ConfigurableApplicationContext run ...
- spring-boot-2.0.3启动源码篇三 - run方法(二)之prepareEnvironment
前言 此系列是针对springboot的启动,旨在于和大家一起来看看springboot启动的过程中到底做了一些什么事.如果大家对springboot的源码有所研究,可以挑些自己感兴趣或者对自己有帮助 ...
- spring-boot-2.0.3启动源码篇二 - run方法(一)之SpringApplicationRunListener
前言 Springboot启动源码系列还只写了一篇,已经过去一周,又到了每周一更的时间了(是不是很熟悉?),大家有没有很期待了?我会尽量保证启动源码系列每周一更,争取不让大家每周的期望落空.一周之中可 ...
- spring-boot-2.0.3启动源码篇五 - run方法(四)之prepareContext
前言 此系列是针对springboot的启动,旨在于和大家一起来看看springboot启动的过程中到底做了一些什么事.如果大家对springboot的源码有所研究,可以挑些自己感兴趣或者对自己有帮助 ...
随机推荐
- WPF [调用线程无法访问此对象,因为另一个线程拥有该对象。] 解决方案以及如何实现字体颜色的渐变
本文说明WPF [调用线程无法访问此对象,因为另一个线程拥有该对象.] 解决方案以及如何实现字体颜色的渐变 先来看看C#中Timer的简单说明,你想必猜到实现需要用到Timer的相关知识了吧. C# ...
- Excel: 公式
单元格内输入 = xx公式 e.g =EXACT(C2,D2) //比较两个单元格内的文本是否相同
- soapui中文操作手册(五)----入门与安全测试
在SoapUI4.0引入的安全测试特点使它非常容易为你来验证你的目标服务的功能性安全,就可以评估您的系统常见的安全攻击的漏洞.特别是如果系统是公开可用的,即使不是这种情况,确保了完全安全的环境也是非常 ...
- [R]R语言里的异常处理与错误控制
之前一直只是在写小程序脚本工具,几乎不会对异常和错误进行控制和处理. 随着脚本结构和逻辑更复杂,脚本输出结果的准确性验证困难,同时已发布脚本的维护也变得困难.所以也开始考虑引入异常处理和测试工具的事情 ...
- change,propertychange,input事件小议
github上关于mootools一个issue的讨论很有意思,所以就想测试记录下.感兴趣的可以点击原页面看看. 这个问题来自IE(LTE8)中对checkbox和radio change事件的实现问 ...
- SPFA 的两个优化
From NOCOW SPFA算法有两个优化算法 SLF 和 LLL: SLF:Small Label First 策略,设要加入的节点是j,队首元素为i,若dist(j)<dist(i),则将 ...
- 利用ngxtop实时监控nginx的访问情况
关于对nginx web server的实时访问的实时监控问题,我很久之前就想实现的,现在虽有nginx自带的status扩展,但那是全局的,无法细分到vhost,并且提供的metric也很少,加之目 ...
- ACM 分数加减法
分数加减法 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 编写一个C程序,实现两个分数的加减法 输入 输入包含多行数据 每行数据是一个字符串,格式是" ...
- 僵尸进程的产生和避免,如何kill杀掉linux系统中的僵尸defunct进程
在 Unix系统管理中,当用ps命令观察进程的执行状态时,经常看到某些进程的状态栏为defunct,这就是所谓的"僵尸"进程."僵尸"进程是一个早已 死亡的进程 ...
- BZOJ4513: [Sdoi2016]储能表
Description 有一个 n 行 m 列的表格,行从 0 到 n−1 编号,列从 0 到 m−1 编号.每个格子都储存着能量.最初,第 i 行第 j 列的格子储存着 (i xor j) 点能量. ...