简体   繁体   English

Pox控制器如何在不安装流规则的情况下发送数据包

[英]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 其实我的算法就像

  1. Suppose that internal host A sends a TCP SYN to a new external host B. Since there are no flows in the switch matching this packet, it will be sent to the POX controller. 假设内部主机A将TCP SYN发送到新的外部主机B。由于交换机中没有与该数据包匹配的流,它将被发送到POX控制器。
  2. The TRW-CB instance running at the POX controller simply forwards this packet through the switch, without setting any flows. 在POX控制器上运行的TRW-CB实例仅通过交换机转发此数据包,而无需设置任何流。 At the same time, the algorithm also does its normal processing (ie adds B to a list of hosts pre- viously contacted by A and adds the connection request to A's queue). 同时,该算法还执行其常规处理(即,将B添加到A先前联系的主机列表中,并将连接请求添加到A的队列中)。
  3. The two possible responses from B are: (a) If a TCP SYNACK from B to A is received, the switch again forwards this to the NOX controller (since it still does not match any flows). 来自B的两个可能的响应是:(a)如果收到了从B到A的TCP SYNACK,则交换机再次将其转发给NOX控制器(因为它仍然不匹配任何流)。 Upon receiving the SYNACK, the TRW-CB instance at the controller installs two flows in the switch. 收到SYNACK后,控制器上的TRW-CB实例会在交换机中安装两个流。 The first flow matches all packets sent from A to B. It contains A's IP address in the IP src field and B's IP address in the IP dst field. 第一个流匹配从A发送到B的所有数据包。它在IP src字段中包含A的IP地址,在IP dst字段中包含B的IP地址。 Except for Ether type (which is set to IP), all other fields in the flow are wildcarded. 除以太类型(已设置为IP)外,流中的所有其他字段都是通配符。 The second flow is similar to the first, but matches all packets sent from B to A. Each flow contains an action to forward matching packets out of the relevant port of the switch. 第二个流程类似于第一个流程,但是将所有从B发送到A的数据包都进行匹配。每个流程都包含一个操作,将匹配的数据包转发出交换机的相关端口。 Ad- ditionally, TRW-CB also does its normal processing (ie removing this connection request from A's queue and decreasing A's likelihood ratio).. (b) If the connection times out, then TRW-CB does its regular processing (for the connection failure case) without interacting with the switch.Thus no flows are installed. 另外,TRW-CB还会执行其正常处理(即,从A的队列中删除此连接请求并降低A的似然比)。(b)如果连接超时,则TRW-CB会进行常规处理(对于连接故障案例),而无需与交换机进行交互,因此未安装任何流程。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM