How to Simulate LAN Protocols Projects Using NS2

To simulate LAN protocols using NS2 that has sequences of steps, which includes configuring a Local Area Network (LAN) with numerous nodes are communicating through LAN-specific protocols, like Ethernet (IEEE 802.3), Token Ring, or Spanning Tree Protocol (STP) for loop-free network topologies.

We will teach you through the simulation process on how to simulate LAN protocols projects using NS2:

Steps to Simulate LAN Protocols projects in NS2

  1. Install NS2

Make certain that NS2 is installed on the machine. We can download it from the NS2 official website.

  1. Choose a LAN Protocol to Simulate

General LAN protocols contain:

  • Ethernet (IEEE 802.3) for wired LANs.
  • STP (Spanning Tree Protocol) to prevent loops in LAN topologies.
  • VLAN (Virtual LAN) for segmenting networks.

In this instance, we will replicate a simple Ethernet LAN network.

  1. Set Up a Basic LAN Network Topology

To simulate a LAN, we will make a network of hosts (nodes) and set up them to communicate over a shared Ethernet link or switch.

Example TCL Script for Ethernet LAN Simulation:

# Create a new simulator instance

set ns [new Simulator]

# Define trace and nam files for logging and visualization

set tracefile [open lan_simulation.tr w]

$ns trace-all $tracefile

set namfile [open lan_simulation.nam w]

$ns namtrace-all $namfile

# Create LAN nodes (hosts)

set h1 [$ns node]  ;# Host 1

set h2 [$ns node]  ;# Host 2

set h3 [$ns node]  ;# Host 3

set h4 [$ns node]  ;# Host 4

# Create a LAN link (Ethernet) with multiple hosts

set lan [$ns newLan “$h1 $h2 $h3 $h4” 10Mb 10ms]

# Set node positions (optional)

$h1 set X_ 100; $h1 set Y_ 100; $h1 set Z_ 0.0

$h2 set X_ 200; $h2 set Y_ 200; $h2 set Z_ 0.0

$h3 set X_ 300; $h3 set Y_ 300; $h3 set Z_ 0.0

$h4 set X_ 400; $h4 set Y_ 400; $h4 set Z_ 0.0

In this setup:

  • LAN link is made utilizing the newLan command that connects all nodes to a shared Ethernet medium with a particular bandwidth (10 Mb) and delay (10 ms).
  1. Simulate Traffic Over the LAN

After configuring the LAN, we can be mimicked traffic among the hosts using TCP or UDP.

Example for TCP Traffic:

# Set up TCP connection between Host 1 and Host 4

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $h1 $tcp0

$ns attach-agent $h4 $sink0

$ns connect $tcp0 $sink0

# Create FTP traffic over TCP

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 2.0 “$ftp0 start”

$ns at 10.0 “$ftp0 stop”

Example for UDP Traffic (CBR):

# Set up UDP communication between Host 2 and Host 3

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

$ns attach-agent $h2 $udp0

$ns attach-agent $h3 $null0

# Generate CBR traffic over UDP

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 100kb

$cbr0 attach-agent $udp0

$ns at 3.0 “$cbr0 start”

$ns at 12.0 “$cbr0 stop”

  1. Simulate VLANs (Optional)

If we require to replicate VLANs then we can split the hosts into distinct VLANs and set up them to communicate only within their allocated VLANs. But, NS2 needs more configuration or custom scripting to mimic VLANs explicitly.

Example for VLAN Setup:

# Create VLAN 1 with Host 1 and Host 2

set vlan1 [$ns newLan “$h1 $h2” 10Mb 10ms]

# Create VLAN 2 with Host 3 and Host 4

set vlan2 [$ns newLan “$h3 $h4” 10Mb 10ms]

In this configuration, Host 1 and Host 2 are in VLAN 1, while Host 3 and Host 4 are in VLAN 2. These VLANs replicate isolate network segments, and communication among VLANs will need a router or Layer 3 switch.

  1. Run the Simulation

When the TCL script is prepared (e.g., lan_simulation.tcl) then we run the simulation in NS2:

ns lan_simulation.tcl

It will make trace files (.tr) and NAM files (.nam) for analysis and visualization in Network Animator (NAM).

  1. Analyze the Simulation Results

We can examine significant performance parameters, like:

  • Packet Delivery Ratio (PDR)
  • Throughput
  • End-to-End Delay
  • Collision Rates (for Ethernet-based networks)

Example AWK Script for Packet Delivery Ratio:

BEGIN { sent = 0; received = 0; }

{

if ($1 == “s” && $4 == “AGT”) { sent++; }

if ($1 == “r” && $4 == “AGT”) { received++; }

}

END { print “Packet Delivery Ratio = “, received/sent*100, “%”; }

This script will compute the Packet Delivery Ratio (PDR) according to the amount of packets transmitted and received.

  1. Example Project Ideas for LAN Protocol Simulation
  1. Performance Analysis of Ethernet vs. Token Ring in LANs:
    • Replicate both Ethernet and Token Ring LANs and compare their performance such as throughput, delay, and collision rates.
  2. VLAN Segmentation in LANs:
    • Mimic VLANs in a LAN environment and examine how traffic segregation enhances security and performance.
  3. Spanning Tree Protocol (STP) Simulation:
    • Model a network with loops and utilize STP to avoid loops and investigate the convergence time for loop-free paths.
  4. LAN QoS for VoIP Traffic:
    • Execute Quality of Service (QoS) within a LAN simulation to prioritize VoIP traffic over data traffic and examine its effect on packet loss and jitter.

Throughout this manual, we learnt regarding on how to simulate and analyse the LAN Protocols projects via above simple method using NS2 tool. Also we presented the example project ideas that very useful for you to implement it. We ready to deliver enhanced insights upon your request.

To simulate LAN protocols using NS2 tool we at phdprime.com will grant you tailored guidance, so send us all your project details we will guide you more.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2