network simulation and simulators

100
Network simulation and simulators Lecturer: Dmitri A. Moltchanov E-mail: [email protected].fi

Upload: trandang

Post on 12-Feb-2017

258 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Network simulation and simulators

Network simulation and simulators

Lecturer: Dmitri A. Moltchanov

E-mail: [email protected]

Page 2: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

OUTLINE

• Theoretical aspects

– why do we need network simulation?

– structure of a simulator

– discrete-event simulation

– data collection and analysis

– simulation with a given accuracy

– variance reduction techniques

• Practical aspects: ns2

– ns2 overview;

– ns2 architecture;

– simulation procedure;

– support tools: nam and xgraph;

– examples: bottleneck, routing and 802.11 WLANs.

Lecture: Network simulation 2

Page 3: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

1. Why do we need network simulations?Analyze communication networks: two ways

• analytical analysis;

• simulation studies.

Example: analysis of queuing system:

• modeling of arrival process as a stochastic process;

• modeling of service time are a stochastic process;

• representation of interactions of these processes as an another process.

What is important for analytical analysis:

• often analytical analysis is too complicated or even not possible;

• even if possible, it requires restrictive assumptions.

Lecture: Network simulation 3

Page 4: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

1.1. Simple example

GI/G/1 queuing system.

......unlimited # of waiting positionsarrivals server

Figure 1: Graphical representation of GI/G/1 queuing system.

System is characterized by:

• arbitrary i.i.d. distributed interarrival times (GI);

• arbitrary i.i.d. distributed service times (G);

• single server;

• FCFS queuing discipline.

Lecture: Network simulation 4

Page 5: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

What should be noted:

• there are no analytical solution for GI/G/1 queue;

• what should we do?

Approximate solution can be derived for:

• overloaded GI/G/1 system (λ→ µ);

• unloaded GI/G/1 system (λ << µ);

• results in terms of bounds.

Notes on GI/G/1 queue:

• GI/G/1 does not capture correlation between arrivals;

• arrival processes in real networks are often correlated;

• simulation is the only suitable way in this case.

Lecture: Network simulation 5

Page 6: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

1.2. Simulations vs. analytic: queue example

Simulation of a queue consists of:

• representation of the arrival process as a stochastic one;

• representation of service time as a stochastic process;

• representation of interoperation as a stochastic process;

• simulation run;

• collection of data;

• statistical analysis of obtained data;

• drawing conclusions.

Differences between analytical analysis and simulations:

• incorporation of simulation execution;

• incorporation of data collection and analysis.

Lecture: Network simulation 6

Page 7: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

1.3. Advantages/shortcoming of simulations

Advantages:

• does not require restrictive assumption or require less of them;

• model structure, algorithms and variable may be changed quickly;

• models of traffic and service times can be used as is just from measurements;

• may provide results which are not obtainable using analytical techniques.

Shortcomings:

• time consuming, it may take much more time that analytic;

• computationally expensive;

• validation of results take additional time;

• results may be inaccurate when time of analysis is not sufficient;

• simulations may be of higher complexity than required;

• relationship between variables is hard to visualize and explain;

• sensitivity analysis is difficult.

Lecture: Network simulation 7

Page 8: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

2. Structure of a simulatorWe have the following components:

• simulation engine (core);

• a collection of models (link, buffer, etc.);

• frontend (interface);

• preprocessing tools (hidden for a user);

• data postprocessing tools.

Engine is the most important:

• specifies how to handle simulations;

• everything is handled in uniform way;

• does not matter what you simulate.

Lecture: Network simulation 8

Page 9: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

2.1. Types of simulations

Continuous simulations:

• real time is used: time increments as fine as possible: to capture all state changes.

Discrete simulations:

• system is observed at discrete times t0, t0 + ∆t, t0 + 2∆t, . . . .

Discrete event simulations:

• we focus on system changes only at event times;

• after processing the current event, the system clock is forwarded to another event

• simulation moves from the current system state to the event occurring next;

• processing of the event may create additional events;

• event list which is updated for the system.

Lecture: Network simulation 9

Page 10: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

t0 t1 t2 t3 t4 t5

t0 t1 t3

Discrete-event

Discrete

t0 t1

Continuous

t2 t3 t4 t5 t6 t7

...

Figure 2: Illustration of different types of simulations.

Lecture: Network simulation 10

Page 11: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

2.2. The simulation procedure

Define the problem

Analyze data

Formulate submodels

Combine submodels

Collect data

Write the program

Debug

Validate model

Design experiments

Run the simulator

Analyze the results

Implement results

Lecture: Network simulation 11

Page 12: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

2.3. The simulation program

Simulation program can be implemented using:

• general purpose programming languages:

– C: suitable for one purpose simulations;

– C++: suitable for writing multiple purposes simulations.

+: very flexible languages;

−: there are no simulation specific functions and error detection.

• simulation oriented programming languages:

– OPNET: all networks;

– OMNET++: all networks;

– Qualnet: very good for cellular networks;

– ns2: all networks:

+: reliable approach;

−: sometimes not fast (incorporate a lot of functionality;)

−: sometimes limited to specific functionality;

−: one more language to learn.

Lecture: Network simulation 12

Page 13: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3. Discrete event simulationThe basic idea:

• only events change the state of the system;

• no need to track state of the system between events.

The whole system consists of the following components:

• system under consideration:

– process under considerations: product of other processes and RVs.

• system state:

– state of the stochastic process.

• simulation clock:

– tells the occurrence time of the next event.

• event list:

– holder for events: consider it as a two dimensional vector: time and event.

Lecture: Network simulation 13

