# M-Emu: A Platform for Multicast Emulation
## 1 Introduction  
Compared with application layer multicast or overlay multicast, network layer multicast has clear advantages in multicast tree cost, end-to-end delay, control overhead, etc., and thus it has always been an important research topic [1, 2]. Recently, increasingly network layer multicast solutions have been designed based on SDN, which can effectively reduce the cost of creating and maintaining multicast trees and improve the efficiency of multicast group member management, etc. [3, 4]. Most network layer multicasts create state information per multicast distribution tree in the network [3, 4, 5]; therefore, the research of network layer multicasting requires simulators or emulators to support SDN, as well as provide a specific structure at the network layer to facilitate packet forwarding, such as a multicast tree. At present, the emulation platforms supporting SDN are mainly driven by Openflow and P4 [6, 7, 8]. Compared with OpenFlow, P4 can generalize the match-action framework to parsing-deparsing arbitrary header fields, flexible lookup tables with rich semantics, configurable control flow and platform-specific extensions. Based on these features, P4 has met with increasing enthusiasm [9, 10, 11]. NS4 is a state-of-the-art emulation platform driven by P4. Although NS4 can effectively simulate a P4 network, it is difficult for NS4 to meet some specific requirements of multicast emulation due to some deficiencies of its architecture and functions. For example: (1) The design of P4 does not take packet scheduling into account, which makes it difficult for NS4 to deal with strict priorities, weighted fair queue, etc. However, in multicast systems, packet scheduling will greatly affect the allocation of network resources and the quality of multicast service, which is a major direction of multicast research. (2) Different from imperative languages, such as C++, P4 is not a Turing-complete language. P4 does not support dynamic memory allocation, resulting in the failure of NS4's data plane to apply basic data structures, such as linked lists. Furthermore, P4 forbids loops with unknown iteration counts, which makes it difficult for the data plane to independently implement certain periodic operations, such as timeout verification and neighboring information detection. Although this feature of P4 can guarantee the delay of packet processing on the switch in real network, the research of multicast algorithms should not be limited by such engineering design. In addition, some network architectures require the data plane to have the ability to deploy applications [12; 13; 14] or respond to network requests without interacting with the control plane [15], which requires the data plane to be able to deal with arbitrary complex algorithms. (3) NS4 does not have a complete multicast tree construction and maintenance mechanism, nor does it provide multicast algorithm interfaces, such as a Rendezvous Point (RP) selection method [16; 17; 18; 19; 20] interface, Grafting Point (GP) selection method [21; 22; 23; 24] interface, etc., which increases the workload of emulations. To solve the above problems, we designed and developed M-Emu based on NS4. The code is in [[https://gitee.com/T1](https://gitee.com/T1) anzhEnyu/multicast-emulation.git]([https://gitee.com/T1](https://gitee.com/T1) anzhEnyu/multicast-emulation.git) (accessed on 2 March 2022). In order to improve the architecture defects of NS4, M-Emu presents a Service-Forwarding Architecture. The data plane of the architecture consists of the forwarding module and service module. The forwarding module can forward packets based on the flow tables. The service module can independently formulate and execute various algorithms according to the network status information, such as the network load status and cache queue status. As the service module can create and monitor the cache queue, the data plane of NS4 can process packet scheduling tasks. The service module is written in C++, which is a Turing-complete language and is capable of any Turing computable function.