How to Implement Network Slicing in NS2

To implement Network slicing in ns2, it is a essential method in next-generation networks like 5G, in which a physical network is divided into multiple virtual networks (slices) to deliver distinct services with diverse requirements such as latency, bandwidth, or reliability. In NS2, even though it does not natively supports cutting-edge virtualization approaches such as network slicing that can replicate network slicing by configuring multiple traffic classes, each with diverse Quality of Service (QoS) requirements, and make sure that traffic is transmitted based on those requirements.

If you need help with Network Slicing using the NS2 tool, feel free to email us all the details. We’ll help you achieve the best results! Our team specializes in setting up different traffic classes, each with its own Quality of Service (QoS) needs. Let our developers assist you with your project’s network comparison analysis.

Here is a brief approach to implement the network slicing in ns2:

Steps to Simulate Network Slicing in NS2:

  1. Define the Network Topology: Configure nodes that denote the components of the network such as User Equipment (UE), Base Stations, and Core Network.
  2. Create Traffic Slices: To mimic different slices by describing separate traffic flows for each service class (eMBB, URLLC, mMTC), with separate QoS requirements.
  3. Manage Bandwidth and Latency: Use numerous links and queue management approaches to distribute resources based on slice requirements.
  4. Monitor and Analyze Traffic: Use trace files to evaluate performance (throughput, delay, and packet loss) for each slice.

Example Scenario: Network Slicing in NS2

In this example, we will mimic three slices denotes different use cases:

  • eMBB (enhanced Mobile Broadband): High bandwidth requirements for video streaming.
  • URLLC (Ultra-Reliable Low Latency Communication): Low latency, high reliability for mission-critical communications.
  • mMTC (massive Machine Type Communication): Low bandwidth for IoT-like traffic with a high number of devices.

Example TCL Script for Simulating Network Slicing in NS2:

# Create a new simulator instance

set ns [new Simulator]

# Define output trace file for logging events

set tracefile [open network_slicing.tr w]

$ns trace-all $tracefile

# Define the animation file for NAM (optional)

set namfile [open network_slicing.nam w]

$ns namtrace-all $namfile

# Create nodes representing the UE, the base station, and the core network

set ue [$ns node]        # User Equipment

set bs [$ns node]        # Base Station

set core [$ns node]      # Core Network

set server [$ns node]    # Service provider (for external internet access)

# Create links between the UE, BS, Core, and Server

# Different slices will use the same physical infrastructure, but with different QoS

$ns duplex-link $ue $bs 10Mb 10ms DropTail  # Link from UE to Base Station

$ns duplex-link $bs $core 50Mb 5ms DropTail  # Link from Base Station to Core

$ns duplex-link $core $server 100Mb 10ms DropTail  # Link from Core to Server

# Define TCP agent for eMBB traffic (Video Streaming) from UE to Server

set tcp_ue_embb [new Agent/TCP]

$ns attach-agent $ue $tcp_ue_embb

set tcp_sink_embb [new Agent/TCPSink]

$ns attach-agent $server $tcp_sink_embb

# Connect the TCP agent and sink for eMBB

$ns connect $tcp_ue_embb $tcp_sink_embb

# Define an FTP application to simulate high-bandwidth traffic for eMBB

set ftp_embb [new Application/FTP]

$ftp_embb attach-agent $tcp_ue_embb

$ns at 0.5 “$ftp_embb start”

# Define UDP agent for URLLC traffic (Critical Communication) from UE to Server

set udp_ue_urllc [new Agent/UDP]

$ns attach-agent $ue $udp_ue_urllc

set udp_sink_urllc [new Agent/Null]

$ns attach-agent $server $udp_sink_urllc

# Connect the UDP agent and sink for URLLC

$ns connect $udp_ue_urllc $udp_sink_urllc

# Define a CBR application to simulate low-latency traffic for URLLC

set cbr_urllc [new Application/Traffic/CBR]

$cbr_urllc attach-agent $udp_ue_urllc

$cbr_urllc set packetSize_ 512  # Small packets for low latency

$cbr_urllc set rate_ 1Mb        # High rate for critical communication

