sdn第五次上機作業


(一)

hub模塊

h1 ping h2

image

h1 ping h3

image

l2_learning模塊

h1 ping h2

image

h1 ping h3

image

區別:hub下h1 ping h2時候h3也會收到數據包,ping h3時h2也會收到數據包,而l2_learning下不會,驗證switch模塊成功!
流程圖:
image

進階:

from pox.core import core

import pox.openflow.libopenflow_01 as of

from pox.lib.util import dpidToStr

from pox.lib.addresses import IPAddr, EthAddr

from pox.lib.packet.arp import arp

from pox.lib.packet.ethernet import ethernet, ETHER_BROADCAST

from pox.lib.packet.packet_base import packet_base

from pox.lib.packet.packet_utils import *

import pox.lib.packet as pkt

from pox.lib.recoco import Timer

import time

log = core.getLogger()

s1_dpid = 0


def _handle_ConnectionUp(event):
    global s1_dpid
    print
    "ConnectionUp: ", dpidToStr(event.connection.dpid)

    # remember the connection dpid for switch

    for m in event.connection.features.ports:

        if m.name == "s1-eth1":
            s1_dpid = event.connection.dpid


def _handle_PacketIn(event):
    global s1_dpid

    packet = event.parsed

    if event.connection.dpid == s1_dpid:

        a = packet.find('arp')

        if a and a.protodst == "10.0.0.1":
            msg = of.ofp_packet_out(data=event.ofp)

            msg.actions.append(of.ofp_action_output(port=1))

            event.connection.send(msg)

        if a and a.protodst == "10.0.0.2":
            msg = of.ofp_packet_out(data=event.ofp)

            msg.actions.append(of.ofp_action_output(port=2))

            event.connection.send(msg)

        if a and a.protodst == "10.0.0.3":
            msg = of.ofp_packet_out(data=event.ofp)

            msg.actions.append(of.ofp_action_output(port=3))

            event.connection.send(msg)

        msg = of.ofp_flow_mod()

        msg.priority = 100

        msg.idle_timeout = 0

        msg.hard_timeout = 0

        msg.match.dl_type = 0x0800

        msg.match.nw_dst = "10.0.0.1"

        msg.actions.append(of.ofp_action_output(port=1))

        event.connection.send(msg)

        msg = of.ofp_flow_mod()

        msg.priority = 100

        msg.idle_timeout = 0

        msg.hard_timeout = 0

        msg.match.dl_type = 0x0800

        msg.match.nw_dst = "10.0.0.2"

        msg.actions.append(of.ofp_action_output(port=2))

        event.connection.send(msg)

        msg = of.ofp_flow_mod()

        msg.priority = 100

        msg.idle_timeout = 0

        msg.hard_timeout = 0

        msg.match.dl_type = 0x0800

        msg.match.nw_dst = "10.0.0.3"

        msg.actions.append(of.ofp_action_output(port=3))

        event.connection.send(msg)

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

    core.openflow.addListenerByName("PacketIn", _handle_PacketIn)

似乎能用。。?
運行截圖:
image

image

心得:連接上拓撲圖使用的代碼是

./pox.py log.level --DEBUG openflow.of_01 --address=127.0.0.1 --port=6633 forwarding.l2_learning
需要指定其所在地址和端口,否則會報錯提示端口被占用。

pox在安裝mininet時自帶,和mininet位於同一個文件夾,無需重新下載

之前忘記流程圖,這次補上。流程圖直接參考了代碼注釋。由於是機翻所以看着可能有點怪。流程圖使用flowchat語言生成,掌握了一門新技巧,不用要死要活的弄還簡潔、自動生成。

打開xterm需要在mininet命令行鍵入代碼為xterm h2 h3,再在里面抓包

進階能找到的資料特別特別少,試了一遍似乎都不太好使。最終的代碼是在SDNLAB里面找到的代碼基礎上修改的。總之一個程序能跑就別管他(?)。花了大功夫。

本次實驗進階確實整麻了。

湊200字湊200字湊200字湊200字湊200字湊200字湊200字湊200字湊200字湊200字


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM