OpenDayLight+Mininet+Postman下发流表实验

VM实验环境

设备 软件环境 硬件环境
Controller Ubuntu 14.04 OpenDaylight Lithium CPU:2核 内存:4G 磁盘:20G
Mininet Ubuntu 14.04 Mininet 2.3.0 CPU:2核 内存:4G 磁盘:20G

笔记本环境

设备 软件环境 硬件环境
postman Postman-win64-7.9.0 Intel® Core™ i5-1035G1 Processor 16G DDR4
Chrome 89.0.4389.82(正式版本)(64 位) Intel® Core™ i5-1035G1 Processor 16G DDR4

Tips1

postman 不需要安装到 vm linux系统内,在windows系统内使用即可

Tips2

ODL 登录网页页面同样不需要再linux系统内进行,依旧在windows 系统下 chrome brower 登录

需要postman软件包的滴滴我

任务目的

1、掌握OpenFlow流表相关知识,理解SDN网络中L2,L3,L4层流表的概念。
2、学习并熟练掌握Postman工具下发L2,L3,L4层流表。

任务内容

1、学习OpenFlow流表的组成,包头域的解析流程及流表的匹配流程。
2、熟悉OpenDaylight对接Mininet的使用。
3、使用Postman工具,下发相应的L2,L3,L4层流表,并验证。

实验原理

SDN的设计目标之一就是将网络设备的控制功能与转发功能进行分离,进而将控制功能全部集中到远程的控制器上完成,而SDN交换机只负责在本地做简单高速的数据转发。在SDN交换机运行的过程中,其数据转发的依据就是流表。

一、 流表结构

所谓流表,其实可被视作是SDN对网络设备的数据转发功能的一种抽象。在传统网络设备中,交换机和路由器的数据转发需要依赖设备中保存的二层MAC地址转发表或者三层的IP地址路由表,SDN交换机中使用的流表也是如此,不过在它的表项中整合了网络中各个层次的网络配置信息,从而在进行数据转发时可以使用更丰富的规则。其流表中的每个表项结果如下图所示:

在这里插入图片描述
• match fields: to match against packets. These consist of the ingress port and packet headers, and optionally metadata specified by a previous table.

• priority: matching precedence of the flow entry

• counters: to update for matching packets

扫描二维码关注公众号,回复: 13036377 查看本文章

• instructions to modify the action set or pipeline processing

• timeouts: maximum amount of time or idle time before flow is expired by the switch

• cookie: opaque data value chosen by the controller. May be used by the controller to filter flow statistics, flow modification and flow deletion, not used when processing packets.

•match fields:它们由入口端口和包头组成以及以及前一个表指定的元数据组成。

•priority:流表项的匹配优先级

•countres:更新匹配的数据包

•instructions:修改动作集或流水线处理的说明

•timeout:交换机流匹配最大计数时间和流有效时间
idle_time 匹配流表的最大计数时间
hard_time 下发流表后有效时间

•cookie:控制器选择的不透明数据值。控制器可以用来过滤流量统计、流修改和流删除信息,处理报文时不使用。

二、 匹配域解析流程

当SDN交换机接收到一个数据包时,将按照优先级从table0依次匹配其本地保存的流表中的表项,并以发生具有最高优先级的匹配表项作为匹配结果,并根据相应的动作对数据包进行操作。同时,一旦匹配成功,对应的计数器将更新;而如果没能找到匹配的表项,则将数据包转发给控制器。

OpenFlow交换机对数据包头的解析和匹配过程的细节操作如图所示:

在这里插入图片描述

1、初始化包头域,按照包头域的组成—设置每个字段,其中入端口是接收数据包的物理端口。

2、如果数据包类型是VLAN(0x8100),那么就使用VLAN
ID和PCP字段进行表查找,解封以太网类型为先的以太网类型解析做准备。

3、(可选)如果是ARP数据包(0x0806),那么匹配字段就可能包含IP源和目的地址。

4、如果是IP数据包(0x0800),那么匹配字段就会包含IP首部。如果IP数据包的分段偏移量不为0或者设置了多个分段bit位,那么将所有传输端口设为0。如果IP数据包在IP协议族中的编号为6或者17(分别是TCP/UDP类型),那么匹配字段包含传输端口。如果编号为1(ICMP数据包)则包含Type和Code字段。

三、 OpenFlow1.3流表匹配流程

OpenFlow1.3匹配流程图与之前版本相比多了一个table-miss流表项,事实上此前版本就已经存在table-miss概念,只是没有在流程图中呈现出来而已。Of1.3版本的匹配流程大致如下图所示:

