How to Implement Network Passive Optical in NS2

To implement a Passive Optical Network (PON) in NS2 has needs to replicate a fiber-optic network in which multiple users distributes the same optical fibre and are associated through passive splitters. A PON contains of an Optical Line Terminal (OLT) at the service provider’s central office and multiple Optical Network Units (ONUs) at the user’s places. A PON usually uses a point-to-multipoint planning with downstream traffic being disseminated to all ONUs and upstream traffic being achieved to evade collisions. For good implementation results you can approach ns2project.com team for  best implementation.

Although NS2 does not have native support for optical components, we can replicate the behaviour of a PON by configuring a network topology with high-speed fiber-optic links and replicating the communication and traffic management among the OLT and ONUs.

Components of a Passive Optical Network (PON):

  1. Optical Line Terminal (OLT): Centralized device at the service provider’s end that transmit downstream traffic to multiple ONUs.
  2. Optical Network Unit (ONU): Devices at the customer’s premises that receive traffic from the OLT and send upstream traffic.
  3. Optical Splitter: Passive device that splits optical signals from the OLT to multiple ONUs.
  4. Upstream and Downstream Traffic: Downstream traffic is broadcast from OLT to ONUs, since an upstream traffic is time-shared to prevent collisions.

Steps to Implement a PON in NS2:

  1. Set up the Simulation Environment

We start by generating a network topology in which the OLT (central node) is connected to multiple ONUs (leaf nodes) via a high-bandwidth optical link. This can be completed using a star topology, with the OLT at the centre and ONUs at the edge.

Example TCL Script for Basic Setup:

# Create a simulator instance

set ns [new Simulator]

# Set optical link parameters

set bw 1Gb          ;# Bandwidth for optical links (can be set to 1Gbps or higher)

set delay 2ms       ;# Delay for optical fiber links

# Create OLT (Optical Line Terminal)

set olt [$ns node]

# Create ONUs (Optical Network Units) for customers

set onu1 [$ns node]

set onu2 [$ns node]

set onu3 [$ns node]

# Connect OLT to ONUs via optical links

$ns duplex-link $olt $onu1 $bw $delay DropTail

$ns duplex-link $olt $onu2 $bw $delay DropTail

$ns duplex-link $olt $onu3 $bw $delay DropTail

This topology generates a basic PON in which the OLT is connected to three ONUs through high-speed fiber-optic links.

  1. Configure Downstream and Upstream Traffic

In a PON, downstream traffic from the OLT is broadcast to all ONUs, since upstream traffic from ONUs is handled to prevent collisions (usually using Time Division Multiple Access – TDMA).

Downstream Traffic (OLT to ONUs):

We emulate the downstream traffic by configuring a traffic generator at the OLT and sending traffic to all ONUs.

# Create a UDP agent at the OLT (source of downstream traffic)

set udp_olt [new Agent/UDP]

$ns attach-agent $olt $udp_olt

# Create a CBR traffic generator at the OLT

set cbr_down [new Application/Traffic/CBR]

$cbr_down set packet_size_ 1000

$cbr_down set rate_ 500Mb      ;# Downstream data rate

$cbr_down attach-agent $udp_olt

# Create UDP sinks (receivers) at ONUs

set null1 [new Agent/Null]

set null2 [new Agent/Null]

set null3 [new Agent/Null]

$ns attach-agent $onu1 $null1

$ns attach-agent $onu2 $null2

$ns attach-agent $onu3 $null3

# Connect the OLT (downstream) to ONUs

$ns connect $udp_olt $null1

$ns connect $udp_olt $null2

$ns connect $udp_olt $null3

# Start the downstream traffic

$ns at 1.0 “$cbr_down start”

$ns at 10.0 “$cbr_down stop”

In this example, OLT transmit the traffic to all ONUs simultaneously, that mimics the broadcasting of downstream traffic in a PON.

Upstream Traffic (ONUs to OLT):

Upstream traffic from the ONUs must be carefully handled to prevent collisions. Each ONU can be allocated a time slot to send its traffic (emulating TDMA).

# Create UDP agents for upstream traffic at ONUs

set udp_onu1 [new Agent/UDP]

set udp_onu2 [new Agent/UDP]

set udp_onu3 [new Agent/UDP]

$ns attach-agent $onu1 $udp_onu1

$ns attach-agent $onu2 $udp_onu2

$ns attach-agent $onu3 $udp_onu3

# Create CBR traffic generators for each ONU to simulate upstream traffic

set cbr_up1 [new Application/Traffic/CBR]

$cbr_up1 set packet_size_ 500

$cbr_up1 set rate_ 200Mb

$cbr_up1 attach-agent $udp_onu1

set cbr_up2 [new Application/Traffic/CBR]

$cbr_up2 set packet_size_ 500

$cbr_up2 set rate_ 200Mb

$cbr_up2 attach-agent $udp_onu2

set cbr_up3 [new Application/Traffic/CBR]

$cbr_up3 set packet_size_ 500

$cbr_up3 set rate_ 200Mb

$cbr_up3 attach-agent $udp_onu3

# Create a UDP sink at the OLT to receive upstream traffic