$cbr_urllc set interval_ 0.01   # Short interval between packets (high frequency)

$ns at 0.5 “$cbr_urllc start”

# Define TCP agent for mMTC traffic (IoT) from UE to Server

set tcp_ue_mmtc [new Agent/TCP]

$ns attach-agent $ue $tcp_ue_mmtc

set tcp_sink_mmtc [new Agent/TCPSink]

$ns attach-agent $server $tcp_sink_mmtc

# Connect the TCP agent and sink for mMTC

$ns connect $tcp_ue_mmtc $tcp_sink_mmtc

# Define an FTP application to simulate low-bandwidth traffic for mMTC

set ftp_mmtc [new Application/FTP]

$ftp_mmtc attach-agent $tcp_ue_mmtc

$ns at 0.5 “$ftp_mmtc start”

# Schedule the simulation end time

$ns at 4.0 “$ftp_embb stop”

$ns at 4.0 “$cbr_urllc stop”

$ns at 4.0 “$ftp_mmtc stop”

# End the simulation at 5 seconds

$ns at 5.0 “finish”

# Define finish procedure to close files and execute NAM for visualization

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam network_slicing.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  1. Node Setup:
    • We configure the nodes for the User Equipment (UE), Base Station (BS), Core Network, and Server. These nodes form the physical infrastructure of the network.
  2. Links:
    • The links among the nodes denotes the physical network distributed by numerous slices. For instance, the UE associate to the Base Station, that connects to the Core Network, and then to the Server (external network).
    • Each link has numerous bandwidth and latency features to mimic realistic traffic conditions.
  3. Slice 1: eMBB (enhanced Mobile Broadband):
    • This slice mimics high-bandwidth traffic using a TCP agent. It denotes video streaming or other high-data-rate applications.
    • An FTP application is used to create large traffic.
  4. Slice 2: URLLC (Ultra-Reliable Low Latency Communication):
    • This slice replicates low-latency, high-reliability traffic using a UDP agent. It denoted mission-critical applications such as emergency services or autonomous driving.
    • A CBR (Constant Bit Rate) application creates small, frequent packets to mimic low-latency communication.
  5. Slice 3: mMTC (massive Machine Type Communication):
    • This slice mimics low-bandwidth, high-device-density traffic using a TCP agent. It denotes IoT traffic, in which many devices send small amounts of data.
    • An FTP application creates traffic similar to IoT communication.
  6. Traffic Scheduling:
    • The simulation initiates all three slices at 0.5 seconds and terminates them at 4.0 seconds. This permits enough time to monitor on how the different slices act as in parallel.
  7. Finish Procedure:
    • At 5.0 seconds, the simulation ends, and NAM envision is launched for measuring on how traffic flows via the network.
  1. Analysing the Network Slicing Simulation

Once the simulation is done, we can evaluate the trace file (network_slicing.tr) and NAM visualization to:

  • Monitor Traffic Performance: See how each slice performs in terms of throughput, latency, and packet loss.
  • Evaluate QoS Guarantees: validate if each slice achieves its preferred QoS. For Instance, URLLC should have low latency, since eMBB should have higher throughput.
  • Packet Flow: Use the trace file to monitor on how packets flow via the network for each slice.
  1. Advanced Features for Realistic Network Slicing

To make the network slicing simulation more realistic, we can:

  • Apply Different Queue Management Techniques: Use Priority Queuing or Weighted Fair Queuing (WFQ) to give different priorities to different slices.
  • Introduce Congestion: To mimic network congestion to see how each slice is impacted.
  • Simulate Failures: Establish link failures or node failures to monitor on how the network slices recover or re-route traffic.

Example: Applying Weighted Fair Queuing (WFQ)

# Enable WFQ on the link between the UE and Base Station

$ns queue-limit $ue $bs 50  # Set the queue limit

$ns queue-type $ue $bs Queue/WFQ  # Use Weighted Fair Queuing

This will distribute bandwidth to each slice according weights; make sure that the more critical slices such as URLLC to get priority over less critical slices such as mMTC.

At the end, we talk about the network slicing that was very useful to maintain the Quality of Service by using the ns2 tool. We also offer how to network slicing will execute in other simulation tool.