Computer Network Simulation Using NS2

Page 1 of 33

CHAPTER 6 WIRED NETWORK SIMULATION

6.1    Introduction The architecture of NS2 and certain preliminary concepts were discussed in Chapter 4 and Chapter 5. In this chapter, we discuss simulation of a wired network. Computer communication networks may be classified into two types: wired and wireless. In wired networks, the nodes are connected via cables. On the other hand, in wireless networks the nodes are connected with air as the medium. In the first case a topology of the network is usually defined, whereas in the second case nodes can move and the topology changes dynamically and hence no static topology can be defined. If a node comes within the communication range of another node, then direct communication between the two nodes is possible. In this chapter we discuss simulation of wired networks, and wireless network simulation is discussed in Chapter 7. We start with a few simple examples and gradually develop programs of increasing sophistication with the objective of being able to simulate real-life wired network scenarios for various kinds of networks.

6.2    Step-by-Step Wired Network Simulation Complete network simulation using NS2 involves many steps. To be able to satisfactorily simulate a network, a thorough understanding of these steps is necessary. A minimal step-by-step process to simulate any wired network is provided in the form of a block diagram in Figure 6.1. The different blocks are briefly discussed below. Each block represents a step, and the details of these steps are discussed in subsequent sections. All simulation scripts are written using Tcl.

Figure 6.1 Block diagram for wired network simulation in NS2 Step I: Creating the Event Scheduler Creating the event scheduler is the first program statement in any NS2 program. This scheduler queues any event that is generated by the simulation. The scheduler is an object of the simulator class. The following Tcl statement is used to create the event scheduler. set ns [new Simulator] Step II: Tracing This step is essential if you need to record the events that are occurring during the simulation experiments in a specific format in a plain-text file. These files are treated as the output of any

file:///C:/Users/admin/AppData/Local/Temp/bityefte.y04/OPS/xhtml/13_Chapter06.xht... 4/16/2018

Computer Network Simulation Using NS2

Page 2 of 33

simulation program execution. Two types of traces are available. One is used by the programmer to analyze the simulation results for various network parameters (like throughput, delay, etc.) and is called the Packet Trace/Event Trace/NS trace. The other one is used by the network animator (NAM) module to create visualization for the simulation and is known as the NAM Trace. The following Tcl syntax may be used to generate traces. Syntax: Packet Trace set ptf [open w] $ns trace-all $ptf Syntax: NAM Trace set ntf [open w] $ns namtrace-all $ntf The file names given in angular brackets are user defined, i.e., the user has to provide the file name. Packet-trace is discussed in more detail in Section 6.7. Step III Creating Network Topology In this step the network topology is created. Different kinds of network topologies can be defined as per the user requirement. To realize a required topology, a set of nodes is first created, and the links between the nodes are defined as per the requirement. The syntax to create the nodes and links is provided below. Also, some complete programs are given to demonstrate the creation of different topologies. These programs may be executed to visualize the topologies in the NAM window. Syntax: Creating nodes set [$ns node] Syntax: Creating a link between two nodes $ns

Link parameters: •  The link-type can be simplex or duplex. •  node1 and node2 represents the nodes between which the link needs to be established. •  link-bw represents the bandwidth of the link normally provided in Mbps. •  Delay is the propagation delay in ms. •  Each link is associated with an interface queue in the MAC sublayer. These queues can be of various types and are discussed in subsequent sections. The simplest queue type is drop-tail, which is essentially a FIFO queue and when the queue is full any arriving packet is dropped. Let’s now write a program to create two nodes and a link between them. The code is given in Listing 6.1. Listing 6.1 A Two Node Network set ns [new Simulator]; # create Simulator Object 1 2 3 set nf [open twoNode . nam w]; # create NAM trace file 4 $ns namtrace -all $nf; # write into nam file 5 6 7 8 9 10 11 12

set n0 [$ns node]; # create node n0 set n1 [$ns node]; # create node n1 # create a duplex link between them $ns duplex -link $n0 $n1 10 Mb 10 ms DropTail $ns run; # run the simulation

file:///C:/Users/admin/AppData/Local/Temp/bityefte.y04/OPS/xhtml/13_Chapter06.xht... 4/16/2018

Computer Network Simulation Using NS2

Page 3 of 33

Write and save the program in a file with extension .tcl (twoNode.tcl). Now run the program using the following command in the command line/shell prompt. $ ns twoNode.tcl This command will execute the Tcl script and produce the NAM traces that are stored in a file named twoNode.nam, as given in line 3 of Listing 6.1. To see the NAM visualization, use the following command. $ nam twoNode.nam & This results in the creation of the topology shown in Figure 6.2. In this program only the NAM trace is used, and no packet trace is used, as no packet transmission is made between these nodes. The packet transmission mechanism will be discussed later in this chapter.

