To simulate Wired LANs using NS2 has includes configuring a network of wired nodes, interconnected through an Ethernet-like links, with communication handled by a MAC protocol appropriate for wired communication like 802.3. Wired LANs usually signify a traditional office or campus network in which nodes such as computers or servers are associated via wired links.
Here’s a guide to help you simulate a Wired LAN project using NS2:
Steps to Simulate Wired LANs Projects in NS2
- Install NS2
Make sure that NS2 is installed on the system. If it’s not installed, we can install it using the following command:
sudo apt-get install ns2
- Key Components in a Wired LAN Simulation
- Nodes: Represent computers, servers, or other devices in a local area network.
- Wired Links: Ethernet-like wired links associates the nodes.
- MAC Protocol: Utilize the 802.3 MAC protocol for handling communication on the wired LAN.
- Traffic Patterns: Describe the communication among nodes such as file transfers or video streaming.
- Topology: The network topology can be simple (linear or star) or more complex (mesh or hierarchical).
- Design the Network Topology
A typical wired LAN topology could have a switch or hub associating multiple nodes (computers, servers, or other devices).
- TCL Script for Wired LAN Simulation
4.1 Define Nodes and Links
In this instance, we will generate multiple nodes denoting the devices in a wired LAN and associate them using duplex links to replicate wired communication.
# Create a simulator object
set ns [new Simulator]
# Open trace and NAM files
set tracefile [open “wired_lan.tr” w]
$ns trace-all $tracefile
set namfile [open “wired_lan.nam” w]
$ns namtrace-all $namfile
# Define simulation parameters
set val(chan) Channel/Wired ;# Wired channel for communication
set val(prop) Propagation/FreeSpace ;# Propagation model for wired communication
set val(mac) Mac/802_3 ;# MAC protocol (802.3 for Ethernet)
set val(ifq) Queue/DropTail/PriQueue;# Interface queue
set val(ifqlen) 50 ;# Queue length
set val(ll) LL ;# Link layer
set val(delay) 1ms;# Propagation delay
set val(bw) 100Mb ;# Bandwidth of wired links (100Mbps)
# Node configuration for wired LAN
$ns node-config -llType $val(ll) \
-macType $val(mac) \
-ifqType $val(ifq) \
-ifqLen $val(ifqlen) \
-propType $val(prop) \
-channelType $val(chan)
# Create nodes representing computers in the LAN
set node1 [$ns node]
set node2 [$ns node]
set node3 [$ns node]
set node4 [$ns node]
# Set positions for the nodes (optional)
$node1 set X_ 100
$node1 set Y_ 100
$node1 set Z_ 0.0
$node2 set X_ 200
$node2 set Y_ 100
$node2 set Z_ 0.0
$node3 set X_ 300
$node3 set Y_ 100
$node3 set Z_ 0.0
$node4 set X_ 400
$node4 set Y_ 100
$node4 set Z_ 0.0
# Define wired links with high bandwidth and low delay
$ns duplex-link $node1 $node2 $val(bw) $val(delay) DropTail
$ns duplex-link $node2 $node3 $val(bw) $val(delay) DropTail
$ns duplex-link $node3 $node4 $val(bw) $val(delay) DropTail
- Configure Traffic Patterns
We can replicate communication among nodes using TCP or UDP traffic depending on the type of application. TCP is usually utilized for reliable communication, since UDP is utilized for real-time communication.
5.1 TCP Traffic for File Transfer
# TCP agent for communication between node1 and node3
set tcp_node1 [new Agent/TCP]
$ns attach-agent $node1 $tcp_node1
# TCP sink at node3
set tcp_sink_node3 [new Agent/TCPSink]
$ns attach-agent $node3 $tcp_sink_node3
# Connect TCP agent to the sink
$ns connect $tcp_node1 $tcp_sink_node3
# Define application traffic (e.g., file transfer)
set app_node1 [new Application/Traffic/FTP]
$app_node1 attach-agent $tcp_node1
$ns at 1.0 “$app_node1 start”
5.2 UDP Traffic for Real-Time Data
# UDP agent for real-time communication between node2 and node4
set udp_node2 [new Agent/UDP]
$ns attach-agent $node2 $udp_node2
# UDP sink at node4
set udp_sink_node4 [new Agent/Null]
$ns attach-agent $node4 $udp_sink_node4
# Connect UDP agent to the sink
$ns connect $udp_node2 $udp_sink_node4
# Define application traffic (e.g., real-time data streaming)
set app_node2 [new Application/Traffic/CBR]
$app_node2 attach-agent $udp_node2
$app_node2 set packetSize_ 512
$app_node2 set interval_ 0.01
$ns at 2.0 “$app_node2 start”
- Run the Simulation
Once the nodes, links, and traffic patterns are defined, we can execute the simulation:
ns wired_lan.tcl
- Visualize the Simulation
we can utilize NAM (Network Animator) to envision the LAN network and track the communication among the wired nodes.
nam wired_lan.nam
- Analyse Simulation Results
After the simulation done, we can evaluate the trace file (wired_lan.tr) for parameters like:
- Throughput: The rate at which data is routed among nodes.
- End-to-End Delay: The time taken for packets to travel from source to destination.
- Packet Loss: The number of packets dropped in the course of the communication.
- Collision Detection: In cases of high traffic, we can monitor packet collisions on the wired links.
Utilize AWK, Python, or Perl scripts to extract and measure the relevant parameters from the trace file.
- Enhancing the Wired LAN Simulation
9.1 Hierarchical LAN Topology
We can generate a hierarchical LAN, in which multiple switches or routers associate different segments of the network, replicates a more complex LAN environment.
9.2 VLAN Support
Execute Virtual LAN (VLAN) configurations to separate traffic among groups of nodes in the same physical network.
9.3 QoS (Quality of Service)
Implement Quality of Service (QoS) mechanisms to select certain kinds of traffic, like real-time voice or video, over regular data transfers.
In this setup, we collect the innovative information regarding the Wired LANs that has simulation procedure and example snippets were delivered to perform in ns2 tool. We design to deliver the more data regarding this process in further setup. Obtain customized wired LAN projects You can get the best topic assistance by staying in contact with us and using the NS2 simulation results from phdprime.com.