How to Implement Distributed Systems in NS2

To implement the Distributed System in Network Simulator 2 (ns2), we need to replicate several interlinked nodes that interact through a network, share tasks and ability to replicate data or resources. These nodes can imitate elements of a distributed system like servers, clients or peer-to-peer nodes. We work on all types of implementation in Distributed System to get best results feel free to contact us.

It is mainly concentrates on simulating networking protocols and communication though can be adjusted to replicate particular characteristics of distributed systems, especially according to the network interaction and distributed computing architectures.

Key Aspects of Distributed Systems to Simulate:

  1. Inter-node Communication: How nodes in the dispersed system interact (such as message relaying through TCP/UDP).
  2. Task Distribution: How tasks are shared or divided among the nodes.
  3. Coordination and Synchronization: Mechanisms for collaborating tasks, which could involve message interchanges.
  4. Fault Tolerance: Replicating node failures and recovery.
  5. Data Replication: Nodes may imitate or share content, simulating distributed file systems.

Steps to Simulate a Distributed System in NS2

  1. Install NS2

Make sure to install the ns2 and verify if it is properly configured on your system.

  1. Define the Network Topology

In a distributed system, the nodes may be linked via different topologies like mesh, ring, star, or fully linked networks. Each node indicates a computing entity (like a server or a client) that participates in the dispersed system.

Below is an example of a simplified distributed system with three nodes interacting through TCP to function distributed tasks.

Example: Simple Distributed System with Three Nodes

# Define a simulator object

set ns [new Simulator]

# Define trace and nam files for output

set tracefile [open out.tr w]

set namfile [open out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Define a ‘finish’ procedure to end the simulation and visualize in NAM

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam out.nam &

exit 0

}

# Create three nodes representing parts of the distributed system

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

# Create a mesh topology between the nodes (fully connected network)

$ns duplex-link $n0 $n1 10Mb 10ms DropTail

$ns duplex-link $n1 $n2 10Mb 10ms DropTail

$ns duplex-link $n0 $n2 10Mb 10ms DropTail

# Define a TCP agent for task distribution from node n0 to n1

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp0

$ns attach-agent $n1 $sink0

$ns connect $tcp0 $sink0

# Create FTP traffic to simulate a distributed task from node n0 to n1

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ftp0 start 1.0

$ftp0 stop 4.0

# Define a second TCP agent to distribute another task from n0 to n2

set tcp1 [new Agent/TCP]

set sink1 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp1

$ns attach-agent $n2 $sink1

$ns connect $tcp1 $sink1

# Create FTP traffic to simulate another distributed task from node n0 to n2

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ftp1 start 2.0

$ftp1 stop 5.0

# Schedule the end of the simulation

$ns at 6.0 “finish”

# Run the simulation

$ns run

  1. Explanation of the Script
  • Nodes: Three nodes (n0, n1, n2) signify three elements of the distributed system.
  • Network Topology: A fully connected mesh network is generated amongst the three nodes. Each node can interact with any other node.
  • Task Distribution: Dispatch data amongst the nodes, replicating task distribution by using TCP agents. FTP applications produce traffic over TCP to simulate distributed file transfer or task distribution.
  • Task Execution: Node n0 disperse tasks to n1 and n2 at various times (using the FTP applications).
  1. Run the Simulation

Store the script as distributed_system.tcl and execute it using the following command:

ns distributed_system.tcl

This will produce a trace file (out.tr) and a NAM file (out.nam), which can be used to evaluate the network activity and visualize the packet transmission amongst nodes.

  1. Visualize the Simulation in NAM

To visualize the communication amongst the nodes, use the NAM tool:

nam out.nam

  1. Simulate Distributed Task Management

Distributed systems frequently involved in task allotment amongst nodes. You can simulate the allocation of tasks by generating various traffic flows between the nodes using TCP or UDP protocols.

Example: Distributed Task Allocation between Multiple Nodes

Here’s an extension of the previous script, where numerous nodes allocate tasks in parallel:

# Define additional nodes

set n3 [$ns node]

set n4 [$ns node]

# Create links to connect nodes in a more complex distributed network

$ns duplex-link $n0 $n3 10Mb 10ms DropTail

$ns duplex-link $n3 $n1 10Mb 10ms DropTail

$ns duplex-link $n2 $n4 10Mb 10ms DropTail

$ns duplex-link $n4 $n1 10Mb 10ms DropTail

# Task distribution from n0 to n3

set tcp2 [new Agent/TCP]

set sink2 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp2

$ns attach-agent $n3 $sink2

$ns connect $tcp2 $sink2

# FTP traffic for task distribution from n0 to n3

set ftp2 [new Application/FTP]

$ftp2 attach-agent $tcp2

$ftp2 start 1.5

$ftp2 stop 4.5

# Task distribution from n3 to n1

set tcp3 [new Agent/TCP]

set sink3 [new Agent/TCPSink]

$ns attach-agent $n3 $tcp3

$ns attach-agent $n1 $sink3

$ns connect $tcp3 $sink3

# FTP traffic for task distribution from n3 to n1

set ftp3 [new Application/FTP]

$ftp3 attach-agent $tcp3

$ftp3 start 2.5

$ftp3 stop 5.5

  1. Simulating Distributed File Systems

Simulate the distributed file system by replicating the model and transferring the data amongst nodes. The integration of TCP flows (or even multicast) are used to mimic the recreation of files from one node to several nodes.

  1. Simulating Fault Tolerance and Node Failure

In distributed systems, fault tolerance is vital. You can simulate a node failure by “killing” one of the nodes in NS2 during the simulation and seeing how other nodes reacts.

Example: Simulating Node Failure

# Simulate node failure at 3.0 seconds by disabling node n1

$ns at 3.0 “$n1 reset”

You can simulate different failure environments and recovery mechanisms to examine the robustness of the distributed system.

  1. Analyzing the Trace File

You can evaluate the trace file (out.tr) to compute various metrics, after the simulation is done such as:

  • Throughput: The total count of data successfully transferred over nodes.
  • Latency: The time it takes for messages or tasks to propagate amongst nodes.
  • Packet Loss: Validate for lost packets, which may signify network problems or failure in task distribution.
  • Fault Tolerance: Monitor how the system acts after a node failure.

In conclusion, we have provided the essential details regarding the implementation of distributed system which is executed in ns2 environment by simulating a fault tolerance and Node Failure for optimization purpose. You can evaluate the simulation to see the outcomes of it.