------------恢复内容开始------------
------------恢复内容开始------------
1. 解压安装OpenDayLight控制器(本次实验统一使用Beryllium版本)
- 用U盘从机房电脑拷贝文件并解压
tar xvf distribution-karaf-0.4.4-Beryllium-SR4.tar.gz
- 安装JAVA环境
- 在JAVA开源网站上下载安装包
- 解压安装包
- 添加环境变量
2. 启动并安装插件
cd distribution-karaf-0.4.4-Beryllium-SR4/bin/
./karaf
feature:install odl-restconf
feature:install odl-l2switch-switch-ui
feature:install odl-openflowplugin-all
feature:install odl-mdsal-apidocs
feature:install odl-dlux-core
feature:install odl-dlux-node
feature:install odl-dlux-yangui
3. 用Python脚本搭建如下拓扑,连接OpenDayLight控制器
- python脚本内容如下:
from mininet.topo import Topo
class MyTopo(Topo):
def __init__(self):
#初始化拓扑
Topo.__init__(self)
#添加主机和交换机
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
s1 = self.addSwitch('s1')
#添加连线
self.addLink(h1, s1, 1, 1)
self.addLink(h2, s1, 1, 2)
self.addLink(h3, s1, 1, 3)
topos = {'mytopo': (lambda: MyTopo())}
- 执行命令
sudo mn --custom ./test.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13
- 执行PING ALL指令后,控制器拓扑图如下:
4. 在控制器提供的WEB UI中下发流表使h2 20s内ping不通h3,20s后恢复
- 下发流表,node填入openflow:1,table为0,flow为1,层级结构如下所示:
- 将GET 改为 PUT
- 查询链路连接情况
- id:流表项id in-port:进接口 type:上层协议类型(0x0800为IP协议)
- layer-3-match: 三层匹配协议选择 source:源IP匹配 destination:目的IP匹配
- instruction list:匹配到流表项以后执行系列动作 (本例中为丢弃报文动作)
- flow_name:流表项名 priority:流表项优先级 hard-timeout:硬超时
- 下发流表(点击SEND)
5. 借助Postman通过OpenDayLight的北向接口下发流表,再利用OpenDayLight北向接口查看已下发的流表。
http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1
{
"flow": [
{
"id": "1",
"match": {
"in-port": "1",
"ethernet-match": {
"ethernet-type": {
"type": "0x0800"
}
},
"ipv4-destination": "10.0.0.3/32"
},
"instructions": {
"instruction": [
{
"order": "0",
"apply-actions": {
"action": [
{
"order": "0",
"drop-action": {}
}
]
}
}
]
},
"flow-name": "flow0",
"priority": "65535",
"hard-timeout": "20",
"cookie": "2",
"table_id": "0"
}
]
}