BCA / B.Tech 8 min read

NS2 Commands in Hindi

RK

लेखक Ratan Kumawat · संस्थापक, NotesMedia

प्रकाशित:

त्वरित सारांश और मुख्य बिंदु

  • • विषय फोकस: Computer Network & Communication Notes in Hindi | कंप्यूटर नेटवर्किंग और कम्युनिकेशन नोट्स (BCA / B.Tech Syllabus)
  • • मुख्य विषय: NS2 Commands in Hindi - General Topics
  • • अवलोकन: Quick Answer: NS2 (Network Simulator 2) ek open-source discrete-event simulator hai jiska use networking research aur student lab experiments mein hota ...
  • • मुख्य अवधारणाएं: NS2 commands, Duplex link simplex queue limit Hindi, Drop tail orientation commands,NS2 commands, Duplex link simplex queue limit, Drop tail orientation commands
Quick Answer: NS2 (Network Simulator 2) ek open-source discrete-event simulator hai jiska use networking research aur student lab experiments mein hota hai. NS2 dual-engine architecture follow karta hai jisme packet processing ke liye fast C++ aur simulation topology, command scripting aur event scheduling ke liye OTcl (Object-oriented Tcl) use hoti hai. Mukhya commands mein simulator object banana (set ns [new Simulator]), nodes create karna ($ns node), duplex links define karna, aur TCP/UDP agents connect karna shamil hai.

NS2 kya hai aur iska Architecture kaise kaam karta hai?

NS2 computer networks ke behavior, routing protocols, traffic flow aur packet loss ko simulate karne ke liye ek widely-used software tool hai. Real network hardware (routers, switches, cables) setup karna costly aur complex hota hai, isliye network researchers aur students software simulation ke through protocols ko test karte hain.

NS2 mein dual-language architecture use hoti hai:

  • C++ Backend: Data packet byte manipulation, packet forwarding, internal routing logic aur complex algorithms ko execute karne ke liye C++ use hoti hai kyunki yah execution mein fast aur memory efficient hai.
  • OTcl (Object Tcl) Frontend: Network topology design karne, nodes create karne, links setup karne, traffic start/stop schedule karne aur command script likhne ke liye OTcl script use hoti hai. Isse baar-baar code compile karne ki zaroorat nahi padti.

Agar aap basic syntax detail mein sikhna chahte hain, toh hamare Basic Syntax of NS2 and NAM aur Node Creation in NS2 notes zaroor padhein.

Advertisement

Simulator Object aur Trace Files Setup Commands

NS2 script hamesha simulator instance create karke shuru hoti hai. Iske baad simulation ka data save karne ke liye trace file (.tr) aur graphical animation ke liye NAM file (.nam) create ki jaati hai.

# 1. Simulator object create karna
set ns [new Simulator]

# 2. Trace file open karna aur trace-all enable karna
set tracefile [open out.tr w]
$ns trace-all $tracefile

# 3. NAM animation file open karna
set namfile [open out.nam w]
$ns namtrace-all $namfile
  • set ns [new Simulator]: Yah simulation engine ka primary instance banata hai jo events aur timer ko control karta hai.
  • trace-all: Network ke har packet transmission, drop, receive aur enqueue event ko text format mein out.tr file mein record karta hai.
  • namtrace-all: Network Animator (NAM) tool ke visual packets aur nodes ki layout details ko out.nam mein save karta hai.

Nodes aur Links Create karne ki Commands

Network topology banane ke liye nodes create kiye jaate hain aur unke beech transmission link establish kiye jaate hain. Links ke bare mein detail jaankari ke liye aap Creating Links in Wired Network note dekh sakte hain.

1. Node Creation Commands

# Teen nodes banana
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]

Har node network mein ek computer, router ya host ki tarah behave karta hai. Simulator object $ns har node ko ek unique integer ID assign karta hai.

2. Link Setup Commands

# Duplex link establish karna
$ns duplex-link $n0 $n1 10Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 20ms DropTail