Page 14: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

The idea of the event list is illustrated in the following figure:

• Ti, i = 1, 2, . . . , are event times;

• Ei, i = 1, 2, . . . , are corresponding events.

E1

T1

E2

T2

E3

T3

...Ei

Ti

...

Figure 3: The idea of the event list.

Events are identified by event time and event type.

There are two general types of events:

• basic events:

– these events modify the state of the system: arrivals/departures of customers.

• additional events:

– these are events needed by additional tasks of simulation: run, stoppage, collection of data.

Lecture: Network simulation 14

Page 15: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

General algorithm:

• initialization procedure:

– system clock should be set to zero;

– system state is assigned an initial value;

– generate list of the event and place the next event to this list.

• handling of events during a simulation:

– system clock should be set to the occurrence time of the first (next) event in event list;

– handle the event making all appropriate actions associated with the event;

– update the system state.

• stop of simulation.

Note that the following is not included:

• storing of statistical data;

• statistical analysis of obtained data.

Lecture: Network simulation 15

Page 16: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3.1. Time advance methods

Time advance methods in discrete-event simulations:

• event-advance method;

• unit-advance method.

t0 t1 t2 t3 t4 t5

t0 t1 t3

event advance:

unit-time advance:

Figure 4: Time advance techniques in discrete-event simulations.

Lecture: Network simulation 16

Page 17: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3.2. Event list

Future event list: collection of events that occur in the future.

What type of operation are performed in a list:

• locating the next event and its type:

– required when advancing the time.

• deleting the event:

– required when the events has already been treated.

• inserting the event in a list:

– required when generating new event;

– required when basic event generates conditional events.

Basically, there are two ways of organizing a list:

• using sequential array;

• using linked list.

Lecture: Network simulation 17

Page 18: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3.3. Sequential arrays

The approach: all future event times are stored sequentially in array.

How to implement:

• associate each event type with a certain integer i;

• clock associated with this event is stored in the ith position in array.

Example: we need N positions in array:

• clock value of the type 1 event is stored in 1st position;

• clock value of the type 2 event is stored in 2nd position;

• . . .

• clock value of the type N event is store in Nth position;

Figure 5: Using sequential array as a future event list.

Lecture: Network simulation 18

Page 19: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

How to find the next event:

• locate the smallest value in array of N elements.

Example: find the smallest element and its index in array E[i], i = 0, 1, . . . , N − 1:

• variable smallest returns the smallest element;

• variable index returns the index of the smallest element.

smallest = E[0];

index = 0;

for (i=1; i<N; i++) {

if (E[i] < smallest) {

smallest = E[i];

index = i;

}

}

Lecture: Network simulation 19

Page 20: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

How to deal with other functions:

• deletion: set the value of the clock associated with event of type i to very big one;

– not deleted physically!

• insertion: update the value of the clock associated with event of type i.

– not inserted physically!

Advantages:

• insertion and deletion are made very easily;

• location of the next event depend on the number of event types:

– complexity is linear in time.

Shortcoming:

• if the number of event types is large location is time consuming;

• in this case different organization of the future event list should be considered.

Lecture: Network simulation 20

Page 21: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3.4. Linked list

The idea: to access data elements in correct order

• we store data element;

• we store pointer to the next element.

Definitions:

• pointer is referred to as link;

• data element and the link(s) are referred to as node.

Example:

• node consists of two elements: one is data elements, the next one is link;

• link F points to the first element; link of the last node is set to zero.

Figure 6: Using linked list as a future event list.

Lecture: Network simulation 21

Page 22: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Implementation example: arrange integer numbers in T in ascending order:

• create new array P of the same dimension;

• the content of P (i) is the link to location in T containing element larger than T (i);

• example: P (1) = 7, next larger after T (1) is T (7)...

Notes:

• F (= 5) is the first element;

• node: location in T and corresponding location in P .

Figure 7: Locating values in a singly linked list.

Lecture: Network simulation 22

Page 23: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Locating element: we want to locate number 10 in T :

• using pointer F we check the value stored in the first node: (T (5), P (5));

• using pointer P (5) we locate the second node: (T (3), P (3));

• using pointer P (3) we locate the third node: (T (1), P (1));

• pointer P (1) contains the address we are looking for;

• general: if we know address of the first node we can locate any element.

Note: we can only move forward using singly linked link!

Figure 8: Deletion of elements in a singly linked list.

Lecture: Network simulation 23

Page 24: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Deletion: we want to delete number 10:

• change the value of the pointer of the previous node;

• previous node: (T (1), P (1)) = (5, 4);

• node containing 10 has the pointer P (7) = 4;

• to delete: set P (1) = P (7) = 4.

Note: information is not physically deleted, just not accessible!

Figure 9: Deletion of elements in a singly linked list.

Lecture: Network simulation 24

Page 25: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Insertion: we want to insert number 6:

• locate two nodes between which we should put 6;

• starting from the first node we find them as: (5, 7) and (10, 4) (see previous slide);

• get unused location in T : T (2);

• set P (1) = 2 to go from T (1) = 5 to T (2) = 6;

• set T (2) = 6, P (2) = 7 to go from T (2) = 6 to T (7) = 10.

Figure 10: Insertion of elements in a singly linked list.

Lecture: Network simulation 25

Page 26: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3.5. Implementation of linked lists

We have to be able:

• organize data elements and pointers into nodes;

• access node using pointer;

• create and delete nodes.

There are two ways:

• use built-in commands to carry these operations (if any);

• set-up your own storage scheme.

Notes:

• must be long enough to accommodate all events that might be generated;

• all unused nodes must be linked together to form a pool of free nodes.

