任何人都可以帮助我在循环拓扑中ping主机。静态痘控制器如下。 我的拓扑有4个交换机和3个主机。左边有一个主机,右边有两个主机。显然,我必须为每个主机实现路由路由,以便数据包可以到达目的地,而不是在无限循环中漫游网络。但我无法让它工作
非常感谢任何帮助,并提前感谢您
from pox.core import core
import pox.openflow.libopenflow_01 as of
from pox.lib.util import dpidToStr
log = core.getLogger()
s1_dpid=0
s2_dpid=0
s3_dpid=0
s4_dpid=0
def _handle_ConnectionUp (event):
global s1_dpid, s2_dpid, s3_dpid, s4_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
print "s1_dpid=", s1_dpid
elif m.name == "s2-eth3":
s2_dpid = event.connection.dpid
print "s2_dpid=", s2_dpid
elif m.name == "s3-eth3":
s3_dpid = event.connection.dpid
print "s3_dpid=", s3_dpid
elif m.name == "s4-eth4":
s4_dpid = event.connection.dpid
print "s4_dpid=", s4_dpid
def _handle_PacketIn (event):
global s1_dpid, s2_dpid, s3_dpid, s4_dpid
print "PacketIn: ", dpidToStr(event.connection.dpid)
if event.connection.dpid==s1_dpid:
msg = of.ofp_flow_mod()
msg.priority =1
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.dl_type = 0x0806
msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority =10
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 =10
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.dl_type = 0x0800
msg.match.nw_dst = "10.0.0.6"
msg.actions.append(of.ofp_action_output(port = 3))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority =10
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)
elif event.connection.dpid==s2_dpid:
msg = of.ofp_flow_mod()
msg.priority =1
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.in_port =3
msg.actions.append(of.ofp_action_output(port =4))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority =1
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.in_port =4
msg.actions.append(of.ofp_action_output(port =3))
event.connection.send(msg)
elif event.connection.dpid==s4_dpid:
msg = of.ofp_flow_mod()
msg.priority =1
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.in_port =3
msg.actions.append(of.ofp_action_output(port = 4))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority =1
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.in_port =4
msg.actions.append(of.ofp_action_output(port = 3))
event.connection.send(msg)
elif event.connection.dpid==s3_dpid:
msg = of.ofp_flow_mod()
msg.priority =1
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.dl_type = 0x0806
msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority =10
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.dl_type = 0x0800
msg.match.nw_dst = "10.0.0.6"
msg.actions.append(of.ofp_action_output(port = 2))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority =10
msg.idle_timeout = 0
msg.hard_timeout = 0
msg.match.dl_type = 0x0800
msg.match.nw_src="10.0.0.6"
msg.match.nw_dst = "10.0.0.1"
msg.actions.append(of.ofp_action_output(port = 4))
event.connection.send(msg)
# msg = of.ofp_flow_mod()
# msg.priority =10
#msg.idle_timeout = 0
#msg.hard_timeout = 0
#msg.match.dl_type = 0x0800
#msg.match.nw_src="10.0.0.5"
#msg.match.nw_dst = "10.0.0.1"
#msg.actions.append(of.ofp_action_output(port = 4))
#event.connection.send(msg)
def launch ():
core.openflow.addListenerByName("ConnectionUp",_handle_ConnectionUp)
core.openflow.addListenerByName("PacketIn",_handle_PacketIn)
答案 0 :(得分:0)
在Mininet中,一个OVS交换机不能连接多个主机。如果您删除h2
或h3
,则应该可以ping通。