How to Simulate Exterior Gateway Protocol Projects Using NS2

To simulate an Exterior Gateway Protocols (EGPs) like BGP (Border Gateway Protocol) using NS2 (Network Simulator 2) that has structured approach, which encompasses configuring a network of several Autonomous Systems (AS) and replicating how routing data is swapped among them. The network simulator NS2 does not provide native support for BGP, however we need to mimic the behaviour of EGP protocols by describing custom network topologies, configuring autonomous systems, and utilizing routing methods, which simulate the operation of BGP or other EGPs.

Here’s a simple guidelines on how to simulate an EGP project using NS2:

Steps to Simulate Exterior Gateway Protocols (BGP-like) in NS2

  1. Install NS2

If NS2 is not installed on the system then we can install it on Linux-based systems such as Ubuntu using:

sudo apt-get install ns2

Make sure that the installation is appropriate by entering ns in the terminal that should open the NS2 prompt (%).

  1. Understand BGP and EGP Concepts

BGP (Border Gateway Protocol), the most general EGP that functions by swapping routing information among the autonomous systems (ASes) on the Internet. BGP routers create routing decisions according to the path attributes and policies, distributing only the finest routes with their neighbours. To replicate it within NS2, we can describe distinct ASes (represented as routers or subnets) and set up routing tables to simulate BGP’s behaviour.

  1. Create the Network Topology

To mimic a BGP-like behaviour in NS2, we require to configure:

  • Several Autonomous Systems (ASes).
  • Routers that communicate among these ASes.
  • Policies or custom routing tables to describe inter-AS routing.

Here’s an instance Tcl script, which replicates a BGP-like setup with numerous ASes.

# Create a new simulator object

set ns [new Simulator]

# Open the trace file

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Create Autonomous Systems (ASes)

# Autonomous System 1

set n0 [$ns node]  ;# AS1 Router 1

set n1 [$ns node]  ;# AS1 Router 2

# Autonomous System 2

set n2 [$ns node]  ;# AS2 Router 1

set n3 [$ns node]  ;# AS2 Router 2

# Autonomous System 3

set n4 [$ns node]  ;# AS3 Router 1

set n5 [$ns node]  ;# AS3 Router 2

# Create links within AS1 (AS1 routers communicating internally)

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

# Create links within AS2 (AS2 routers communicating internally)

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

# Create links within AS3 (AS3 routers communicating internally)

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

# Connect AS1 with AS2 (inter-AS communication mimicking BGP)

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

# Connect AS2 with AS3 (inter-AS communication mimicking BGP)

$ns duplex-link $n3 $n4 10Mb 30ms DropTail

# Set IP addresses (simulating BGP-style addressing between ASes)

$n0 set address 192.168.1.1

$n1 set address 192.168.1.2

$n2 set address 10.1.1.1

$n3 set address 10.1.1.2

$n4 set address 172.16.1.1

$n5 set address 172.16.1.2

# Define custom routes (simulating BGP route exchanges)

# Routing table for AS1

$n0 add-route 10.1.1.0/24 $n1

$n0 add-route 172.16.1.0/24 $n1

$n1 add-route 10.1.1.0/24 $n2

$n1 add-route 172.16.1.0/24 $n2

# Routing table for AS2

$n2 add-route 192.168.1.0/24 $n1

$n2 add-route 172.16.1.0/24 $n3

$n3 add-route 192.168.1.0/24 $n2

$n3 add-route 172.16.1.0/24 $n4

# Routing table for AS3

$n4 add-route 10.1.1.0/24 $n3

$n4 add-route 192.168.1.0/24 $n3

$n5 add-route 10.1.1.0/24 $n4

$n5 add-route 192.168.1.0/24 $n4

# Define traffic flow from AS1 to AS3 (mimicking inter-AS traffic via BGP)

set tcp [new Agent/TCP]

set sink [new Agent/TCPSink]

$ns attach-agent $n0 $tcp

$ns attach-agent $n5 $sink

$ns connect $tcp $sink

set ftp [new Application/FTP]

$ftp attach-agent $tcp

# Start and stop the FTP application

$ns at 1.0 “$ftp start”

$ns at 9.0 “$ftp stop”

# End the simulation

$ns at 10.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exec nam out.nam &

exit 0

}

# Run the simulation

$ns run

Explanation of the Tcl Script

  • Autonomous Systems (AS): The nodes (n0, n1, n2, etc.) are signify routers in distinct autonomous systems. AS1 has two routers (n0, n1), AS2 has two routers (n2, n3), and AS3 has two routers (n4, n5).
  • Links between ASes: Duplex links among the routers from distinct ASes replicate inter-AS communication, as seen in BGP-like routing.
  • Routing tables: Custom routing tables describe routes among distinct ASes, that replicating how BGP routers could advertise and utilize routes.
  • Traffic flow: TCP traffic is introduced among a router in AS1 (n0) and a router in AS3 (n5), replicating data exchange among ASes, much like how BGP enables routing among diverse ASes in the real world.
  1. Run the Tcl Script

We need save the script as egp_simulation.tcl and execute the simulation using the below command:

ns egp_simulation.tcl

This command will make trace files (out.tr) and NAM files (out.nam) to envision the network and the packet flow.

  1. Visualize the Simulation with NAM

We can be envisioned the network and traffic flow using the Network Animator (NAM) by entering the below command:

nam out.nam

It will open a graphical window in which we can monitor the interaction among ASes and how data packets are move among them.

  1. Analyzing the Trace File

The trace file (out.tr) encompasses detailed simulation records, which involves packet transmissions, receptions, and drops. We can be utilized AWK, Perl, or Python to examine the trace file for parameters such as throughput, packet loss, latency, and so on.

For example, to compute the amount of packets are received by the destination (AS3 router):

awk ‘($1 == “r” && $4 == “tcp”) {print “Packet received at time: ” $2}’ out.tr

  1. Enhancing the Simulation

We can prolong the simulation by:

  • Adding more ASes: Replicate more complex topologies by describing additional routers and autonomous systems.
  • Policy-based routing: Execute routing policies, which mimic BGP decision-making rules, like favouring shorter paths or preventing particular ASes.
  • BGP convergence: Mimic link failures and monitor how the routing tables are updated in distinct ASes, simulating BGP convergence behaviour.
  1. Troubleshooting
  • Simulation errors: Verify the syntax in the Tcl script if there are errors for the period of the simulation. NS2 will indicate the particular line where the error happened.
  • No traffic flow: Make certain that the routing tables are appropriately defined and that each router has a route to the destination. We require to modify the route set up for complex configurations.

At the end of these Exterior Gateway protocol projects were replicated and analysed using the above basic steps with NS2 tool. Likewise, comprehensive details will be added later in upcoming manual.phdprime.com provide complete guidelines to assist you in building Exterior Gateway Protocol Projects using NS2 tailored to your requirements.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2