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
def _handle_PacketIn (self, event):
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
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.