Lecture: Network simulation 26

Page 27: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3.6. Event list using linked list

General notes:

• nodes are organized such that CLi < CLj < · · · < CLn;

• the next event is given by pointer F (first node);

• when the event occurred and processed it should be deleted;

• if conditional events are generated they are place in linked list.

Advantages:

• location and deletion is made easily:

– using linked lists in simulation we have to delete only the first node!

Shortcomings

• we have to use location procedure to insert an event in a linked list;

• search of the linked lists might be time consuming if the number of event types is large;

• solution: use better location procedure (e.g. use pointer pointing to the middle of the list)!

Lecture: Network simulation 27

Page 28: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

3.7. Doubly linked lists

The main problem of the singly linked lists:

• we can go only forward!

Doubly linked lists:

• link two successive node with two pointers;

• we can go forward and backward!

Note: there are some advantages for specific applications.

Figure 11: Example of the doubly linked list.

Lecture: Network simulation 28

Page 29: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4. Data collectionHow to carry out a simulation:

• set the initial state;

• start the simulation;

• obtain simulation results for some time...

We distinguish between:

• transient simulations (results for warm-up period);

• steady-state simulation (results for steady-state period).

N(t)

t

steady-state

warm-up

TW T

Lecture: Network simulation 29

Page 30: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.1. Transient simulations

What is the reason:

• analyze problems associated with a specific initial state;

– TW is a function of the initial conditions;

– this might give some hints how to start a certain system...

– example: which initial state faster leads to steady-state.

• analyze transient state itself:

– a certain system may not have a steady-state at all;

– example: M/M/1 queuing system with λ/µ = ρ > 1.N

(t),

nu

mb

er

of

job

s

lambda/mu10

M/M/1

Lecture: Network simulation 30

Page 31: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.2. Steady-state simulations: initial condition

What is the reason:

• typical application of simulations;

• simulation has to run long enough to get away from the transient state (TW ).

Note: TW is a function of the initial conditions.

How to choose initial condition:

• assume no activities in the system prior to time 0;

– no particular reasons for that;

– as good as any other choice of the initial state.

• set to some typical state of the system:

– should be as representative as possible;

– a-priori knowledge of the system is required;

– advantage: may significantly shorten the length of the transient period, TW .

Lecture: Network simulation 31

Page 32: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.3. Steady-state simulation: effect of the transient period

Transient period: may deteriorate statistics:

• how to remove transient period;

• how to determine the length of the transient period.

What are approaches to deal with:

• use very long simulation runs such that (meanwhile, how long is ’long enough’?):

– the amount of data in transient period is small relative to those of steady-state;

– time-consuming approach.

• no data collection during transient period:

– simulate till the steady-state is reached;

– clear all data accumulated up to this point;

– continue to get enough statistical data.

Hint for both approaches: set the initial state to what is expected in the long run.

Lecture: Network simulation 32

Page 33: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.4. Steady-state simulation: detecting transient period

There are three methods to detect TW :

• method of trials;

• moving-average method;

• blind guess using time-series...

Method of trials:

• try out different transient periods: T1, T2, . . . , Tk, T1 < T2 < . . . , < Tk;

• compile steady-state statistics for each run;

• choose Ti such that for all j > i statistics do not change significantly.

Moving-average method:

• compute moving average as time progresses: Ri =∑i

j=i−rNj;

– where Nj is some metric of interest, r is the range of moving averages.

• steady-state when Ri no longer changes significantly over time.

Lecture: Network simulation 33

Page 34: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.5. Estimating metrics

How to estimate the mean:

• use point estimator;

• estimate confidence intervals.

Confidence interval for the mean:

Pr

{E[X]− zα/2

s√N≤ µ ≤ E[X] + zα/2

s√N

}≈ 1− α, (1)

Note: interval [E[X]− zα/2 s√N, E[X] + zα/2

s√N

] is 100(1− α)% confidence interval for µ.

2

a

2

a

Lecture: Network simulation 34

Page 35: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

What is the problem with the following expression?

Pr

{E[X]− zα/2

s√N≤ µ ≤ E[X] + zα/2

s√N

}≈ 1− α, (2)

• we have to estimate sample mean and sample variance;

• point estimator of the variance is given by:

s2 =1

N − 1

N∑i=0

(Xi − E[X])2,

E[X] =1

N

N∑i=0

Xi, (3)

• Xi, i = 1, 2, . . . , N must be independent for s2 to be unbiased!

• quite often observations are dependent (correlated, in particular):

– example: waiting time of the packet i depends on the waiting time of packet (i− 1)!

The main problem! how to remove dependence between observations?

Lecture: Network simulation 35

Page 36: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

The following approaches have been proposed:

• use of autocorrelation function:

– tries to explicitly take correlation into account.

• batch means method;

– tries to remove correlation from observations.

• replication method;

– tries to remove correlation from observations.

• regenerative method.

– tries to remove correlation from observations.

Note the following:

• when sample size is really large the effect of dependence can be negligible;

• use any of above methods when sample size is not really huge.

Lecture: Network simulation 36

Page 37: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.6. Use of ACF

How to estimate the variance:

• idea: take into account the effect of correlation explicitly (σ2X+Y = σ2

X + σ2Y + 2CovXY );

• get the sample X1, X2, . . . , XN ;

• compute autocorrelation coefficients R(i), i = 0, 1, . . . , k;

• the variance can now be estimated as:

s2 = s2X

1 + 2

N/4∑k=1

(1− k

NR(k)

) . (4)

• s2X is the point estimator of the variance assuming no serial correlation:

s2X =1

N − 1

