noxrepo / pox

The POX network software platform
https://noxrepo.github.io/pox-doc/html/
Apache License 2.0
624 stars 471 forks source link

Redirect packet_in #239

Closed spartakos87 closed 10 months ago

spartakos87 commented 4 years ago

I have a simple use case, but I cannot find something similar. What I want to do is that, In mininet I have a simple topo of four hosts and one switch sudo mn --topo single,4 --mac --switch ovsk --controller remote I in host h1(10.0.0.1) I host a simple python server python -m SimpleHTTPServer 80 That I want to do is when the h2 make a wget in any other host change the ip destination and redirect the wget to h1. First of all, is this possible? And if it is how can I achieve this?

MurphyMc commented 4 years ago

Sure.

This is not that different than POX's misc.nat and misc.ip_loadbalancer components.

spartakos87 commented 4 years ago

I checked but I didn't anything which can help, not even any tutorial on the whole internet, my code until now is,

 if packet.type == ethernet.IP_TYPE:
       ipv4_packet=event.parsed.find('ipv4')
       tcp_packet=event.parsed.find('tcp')
       flag_tcp = False
       if tcp_packet:
          src_ip=ipv4_packet.srcip
         dst_ip=ipv4_packet.dstip
         msg = of.ofp_flow_mod()
         msg.priority = 65535
         msg.match.dl_type=0x800
         msg.match.tcp_src=80
         # 6 is match tcp
         msg.match.nw_proto=6
         msg.idle_timeout = 30
         msg.hard_timeout = 30
         msg.match.nw_src = IPAddr("10.0.0.2")
         msg.actions.append(of.ofp_action_nw_addr.set_dst(IPAddr("10.0.0.1")))
         msg.actions.append(of.ofp_action_dl_addr.set_dst(EthAddr("00:00:00:00:00:01")))
         msg.actions.append(of.ofp_action_output(port = 1))
         self.connection.send(msg)   

If I remove the lines msg.match.nw_proto=6 I can redirect the ping to h1 when the source is h2. But in other cases when I do wget to h3 for example for h2 the, with the use of tcpdump I see in h1 to arrive request from h2 until get a timeout. Is something with tcp handshake? Any idea? Thanks a lot!

MurphyMc commented 4 years ago

Have you taken a look at the POX manual? And done a POX/OpenFlow tutorial? Glanced through the OpenFlow 1.0 spec?

Off the top of my head, all of that looks like a decent enough start, but... what about traffic coming back from the web server? It's going to be coming from 10.0.0.1, but the client never sent data to 10.0.0.1 -- it would have sent it to 10.0.0.3 or 10.0.0.4, right? So you need to rewrite the packets in the reverse direction too so that they look like what h2 is expecting.

This can be a bit tricky, though. How do you know whether to write the address back to 10.0.0.3 or 10.0.0.4? Maybe you could encode this information in the packet somehow (e.g., by rewriting port numbers in a particular way). Another common approach is to keep state for each connection, which is what the nat and load balancer components I pointed you to do. Of course, the stateful approach has its own problems, but that's a deeper issue.