How to Implement VLAN Trunking Protocol in NS2

 

To implement VLAN Trunking Protocol (VTP) in Network Simulator 2 (NS2), we will need to mimic on how Virtual Local Area Networks (VLANs) and VTP behave in a switched network. NS2 primarily mimic at Layer 3 (network layer) instead of Layer 2 (data link layer), so it doesn’t support natively to the protocols such as VTP or VLANs. Nevertheless, we can mimic the VLAN behaviour by separating the traffic among the nodes and custom handling of how VLANs would performs in a Layer 2 switch environment. The below is procedure to implement the simple VLANs and VTP in NS2:

Overview of VTP and VLAN:

  • VLAN: Virtual LAN is a network structure that permits the partitioning of a physical LAN into multiple logical LANs.
  • VTP: VLAN Trunking Protocol is used to handle VLANs through a network that permits switches to distribute VLAN information so that VLAN configuration is reliable via the network.
  • VLAN Trunking: Trunking enable multiple VLANs to traverse a single link among the switches by tagging packets with VLAN IDs.

Steps to Simulate VLAN and VTP Behavior in NS2

  1. Understand VLAN and VTP Behavior:
  • VLANs logically divide a physical network into distinct broadcast domains.
  • VTP shares the VLAN information among the switches to sustain consistent VLAN configurations through the network.
  • While VLAN traffic is sent among the switches, trunking encapsulates VLAN information into packets (using VLAN tags).
  1. Simulate VLANs by Partitioning Traffic:
  • We can mimic the VLAN behaviour by dividing nodes into VLAN groups and avoiding the traffic to specific VLANs.
  • Use traffic shaping, custom routing, or packet filtering approaches in NS2 to control that nodes belong to which VLANs.
  1. VTP-Like Behavior:
  • Regulate VTP by permits the certain nodes to act as switches that “advertise” VLAN configurations to other nodes.
  • Describe VLANs statically in the TCL script or execute dynamic VLAN updates (similar to VTP).
  1. TCL Script Example for Simulating VLAN Trunking and VTP

The following script shows a simple technique to mimic the VLAN and VTP behaviour:

# Create a new simulator instance

set ns [new Simulator]

# Open trace and nam files

set tracefile [open “vtp_trace.tr” w]

$ns trace-all $tracefile

set namfile [open “vtp.nam” w]

$ns namtrace-all-wireless $namfile

# Define nodes (representing switches and end hosts)

set s1 [$ns node]  ;# Switch 1

set s2 [$ns node]  ;# Switch 2

set h1 [$ns node]  ;# Host in VLAN 10

set h2 [$ns node]  ;# Host in VLAN 10

set h3 [$ns node]  ;# Host in VLAN 20

set h4 [$ns node]  ;# Host in VLAN 20

# Create links between switches (trunk links)

$ns duplex-link $s1 $s2 10Mb 10ms DropTail

# Create links between switches and hosts (access links)

$ns duplex-link $s1 $h1 10Mb 10ms DropTail

$ns duplex-link $s1 $h2 10Mb 10ms DropTail

$ns duplex-link $s2 $h3 10Mb 10ms DropTail

$ns duplex-link $s2 $h4 10Mb 10ms DropTail

# Set up VLAN assignments manually

# In this simple example, h1 and h2 are in VLAN 10, h3 and h4 are in VLAN 20

# VLAN 10 communication should only occur between h1 and h2

# VLAN 20 communication should only occur between h3 and h4