N∑i=1

(Xi − E[X])2. (5)

Lecture: Network simulation 37

Page 38: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.7. Batch means method

N(t)

timeTWb

atc

h1

ba

tch

2

ba

tch

k

ba

tch

3

...

correlation

Figure 12: Correlation between successive batches.

Do the following:

• let E[Xi] be the sample mean of the batch i, i = 1, 2, . . . , k;

• if b is large: E[X1], E[X2], . . . , E[Xk] are approximately uncorrelated and normally distributed.

Lecture: Network simulation 38

Page 39: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Given that E[X1], E[X2], . . . , E[Xk] are uncorrelated and normally distributed:

E[X] =1

k

k∑i=1

E[Xi],

s2 =1

k − 1

k∑i=1

(E[Xi]− E[X])2. (6)

Thus, for large k, k > 30 we get the following confidential intervals:(E[X]− 1.96

s√k, E[X] + 1.96

s√k

). (7)

• construct confidential intervals using t distribution.

Important notes:

• if b is not large enough, this computation gives biased estimates;

• estimate of b: plot ACF of X1, X2, . . . , XN :

– b should be approximately 5 times greater than the last significant correlation.

Lecture: Network simulation 39

Page 40: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.8. Method of replications

The idea: replicate simulation run several times:

• make n runs each resulting in m observations:

(X11, X12, . . . , X1m), (X21, X22, . . . , X2m), . . . , (Xn1, Xn2, . . . , Xnm). (8)

• for each sample compute the sample mean using point estimator of the mean:

E[Xi] =1

m

n∑j=1

x (9)

• treat sample means as a sample of independent observations:

E[X] =1

n

n∑i=1

E[Xi], s2 =1

n− 1

n∑i=1

(E[Xi]− E[X])2. (10)

Classic problems:

• determine the length of each simulation run;

• determine the length of the transient period.

Lecture: Network simulation 40

Page 41: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.9. Regenerative method

Comparison of methods:

• batch means:

– obtain approximately independent samples from a single run.

• method of replications:

– obtain strictly independent samples from multiples runs;

• regenerative method:

– obtain strictly independent samples from a single run;

– application is limited to systems with specific behavior.

Where it is used:

• simulation of queue-related problems.

Lecture: Network simulation 41

Page 42: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

4.10. Estimation for transient simulations

Two cases are possible:

• trajectories are all random: estimation may have no sense;

• trajectories are somewhat similar.

How to estimate:

• the transient state depends on initial conditions;

• the only way to get independent realizations of X is to use method of replications;

Repeating experiments:

• must start with the same initial condition;

• must use different random numbers (different seeds);

• we have to know the length of transient period.

Lecture: Network simulation 42

Page 43: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

5. Simulation with a given accuracyTwo inverse tasks:

• we considered: what are the confidence intervals given N observation:

– is it OK to say that mean is 50± 30?

• what we are asked: provide a kind of assurance:

– say what would be the values with confidence ±3...

• question: how many experiments are needed to achieve that?

General notes:

• recall, width of confidence intervals is proportional to 1/√N ;(

E[X]− zα/2s√N, E[X] + zα/2

s√N

). (11)

– N : number of iid observations;

– the larger N the smaller is the interval.

• to halve the confidence interval: increase N four times.

Lecture: Network simulation 43

Page 44: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Observe that:

• we do not know how many observations are needed:

– what accuracy may N experiments give?

– e.g. how many observations are needed to get 50± 3?

Two techniques:

• Solution 1: use of pilot experiments:

– aim 1: to get overall idea how things go;

– aim 2: obtain rough estimate of N providing required accuracy.

• Solution 2: sequential ’in-simulation’ checking:

– test is carried out periodically to check whether required accuracy is achieved.

Can be applied to:

• batch mean method;

• method of replications.

Lecture: Network simulation 44

Page 45: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

5.1. Example: replications + pilot experiments

Use of pilot experiments:

• we want to estimate statistics a with the intervals ±0.1a:

• pilot experiments is carried out to collect N1 replications;

• let a1 be a point estimator of a;

• let ∆1 be the width of confidence intervals;

• check the following:

– if ∆1 ≤ 0.1a1 we stop;

– if ∆1 > 0.1a1 we carry out main simulation with N2 = (∆1/0.1a1)2N1 replications;

• we obtain new a2 and ∆2:

– they may not be exactly what we wanted (0.1a2) due to randomness.

• if ∆1 > 0.1a1 carry out new attempt.

Lecture: Network simulation 45

Page 46: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

5.2. Example: batch means + in-simulation checking

Sequential ’in-simulations’ checking:

• we want to estimate statistics a with the intervals ±0.1a:

• gather k? batches;

• estimate a1 and ∆1;

• check the following:

– if ∆1 ≤ 0.1a1 we stop;

– if ∆1 > 0.1a1 gather k? additional batches.

• calculate new a2 and ∆2 based on total 2k? batches;

• check the following:

– if ∆2 ≤ 0.1a2 we stop;

– if ∆2 > 0.1a2 gather k? additional batches.

• repeat...

Lecture: Network simulation 46

Page 47: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

6. Variance reduction techniquesSuppose we have to estimate mean given N iid observations:

• point estimate of the mean is:

E[X] =1

N

N∑i=1

Xi, (12)

• confidence intervals for the mean are given by:(E[X]− zα/2

s√N, E[X] + zα/2

s√N

). (13)

– where s2 is the estimate of the variance.

How to shorten the confidence intervals:

• accuracy of an estimate can be increased by increasing the number of observations;

– shortcoming: may require very long simulations.

• accuracy can also be achieved by reducing variance.

