我需要使用 Ryu SDN 控制器模拟网络延迟。我首先尝试在每次控制器接收到消息中的数据包时调用一个函数的装饰器之后添加一个睡眠时间,但问题是这个函数在当前完成之前无法处理下一个数据包。有没有办法让这个函数成为多线程?
@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.