在这里插入图片描述
首先SDN交换机解析进入设备的报文,然后从table0开始匹配,按照优先级高低依次匹配该流表中的表项,一个报文在一个流表中只会匹配上一条流表项。通常根据报文的类型,报文头的字段例如源MAC地址、目的MAC地址、源IP地址、目的IP地址等进行匹配,大部分匹配还支持掩码进行更精确、灵活的匹配。也可以通过报文的入端口或者元数据信息来进行报文的匹配,一个流表项中可以同时存在多个匹配项,一个报文需要同时普票流表项中所有匹配项才能匹配该流表项。报文匹配按照现有的报文字段进行,比如前一个流表通过apply actions改变了该报文的某个字段,则下一个表现按照修改后的字段进行匹配。如果匹配成功。则按照指令集里的动作更新动作集,活更新报文/匹配集字段,或更新元数据和计数器。根据指令是否继续前往下一个流表,不继续则终止匹配流程执行动作集,如果指令要去继续前往下一流表则继续匹配,下一个流表的ID需要比当前流表ID大。当报文匹配失败,如果存在无匹配流表项(table-miss)就按照该表项执行指令,一般是将报文转发给控制器、丢弃或者转发给其他流表。如果没有table-miss表项则默认丢弃该报文。

实验步骤

Step1 开ODL 控制器

#cd distribution-karaf-0.3.0-Lithium/
#./bin/karaf

如下:
在这里插入图片描述

Tips:
切记这里多等一会不要着急登录页面

Step2 VM ifconfig查看地址,电脑登陆页面

在这里插入图片描述

看到这里有两个地址,请记住它,
我这里第一个是192.168.137.143,第二个都是127.0.0.1
这里只有mininet连接ODL用到127.0.0.1,其他都是用另一个地址。

然后用你的电脑登录网址http:// [IP address]:8080/index.html,username 和 password 都是admin。(不是VM 里的firefox的浏览器)

登录结果如下:
在这里插入图片描述

Step3 Mininet连接ODL,查看topo结构

#mn --custom example1.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633

在这里插入图片描述

这里注意看自己有么有连上ODL controller,还有就是地址注意是127.0.0.1,
没有连接上控制器的同学还有不知道为什么两个地址是这样分配的评论区问。

在上面界面下pingall下

mininet>pingall

返回本机电脑网页reload下可以看到topo

在这里插入图片描述
细致topo图如下:
在这里插入图片描述

Step4 Windows下打开Postman查看交换机信息

Basic Auth页签,Username字段填写admin,Password字段填写admin完成认证。

提交方式为GET,URL地址栏中输入http://192.168.137.143:8080/restconf/operational/network-topology:network-topology ,设置完成,单击Send按钮,获取交换机id信息输入。

这里ip地址每个人不一样,自己在VM里用ifconfig查看

在这里插入图片描述

L2层流表下发与验证

L2层即对应OSI模型的二层,也就是说通过匹配源MAC(Ether source)、目的MAC地址(Ether dst)、以太网类型(Ether Type)VLAN id、VLAN优先级等字段来实现流的转发。本实验将基于源和目的MAC进行数据流的转发。

Step5 下发第一条流表,选择PUT,填写URL和Headers信息

选择提交方式“PUT”。
URL地址栏输入如下形式的地址:http://{controllerip}:8080/restconf/config/opendaylight-inventory:nodes/node/{node-id}/table/{table-id}/flow/{flow-id}。

其中,{controller-ip}为控制器的ip地址,node-id为上面获取到的交换机id信息,table-id这里为0,flow-id根据下发不同流表变化,可自定义。

本实验URL地址栏输入如下地址:
http://192.168.137.143:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/107

填写Headers信息,如下图所示
在这里插入图片描述

Step6 填写body

流表:匹配源MAC(host1)为7e:24:bb:47:6f:58,目的MAC(host2)为42:30:90:5d:df:02的流量,出端口为2。

“body”中选择“raw”,格式为XML(application/xml),并填写如下消息体:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-source>
<address>7e:24:bb:47:6f:58</address>
</ethernet-source>
<ethernet-destination>
<address>42:30:90:5d:df:02</address>
</ethernet-destination>
</ethernet-match>
</match>
<id>107</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

在这里插入图片描述

Step7 SEND 发送下发流表,在mininet下查找流表

mininet>sh ovs-vsctl dump-flows s1

可以看到有priority=200的流表
在这里插入图片描述

Step8 发送第二条流表

流表:匹配源MAC(host2)为42:30:90:5d:df:02的流量,目的MAC(host1)为7e:24:bb:47:6f:58,出端口为1。
在这里插入图片描述