Lecture: Network simulation 47

Page 48: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Lecture: Network simulation 48

Page 49: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

7. Network simulatorsFree simulators

• ns2/ns3: www.isi.edu/nsnam/ns;

• OMNET++: www.omnetpp.org

• QualNet: www.scalable-networks.com

• ITGuru: www.opnet.com

Commercial:

• OPNET: www.opnet.com

• a plenty of others....

Note: ITGuru is an academic edition of OPNET.

Lecture: Network simulation 49

Page 50: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

8. ns2 OverviewCharacteristics:

• discrete-event engine;

• network simulator;

• basically TCP/IP networks;

• wired and wireless components included.

Intended usage:

• research;

• development;

• education.

Developing:

• research institutes and universities;

• freely distributed and open source.

Lecture: Network simulation 50

Page 51: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

8.1. History of developing

Briefly:

• 1989: REAL simulator by UCB;

• 1990: ns1: LBL;

• 1995: ns2 DARPA VINT project (Virtual InterNet Testbed)

• 2011: ns3.

Current status:

• ns2 runs on:

– almost all UNIX and Linux and Win 95/98/2000/XP.

• last stable version: 2.35 released in Nov. 4, 2011

– roughly 1 release in 6 months + daily snapshots.

• http://www.isi.edu/nsnam/ns/ or http://nsnam.isi.edu/nsnam/index.php/Main Page

• > 200000 line of codes; > 1000 institutions; > 10000 users; > 400 pages of short manual;

• ns3 project started in July 2006, http://www.nsnam.org/

Lecture: Network simulation 51

Page 52: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

8.2. Components

ns2 distribution consists of:

• ns2 itself;

• nam: Network AniMator

– visualizing ns2 output;

– GUI for simple scenarios.

• Mandatory support tools:

– tcl/tk: script language

– otcl: object-oriented tcl;

– TclCL: tcl library.

• Pre-processing tools:

– traffic, topology generators, converters.

• Post-processing tools:

– trace analysis: awk, sed, perl, tcl.

– very simple and not recommended.

Lecture: Network simulation 52

Page 53: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

8.3. Installation

Differs for:

• Unix/Linux;

• Windows.

Two types are available:

• Via compilation;

– get ’all-in-one package’;

– get pieces and then compile.

• Obtaining binaries.

– easiest way to run on Win platform.

Hints and notes:

• to compile on Windows you need Cygwin (Unix emulation);

• Size of ’all-in-one’ is around 320Mb (v2.29).

Lecture: Network simulation 53

Page 54: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Building from pieces (Unix/Linux):

• get Otcl, TclCL and ns2;

• unpack in some temp folder at the same level;

• cd into the OTcl directory;

• run ./configure;

• run make;

• cd into the TclCL directory;

• run ./configure;

• run make;

• cd into the ns directory;

• run ./configure;

• run make;

• Verify that it built correctly and runs by running ./validate.

Note: ns2 ’all-in-one’ contains ’install’ script (just run it).

Lecture: Network simulation 54

Page 55: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

8.4. Support

Documentation:

• mailing list: [email protected]

– to get in send message to the address with ”subscribe ns-users” in the body;

– to browse archive go to http://www.isi.edu/nsnam/ns/.

• ns manual:

– available at http://www.isi.edu/nsnam/ns/;

– is only a short reference guide.

• tutorials:

– a number is available on http://www.isi.edu/nsnam/ns/;

– FAQ: http://www.isi.edu/nsnam/ns/ns-faq.html;

– de-facto tutorial: http://www.isi.edu/nsnam/ns/tutorial/index.html;

– installation and bug fixes: http://www.isi.edu/nsnam/ns/ns-problems.html;

– E. Altman, T. Jimenez: http://www-sop.inria.fr/maestro/personnel/Eitan.Altman/ns.htm.

Lecture: Network simulation 55

Page 56: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

9. Ns 2 architectureObject-oriented structure:

• advantage: code reuse;

• shortcomings: performance.

Software structure:

• uses two languages to separate control and processing:

– C++: packet processing;

– Otcl: control.

• Packet processing:

– C++ makes it fast and detailed;

– C++ makes it scalable.

• Control:

– Otcl makes it easy to create scenarios;

– Otcl makes it easy to understand third party scripts.

Lecture: Network simulation 56

Page 57: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

9.1. Scalability and extensibility

Scalability:

• per-packet processing must be fast;

• separating control and packet handling.

Extensibility:

• must be easy to add new objects;

• object trees to understand hierarchy:

– in C++;

– in Otcl.

• C++ and Otcl trees are split:

– if not needed nothing have to be changed at a certain level;

– helps a lot!

• Otcl class hierarchy: http://www-sop.inria.fr/planete/software/ns-doc/ns-current/;

• C++ class hierarchy: http://www.isi.edu/nsnam/nsdoc-classes/index.html.

Lecture: Network simulation 57

Page 58: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

9.2. Simple script

Lecture: Network simulation 58

Page 59: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

9.3. Tcl basics

Tcl language:

• semantics is similar to perl;

• one can check tutorial at: http://www.msen.com/%7Eclif/TclTutor.html;

• real programming language to create network topology;

• tcl is used by Otcl to construct advanced objects.

Tcl contains:

• lists, arrays, associative arrays etc.;

• procedures and functions;

• flow controls: if, while, for, etc.

Lecture: Network simulation 59

Page 60: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Lecture: Network simulation 60

Page 61: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

9.4. Otcl basics

• codes can be reused (for example, different version of TCP).

Lecture: Network simulation 61

Page 62: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

9.5. Viewing source code

