I need to emulate network latency using Ryu SDN controller. I first tried to add a sleep time after the decorator which calls a function everytime the controler receives a packet in message but the problem is this function is not able to treat the next packet in until the current is finished. Is there a way to make this function multithread?
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
time.sleep(LATENCY)
...
If you want to emulate network latency, you should rather try to apply the latency to the link rather than the application.
If you are using a network simulator, this may be done in its API (e.g. mininet: mininet.link.TCLink)
If you are using Virtual Machines, you can set up netem to emulate delay on the interfaces you are using.