# NAM layout orientation set karna
$ns duplex-link-op $n0 $n1 orient right
$ns duplex-link-op $n1 $n2 orient right-down
  • duplex-link: Dono directions mein do-tarfa bidirectional communication link banata hai. Agar ek hi direction mein link chahiye toh simplex-link command use hoti hai.
  • 10Mb: Link ki bandwidth capacity specify karta hai.
  • 10ms: Propagation delay define karta hai.
  • DropTail: Queue management strategy hai. Agar buffer full ho jaaye toh naye aane wale packets drop ho jaate hain. Anya queue types mein RED (Random Early Detection) bhi use hota hai.

Transport Agents aur Traffic Generators Setup

Nodes ke physical link banne ke baad communication protocol (Transport Layer Agent) aur data flow (Application Layer Traffic) setup kiya jaata hai.

1. TCP Connection Setup (Reliable)

# Source node n0 par TCP Agent lagana
set tcp [new Agent/TCP]
$ns attach-agent $n0 $tcp

# Destination node n2 par TCPSink lagana
set sink [new Agent/TCPSink]
$ns attach-agent $n2 $sink

# Source aur Destination ko connect karna
$ns connect $tcp $sink

# TCP par FTP application traffic attach karna
set ftp [new Application/FTP]
$ftp attach-agent $tcp

2. UDP Connection Setup (Unreliable, Fast)

# Source node n1 par UDP Agent lagana
set udp [new Agent/UDP]
$ns attach-agent $n1 $udp

# Destination node n2 par Null Agent lagana (packet consumer)
set null [new Agent/Null]
$ns attach-agent $n2 $null

# UDP aur Null ko connect karna
$ns connect $udp $null

# UDP par CBR (Constant Bit Rate) traffic lagana
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 1000
$cbr set interval_ 0.005

Event Scheduling aur Finish Procedure

NS2 discrete-event simulator hai, iska matlab hai ki time aage badhta hai events ke schedule ke hisab se. Events ko schedule karne ke liye $ns at <time> <command> use kiya jaata hai.

# Events start aur stop schedule karna
$ns at 0.5 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"

# Finish procedure call karna aur simulation run karna
$ns at 5.0 "finish"
$ns run

Finish procedure ke structure aur cleanup logic ko detail mein samajhne ke liye Finish Procedure in NS2 note refer karein:

proc finish {} {
    global ns tracefile namfile
    $ns flush-trace
    close $tracefile
    close $namfile
    exec nam out.nam &
    exit 0
}

Essential NS2 Commands Reference Table

Neeche diye gaye table mein exam aur lab ke liye sabse important NS2 OTcl commands unke syntax aur purpose ke sath listed hain:

Command / Keyword Syntax Example Function / Purpose
new Simulator set ns [new Simulator] Naya simulation engine instance create karta hai.
trace-all $ns trace-all $tracefile Packet level events ko trace file (.tr) mein log karta hai.
namtrace-all $ns namtrace-all $namfile Graphical animator ke liye events ko record karta hai.
node set n0 [$ns node] Topology mein naya node create karta hai.
duplex-link $ns duplex-link $n0 $n1 10Mb 10ms DropTail Do nodes ke beech bidirectional channel banata hai.
duplex-link-op $ns duplex-link-op $n0 $n1 orient right NAM display screen par link ki visual direction set karta hai.
attach-agent $ns attach-agent $n0 $tcp Node par protocol agent (TCP/UDP) bind karta hai.
connect $ns connect $tcp $sink Source agent aur destination receiver ke beech logical channel banata hai.
at $ns at 1.0 "$cbr start" Specified simulation time (seconds) par event schedule karta hai.
run $ns run Event queue processing shuru karta hai.
flush-trace $ns flush-trace Memory buffer mein bacha trace data disk file mein write karta hai.
Advertisement

Comparison: Transport Agents aur Traffic Generators

NS2 mein agent aur application layer ke combinations ka comparison neeche table mein dekhein:

Parameter TCP + FTP Setup UDP + CBR Setup
Source Agent Agent/TCP Agent/UDP
Destination Agent Agent/TCPSink (acknowledgement receiver) Agent/Null (packet consumer)
Application Type Application/FTP ya Application/Telnet Application/Traffic/CBR ya Exponential
Reliability Reliable (packet loss hone par retransmission hota hai) Unreliable (loss recovery mechanism nahi hota)
Flow / Congestion Control Yes (Window size dynamically adjust hoti hai) No (Constant bit rate par packets flow hote hain)
Best Use Case File transfer, web browsing simulations VoIP, video streaming, DNS query simulations

Complete Working NS2 OTcl Script Example

Neeche ek complete, self-contained NS2 simulation script di gayi hai jise aap terminal mein ns simple.tcl run karke test kar sakte hain:

# Step 1: Simulator instance banana
set ns [new Simulator]

# Step 2: Trace files open karna
set tracefile [open out.tr w]
$ns trace-all $tracefile
set namfile [open out.nam w]
$ns namtrace-all $namfile

# Step 3: Finish procedure define karna
proc finish {} {
    global ns tracefile namfile
    $ns flush-trace
    close $tracefile
    close $namfile
    exec nam out.nam &
    exit 0
}

# Step 4: Do nodes create karna
set n0 [$ns node]
set n1 [$ns node]

# Step 5: Duplex link create karna
$ns duplex-link $n0 $n1 5Mb 10ms DropTail
$ns duplex-link-op $n0 $n1 orient right

# Step 6: UDP Agent aur CBR traffic attach karna
set udp [new Agent/UDP]
$ns attach-agent $n0 $udp
set null [new Agent/Null]
$ns attach-agent $n1 $null
$ns connect $udp $null

set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set packetSize_ 500
$cbr set interval_ 0.005

# Step 7: Events schedule karna
$ns at 0.5 "$cbr start"
$ns at 4.0 "$cbr stop"
$ns at 4.5 "finish"

# Step 8: Simulation execute karna
$ns run

Common Mistakes to Avoid

  • Agent/TCPSink ke badle galti se Agent/Null ko TCP se connect mat karein. TCP ko acknowledgements ke liye TCPSink ki zaroorat hoti hai.
  • flush-trace call karna bhoolne par out.tr aur out.nam files incomplete reh sakti hain.
  • Bandwidth likhte samay 10Mb (Megabits) aur 10MB (Megabytes) ke case sensitivity ka dhyan rakhein; NS2 command syntax mein capital/small letters important hain.
  • Variables ko access karte samay $ sign lagana zaroori hai (jaise $ns node, na ki ns node).

Exam के लिए Important Questions

Short Questions (2-3 marks)

  1. NS2 mein C++ aur OTcl ka combination kyon use kiya jaata hai?
  2. duplex-link command ka syntax aur parameters samjhaiye.
  3. trace-all aur namtrace-all commands mein kya antar hai?
  4. TCPSink aur Null agent mein mukhya bhed kya hai?

Long Questions (5-10 marks)

  1. NS2 simulator ka architectural structure explain kijiye aur batayein ki dual-language framework kaise kaam karta hai.
  2. Ek complete OTcl script likhkar samjhaiye jisme teen nodes ho, DropTail queue ke sath link ho, aur TCP/FTP traffic simulate kiya gaya ho.
  3. NS2 simulation mein trace file analysis aur NAM animation tool ke role par detail note likhiye.

Frequently Asked Questions (FAQs)

NS2 script ko execute kaise karte hain?

Terminal ya command prompt par ns script_name.tcl type karke enter dabayein. Yah OTcl script ko interpret karke simulation run karega aur trace files generate karega.

NAM (Network Animator) ka kya kaam hai?

NAM ek visual graphical animation tool hai jo .nam file ko read karke nodes, packet movements, queue buffering aur packet drop ko real-time screen par animate karta hai.

Kya NS2 wireless networks ko bhi simulate kar sakta hai?

Haan, NS2 wired networks ke alawa wireless ad-hoc networks (MANET), mobile IP, aur sensor networks (WSN) ko bhi simulate karne ke liye mobile node extensions provide karta hai.

DropTail queue policy ka matlab kya hai?

DropTail queueing mechanism mein jab router ya link ka buffer full ho jaata hai, toh naye aane wale har incoming packet ko drop kar diya jaata hai jab tak buffer space khali na ho.