Where to find:

• C++:

– /whereYouInstalled/ns-(ver)/

– where (ver) is your version of ns2 (e.g. 2.1b9a).

• Otcl:

– /whereYouInstalled/ns-(ver)/tcl/lib/

∗ ns-default.tcl: default values for ns2 objects;

∗ other Otcl definitions.

– /whereYouInstalled/ns-(ver)/tcl/

∗ specialized objects in subdirs.

Lecture: Network simulation 62

Page 63: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10. Simulation procedureBasic steps:

• Create the simulation environment;

– event list, scheduler, etc.;

• Create the network:

– nodes and links between them.

• Create connections:

– TCP, UDP (in some sense).

• Create applications:

– CBR flow, FTP, WWW traffic.

• Trace network elements:

– trace queue, trace flow.

Lecture: Network simulation 63

Page 64: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.1. Creating environment

The following are the common commands:

• Create event scheduler:

– set ns [new Simulator];

• Schedule events:

– $ns at <time> <event>;

• Start scheduler:

– $ns run.

• Stop and close everything:

– $ns at $x ”exit”.

– where $x is some instant of time.

Note: before closing you must take additional actions:

• flush all traces to files;

• close all files.

Lecture: Network simulation 64

Page 65: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.2. Generating RVs

Create new generator:

• set rng [new RNG];

• $rng seed 0.

RNs from other distributions:

• using class RNG:

– uniform: $rng uniform a b.

• using class RandomVariable:

– distributions: uniform, exponential, hyperexponential, Pareto;

Lecture: Network simulation 65

Page 66: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.3. Creating the network

Nodes:

• set n0 [$ns node].

Links and queuing:

• $ns duplex-link $n0 $n1 <bandwidth> <delay> <queue type>;

• <queue type>: DropTail, RED, CBQ, FQ, SFQ, DRR;

• example: link with 10 Mbps, 10 ms delay, buffer size 100, RED buffer control

Lecture: Network simulation 66

Page 67: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.4. Creating connections

Creating UDP flow

In one command:

• $ns create-connection <src type> <src node> <dst type> <dst node> <packet class>;

• example: $ns create-connection UDP $n0 Null $n1 1.

Other sources:

• TCP (we will consider);

• RTP source, RTCP source.

• TCP for wireless links.

Lecture: Network simulation 67

Page 68: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Creating TCP flow

In one command:

• $ns create-connection <src type> <src node> <dst type> <dst node> <packet class>;

• example: $ns create-connection TCP $n0 TCPSink $n1 1.

Some included TCP versions:

• TCP: Tahoe TCP (slow start and AIMD);

• TCP/Reno: Reno TCP (... + fast retransmit/fast recovery);

• TCP/NewReno: TCP Reno with improved fast retransmit;

• TCP/Sack: TCP SACK (Selective ACK).

Lecture: Network simulation 68

Page 69: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.5. Creating traffic on top of UDP

CBR:

• Constant bit rate;

• set src [new Application/Traffic/CBR].

Exponential or Pareto ON/OFF:

• on/off times are exponentially distributed;

• set src [new Application/Traffic/Exponential];

• set src [new Application/Traffic/Pareto].

Connecting to transport:

• $udp defined earlier;

• $src attach-agent $udp.

Lecture: Network simulation 69

Page 70: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

ns2 includes support for traffic traces:

What <file> should look like:

• each record consist of two 32 bit field;

• inter-packet time (msec) and packet size (in bytes).

For example: there is converter for MPEG frame size file to ns2.

Lecture: Network simulation 70

Page 71: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.6. Creating traffic on top of TCP

FTP:

• set ftp [new Application/FTP];

• attaching to TCP: $ftp attach-agent $tcp.

Telnet:

• set telnet [new Application/Telnet];

• attaching to TCP: $telnet attach-agent $tcp.

Lecture: Network simulation 71

Page 72: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.7. Starting/stopping traffic sources

Starting and stopping times scheduled as events to the scheduler:

• $ns at <time> <event>.

Starting:

• $ns at 1.0 ”$ftp start”;

• sends infinitely long;

• the same for CBR, telnet and on/off sources.

Stopping:

• $ns at 5.0 ”$ftp stop”;

• the same for CBR, telnet and on/off sources.

Sending for example 1000 packets:

• $ns at 7.0 ”$ftp produce 1000”;

• works for FTP only.

Lecture: Network simulation 72

Page 73: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.8. Tracing

Trace packets on all links of the network:

• $ns trace-all [open test.out w].

Tracing on specific links:

• $ns trace-queue $n0 $n1.

Lecture: Network simulation 73

Page 74: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.9. Monitoring

Queue monitor:

• set qmon [$ns monitor-queue $n0 $n1];

• for packet arrivals and drops:

– set parr [$qmon set parrivals ];

– set drops [$qmon set pdrops ].

Flow monitor:

• enable flow monitoring:

– set fmon [$nssim makeflowmon Fid];

– $nssim attach-fmon [$nssim link $n0 $n1] $fmon.

• count arrivals and drops for flow with id xx:

– set fclassifier [$fmon classifier];

– set flow1 [$fclassifier lookup auto 0 0 xx];

– set parr [$flow1 set parrivals ]; set pdrops [$flow1 set pdrops ].

Lecture: Network simulation 74

Page 75: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.10. Generic methodology

Lecture: Network simulation 75

Page 76: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

10.11. Other functionalities

ns2 also provides:

• errors on the data-link layer;

• LAN and WLAN;

• Routing;

• Multicasting;

• Mobile IP;

• DiffServ;

• MPLS;

• . . .