proc simulate_vlan_traffic {} {

global ns h1 h2 h3 h4

# Set up UDP agents and traffic

set udp1 [new Agent/UDP]

set sink1 [new Agent/Null]

set udp2 [new Agent/UDP]

set sink2 [new Agent/Null]

# Attach UDP and Null agents to nodes in VLAN 10

$ns attach-agent $h1 $udp1

$ns attach-agent $h2 $sink1

$ns connect $udp1 $sink1

# Attach UDP and Null agents to nodes in VLAN 20

$ns attach-agent $h3 $udp2

$ns attach-agent $h4 $sink2

$ns connect $udp2 $sink2

# Set up CBR traffic generators

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 500

$cbr1 set rate_ 1Mb

$cbr1 attach-agent $udp1

set cbr2 [new Application/Traffic/CBR]

$cbr2 set packetSize_ 500

$cbr2 set rate_ 1Mb

$cbr2 attach-agent $udp2

# Schedule traffic (simulating traffic within VLANs)

$ns at 1.0 “$cbr1 start”   ;# Traffic within VLAN 10

$ns at 1.0 “$cbr2 start”   ;# Traffic within VLAN 20

}

# Simulate VLAN and VTP behavior at time 0.5 seconds

$ns at 0.5 “simulate_vlan_traffic”

# Define finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam vtp.nam &

exit 0

}

# End the simulation at 5.0 seconds

$ns at 5.0 “finish”

# Run the simulation

$ns run

Explanation of the TCL Script:

  1. Nodes and Links:
    • Two nodes (s1 and s2) are switches, though h1, h2, h3, and h4 are hosts.
    • Links among the switches denotes trunk links, while links among the switches and hosts denotes access links.
  2. VLAN Assignment:
    • Hosts h1 and h2 are in VLAN 10, and hosts h3 and h4 are in VLAN 20.
    • Traffic among the VLANs is isolated by physically configure the UDP connections only among the hosts in the same VLAN.
  3. Simulating VTP:
    • In this simplified sample, VTP is implemented by manually allocating VLANs to nodes. A more advanced simulation would contain enthusiastically updating VLAN configurations, similar to VTP’s role.
  4. Traffic Generation:
    • Constant Bit Rate (CBR) traffic is created within each VLAN to mimic intra-VLAN communication.
  5. Ending the Simulation:
    • The simulation executes for 5 seconds, and outcomes are output to a trace file and a NAM file for visualization.
  1. Running the Simulation:
  1. Save the TCL script as vtp_simulation.tcl.
  2. Execute the simulation:

ns vtp_simulation.tcl

  1. After running the simulation, visualize the network and traffic using NAM:

nam vtp.nam

  1. Enhancing the Simulation:
  • VLAN Tagging: We can establish VLAN tagging into the traffic by adjusting the C++ code to mimic the adding VLAN tags to packets.
  • VTP Updates: To mimic VLAN updates being distributed among switches by executing dynamic VLAN configuration changes at runtime, similar to how VTP updates VLANs via the network.
  • Traffic Isolation: Establish more complex scenarios in which VLAN traffic is enthusiastically transmitted and in which the VLAN trunking and tagging behaviour is more explicitly modelled.
  1. Modifying NS2 for VLAN Tagging and VTP (Optional):

To model VLAN trunking and tagging explicitly, we can modify the C++ source code in NS2:

  • Adjust the packet structure to contain VLAN tags.
  • Add logic for mimic switches that identify VLAN tags and route traffic consequently.

Here’s an outline of in which to modify NS2:

  1. Packet Format: Adjust the packet header (packet.h) to contain a VLAN tag field.

struct hdr_vlan {

int vlan_id_;

static int offset_;

};

  1. Switch Logic: Execute a simple VLAN-aware switch that forwards traffic according to VLAN tags.
  2. VTP Protocol Logic: We can generate a new protocol to handles the VLANs enthusiastically by interexchange VLAN configuration messages among the switches.

In this manual, we clearly show how the VLAN trunking protocol will implement in ns2 settings. We deliver the additional information about how the VLAN trunking protocol performs in other simulation scenarios. Discover innovative project ideas from the experts at ns2project.com, where we offer a range of creative topics for your research endeavors. Our team provides tailored support for implementing the VLAN Trunking Protocol in NS2. Should you require further assistance, feel free to contact us; we are dedicated to helping you achieve outstanding project performance results.