stateful.p4

#include "includes/headers.p4"
#include "includes/parser.p4" action hop(ttl, egress_spec) {
add_to_field(ttl, -1);
modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF);
} action hop_ipv4(egress_spec) {
hop(ipv4.ttl, egress_spec);
} /* This should not be necessary if drop is allowed in table action specs */
action drop_pkt() {
drop();
} table ipv4_routing {
reads {
ipv4.dstAddr : lpm;
}
actions {
drop_pkt;
hop_ipv4;
}
} action act() {
count(cnt1, 10);
} table table_2 {
reads {
ipv4.dstAddr : lpm;
}
actions {
act;
}
} counter cnt1 {
type : packets;
static : table_2;
instance_count : 32;
} register reg1 {
width : 20;
static : ipv4_routing;
instance_count : 100;
attributes : saturating, signed;
} register reg2 {
layout : ipv4_t;
direct : ipv4_routing;
} control ingress {
apply(ipv4_routing);
apply(table_2);
} control egress { }

control_flow_opt.p4

#include "includes/headers.p4"
#include "includes/parser.p4" action hop(ttl, egress_spec) {
add_to_field(ttl, -1);
modify_field(standard_metadata.egress_spec, egress_spec, 0xFFFFFFFF);
} action hop_ipv4(egress_spec) {
hop(ipv4.ttl, egress_spec);
} /* This should not be necessary if drop is allowed in table action specs */
action drop_pkt() {
drop();
} table ipv4_routing {
reads {
ipv4.dstAddr : lpm;
}
actions {
drop_pkt;
hop_ipv4;
}
} action act() {
count(cnt1, 10);
} action lala() { } table table_2 {
reads {
ipv4.dstAddr : lpm;
}
actions {
act;
}
} table table_3 {
reads {
ipv4.dstAddr : lpm;
}
actions {
lala;
}
} counter cnt1 {
type : packets;
static : table_2;
instance_count : 32;
} register reg1 {
width : 20;
static : ipv4_routing;
instance_count : 100;
attributes : saturating, signed;
} register reg2 {
layout : ipv4_t;
direct : ipv4_routing;
} control ingress {
if (valid(ipv4)) {
apply(ipv4_routing);
if (valid(ipv4)) {
apply(table_3);
}
}
if (valid(ipv6)) {
apply(table_2);
} } control egress { }

headers.p4

header_type ethernet_t {
fields {
dstAddr : 48;
srcAddr : 48;
etherType : 16;
}
} header_type vlan_tag_t {
fields {
pcp : 3;
cfi : 1;
vid : 12;
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 ipv6_t {
fields {
version : 4;
trafficClass : 8;
flowLabel : 20;
payloadLen : 16;
nextHdr : 8;
hopLimit : 8;
srcAddr : 128;
dstAddr : 128;
}
} header_type icmp_t {
fields {
hdr_type : 8;
code : 8;
hdrChecksum : 16;
}
} header_type icmpv6_t {
fields {
hdr_type : 8;
code : 8;
hdrChecksum : 16;
}
} 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;
}
} header_type udp_t {
fields {
srcPort : 16;
dstPort : 16;
hdr_length : 16;
checksum : 16;
}
} header_type routing_metadata_t {
fields {
drop : 1;
}
}

parser.p4


metadata routing_metadata_t routing_metadata; parser start {
set_metadata(routing_metadata.drop, 0);
return parse_ethernet;
} #define ETHERTYPE_VLAN 0x8100, 0x9100, 0x9200, 0x9300
#define ETHERTYPE_IPV4 0x0800
#define ETHERTYPE_IPV6 0x86dd
#define ETHERTYPE_ARP 0x0806
#define ETHERTYPE_RARP 0x8035 header ethernet_t ethernet; parser parse_ethernet {
extract(ethernet);
return select(latest.etherType) {
ETHERTYPE_VLAN : parse_vlan;
ETHERTYPE_IPV4 : parse_ipv4;
ETHERTYPE_IPV6 : parse_ipv6;
}
} #define VLAN_DEPTH 4
header vlan_tag_t vlan_tag_[VLAN_DEPTH]; parser parse_vlan {
extract(vlan_tag_[next]);
return select(latest.etherType) {
ETHERTYPE_VLAN : parse_vlan;
ETHERTYPE_IPV4 : parse_ipv4;
ETHERTYPE_IPV6 : parse_ipv6;
}
} #define IP_PROTOCOLS_ICMP 1
#define IP_PROTOCOLS_TCP 6
#define IP_PROTOCOLS_UDP 17
#define IP_PROTOCOLS_ICMPV6 58 header ipv4_t ipv4; parser parse_ipv4 {
extract(ipv4);
return select(latest.fragOffset, latest.protocol) {
IP_PROTOCOLS_ICMP : parse_icmp;
IP_PROTOCOLS_TCP : parse_tcp;
IP_PROTOCOLS_UDP : parse_udp;
}
} header ipv6_t ipv6; parser parse_ipv6 {
extract(ipv6);
return select(latest.nextHdr) {
IP_PROTOCOLS_ICMPV6 : parse_icmpv6;
IP_PROTOCOLS_TCP : parse_tcp;
IP_PROTOCOLS_UDP : parse_udp;
}
} header icmp_t icmp; parser parse_icmp {
extract(icmp);
return ingress;
} header icmpv6_t icmpv6; parser parse_icmpv6 {
extract(icmpv6);
return ingress;
} header tcp_t tcp; parser parse_tcp {
extract(tcp);
return ingress;
} header udp_t udp; parser parse_udp {
extract(udp);
return ingress;
}