“body”中选择“raw”,格式为XML(application/xml),并填写如下消息体:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-source>
<address>42:30:90:5d:df:02</address>
</ethernet-source>
<ethernet-destination>
<address>7e:24:bb:47:6f:58</address>
</ethernet-destination>
</ethernet-match>
</match>
<id>108</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

Step9 SEND 发送下发流表,在mininet下查找流表

可以看到两条priority=200的流表项,分别对应刚刚的下发的两条刘表
在这里插入图片描述

STEP10 测试流表是否有效

先后用用下列命令测试连通性和查看数组是否有增加

mininet>h1 ping h2
mininet>h2 ping h1
sh ovs-ofctl dump-flows s1

在这里插入图片描述

STEP11 删除下发的两条流表,mininet查看是否删除

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

L3层L4层就简写了,给出关键步骤,仅仅给出下发过程,自行检验

L3层流表下发

L3层对应OSI模型的三层,三层流表主要匹配的是IP包的协议类型和IP地址。

在这里插入图片描述
URL地址栏输入:http://192.168.137.143:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/111
填写Hearders信息
“body”中选择“raw”,格式为XML(application/xml)
流表:匹配源IP地址为10.0.0.2/32的报文,并将其转发到1端口
匹配源IP地址为10.0.0.1/32的报文,并将其转发到2端口。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-source>10.0.0.1/32</ipv4-source>
</match>
<id>111</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

URL地址栏输入:http://192.168.137.143:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/112
填写Hearders信息
“body”中选择“raw”,格式为XML(application/xml)
流表:匹配源IP地址为10.0.0.2/32的报文,并将其转发到1端口

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-source>10.0.0.2/32</ipv4-source>
</match>
<id>112</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

URL地址栏输入:http://192.168.137.143:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/113
填写Hearders信息
“body”中选择“raw”,格式为XML(application/xml)
流表:下发arp匹配流表

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2054</type>
</ethernet-type>
</ethernet-match>
</match>
<id>113</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>NORMAL</output-node-connector>
<max-length>0</max-length>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

L4层流表下发

L4对应的OSI模型中的四层,即流表对应的TCP/UDP源端口(TCP/UDP src port)、TCP/UDP目的端口号(TCP/UDP dst port)字段。本实验匹配TCP目的端口

URL地址栏输入
http://192.168.137.143:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/117
填写Hearders信息
“body”中选择“raw”,格式为XML(application/xml)】
匹配到目的IP地址为10.0.0.1/32且目的端口为5001的TCP报文,将其转发到2端口

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<tcp-destination-port>5001</tcp-destination-port>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.0.1/32</ipv4-destination>
<ip-match>
<ip-protocol>6</ip-protocol>
</ip-match>
</match>
<id>117</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>2</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

URL地址栏输入
http://192.168.137.143:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/117
填写Hearders信息
“body”中选择“raw”,格式为XML(application/xml)
匹配到目的IP地址为10.0.0.2/32且目的端口为5001的TCP报文,将其转发到1端口

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2048</type>
</ethernet-type>
</ethernet-match>
<ipv4-destination>10.0.0.2/32</ipv4-destination>
<ip-match>
<ip-protocol>6</ip-protocol>
</ip-match>
</match>
<id>118</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>1</output-node-connector>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

URL地址栏输入
http://192.168.137.143:8080/restconf/config/opendaylight-inventory:nodes/node/openflow:1/table/0/flow/119
填写Hearders信息
“body”中选择“raw”,格式为XML(application/xml)
流表:下发arp匹配流表。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="urn:opendaylight:flow:inventory">
<priority>200</priority>
<flow-name>Foo1</flow-name>
<idle-timeout>0</idle-timeout>
<hard-timeout>0</hard-timeout>
<match>
<ethernet-match>
<ethernet-type>
<type>2054</type>
</ethernet-type>
</ethernet-match>
</match>
<id>119</id>
<table_id>0</table_id>
<instructions>
<instruction>
<order>0</order>
<apply-actions>
<action>
<order>0</order>
<output-action>
<output-node-connector>FLOOD</output-node-connector>
<max-length>0</max-length>
</output-action>
</action>
</apply-actions>
</instruction>
</instructions>
</flow>

实验参考

实验参考:

https://blog.csdn.net/hao_shujing/article/details/106137888

《软件定义网络实验教程 人民邮电出版社》

《OpenFlow Switch Specification Version 1.3.0 (Wire Protocol 0x04) June 25, 2012》

猜你喜欢

转载自blog.csdn.net/weixin_46239293/article/details/115030311