अक्सर पूछे जाने वाले प्रश्न (FAQs)

Quick Answer: NS2 (Network Simulator 2) ek open-source discrete-event simulator hai jiska use networking research aur student lab experiments mein hota hai.
Computer Network & Communication Notes in Hindi | कंप्यूटर नेटवर्किंग और कम्युनिकेशन नोट्स के पाठ्यक्रम में NS2 Commands in Hindi एक महत्वपूर्ण अध्याय है। यह मुख्य सिद्धांतों, परीक्षा प्रश्नों और सूत्रों को समझने के लिए अत्यधिक आवश्यक है।
हाँ, NotesMedia पर आपको NS2 Commands in Hindi के महत्वपूर्ण प्रश्नोत्तर, हल किए गए उदाहरण और नोट्स बिल्कुल मुफ्त मिलेंगे। अधिक अभ्यास के लिए आप हमारा ऐप भी डाउनलोड कर सकते हैं।
Advertisement

In this Chapter

NS2 Commands in Hindi
Auto Configuration Anycast in Hindi
Modified EUI-64 in Hindi | Modified EUI-64 क्या है?
Architecture of Mobile Computing in Hindi
Wireless LAN in Hindi | Wireless LAN क्या है?
Wireless User Devices in Hindi
MAC Protocol in Hindi | MAC प्रोटोकॉल क्या है?
IEEE 802.11 in Hindi | IEEE 802.11 क्या है
Mobile IP in Hindi | Mobile IP हिंदी में
Wireless TCP IP in Hindi
Unicast & Multicast Communication in Hindi
Bluetooth in Hindi | Bluetooth क्या है?
NS2 & NAM in Hindi | NS2 और NAM क्या है?
Purpose & installation of NS2 & NAM in Hindi
Background of NS2 & NAM in Hindi
Architecture of NS2 & NAM in Hindi
Interface of OTcl & C++ in Hindi
Trace Files & Formats in Hindi
Protocol Support of NS2 in Hindi
Simulation Object of NS2 & NAM in Hindi
Basic Syntax of NS2 & NAM in Hindi
Node Creation of NS2 & NAM in Hindi
Running NS2 & NAM in Hindi
Finish Procedure NS2 & NAM in Hindi
Invoking external commands within NS2 in Hindi
Nodes & Agents of NS2 & NAM in Hindi
Creating Links in Wired Network in Hindi
Setting Link Parameters in Hindi
Sending Traffics Through NS2 Links in Hindi
Routing Protocol Support of NS2 in Hindi
Scenarios in Hindi
Additional Parameters in Hindi
Setting node positions in Hindi
God object & topography in Hindi
Protocol Support in Hindi
Scenarios in Wireless Network in Hindi
Internet क्या है? Intranet और Extranet के बीच अंतर
इंटरनेट के प्रकार | Types of Internet in Hindi
OSI Model in Hindi - OSI मॉडल क्या है और इसकी लेयर हिंदी में
Computer Network (CN) All Important Questions and Answers in Hindi (MDSU)
BCA | Computer Network | 2025 Paper | MDSU Exam Paper
Importance of Layer Model in Hindi
Network Classification in Hindi
Network Topology in Hindi
Network Switching & Component in Hindi
Ethernet in Hindi
Token Ring in Hindi
Basic working & Cabling in Hindi
What is Computer in Hindi | कंप्यूटर क्या है?
Bridges in Hindi
Router in Hindi
Gateway in Hindi
Public & Private Network in Hindi
FDMA in Hindi
BCA | CN(Computer Network) Paper | MDSU 2023 Exam Paper
What is WWW in Hindi and Introduction of WWW
CDMA,SDMA,TDMA in Hindi
Personal communication system in Hindi | PCS क्या है
IPv4 in Hindi | IPv4 क्या है?
Subnetting IPv4 address in Hindi
Casting in Hindi | कास्टिंग हिंदी में
Private IPv4 Addressing in Hindi
IPv4 Address Scheme in Hindi
IPv6 Addressing Scheme in Hindi
Types of IPv6 Addressing in Hindi