Lecture: Network simulation 76

Page 77: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

11. Support tools: nam and xgraphNam (Network AniMator):

• packet-level animation;

• almost integrated with ns2.

controls

node

link

packet

time

Lecture: Network simulation 77

Page 78: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Lecture: Network simulation 78

Page 79: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Xgraph allows to make graphs:

• frequently used with ns2;

• simple visualizer.

Lecture: Network simulation 79

Page 80: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

12. Example: analyzing a bottleneckEnvironment is the same!

# Create a simulator object

set ns [new Simulator]# Open the nam trace file

set nf [open out.nam w]$ns namtrace-all $nf# Define a 'finish' procedure

proc finish {} {global ns nf$ns flush-traceclose $nfexec nam out.nam &exit 0

}

BODY

# Call the finish procedure after 5 seconds simulation time

$ns at 5.0 "finish"# Run the simulation

$ns run

Lecture: Network simulation 80

Page 81: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Let’s create four nodes:

set n0 [$ns node]set n1 [$ns node]set n2 [$ns node]set n3 [$ns node]

Duplex links between them with droptail queuing:

$ns duplex-link $n0 $n2 1Mb 10ms DropTail$ns duplex-link $n1 $n2 1Mb 10ms DropTail$ns duplex-link $n3 $n2 1Mb 10ms DropTail

Re-layout topology for good-looking in nam:

$ns duplex-link-op $n0 $n2 orient right-down$ns duplex-link-op $n1 $n2 orient right-up$ns duplex-link-op $n2 $n3 orient right

Lecture: Network simulation 81

Page 82: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

What we get in nam:

What is next:

• two UDP agents with CBR sources at n0 and n1;

• null agent at node n3.

Lecture: Network simulation 82

Page 83: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

We use these commands:

#Create a UDP agent and attach it to node n0

set udp0 [new Agent/UDP]$ns attach-agent $n0 $udp0# Create a CBR traffic source and attach it to udp0

set cbr0 [new Application/Traffic/CBR]$cbr0 set packetSize_ 500$cbr0 set interval_ 0.005$cbr0 attach-agent $udp0#Create a UDP agent and attach it to node n1

set udp1 [new Agent/UDP]$ns attach-agent $n1 $udp1# Create a CBR traffic source and attach it to udp1

set cbr1 [new Application/Traffic/CBR]$cbr1 set packetSize_ 500$cbr1 set interval_ 0.005$cbr1 attach-agent $udp1# Create a Null agent and attach it to node n3

set null0 [new Agent/Null]$ns attach-agent $n3 $nul

Lecture: Network simulation 83

Page 84: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Connect two CBR agents to the Null agent:

$ns connect $udp0 $null0$ns connect $udp1 $null0...

Schedule their sending times:

$ns at 0.5 "$cbr0 start"$ns at 1.0 "$cbr1 start"$ns at 4.0 "$cbr1 stop"$ns at 4.5 "$cbr0 stop"

Classic bottleneck scenario:

• both sources send 200 pps with size 500 bytes;

• n0 to n2: 0.8 Mbps, n1 to n2: 0.8 Mbps;

• link between n2 and n3 is 1 Mbps.

Questions: which packets get lost? how many? what is the effect of queuing?

Lecture: Network simulation 84

Page 85: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

12.1. Marking flows

Set class to UDP sources first:

$udp0 set class_ 1$udp1 set class_ 2

Set colors to flows:

$ns color 1 Blue

$ns color 2 Red

Lecture: Network simulation 85

Page 86: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

12.2. Monitoring a queue

Add queue monitor:

$ns duplex-link-op $n2 $n3 queuePos 0.5

Everything is droptail on that queue!

Lecture: Network simulation 86

Page 87: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Why not to add some fairness with stochastic fair queuing (SFQ):

$ns duplex-link $n3 $n2 1Mb 10ms SFQ

Everything is SFQ on that queue!

Example: http://www.isi.edu/nsnam/ns/tutorial/examples/example2.tcl

Lecture: Network simulation 87

Page 88: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

13. RoutingCreate 8 nodes:

for {set i 0} {$i < 7} {incr i} {set n($i) [$ns node]

}

Create circular topology:

for {set i 0} {$i < 7} {incr i} {$ns duplex-link $n($i) $n([expr ($i+1)%7]) 1Mb 10ms DropTail

}

Lecture: Network simulation 88

Page 89: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Lecture: Network simulation 89

Page 90: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Send some data from n0 to n3:

#Create a UDP agent and attach it to node n(0)

set udp0 [new Agent/UDP]$ns attach-agent $n(0) $udp0# Create a CBR traffic source and attach it to udp0

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

set null0 [new Agent/Null]$ns attach-agent $n(3) $null0$ns connect $udp0 $null0

$ns at 0.5 "$cbr0 start"$ns at 4.5 "$cbr0 stop"

By default traffic goes over shortest path n0-n1-n2-n3!

Lecture: Network simulation 90

Page 91: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Introducing link failure:

$ns rtmodel-at 1.0 down $n(1) $n(2)$ns rtmodel-at 2.0 up $n(1) $n(2)

Lecture: Network simulation 91

Page 92: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Introduce destination vector (DV) routing to tackle the problem:

$ns rtproto DV.

Example: http://www.isi.edu/nsnam/ns/tutorial/examples/example3.tcl

Lecture: Network simulation 92

Page 93: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

14. Wireless simulations in ns2What we consider:

• simple 2-nodes wireless scenario;

• nodes move within the area 500m× 500m;

• nodes start out initially at two opposite ends of the boundary;

• nodes move towards each other and then move away;

