# Experimenting with Routing Protocols in the Data Center: An ns-3 Simulation Approach
## 3 FRR Port to ns-3 DCE
### Background on ns-3 and DCE  
ns-3 [16] is a discrete-event network simulator used mainly in research and education. It is open-source and free, licensed under the GNU GPLv2 license. Both ns-3 core and models are implemented in C++. It is built as a library that can be linked both statically and dynamically by a main C++ program, which defines the network topology and starts the simulation [23]. Typically, to run a simulation in ns-3, a C++ program is created (script in the ns-3 nomenclature) that defines the topology and configuration for the simulation. This program includes at the end a call to the Run() function of the Simulator class that will start the simulation. Regarding Direct Code Execution (DCE) [15], it is a framework for ns-3 that allows us to execute existing implementations of network applications or protocols within ns-3 without any changes to the source code. This permits us to execute existing real applications such as the ping application or even more, the entire Linux networking stack within an ns-3 simulation. Thus, in a ns-3 simulation which uses DCE, the network topology as well as channel configurations will be done in ns-3, while applications running on nodes can use DCE, including Linux native applications or actual implementations of network protocols, such as Linux's TCP, as shown in Figure 2.  
There are two ways to run DCE: basic mode and advanced mode. Basic mode uses the ns-3 networking stack, while advanced mode uses the Linux networking stack. The latter is done using the Linux kernel as a library. The design of DCE takes its idea from the library operating system (_LibOS_[24]). DCE is structured around three components: Core, Kernel and POSIX, as shown in Figure 3. First, at the bottom level is the Core module that handles memory virtualization: stack, heap and global variables. Above that is the Kernel layer that takes advantage of these services to provide an execution environment for the Linux network stack within the simulator. For Advanced Mode, DCE uses the Linux kernel implementation of layer 3 and 4 protocols and Layers 1 and 2 are simulated with ns-3. DCE takes care of synchronization, making the Linux kernel see ns-3 network devices as if they were real devices. Finally, the POSIX layer builds on top of the Core and Kernel layers to re-implement the standard socket API for use by simulated applications. Figure 2: DCE is used for running Linux applications without code changes. On top of that, it enables the use of the Linux network protocol stack in ns-3 simulations. Net devices (and channel) are simulated only with ns-3, while applications and network protocols can use DCE. DCE runs each simulated process on the same host process. This model makes it possible to synchronize and schedule each simulated process without having to use inter-process synchronization mechanisms. What's more, it allows the user to track the behavior of the experiment by different processes without having to use a distributed debugger, which tends to be more complex. The threads in each simulated process are managed by a task handler, implemented in DCE, synchronized with the simulated host and isolated from the other simulated hosts. Since the loader of the host system aims to ensure that each process does not contain more than one instance of each global variable, DCE provides its own implementation of the loader with a specific loading mechanism to instantiate each global variable, once per simulated instance. The POSIX implementation in DCE replaces the use of the traditional glibc library. Thus, when an application running on top of DCE makes a call to glibc, DCE intercepts the call and executes the re-implemented function. Most of these functions are simply a handshake to the corresponding function in the host's glibc library. However, calls that involve system resources must be re-implemented. These include calls involving network resources, the system clock, or memory management. DCE classifies the functions of the library glibc using the macros DCE or NATIVE.