How to Start Unicast Routing Projects Using NS2
To start a Unicast Routing project in Network Simulator 2 (NS2) encompasses the data packets distribution from a single sender to a single receiver over network. This guide will walk you through these structured methods to get started.
Steps to Start Unicast Routing Projects in NS2
Step 1: Setup NS2 Environment
- Install NS2:
- We can download and install the new version of NS2 on the system.
- Make sure that all necessary dependencies such as Tcl, OTcl, NAM are installed.
- Confirm installation by running:
ns -version
- Understand NS2 Basics:
- Study the basic Tcl scripts to make nodes, links, and traffic flows in the network.
- Search related samples within ns-allinone-2.x/examples/ directory.
Step 2: Understand Unicast Routing
- What is Unicast Routing?
- Packets are transmitted from a source node to a single destination node.
- Based on the routing protocol, these routes are found dynamically or statically.
- Examples of Unicast Routing Protocols:
- Static Routing: Predefined routes and no active modernize.
- Dynamic Routing: Routes are actively determined and modernized such as AODV, DSR.
- Application Scenarios:
- It utilises in ad-hoc networks, wired/wireless interaction, and data packet sending.
Step 3: Design a Basic Network Topology
- Utilise NS2 Tcl script to make a network topology with nodes and links:
set ns [new Simulator]
# Define nodes
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Create links with bandwidth, delay, and queue type
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 15ms DropTail
$ns duplex-link $n3 $n4 1Mb 20ms DropTail
$ns duplex-link $n1 $n4 1Mb 30ms DropTail
- Assign unique IDs or addresses to the nodes.
Step 4: Implement Unicast Routing
Option 1: Static Routing
- We describe the routes among nodes in unicast routing:
$ns rtproto Static
$ns add-route $n1 $n2 1
$ns add-route $n2 $n3 1
$ns add-route $n3 $n4 1
- We need to store and execute the command.
Option 2: Dynamic Routing
- Use Built-In Protocols:
- For instance, for dynamic unicast routing we can utilise built-in protocols like AODV or DSR.
set ns [new Simulator]
# Use AODV routing protocol
$ns node-config -adhocRouting AODV \
-llType LL \
-macType Mac/802_11 \
-ifqType Queue/DropTail/PriQueue \
-ifqLen 50 \
-antType Antenna/OmniAntenna \
-propType Propagation/TwoRayGround
# Define nodes
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
# Create links
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 15ms DropTail
$ns duplex-link $n3 $n4 1Mb 20ms DropTail
- Add Traffic Sources:
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set sink [new Agent/Null]
$ns attach-agent $n4 $sink
$ns connect $udp $sink
# Generate traffic
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 512
$cbr set interval_ 0.05
$ns at 1.0 “$cbr start”
- We can save the script and execute the command:
ns unicast_routing.tcl
Option 3: Custom Unicast Routing Protocol
- Create a Custom Routing Agent:
- In NS2, prolong the Agent class.
Example in C++:
class UnicastRoutingAgent : public Agent {
public:
UnicastRoutingAgent();
void recv(Packet* p, Handler* h);
private:
std::map<int, int> routingTable; // Destination -> Next Hop
};
- Implement unicast routing logic:
- Sustain a routing table in unicast routing.
- Actively modernize routes or utilise the predefined routes.
- Compile and link the new protocol:
- Change the NS2 Makefile with new agent.
- Recompile:
make clean && make
Step 5: Simulate and Analyze
- Run the Simulation:
- Run the simulation using Tcl script:
ns unicast_routing.tcl
- Visualize in NAM:
- Envision the packet flow and confirm unicast behavior with the support of Network Animator (NAM):
nam unicast_routing.nam
- Trace File Analysis:
- Analyze the generated trace file for:
- Packet delivery ratio
- Latency
- Packet loss
- Analyze the generated trace file for:
Step 6: Enhance the Project
- Dynamic Updates:
- We need to replicate the link failures or topology modifications and also monitor how routes adjust.
- Performance Metrics:
- Equate the unicast routing performance indicators like delay, throughput, and routing overhead.
- Scalability Testing:
- Replicate larger networks including 20+ nodes for analysing the scalability.
- Advanced Features:
- We will need to execute the further aspects such as QoS-aware unicast routing, energy-efficient routing, or secure unicast protocols.
In this guide, Unicast Routing Projects was simulated and analysed using NS2 through an innovative approach with sample coding. More detailed explanation and insights to be added in the next manual.