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下不会,验证switch模块成功!
流程图:
进阶:
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)
似乎能用。。?
运行截图:
心得:连接上拓扑图使用的代码是
./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字