set null_olt [new Agent/Null]

$ns attach-agent $olt $null_olt

# Connect the ONUs (upstream) to the OLT

$ns connect $udp_onu1 $null_olt

$ns connect $udp_onu2 $null_olt

$ns connect $udp_onu3 $null_olt

# Assign time slots for each ONU to send upstream traffic (TDMA)

$ns at 2.0 “$cbr_up1 start”

$ns at 3.0 “$cbr_up1 stop”

$ns at 4.0 “$cbr_up2 start”

$ns at 5.0 “$cbr_up2 stop”

$ns at 6.0 “$cbr_up3 start”

$ns at 7.0 “$cbr_up3 stop”

In this script:

  • Each ONU sends traffic upstream to the OLT in its assigned time slot, that mimic TDMA.
  • The ONUs send data at 200 Mbps, and their transmissions are spaced to mitigate collisions.
  1. Monitor and Trace the Simulation

To measure the performance of the PON, that permit tracing to capture the behaviour of the downstream and upstream traffic, like throughput, delay, and packet loss.

Enable Trace Files:

# Enable tracing for the simulation

set tracefile [open “pon_trace.tr” w]

$ns trace-all $tracefile

# Define a finish procedure to end the simulation and close the trace file

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Set the simulation end time

$ns at 20.0 “finish”

The trace file will record all the events in the network, that has packet transmissions, receptions, and delays, enable them to evaluate the performance of the PON.

  1. Run the Simulation

Finally, execute the simulation to monitor the behaviour of the PON, both for downstream and upstream traffic.

# Run the simulation

$ns run

Example Complete TCL Script for PON Simulation

# Create a simulator instance

set ns [new Simulator]

# Set optical link parameters

set bw 1Gb

set delay 2ms

# Create OLT (Optical Line Terminal)

set olt [$ns node]

# Create ONUs (Optical Network Units)

set onu1 [$ns node]

set onu2 [$ns node]

set onu3 [$ns node]

# Connect OLT to ONUs via optical links

$ns duplex-link $olt $onu1 $bw $delay DropTail

$ns duplex-link $olt $onu2 $bw $delay DropTail

$ns duplex-link $olt $onu3 $bw $delay DropTail

# Create UDP agent for downstream traffic at OLT

set udp_olt [new Agent/UDP]

$ns attach-agent $olt $udp_olt

# Create a CBR traffic generator for downstream traffic

set cbr_down [new Application/Traffic/CBR]

$cbr_down set packet_size_ 1000

$cbr_down set rate_ 500Mb

$cbr_down attach-agent $udp_olt

# Create UDP sinks at ONUs

set null1 [new Agent/Null]

set null2 [new Agent/Null]

set null3 [new Agent/Null]

$ns attach-agent $onu1 $null1

$ns attach-agent $onu2 $null2

$ns attach-agent $onu3 $null3

# Connect OLT to ONUs (downstream)

$ns connect $udp_olt $null1

$ns connect $udp_olt $null2

$ns connect $udp_olt $null3

# Start and stop downstream traffic

$ns at 1.0 “$cbr_down start”

$ns at 10.0 “$cbr_down stop”

# Create UDP agents for upstream traffic at ONUs

set udp_onu1 [new Agent/UDP]

set udp_onu2 [new Agent/UDP]

set udp_onu3 [new Agent/UDP]

$ns attach-agent $onu1 $udp_onu1

$ns attach-agent $onu2 $udp_onu2

$ns attach-agent $onu3 $udp_onu3

# Create CBR traffic generators for upstream traffic

set cbr_up1 [new Application/Traffic/CBR]

$cbr_up1 set packet_size_ 500

$cbr_up1 set rate_ 200Mb

$cbr_up1 attach-agent $udp_onu1

set cbr_up2 [new Application/Traffic/CBR]

$cbr_up2 set packet_size_ 500

$cbr_up2 set rate_ 200Mb

$cbr_up2 attach-agent $udp_onu2

set cbr_up3 [new Application/Traffic/CBR]

$cbr_up3 set packet_size_ 500

$cbr_up3 set rate_ 200Mb

$cbr_up3 attach-agent $udp_onu3

# Create UDP sink at OLT for upstream traffic

set null_olt [new Agent/Null]

$ns attach-agent $olt $null_olt

# Connect ONUs to OLT (upstream)

$ns connect $udp_onu1 $null_olt

$ns connect $udp_onu2 $null_olt

$ns connect $udp_onu3 $null_olt

# Assign time slots for ONUs to send upstream traffic (TDMA)

$ns at 2.0 “$cbr_up1 start”

$ns at 3.0 “$cbr_up1 stop”

$ns at 4.0 “$cbr_up2 start”

$ns at 5.0 “$cbr_up2 stop”

$ns at 6.0 “$cbr_up3 start”

$ns at 7.0 “$cbr_up3 stop”

# Enable tracing

set tracefile [open “pon_trace.tr” w]

$ns trace-all $tracefile

# End simulation

$ns at 20.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

We obviously implicit the basic implementation procedures for Passive Optical Network that were securely implemented using the ns2 tool. We also outline additional information about how the Passive Optical Network performs in diverse simulation tool.