SDN第五次实验

(一)

hub模块

h1 ping h2

 

h1 ping h3

 

l2_learning模块

h1 ping h2

 

h1 ping h3

 

区别:hub下h1 ping h2时候h3也会收到数据包,ping h3时h2也会收到数据包; 而来l2_learning可以看到h3只抓到了h1 ping h2的第一个包,后面的包全部抓不到,这就符合交换机的Switch模式。

 

L2_learning模块代码,画出程序流程图.#

 

 

 

进阶任务#

代码如下

Copy
from pox.core import core
import pox.openflow.libopenflow_01 as of
from pox.openflow.of_json import *

def _handle_ConnectionUp(event):
    msg = of.ofp_flow_mod()
    msg.priority = 1
    msg.match.in_port = 1
    msg.actions.append(of.ofp_action_output(port=2))
    msg.actions.append(of.ofp_action_output(port=3))
    event.connection.send(msg)

    msg = of.ofp_flow_mod()
    msg.priority = 1
    msg.match.in_port = 2
    msg.actions.append(of.ofp_action_output(port=1))
    msg.actions.append(of.ofp_action_output(port=3))
    event.connection.send(msg)

    msg = of.ofp_flow_mod()
    msg.priority = 1
    msg.match.in_port = 3
    msg.actions.append(of.ofp_action_output(port=1))
    msg.actions.append(of.ofp_action_output(port=2))
    event.connection.send(msg)


def launch():
    core.openflow.addListenerByName("ConnectionUp", _handle_ConnectionUp)

 

心得体会

        此次实验非进阶部分较于简单,只要成功输入对应的命令,并且打开xterm在其中抓包即可。通过对比可以发现forwarding.hub与 forwarding.l2_learning 的不同,验证 了switch 模块。 l2_learning可以看到h3只抓到了h2 ping h1的第一个包,后面的包全部抓不到,这就符合交换机的Switch模式。至于为什么第一个包抓的到,我们开启wireshark对抓包进行分析查明此端口意义是将此数据包进行泛洪,所以交换机就会将此数据包就行泛洪,所以h3也能捕获到h2 ping h1的第一个数据包。进阶中看了代码就头大哈哈哈哈,借鉴了同学的方法。希望接下来也可以先摸清实验在干嘛再开始实验,并且注重细节。

 

posted @ 2021-10-10 16:33  bbbblur  阅读(65)  评论(0编辑  收藏  举报