• TCP connection is setup between the two nodes;

• packets are exchanged as nodes come within hearing range of each other;

• as nodes move away, packets start getting dropped.

We start with simple template:

• just as usual - some ’must do’ things;

• http://www.isi.edu/nsnam/ns/tutorial/examples/simple-wireless.tcl

Lecture: Network simulation 93

Page 94: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Array ’val()’ is used to set basic parameters:

• link layer (LL);

• interface queue (IfQ);

• MAC layer;

• wireless channel nodes transmit and receive signals from...

# ======================================================================

# Define options

# ======================================================================

set val(chan) Channel/WirelessChannel ;# channel type

set val(prop) Propagation/TwoRayGround ;# radio-propagation model

set val(ant) Antenna/OmniAntenna ;# Antenna type

set val(ll) LL ;# Link layer type

set val(ifq) Queue/DropTail/PriQueue ;# Interface queue type

set val(ifqlen) 50 ;# max packet in ifq

set val(netif) Phy/WirelessPhy ;# network interface type

set val(mac) Mac/802_11 ;# MAC type

set val(rp) DSDV ;# ad-hoc routing protocol

set val(nn) 2 ;# number of mobile nodes

Lecture: Network simulation 94

Page 95: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Create an instance of the simulator:

set ns_ [new Simulator]

Setup trace supportand call the procedure ’trace-all’:

set tracefd [open simple.tr w]$ns_ trace-all $tracefd

Create a topology object that keeps track of movements:

set topo [new Topography]

Provide the topography object with x and y coordinates:

$topo load_flatgrid 500 500

Next we create the object God (general operations director), as follows:

create-god $val(n

• keeps track of wireless environment.

Lecture: Network simulation 95

Page 96: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

We have to configure nodes before creating them providing e.g.:

• type of adressing (flat or hierarchial or...);

• routing protocol, LL, IfQ, MAC, etc.

# $ns_ node-config -addressingType flat or hierarchical or expanded# -adhocRouting DSDV or DSR or TORA# -llType LL# -macType Mac/802_11# -propType "Propagation/TwoRayGround"# -ifqType "Queue/DropTail/PriQueue"# -ifqLen 50# -phyType "Phy/WirelessPhy"# -antType "Antenna/OmniAntenna"# -channelType "Channel/WirelessChannel"# -topoInstance $topo# -energyModel "EnergyModel"# -initialEnergy (in Joules)# -rxPower (in W)# -txPower (in W)# -agentTrace ON or OFF# -routerTrace ON or OFF# -macTrace ON or OFF# -movementTrace ON or OFF

Lecture: Network simulation 96

Page 97: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

We use the following configuration:

# Configure nodes$ns_ node-config -adhocRouting $val(rp) \

-llType $val(ll) \-macType $val(mac) \-ifqType $val(ifq) \-ifqLen $val(ifqlen) \-antType $val(ant) \-propType $val(prop) \-phyType $val(netif) \-topoInstance $topo \-channelType $val(chan) \-agentTrace ON \-routerTrace ON \-macTrace OFF \-movementTrace OFF

Then we create two nodes disabling random movement:

for {set i 0} {$i < $val(nn) } {incr i} {set node_($i) [$ns_ node ]$node_($i) random-motion 0 ;# disable random motion

}

Lecture: Network simulation 97

Page 98: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Give initial positions of nodes:

# Provide initial (X,Y, for now Z=0) co-ordinates for node_(0) and node_(1)#$node_(0) set X_ 5.0$node_(0) set Y_ 2.0$node_(0) set Z_ 0.0

$node_(1) set X_ 390.0$node_(1) set Y_ 385.0$node_(1) set Z_ 0.0

Setting movement of nodes:

## Node_(1) starts to move towards node_(0)$ns_ at 50.0 "$node_(1) setdest 25.0 20.0 15.0"$ns_ at 10.0 "$node_(0) setdest 20.0 18.0 1.0"

# Node_(1) then starts to move away from node_(0)$ns_ at 100.0 "$node_(1) setdest 490.0 480.0 15.0"

ns at 50.0 ”node (1) setdest 25.0 20.0 15.0”: at 50.0s, it moves to (x=25,y=20) at 15m/s.

Lecture: Network simulation 98

Page 99: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Setup traffic flow between nodes:

set tcp [new Agent/TCP]$tcp set class_ 2set sink [new Agent/TCPSink]$ns_ attach-agent $node_(0) $tcp$ns_ attach-agent $node_(1) $sink$ns_ connect $tcp $sinkset ftp [new Application/FTP]$ftp attach-agent $tcp$ns_ at 10.0 "$ftp start"

Setting up time when simulation ends and reset to initial states:

for {set i 0} {$i < $val(nn) } {incr i} {$ns_ at 150.0 "$node_($i) reset";

}$ns_ at 150.0001 "stop"$ns_ at 150.0002 "puts \"NS EXITING...\" ; $ns_halt"proc stop {} {

global ns_ tracefdclose $tracefd

}

Lecture: Network simulation 99

Page 100: Network simulation and simulators

Network simulation techniques D.Moltchanov, TUT, 2012

Example: http://www.isi.edu/nsnam/ns/tutorial/examples/simple-wireless.tcl

What actually happens:

• TCP flow starting at 10.0s from node0;

• no packets are exchanged as nodes too far apart;

• around 81.0s the routing info begins to be exchanged between both the nodes;

• around 100.0s we see the first TCP packet being received by node1;

• the connection breaks down again around time 116.0s.

Note the following:

• all wireless traces starts with WL in their first field;

• we enabled DSDV so we have routing messages.

Lecture: Network simulation 100