Figure 6.2 A two-node network with a point-to-point link. Let us now write another program for a four-node mesh network, as shown in Listing 6.2. Listing 6.2 Four-node mesh network 1 # Four node Mesh Topology set ns [new Simulator] 2 3 set nf [open fourNode . nam w] 4 $ns namtrace - all $nf 5 6 set n0 [$ns node] 7 set n1 [$ns node] 8 set n2 [$ns node] 9 set n3 [$ns node] 10 11 # create link between each node 12 $ns duplex - link $n0 $n1 10 Mb 10 ms DropTail 13 $ns duplex - link $n0 $n2 10 Mb 10 ms DropTail 14 $ns duplex - link $n0 $n3 10 Mb 10 ms DropTail 15 $ns duplex - link $n0 $n2 10 Mb 10 ms DropTail 16 $ns duplex - link $n1 $n3 10 Mb 10 ms DropTail 17 $ns duplex - link $n1 $n3 10 Mb 10 ms DropTail 18 19 $ns run 20 When code Listing 6.2 is executed using execution commands (as in the previous program), it will produce the topology provided in Figure 6.3 with four nodes and six links among them. If the actual layout does not resemble the figure provided, then click on the relayout button of the NAM window provided in the right bottom corner to get the figure in the proper layout (it may sometimes require multiple clicks).

Figure 6.3 Four-node mesh topology

file:///C:/Users/admin/AppData/Local/Temp/bityefte.y04/OPS/xhtml/13_Chapter06.xht... 4/16/2018

Computer Network Simulation Using NS2

Page 4 of 33

As can be seen from Listing 6.2, to create multiple nodes and links lines 7 to 10 and lines 13 to 18 are repeated redundantly. The same program may be rewritten using loops and arrays, as shown in Listing 6.3. Listing 6.3 Four-node mesh network using loops #Four node Mesh Topology 1 2 set ns [new Simulator] 3 4 set nf [open fourNode . nam w] 5 $ns namtrace - all $nf 6 #create nodes 7 for {set i 0} {$i < 4} {incr i} { set n($i) [$ns node] 8 9 } 10 #create links 11 for {set i 0} {$i < 3} {incr i} { for {set j [expr $i +1]} {$j < 4} {incr j} { 12 $ns duplex - link $n($i) $n($j) 10 Mb 10 ms DropTail 13 } 14 15 } 16 17 $ns run Step IV: Simulating Network Layer Protocol The network layer activity definition is optional in NS2. That is, if the user does not define any protocol for the network layer, then the simulator chooses a default routing protocol. We defer discussion of the definition of the network layer to subsequent sections. Step V: Attaching Transport Protocol Transport agents are created in pairs, as default options of NS2 support half-duplex connections in the transport layer. That is, one source agent and one sink agent need to be created for any connection. Many transport layer protocols are available in NS2, but here we discuss the UDP agent, the simplest one, and other agents are discussed later in this chapter. Syntax: Create source agent set [new Agent/UDP] Syntax: Attach the agent to a specific node (sender) $ns attach-agent Syntax: Create sink agent set [new Agent/Null] Syntax: Attach the sink agent to another node (receiver) $ns attach-agent Syntax: Connect two agents $ns connect Step VI: Application Now we need to attach an application that generates packets for transmission through the connections (traffic generation). Out of many traffic types available in NS2, we choose constant bit rate traffic for this example. Other traffic types will be discussed later in this chapter. Syntax: Create and attach application traffic set [new Application/Traffic/CBR] attach-agent Syntax: start and stop data transmission $ns at

chapter 6 wired network simulation -

Page 1 of 33. Computer Network Simulation Using NS2. 4/16/2018 file:///C:/Users/admin/AppData/Local/Temp/bityefte.y04/OPS/xhtml/13_Chapter06.xht.

3MB Sizes 0 Downloads 90 Views

Recommend Documents

Chapter 6.pdf
by gulping air at the surface of the water or by releasing dissolved gases. from their blood. 6.1. expanded swim bladder contracted swim bladder. Figure 2.

chapter 6.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. chapter 6.pdf.

GNS3 Network Simulation Guide.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Main menu.

Chapter 6 Synchronous Sequential Machines - Wiley
A description for this result is not available because of this site's robots.txtLearn more

Chapter 6 PowerPoint Review.pdf
Page 2 of 19. Introduction. In past chapters we covered different types of data. distribution. In chapter 6, we moved from discrete probability. distributions to continuous probability distributions. Although. part of the chapter focuses on uniform d

Chapter 6 Systems in Motion.pdf
Download. Connect more apps... Try one of the apps below to open or edit this item. Chapter 6 Systems in Motion.pdf. Chapter 6 Systems in Motion.pdf. Open.