2019 SDN上机第4次作业
1.用Python脚本搭建如下拓扑,连接OpenDayLight控制器
创建拓扑如下
from mininet.topo import Topo
class MyTopo(Topo):
def __init__(self):
# initilaize topology
Topo.__init__(self)
# add hosts and switches
h1 = self.addHost('h1')
h2 = self.addHost('h2')
h3 = self.addHost('h3')
s1 = self.addSwitch('s1')
# add links
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 a.py --topo mytopo --controller=remote,ip=127.0.0.1,port=6633 --switch ovsk,protocols=OpenFlow13
使用pingall命令测试连通性
控制器端的拓扑图
2.在控制器提供的WEB UI中下发流表使h2 20s内ping不通h3,20s后恢复
依次打开:Yang UI>Opendaylight-inventory>config>nodes>table>flow
首先使用links查询链路连接情况
可以看出h2连接s1的port2, h3连接s1的port3
故可以让下发策略使port2进来的目的IP为h3的数据包都drop掉,这样就可以ping不通
按一下方法设置即可,注意get要改成put
验证h2 ping h3中断又恢复
3.借助Postman通过OpenDayLight的北向接口下发流表,再利用OpenDayLight北向接口查看已下发的流表
对Postman的安装,下完安装包后,使用命令如下,即可安装成功
sudo tar -xzf Postman-linux-x64-7.11.0.tar.gz
./Postman/Postman
Postman下发流表及查看流表
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": "2",
"ethernet-match": {
"ethernet-type": {
"type": "0x0800"
}
},
"ipv4-destination": "10.0.0.3/32"
},
"instructions": {
"instruction": [
{
"order": "0",
"apply-actions": {
"action": [
{
"order": "0",
"drop-action": {}
}
]
}
}
]
},
"priority": "65535",
"hard-timeout": "20",
"table_id": "0"
}
]
}
可使用postman下发流表
下发效果
使用postman的get来调用接口查看流表