逃离回调地狱!一种新的网络模拟编程范式
Beyond Callbacks: A Developer-friendly Programming Paradigm for Network Simulation
AI总结:
本文提出了一种名为CoDES的新型网络模拟开发范式,通过协程机制优化网络模拟开发流程,有效解决网络事件模拟中的复杂性和可维护性问题,减少开发工作量并提升代码可读性和可维护性。
摘要:
网络模拟在网络研究和工业中扮演着关键角色。现有的常用离散事件模拟(DES)基于回调机制来模拟离散事件(DE)。然而,由于回调无法自然模拟网络事件,网络模拟程序无法以顺序工作流方式编写。这导致了固有的复杂性和较差的可维护性,从而产生栈撕裂和回调地狱问题。这些问题显著增加了模拟开发的工作量,并引入了与编程和调试相关的重大认知负担。为了更高效地开发网络模拟并促进网络功能的快速评估和演进,我们提出了一种新的网络模拟开发范式,称为“CoDES”(基于协程的DES)。到目前为止,我们是第一个专注于优化网络模拟开发流程而不是基于协程机制的性能优化。我们实现了一个基于CoDES的新网络模拟框架,能够自然模拟网络事件并有效解决与正确性、功能、兼容性和开销相关的系统挑战。它使开发人员能够为网络程序创建顺序工作流,并简化代码结构,从而减少开发工作量,同时提高代码的可读性和可维护性。我们应用这种范式到常用的网络模拟器NS-3中,实现了消息传递接口(MPI)、高精度拥塞控制(HPCC)和路由信息协议(RIP),在不牺牲模拟准确性、扩展执行时间和不增加模拟运行时内存的情况下,实现了代码体积和结构复杂度分别减少62.3%和82.6%。
英文摘要:
Network simulation plays a crucial role in both networking research and industry. Existing commonly-used Discrete Event Simulations (DES) are based on the callback mechanism for discrete events. However, as network functions grow in complexity, callbacks reveal a fundamental structural limitation: a callback can only represent a single point in a blocking operation and cannot capture the full operation as a coherent whole. This forces developers to manually decompose sequential network logic into scattered callback fragments, leading to stack ripping, callback hell, and heavy development and debugging burdens. We propose CoDES (\textbf{Co}routine-based \textbf{DES}), a coroutine-based programming paradigm for network simulation that addresses this structural limitation. CoDES targets development productivity rather than execution performance. Realizing CoDES in existing DES simulators is non-trivial, as coroutine suspension must be coordinated with the event scheduler, introducing challenges in coroutine resource conflicts, operation-level computation requirements, compatibility with existing callback-based simulators, and overhead. We implement a CoDES-based framework in ns-3, address all four challenges, and release it as open source. We evaluate CoDES by implementing Message Passing Interface (MPI), High Precision Congestion Control (HPCC), and Routing Information Protocol (RIP) in ns-3, spanning the transport, congestion control, and routing layers. Compared with callback-based counterparts, CoDES reduces lines of code by up to 51.4% and nesting depth by up to 50%, with no accuracy loss and negligible runtime and memory overhead.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。