Openvswitch原理与代码分析(7): 添加一条流表flow
添加一个flow,调用的命令为
ovs-ofctl add-flow hello "hard_timeout=0 idle_timeout=0 priority=1 table=21 pkt_mark=0x55 tun_id=0x55 actions=mod_nw_dst:192.168.56.101,output:2"
这里调用的是调用ovs/utilities/ovs-ofctl.c的命令行工具
这个命令行工具支持的所有的命令及处理函数定义如下:
|
根据这个数据结构的定义,"add-flow"调用的函数为
|
调用ofctl_flow_mod,parse_ofp_flow_mod_str将字符串解析为ofputil_flow_mod fm
ofputil_flow_mod包含两个最重要的成员变量:
struct match match,所谓match就是一个key。
struct ofpact *ofpacts; /* Series of "struct ofpact"s. */
|
ofctl_flow_mod__会打开一个指向ovs-vswitchd的socket,将flow match变成openflow的协议,发出去transact_noreply
|
Ovs-vswitchd会监听socket,在ovs-vswitchd.c中bridge_run每个bridge会监听消息,ofproto_run监听openflow的调用,connmgr_run网络连接管理,ofconn_run管理socket连接。
connmgr_run(p->connmgr, handle_openflow);会设置当有openflow调用的时候,handle_openflow会被调用。
|
handle_openflow__会做如下的调用:
|
handle_flow_mod首先将openflow协议解析为fm和ofpacts
|
然后调用static enum ofperr handle_flow_mod__(struct ofproto *ofproto, struct ofproto_flow_mod *ofm, const struct flow_mod_requester *req)
会调用static enum ofperr ofproto_flow_mod_start(struct ofproto *ofproto, struct ofproto_flow_mod *ofm) OVS_REQUIRES(ofproto_mutex)
|
在函数add_flow_start中,首先cls_rule_init(&cr, &fm->match, fm->priority); 将match也即key变成一个cls_rule,cls_rule是一个压缩版本的match,match是一个整个数据结构保存整个package,从L1一直到L4全都有,比较大,如果保存在内存太浪费,cls_rule中有一个minimatch,是用压缩的方式保存match,也即如果match中为0的部分不保存,采取稀疏矩阵的方式。
接下来创建一个新的rule,error = replace_rule_create(ofproto, fm, &cr, table - ofproto->tables, rule, new_rule);
最后replace_rule_start(ofproto, ofm->version, rule, *new_rule, conjs, n_conjs); 将rule替换现在的rule,有则替换,没有则插入。
|
最新文章
- ZeroMQ接口函数之 :zmq_msg_set - 设置消息的性质
- 谢欣伦 - OpenDev原创教程 - 通信开发库libComm
- delphi真随机数发生器
- HTML5之创新的视频拼图剖析式学习之二
- mybatis热加载的实现
- WPF之基于路径的动画
- iOS 使用compare 进行对比
- pl/sql插入报错
- 聊聊 Statsd 和 Collectd 那点事!
- Base64笔记
- WebGL多模型光照综合实例
- 【JavaScript 实现当前动态时间】
- HTML5 canvas clearRect() 方法
- 使用Jmeter监测服务器性能指标
- 关于java实现自定义曲线拟合的研究
- Hadoop入门
- Django的View(视图)
- Linux - 查看进程状态
- yield函数的理解
- python dash 初探 --- k 线国内版