NS2 Keywords-Commands-Components
NS2 Keywords-Commands-Components
1. attach-agent:
• Attaches an agent (e.g., TCP, UDP, CBR traffic source) to a node.
• Example: $ns attach-agent $node0 $tcpAgent
2. trace-all:
• Enables tracing of all events in the simulation to a trace file.
• Example: $ns trace-all $traceFile
3. namtrace-all:
• Enables NAM animation tracing for all events, capturing node movement and
packet flow.
• Example: $ns namtrace-all $namFile
4. flush-trace:
• Flushes remaining trace data to the trace file, ensuring complete data collection.
• Example: $ns flush-trace
5. namtrace-all-wireless:
• Specific for wireless simulations, enables NAM animation tracing for wireless
events.
• Example: $ns namtrace-all-wireless $namFile $width $height
6. node-config:
• Configures common settings for multiple nodes, such as routing protocol, MAC
type, queue type, etc.
• Example: $ns node-config -adhocRouting DSDV
7. setdest:
• Schedules a node's movement to a new destination at a specified time.
• Example: $ns at 10 "$node1 setdest 500 500 10"
8. DropTail:
• A simple queue type that drops packets when the queue is full.
• Used in links and nodes to manage congestion.
9. duplex-link:
• Creates a bidirectional link between two nodes, with specified bandwidth and
delay.
• Example: $ns duplex-link $node0 $node1 1Mb 20ms DropTail
10. queue-limit:
• Sets the maximum queue length for a link or node, limiting the amount of
buffered data.
• Example: $ns queue-limit $link 50
11. label:
• Assigns a text label to a node for identification in NAM animation and trace files.
• Example: $node0 label "source"
12. Application/Traffic/CBR:
• Creates a Constant Bit Rate (CBR) traffic source, generating packets at a fixed
rate.
• Example: $cbr0 set packetSize_ 500
13. connect:
• Connects two agents (e.g., TCP sender and receiver) to establish a
communication path.
• Example: $ns connect $tcpSource $tcpSink
14. packetSize_:
• Sets the packet size in bytes for a traffic source or application.
• Example: $cbr0 set packetSize_ 1000
15. interval_:
• Sets the inter-packet interval in seconds for a CBR traffic source.
• Example: $cbr0 set interval_ 0.01
I. Commands:
1. Node Creation:
• duplex-link $n0 $n1 1Mb 20ms DropTail: Creates a bidirectional link between
nodes with specified bandwidth, delay, and queue type.
• simplex-link: Creates a unidirectional link.
3. Agent Creation:
1. Nodes: