Control block

Control block之中用于放置设计好的Table和Action。

可以把control block认为是pipeline的一个模板,之前用的v1model中就是ingress和egress。 不同的架构中的control block格式不同。 其主要的功能就是知道每一个封包经过的table顺序以及采用的规则(触发条件等)。还能放置一些其他的功能部件,例如计数器counter等。


对于一个match-action pipeline通过control block的执行流程描述如下:

  • At runtime, statements within a block are executed in the order they appear in the control block.
  • Execution of the return statement causes immediate termination of the execution of the current control block, and a return to the caller.
  • Execution of the exit statement causes the immediate termination of the execution of the current control block and of all the enclosing caller control blocks.
  • Applying a table executes the corresponding match-action unit, as described above.

简单来说就是return退出并返回,exit退出,或者继续执行table中的规则。


p4中允许control调用其他control的服务,但是必须得在当前的control中进行实例化申明。

 control Callee(inout IPv4 ipv4) { ...}
control Caller(inout Headers h) {
Callee() instance; // instance of callee
apply {
instance.apply(h.ipv4); // invoke control
}
}

v1model

 control Ingress_name(inout H hdr,
inout M meta,
inout standard_metadata_t stand_metadata);

从参数中可以看出,需要包含定义好的header和metadata。且包含架构中提供的stand_metadata。

样例

ipv4转发:

 control MyIngress(inout headers hdr,
inout metadata meta,
inout standard_metadata_t standard_metadata)
{
action drop(){
mark_to_drop();
} action ipv4_forward(macAddr_t dstAddr,egressSpec_t port){
standard_metadata.egress_spec = port;
hdr.ethernet.srcAddr = hdr.ethernet.dstAddr;
hdr.ethernet.dstAddr = dstAddr;
hdr.ipv4.ttl = hdr.ipv4.ttl - ;
} table ipv4_lpm{
key = {
hdr.ipv4.dstAddr: lpm;
} actions = {
ipv4_forward;
drop;
NoAction;
} size = ; default_action = drop();
} apply{
if(hdr.ipv4.isValid()){
ipv4_lpm.apply();
}
}
}

从code的apply中看出,当封包是ipv4协议的时候,执行ipv4_lpm的table。

P4语法(4)Control block的更多相关文章

  1. P4语法(5) Package

    Package 对于package这个概念,类似于将一个框架中各组成部件以一个规律进行打包,以正常运转. 基于一个架构去编写一个新的pipeline的时候,需要先了解初始化的时候需要提供那些东西,pa ...

  2. Thread control block & thread

    https://en.wikipedia.org/wiki/Thread_control_block Thread Control Block (TCB) is a data structure in ...

  3. Thread Control Block

    Thread Control Block The following is the declaration of the Thread Control Block. struct tcb { u32_ ...

  4. P4语法(2) Parser

    这里参考学习了: P4语言规范 P4台湾社群 Parser 关于parser 在P4程序中,有着大量的首部(header)和首部实例,但每次只有部分首部实例会对数据包进行操作,而parser会用于生成 ...

  5. Sublime P4语法高亮设置

    Github插件链接:p4-syntax-highlighter 首先安装Package Control. 进入Package界面,我的目录: /Users/wasdns/Library/Applic ...

  6. iOS开发——语法OC篇&Block回顾

    Block回顾 这里知识简单介绍一下关于Block的语法,如果你觉得这里很简单或者想学习更深入的的使用清查看记者之前写的使用block传值和高级Block使用: http://www.cnblogs. ...

  7. P4语法(3)Table,Action

    Table table是p4的匹配——动作表,定义了匹配字段(key).动作(action)和一些其他相关属性. 其处理数据包的流程: Key construction.建立其匹配字段 Key loo ...

  8. P4语法(1)基础数据类型和Header

    文章学习自:P4语言编程详解 由于原文有一点的年份,所以也继续阅读了相关的最新规范. P4语言规范 基础数据类型 布尔型(bool) 运算符 描述 and 双目运算符,结果为布尔型 or 双目运算符, ...

  9. 进程控制块(Process Control Block, PCB)

    是为了管理进程设置的一个数据结构.是系统感知进程存在的唯一标志.通常包含如以下的信息:(1)进程标识符(唯一)(2)进程当前状态,通常同一状态的进程会被放到同一个队列:(3)进程的程序和数据地址(4) ...

随机推荐

  1. mysql截取字段并插入到新的字段中

    例如:在产品表product表中字段content值为["10"],然后在产品表中新建一个字段product_id,提出字段content的值10,如何实现呢? 解: update ...

  2. 初次使用vue-cli3 来搭建项目

    1,细数项目中使用的技术:vue, vue-router, vuex ,axios,vue-cli3, 快速建站. 2,mock技术使用的express-mockjs . 由于cli3 最新版的话缺少 ...

  3. Struts2速记手册

    工作原理 Action类 Action类 普通Action类 私有属性及getter.setter(处理请求参数) execute()方法(处理请求)   实现Action接口 提供常量   继承Ac ...

  4. Delphi写的DLL,OCX中多线程一个同步问题

    Delphi写的DLL,OCX中如果使用了TThread.Synchronze(Proc),可能导致线程死锁,原因是无法唤醒EXE中主线程, Synchronze并不会进入EXE主线程消息队列. 下面 ...

  5. T+API HTTPServer服务端

    该服务端是一个HTTP服务器,这样其他语言调用也方便. 出于某些原因,只支持Post方法,不打算支持其他方法,例如Get. API所接受的参数将以Json传送,回传的数据也是一个Json数据,一切只是 ...

  6. 笔记-scrapy-selector

    笔记-scrapy-selector scrapy版本:1.5.0 1.总述 scrapy内置selector建立在lxml上. 2.使用 可以使用xpath和css方法来进行解析,两者都返回列表: ...

  7. 【SQLSERVER】索引的维护优化

    一.索引的利弊   优点: 1.大大加快数据的检索速度: 2.创建唯一性索引,保证数据库表中每一行数据的唯一性: 3.加速表和表之间的连接: 4.在使用分组和排序子句进行数据检索时,可以显著减少查询中 ...

  8. wpf TabControl控件的SelectionChanged方法

    对于老手来说很简单,但是新手我从百度上找了好久没找到,最后还是去谷歌找到的,哎,万能的google. 前端界面: <TabControl Margin="0,10,0,0" ...

  9. Yii 2.0 使用片段缓存

    网站首页footer中的菜单标题是从数据库读取并显示处理的. 也就是 <footer>标题里面是foreach.这样每个人打开网站就查询遍历效率会很低. <footer class= ...

  10. Mac 安装PHP Redis 扩展

    其实 Mac 安装 Redis 还是很简单,以下为个人搭建配置.注意:文章中的“*”代表任意版本号 安装 Redis 服务 安装 brew install redis 使用 # 启动 redis-se ...