Connecting NS-3 and Docker

Date: 2026-06-03

Link: https://www.sei.cmu.edu/blog/how-to-use-docker-and-ns-3-to-create-realistic-network-simulations/


TapBridge Creation:

// Create an ns-3 node
NodeContainer node;
node.Create(1);
// Create a channel that the node connects to
CsmaHelper csma;
NetDeviceContainer devices = csma.Install(node);
//Create an instance of a TapBridge
TapBridgeHelper tapBridge;
// Enable UseBridge mode, which has the user define the tap device it will
//connect to. There are more modes available which we won’t discuss here.
tapBridge.SetAttribute("Mode", StringValue("UseBridge"));
// we are defining our tap device which named mytap
tapBridge.SetAttribute("DeviceName", StringValue("mytap"));
tapBridge.Install(node.Get(0));

Overview of Network Creation for Containers

                       ┌─────────────┐                                 
            ┌──────────►    ns-3     ◄────────────┐                    
            │          └─────────────┘            │                    
            │                                     │                    
            │                                     │                    
   ┌────────┼────────┐                   ┌────────┼────────┐           
   │                 │                   │                 │           
   │    Tap-Left     │                   │    Tap-Right    │           
   │                 │                   │                 │           
   └────────▲────────┘promiscuous        └────────▲────────┘promiscuous
            │                                     │                    
   ┌────────▼────────┐                   ┌────────▼────────┐           
   │                 │                   │                 │           
   │  Bridge-Left    │                   │  Bridge-Right   │           
   │                 │                   │                 │           
   └────────▲────────┘                   └────────▲────────┘           
            │                                     │                    
   ┌────────▼────────┐                   ┌────────▼────────┐           
   │                 │                   │                 │           
   │ Internal-Left   │                   │ Internal-Right  │           
   │     (Host)      │                   │     (Host)      │           
   └────────▲────────┘                   └────────▲────────┘           
            │ veth                                │ veth               
┌───────────┼──────────┐               ┌──────────┼──────────┐         
│  ┌────────▼────────┐ │               │ ┌────────▼────────┐ │         
│  │                 │ │               │ │                 │ │         
│  │  External-Left  │ │               │ │  External-Right │ │         
│  │   (Container)   │ │               │ │   (Container)   │ │         
│  └─────────────────┘ │               │ └─────────────────┘ │         
│  netns/$pid_left     │               │  netns/$pid_right   │         
└──────────────────────┘               └─────────────────────┘         

Notes and Missing Requirements

  • This example is useful in that is showcase the process of how to set up the network such that a TapBridge can be used.
  • This example is specifically implemented for a set of Docker container-container that communicate over ns-3.
  • The linked GitHub repository has more scenarios that can be used for setting up containers with ns-3, but they are specific to each example that is present.
  • There isn't a generic methodology to setting up the bridges and interfaces in a more uniform, plug-and-play manner.