1.基础要求:
h1 ping h2
h1 ping h3
L2_learning模块代码流程图:
2.进阶要求(1):
SendFlowInSingle3.py
from pox.core import core
import pox.openflow.libopenflow_01 as of # POX convention
from pox.openflow.of_json import *
def SendFlowInSingle3(event):
msg = of.ofp_flow_mod() # 向交换机下发流表
msg.priority = 1
msg.match.in_port = 1 # 数据包进入端口1
msg.actions.append(of.ofp_action_output(port=2)) # 从端口2转发
msg.actions.append(of.ofp_action_output(port=3)) # 从端口3转发
event.connection.send(msg) #send flowmod to the switch.
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", SendFlowInSingle3)
进阶要求(2):
SendPoxHardTimeOut.py
from pox.core import core
import pox.openflow.libopenflow_01 as of
class SendPoxHardTimeOut(object):
def init(self):
core.openflow.addListeners(self)
def _handle_ConnectionUp(self, event):
msg = of.ofp_flow_mod()
msg.priority = 3
msg.match.in_port = 1
msg.hard_timeout = 10 #硬超时10秒
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority = 1
msg.match.in_port = 1
msg.actions.append(of.ofp_action_output(port = of.OFPP_ALL))
event.connection.send(msg)
msg = of.ofp_flow_mod()
msg.priority = 3
msg.match.in_port = 3
msg.hard_timeout = 10 #硬超时10秒
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 = of.OFPP_ALL))
event.connection.send(msg)
def launch():
core.registerNew(SendPoxHardTimeOut)