2019 SDN上机第4次作业

1. 解压安装OpenDayLight控制器(本次实验统一使用Beryllium版本)

  • 安装完成:

2. 启动并安装插件

3. 用Python脚本搭建如下拓扑,连接OpenDayLight控制器

  • py代码:
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController,CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
 
class MyTopo( Topo ):
    "Simple topology example."
 
    def __init__( self ):
        "Create custom topo."
 
        Topo.__init__( self )

	switchs = []
        sw = self.addSwitch("s{}".format(1))
        switchs.append(sw)	

        for sw in switchs:
            for i in range(3):
                h = self.addHost("h{}".format(i+1))
                self.addLink(sw, h)
        
topos = { 'mytopo': ( lambda: MyTopo() ) }
  • 运行结果:

  • pingall后结果:

  • 拓扑图:

4. 在控制器提供的WEB UI中下发流表使h2 20s内ping不通h3,20s后恢复

  • 查看拓扑端口连接:

    h1 连接 s1 端口 1、h2 连接 s1 端口 2、h3 连接 s1 端口 3

  • ODL:

  • ODL具体设置:

    • get要改成put,node/openflow:1,table/0,flow/不超过1024,flow id为1,in-port为2,type为0x0800,目的地之为10.0.0.3/32
    • instruction list中order为0,action list中order为0
    • hard-timeout为20
  • 效果:

5. 借助Postman通过OpenDayLight的北向接口下发流表,再利用OpenDayLight北向接口查看已下发的流表。

  • 查看preview
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": {}
                                }
                            ]
                        }
                    }
                ]
            },
            "hard-timeout": "20",
            "table_id": "0"
        }
    ]
}

打开postman,但是卡在进入界面,上网查资料后,用rm -rf $HOME/.config/Postman后再./Postman,进入页面

  • 将preview里的url复制到地址栏,消息方式选PUT
    IP为控制器所在的PC的IP
    type选择Basic Auth 用户名和密码是ODL的登录账号和密码都是admin
  • Body中将消息格式设置成json,上传方式设置为raw
    将preview中的消息粘贴在文本框内,更改id为10,点击send后下发成功
  • 发送成功后改为GET并send查看刚刚下发的流表项
{
    "flow": [
        {
      "id":"10" ,
      "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": {}
                                }
                            ]
                        }
                    }
                ]
            },
            "hard-timeout": "20",
            "table_id": "0"
        }
    ]
}
posted @ 2019-11-24 14:20  方道友  阅读(223)  评论(0编辑  收藏  举报