[英]How Pox controller will send packet without installing flow rules
I am writing worm detection code using pox controller can anyone tell me how to write a function where my controller will send packet to host directly i mean suppose host A send ****TCPSYN**** packet to host B now as flow rules not available than switch will send packet to controller now i want to write function where ****controller**** will send packet to host B without installing any flow rules.I am writing packetin handeling code 我正在使用pox控制器编写蠕虫检测代码,有人可以告诉我如何编写一个函数,其中我的控制器将直接向主机发送数据包。我的意思是假设主机A现在将**** TCPSYN ****数据包作为流规则发送至主机B不可用,交换机现在将数据包发送到控制器我想编写函数**** controller ****将数据包发送到主机B而不安装任何流规则。
def _handle_PacketIn (self, event): def _handle_PacketIn(自身,事件):
packet = event.parsed
log.info("Packet come in %s"%packet.type)
dpidstr = dpid_to_str(event.dpid)
# updating out mac to port mapping
self.macToPort[(event.connection,packet.src)] = event.port
dst_port = self.macToPort.get((event.connection,packet.dst))
tcpp = packet.find('tcp')
if tcpp and tcpp.SYN:
#here i want to write code where my controller will send tcp syn packet received from host A to the destination host(B) with installing any flow rules
if tcpp and tcpp.ACK:
#here i want to write code where my controller will receive tcp synack packet and send this syn ack packet to the sender(A) which has sent syn packet to host (B)
actually my algorithm is like 其实我的算法就像
It would help to have some code for this to handle the packet in but anyways , let me try and cover the most simple and generic situation. 这样做会有一些代码来处理数据包将有所帮助,但是无论如何,让我尝试介绍最简单和最通用的情况。
Assuming you have a listener for packet in events in your main class init function, something like 假设您在主类init函数中有一个监听数据包事件的监听器,例如
core.openflow.addListenerByName("PacketIn", self._handle_PacketIn)
And then in the function that handles the event 然后在处理事件的函数中
def _handle_PacketIn (self, event): msg = of.ofp_packet_out(data=event.ofp) msg.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD)) event.connection.send(msg)
So the msg is the one the controller sends to the switch, and to cover all ports you just flooding the incoming packet everywhere. 因此,味精是控制器发送到交换机的味精,并且为了覆盖所有端口,您只需将传入的数据包泛洪到任何地方。 If you knew the destination you could adjust here to send packet out only to the desired port.
如果您知道目的地,则可以在此处进行调整以仅将数据包发送到所需的端口。 This will fail in closed loops but it will give you a starting point.
这将在闭环中失败,但是它将为您提供一个起点。 Check more for ofp_action_output class at http://archive.openflow.org/wk/index.php/OpenFlow_Tutorial#ofp_action_output_class .
在http://archive.openflow.org/wk/index.php/OpenFlow_Tutorial#ofp_action_output_class上检查更多有关ofp_action_output类的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.