2016/12/2

p4-hlir/test源码 stateful.p4 control_flow_opt.p4的更多相关文章

  1. maven 下载 源码和javadoc 命令

    摘要:我们在写代码时候,往往是想查看一下源码,看看源码的一些细节内容.一般情况下,在IDE(如eclipse)中近仅仅只需按住ctrl+ 点击对应的方法即可进入对应的源码部分.但是有些时候很多依赖项并 ...

  2. android源码的目录结构

    android源码的目录结构 [以下网络摘抄] |-- Makefile ! l/ a5 n% S% @- `0 d# z# a$ P4 V3 o7 R|-- bionic              ...

  3. JS魔法堂:剖析源码理解Promises/A规范

    一.前言 Promises/A是由CommonJS组织制定的异步模式编程规范,有不少库已根据该规范及后来经改进的Promises/A+规范提供了实现 如Q, Bluebird, when, rsvp. ...

  4. AndFix热修复 —— 实战与源码解析

    当你的应用发布后第二天却发现一个重要的bug要修复,头疼的同时你可能想着赶紧修复重新打个包发布出去,让用户收到自动更新重新下载.但是万事皆有可能,万一隔一天又发现一个急需修复的bug呢?难道再次发布打 ...

  5. socket_server源码剖析、python作用域、IO多路复用

    本节内容: 课前准备知识: 函数嵌套函数的使用方法: 我们在使用函数嵌套函数的时候,是学习装饰器的时候,出现过,由一个函数返回值是一个函数体情况. 我们在使用函数嵌套函数的时候,最好也这么写. def ...

  6. JQuery源码分析(七)

    了解jQuery对DOM进行遍历背后的工作机制,这样可以在编写代码时有意识地避免一些不必要的重复操作,从而提升代码的性能. 关于jQuery对象的包装 var $aaron = $("aar ...

  7. Hadoop源码的编译过程详细解读(各版本)

    说在前面的话   重新试多几次.编译过程中会出现下载某个包的时间太久,这是由于连接网站的过程中会出现假死,按ctrl+c,重新运行编译命令. 如果出现缺少了某个文件的情况,则要先清理maven(使用命 ...

  8. Android中Canvas绘图基础详解(附源码下载) (转)

    Android中Canvas绘图基础详解(附源码下载) 原文链接  http://blog.csdn.net/iispring/article/details/49770651   AndroidCa ...

  9. 关于源码编译每次提示有错误 要make update-api

    最近编译newline的版本的时候..同事修改了andoid默认输入法为百度.这是系统自动提供的API,所以每次编译会提示 此时在编译源码生成SDK的过程中会出现这个问题:************** ...

随机推荐

  1. python基础——迭代

    python基础——迭代 如果给定一个list或tuple,我们可以通过for循环来遍历这个list或tuple,这种遍历我们称为迭代(Iteration). 在Python中,迭代是通过for .. ...

  2. fork

    #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> ...

  3. show processlist

    mysql> show processlist; #mysql服务器查看有那些主机连进来,并列出它们查什么库 +-----+------+-----------+------+--------- ...

  4. js伪数组及转换

    什么是伪数组 能通过Array.prototype.slice转换为真正的数组的带有length属性的对象. 这种对象有很多,比较特别的是arguments对象,还有像调用getElementsByT ...

  5. SQL with as

    姓名 课程 分数 张三 语文 张三 数学 张三 物理 李四 语文 李四 数学 李四 物理 先看下面一个嵌套的查询语句 ) 上面的查询语句使用了一个子查询.虽然这条SQL语句并不复杂,但如果嵌套的层次过 ...

  6. Java Hour 48 Servlet 简介

    搞Java Web 开发,绕不开的就是Servlet 了.传说Servlet 是一种比JSP 更加古董的动态网页编程技术.在没有JSP 之前,Servlet 同时充当了展现层,业务逻辑层和持久层. 这 ...

  7. vijos 1037 ***

    链接:点我 #include <cstdio> #include <cstring> #include <algorithm> #include <iostr ...

  8. hdu 4091 线性规划

    分析转自:http://blog.csdn.net/dongdongzhang_/article/details/7955136 题意 :  背包能装体积为N,  有两种宝石, 数量无限, 不能切割. ...

  9. 为什么是List list = new ArrayList() 而不直接用ArrayList

    为什么是List list = new ArrayList(),而不直接用ArrayList? 编程是要面向对象编程,针对抽象(接口),而非具体.List 是接口,ArrayList是实现. 实现Li ...

  10. Codeforces Round #352 (Div. 2) D. Robin Hood 二分

    D. Robin Hood   We all know the impressive story of Robin Hood. Robin Hood uses his archery skills a ...