Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry...

122
Simulation and Ns-3 Stein Kristiansen Postdoc, DMMS [email protected]

Transcript of Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry...

Page 1: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation and Ns-3

Stein KristiansenPostdoc, [email protected]

Page 2: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Outline

● Part I: Simulation Overview– What, why and how

– Discrete-event simulation with example

● Part II: Ns-3 Tutorial– About Ns-3

– Performing simulations

– Data collection

– Extending Ns-3

● Resources

Page 3: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Goals

Part I● Understand why we do simulation, and when it is approapriate● Understand the overall simulation workflow● Understand the main principles behind discrete event

simulation

Part II:● Learn the basic Ns-3 Object-model● Learn to use and extend Ns-3

Page 4: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Part I

Simulation“A simulation is the imitation of the operation of a real-world process or system over time. Whether done by hand or on a computer, simulation involves the generation of an artificial history of a system and the obser vation of that artificial history to draw inferences concerning the operating characteristics of the real system”

- Jerry Banks on “Simulation”

Page 5: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

System:“Entities that interact

over time to accomplishone or more goals”.

- Jerry Banks

Definition of System

Page 6: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Computer Networks:Computers, links,

protocols, packets,applications,

...

Definition of System

Page 7: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Understanding Systems

Computer Networks:Computers, links,

protocols, packets,applications,

...

Performance?

Impact of specificmodification?

How does it work?

How to improve?

Correctness

VerificationEducation

...

Cost-effectiveProvisioning

Students andteachers

Researchers Service providers

Developers

...

Page 8: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Understanding Systems

● Common sense?● Analytical models?● Real-world experiments?● Simulation?

Performance?

Impact of specificmodification?

How does it work?

How to improve?

VerificationEducation

...

Cost-effectiveProvisioning

Students andteachers

Researchers Service providers

Developers

Correctness

Page 9: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

When is Simulation Appropriate?

● Common sense?– Always consider first!

– Works for simple systems and problems

● E.g., provisioning for HD-movies in the home

– Limitation: systems and problems quickly grow too complex

Page 10: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

● Common sense?– Always consider first!

– Works for simple systems and problems

● E.g., provisioning for HD-movies in the home

– Limitation: systems and problems quickly grow too complex

● Use analytical models?– Captures more complex interactions

– E.g., the transfer time of a TCP stream

– Fast and accurate for specific system

– Limitations:● Limited applicability● Unfeasible for very complex systems

When is Simulation Appropriate?

“An analytical model for the capacity estimation of combined VoIP and TCP file transfers over EDCA in an IEEE 802.11 e WLAN”

Page 11: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

● Common sense?– Always consider first!

– Works for simple systems and problems

● E.g., provisioning for HD-movies in the home

– Limitation: systems and problems quickly grow too complex

● Use analytical models?– Captures more complex interactions

– E.g., the transfer time of a TCP stream

– Fast and accurate for specific system

– Limitations:● Limited applicability● Unfeasible for very complex systems

● Experiments with real equipment?– Most realistic results!

– Limitations:● Expensive● Time-consuming● Difficult to analyze results● Impossible with non-existing systems● Impossible with too big or complex systems● Often hard to reproduce results

[Source: www.wikipedia.org]

When is Simulation Appropriate?

Page 12: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

● Common sense?– Always consider first!

– Works for simple systems and problems

● E.g., provisioning for HD-movies in the home

– Limitation: systems and problems quickly grow too complex

● Use analytical models?– Captures more complex interactions

– E.g., the transfer time of a TCP stream

– Fast and accurate for specific system

– Limitations:● Limited applicability● Unfeasible for very complex systems

● Experiments with real equipment?– Most realistic results!

– Limitations:● Expensive● Time-consuming● Difficult to analyze results● Impossible with non-existing systems● Impossible with too big or complex systems● Often hard to reproduce results

– Simulation● Reproducibility● Inexpensive● Facilitates understanding● Allows exploration of modifications and non-

existing systems● Limitations:

– Requires accurate modeling

When is Simulation Appropriate?

Page 13: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Steps in a Simulation StudyProblem formulation

● What do we want to know?– Performance?

– To understand a system?

– Assess impact of modification?

– For pedagogical purposes?

– Capacity planning?

● Which aspects, metrics, …?● Is simulation the best

alternative?

Setting of objectives and overall project plan

[Source: www.wikipedia.org]

Page 14: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

[Source: www.wikipedia.org]

Steps in a Simulation StudyProblem formulation

Setting of objectives and overall project plan

Model conceptualization Data collection

Model translation

Validated?

Verified?t

tNs-3

● Analyze system to uncover fundamental constituents

● Create model of these entities● Implement in simulator● Verify and validate

Page 15: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Steps in a Simulation StudyProblem formulation

Setting of objectives and overall project plan

Model conceptualization Data collection

Model translation

Experimental design

Production runs and analysis

Validated?

Verified?

More runs?

tNs-3

t

● Parameters?● Measurements?● Metrics?

Page 16: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

[Source: www.wikipedia.org]

Steps in a Simulation StudyProblem formulation

Setting of objectives and overall project plan

Model conceptualization Data collection

Model translation

Experimental design

Production runs and analysis

Documentation and reporting

Implementation

Validated?

Verified?

More runs?

Publish?

Page 17: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Types of Models

● Static or Dynamic● Deterministic or Stochastic● Continuous or Discrete-Event● Network simulators: Dynamic, stochastic and

discrete-event

Page 18: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Model state:Scheduler (object name: sch)

Simulation Script

Discrete-Event Simulation

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event handler:

1.000

clock

function(arg1, arg2, ...){ <update model state> <schedule prosp. new events>}

main(){ <create objects> <schedule initial events> <call event loop> <clean up>}

function(),args,schedT0

function(),args,schedT1

schedT0 <schedT1 <schedT2 <... 1.Schedule initial events

2.Dequeue earliest event and update clock

3.Handle event: update model state and schedule new events

4.Jump to step 2 if more events and simulation duration is not exceeded

Page 19: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Discrete-Event Simulation

5 ms1 Mbps

Send.app.

Recv.app.

Problem formulation:

End-to-end delay, 100 pps a 1450 bytes?

Delay?

Page 20: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Script

Discrete-Event Simulationmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Page 21: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

State:Scheduler (object name: sch)

Simulation Script

Discrete-Event Simulation

5 ms1 Mbps

sa ra

sn rn

sq rql

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Page 22: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

State:Scheduler (object name: sch)

Simulation Script

Discrete-Event Simulation

sa.send(),1450, 100,1.000

5 ms1 Mbps

sa ra

sn rn

sq rql

eq

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Page 23: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

State:Scheduler (object name: sch)

Simulation Script

Discrete-Event Simulation

sa.send(),1450, 100,1.000

5 ms1 Mbps

sa ra

sn rn

sq rql

eq

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

Page 24: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch)

Simulation Script

State:

Discrete-Event Simulation

sa.send(),1450, 100,1.000

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false

Page 25: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch)

Simulation Script

State:

Discrete-Event Simulation

sa.send(),1450, 100,1.000

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false

Page 26: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch)

Simulation Script

State:

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(),1450, 100,1.000

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 27: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

1.000

clock

sa.send(size,rate){ pkt = createPkt(1450); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

sa.send(),1450, 100,1.000

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 28: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

0

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 29: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

0

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 30: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:sn.send(size){ <protocol processing> sq.enqueue(pkt);}

0

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 31: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:sn.send(size){ <protocol processing> sq.enqueue(pkt);}

0

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 32: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:sn.send(size){ <protocol processing> sq.enqueue(pkt);}

0

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 33: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send();}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 34: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send();}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 35: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send();}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000s = false

Page 36: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(size,rate){ sn.sendPkt(size); print(sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, 500,100);}

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.notify(this);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send(this);}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

sch.stop(),

60.000s = false

Page 37: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Event Handler:

Scheduler (object name: sch) State:

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(size,rate){ sn.sendPkt(size); print(sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, 500,100);}

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.notify(this);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send(this);}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

5 ms1 Mbps

sch.stop(),

60.000s = false transmitting = false

Page 38: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Event Handler:

Scheduler (object name: sch) State:

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(size,rate){ sn.sendPkt(size); print(sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, 500,100);}

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.notify(this);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send(this);}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

5 ms1 Mbps

sch.stop(),

60.000s = false transmitting = false

Page 39: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Event Handler:

Scheduler (object name: sch) State:

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(size,rate){ sn.sendPkt(size); print(sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, 500,100);}

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.notify(this);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send(this);}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

rn.recv (),pkt,1.016

5 ms1 Mbps

sch.stop(),

60.000

s = false transmitting = false

Page 40: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Event Handler:

Scheduler (object name: sch) State:

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

sa.send(size,rate){ sn.sendPkt(size); print(sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, 500,100);}

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.notify(this);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send(this);}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

rn.recv (),pkt,1.016

5 ms1 Mbps

sch.stop(),

60.000

s = false transmitting = true

Page 41: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.notify(this);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send();}

rn.recv (),pkt,1.016

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 42: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); print(pkt.seqnr + “ “ + sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

Event Handler:

0

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

rn.recv (),pkt,1.016

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 43: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

0

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

rn.recv (),pkt,1.016

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 44: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

0

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

rn.recv (),pkt,1.016

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 45: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

0

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

rn.recv (),pkt,1.016

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = trues = false

Page 46: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.000

clock

0

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

rn.recv (),pkt,1.016sa.send(),1450, 100,1.010

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 47: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

1.000

clock

0

rn.recv (),pkt,1.016sa.send(),1450, 100,1.010

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 48: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

1.000

clock

0

rn.recv (),pkt,1.016sa.send(),1450, 100,1.010

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 49: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

1.000

clock

0

rn.recv (),pkt,1.016

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

sa.send(),1450, 100,1.010

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 50: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

1.010

clock

0rn.recv (),pkt,1.016

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

sa.send(),1450, 100,1.010

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 51: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rql

eq

1.010

clock

0rn.recv (),pkt,1.016

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

sa.send(),1450, 100,1.010

Event Handler:

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

5 ms1 Mbps

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 52: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Event Handler:

Scheduler (object name: sch) State:

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.010

clock

sa.send(size,rate){ sn.sendPkt(size); print(sch.clock); nextP=sch.clock + 1/rate; schedule(sa.send,nextP, 500,100);}

Event Handler:

1

sn.send(size){ pkt=createPkt(size); sq.enqueue(pkt);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.notify(this);}

Event Handler:sq.send(pkt){ enqueue(pkt); l.send(this);}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

rn.recv (),pkt,1.016

l0

5 ms1 Mbps

sch.stop(),

60.000

s = false transmitting = true

Page 53: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.010

clock

1rn.recv (),pkt,1.016

l0

5 ms1 Mbps

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 54: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.010

clock

1rn.recv (),pkt,1.016

l0

5 ms1 Mbps

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 55: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Event Handler:

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

1.010

clock

1rn.recv (),pkt,1.016

l0

5 ms1 Mbps

sa.send(size,rate){ pkt = createPkt(size); sn.send(pkt); pkt.timestamps.push(sch.clock) nextP=sch.clock + 1/rate; schedule(sa.send,nextP, size,rate);}

sa.send(),1450, 100,1.020

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 56: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

clock

1

rn.recv (),pkt,1.016 l

05 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv();}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 57: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

clock

1

l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

0

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = false

Page 58: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

clock

1

l0

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = false

Page 59: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Scheduler (object name: sch) State:

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

clock

1

l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

0

sch.stop(),

60.000

s = false transmitting = false

Page 60: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Scheduler (object name: sch) State:

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

clock

1l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

Event Handler:l.send(){ if(!transmitting) pkt = sq.dequeue(); if(pkt) { sch.schedule(rn.recv(), pkt, sch.clock + (l.propDel + (pkt.size * 8) / l.transRt)); transmitting = true; } }}

0

rn.recv(),pkt,1.032

s = false transmitting = true

Page 61: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

1l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

0

rn.recv(),pkt,1.032

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 62: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

1l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

0rn.recv(),pkt,1.032

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 63: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

1l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

0rn.recv(),pkt,1.032

Event Handler:ra.recv(pkt){ print(pkt.seqNr + “ “ + sch.clock – pkt.timestamps.pop()); delete(pkt);}

Output:0 0.016

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 64: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

1l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

rn.recv(),pkt,1.032

Event Handler:ra.recv(pkt){ print(pkt.seqNr + “ “ + sch.clock – pkt.timestamps.pop()); delete(pkt);}

Output:0 0.016

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 65: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

1l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:

rn.recv(pkt){ l.transmitting = false; l.send(); ra.recv(pkt);}

rn.recv(),pkt,1.032

Output:0 0.016

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 66: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.016

1l

5 ms1 Mbps

sa.send(),1450, 100,1.020

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

rn.recv(),pkt,1.022

Output:0 0.016

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 67: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

1.032

1

l

5 ms1 Mbps

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Event Handler:Event Handler:ra.recv(pkt){ print(pkt.seqNr + “ “ + sch.clock – pkt.timestamps.pop()); delete(pkt);}

Output:0 0.0161 0.022

...2

34

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

sch.stop(),

60.000

s = false transmitting = true

Page 68: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

60.000

l

5 ms1 Mbps

Event Handler:

sch.stop(){ s = true;}

Output:0 0.0161 0.022

sch.stop(),

60.000

...222

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = false transmitting = true

Page 69: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

60.000

l

5 ms1 Mbps

Event Handler:

Output:0 0.0161 0.022

...222

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

sch.stop(){ s = true;}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = true transmitting = true

Page 70: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

60.000

l

5 ms1 Mbps

Output:0 0.0161 0.022

222

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = true transmitting = true

Page 71: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

60.000

l

5 ms1 Mbps

Output:0 0.0161 0.022

222

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = true transmitting = true

Page 72: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

60.000

l

5 ms1 Mbps

222

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

Output:0 0.0161 0.022

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

s = true transmitting = true

Page 73: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Scheduler (object name: sch) State:

Simulation Script

Discrete-Event Simulation

sa ra

sn rn

sq rq

eq

60.000

l

5 ms1 Mbps

222

eventLoop(){ do { e = eq.dequeue(); clock = e.scheduledTime; e.f(e.args); } while (!eq.empty()&&!s)}

main(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Output:0 0.0161 0.0222 ...

s = true transmitting = true

Page 74: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Additional Issues

● Random variables– To model stochastic phenomena

– E.g., bit errors, backoff, mobility, ...

● Multiple runs– Do not use same random numbers in different runs

● Statistics– Often, average and standard deviation across runs

is sufficient

Page 75: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Part II

● Free and open source network simulator● Intended as a replacement for Ns-2

– Clean slate implementation: no re-use of Ns-2 code

– Easier to use, more facilities, faster, more accurate, more flexible

● First version 3.1 June 2008– Current version 3.24

– Available for Linux, OS X and Windows w/ Cygwin

● Written in C++– Simulation scripts in C++ (python optional)

– Helper classes make “scripting” in C++ easy

Page 76: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Installing Ns-3

● Simplest approach: download tar ball, exstract and build

● For eclipse: see https://www.nsnam.org/wiki/HOWTO_configure_Eclipse_with_ns-3– The part about mercurial can be ignored

$ wget https://www.nsnam.org/release/ns-allinone-3.24.tar.bz2$ tar jxfv ns-allinone-3.24.tar.bz2$ cd ns-allinone-3.24/ns-3.24$ ./waf configure --enable-examples$ ./waf

Page 77: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Ns-3 Objects

● Very important information to use and extend Ns-3● Most objects inherit from ns3::Object● Provides a range of useful properties for simulation

– Smart pointers

– Aggregation

– Run-time type information

– Attributes

– Trace sources

● Ns-3 objects are created with CreateObject<Class> (constructor arguments)

State:

sa ra

sn rn

sq rq1l

5 ms1 Mbps

Page 78: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Smart Pointers

● Provides a form of “garbage-collection”● Enables object aggregation● CreateObject returns smart pointer:

● Always check return values and parameters: Ptr<T> or not?

Ptr<PacketSocketFactory> factory =CreateObject<PacketSocketFactory> ();

Page 79: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Object Aggregation

● Objects can be dynamically aggregated to each other

● All objects in an aggregation can be access via any objects in said aggregation– Avoids huge classes that encompass all possible

functionalitynode mobility

node mobility

node­>AggregateObject(mobility);

Ptr<MobilityModel> mob =node­>GetObject<MobilityModel> ();

Page 80: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Run-Time Type Information

● All Ns-3 objects must implement TypeId  GetTypeId(void)

● TypeId informs about attributes, runtime type information and trace sources

TypeId RoutingProtocol::GetTypeId (void){  static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol")    .SetParent<Ipv4RoutingProtocol> ()    .SetGroupName ("Olsr")    .AddConstructor<RoutingProtocol> ()    .AddAttribute ("HelloInterval", "HELLO messages emission interval.",                   TimeValue (Seconds (2)),                   MakeTimeAccessor (&RoutingProtocol::m_helloInterval),                   MakeTimeChecker ())

...    .AddTraceSource ("RoutingTableChanged", "The OLSR routing table has changed.",                     MakeTraceSourceAccessor (&RoutingProtocol::m_routingTableChanged),                     "ns3::olsr::RoutingProtocol::TableChangeTracedCallback")  ;  return tid;}

Page 81: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Run-Time Type Information

TypeId RoutingProtocol::GetTypeId (void){  static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol")    .SetParent<Ipv4RoutingProtocol> ()    .SetGroupName ("Olsr")    .AddConstructor<RoutingProtocol> ()

...

● Objects, attributes and trace sources can be located via textual paths via functions in the Config namespace (objects):

Config::MatchContainer m =Config::LookupMatches("NodeList/*/$ns3::olsr::RoutingProtocol”);

Ptr<Olsr::RoutingProtocol> olsr =m.Get(0)­>GetObject<Olsr::RoutingProtocol> ();

nodes.Get(0)­>GetObject<Olsr::RoutingProtocol> ();Equivalent to:

Page 82: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Run-Time Type Information

TypeId RoutingProtocol::GetTypeId (void){  static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol")    .SetParent<Ipv4RoutingProtocol> ()    .SetGroupName ("Olsr")    .AddConstructor<RoutingProtocol> ()

...

● Objects, attributes and trace sources can be located via textual paths via functions in the Config namespace (objects):

Config::MatchContainer m =Config::LookupMatches("NodeList/*/$ns3::olsr::RoutingProtocol”);

Ptr<Olsr::RoutingProtocol> olsr =m.Get(0)­>GetObject<Olsr::RoutingProtocol> ();

nodes.Get(0)­>GetObject<Olsr::RoutingProtocol> ();Equivalent to:

Example paths:

/NodeList/[3-5]|8|[0-1]matches nodes index 0, 1, 3, 4, 5, 8

/NodeList/*matches all nodes

/NodeList/3/$ns3::Ipv4matches object of type ns3::Ipv4 aggregated to node number 3

/NodeList/3/DeviceList/*/$ns3::CsmaNetDevicematches all devices of type ns3::CsmaNetDevice in node number 3

(See Doxygen for paths to particular objects)

Page 83: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Run-Time Type Information

TypeId RoutingProtocol::GetTypeId (void){  static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol")    .SetParent<Ipv4RoutingProtocol> ()    .SetGroupName ("Olsr")    .AddConstructor<RoutingProtocol> ()

...

● Objects, attributes and trace sources can be located via textual paths via functions in the Config namespace (objects):

Config::MatchContainer m =Config::LookupMatches("NodeList/*/$ns3::olsr::RoutingProtocol”);

Ptr<Olsr::RoutingProtocol> olsr =m.Get(0)­>GetObject<Olsr::RoutingProtocol> ();

nodes.Get(0)­>GetObject<Olsr::RoutingProtocol> ();Equivalent to:

Typecasting via object->GetObject<Class>

Page 84: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Run-Time Type Information

TypeId RoutingProtocol::GetTypeId (void){  static TypeId tid = TypeId ("ns3::olsr::RoutingProtocol")    .SetParent<Ipv4RoutingProtocol> ()    .SetGroupName ("Olsr")    .AddConstructor<RoutingProtocol> ()    .AddAttribute ("HelloInterval", "HELLO messages emission interval.",                   TimeValue (Seconds (2)),                   MakeTimeAccessor (&RoutingProtocol::m_helloInterval),                   MakeTimeChecker ())

...}

Config::SetDefault("ns3::olsr::RoutingProtocol::HelloInterval", TimeValue (Seconds(2)));Config::Set("/NodeList/*/$ns3::olsr::RoutingProtocol/HelloInterval",

  TimeValue(Seconds(5)));routingProtocolObject­>SetAttribute("HelloInterval", TimeValue(Seconds(1)));

● Objects, attributes and trace sources can be located via textual paths via functions in the Config namespace (attributes):

Page 85: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Using Ns-3 – Via Example

● Example: manet-2015.cc● MANET with 25 nodes

– Based on 802.11g wifi

● Routing protocol: OLSR● Workload: uniform UDP traffic

– 500-byte packets, 20 pps

– No background traffic

● Mobility: random walk– Initial placement: 5 x ceil(5 / y) grid

– y is the number of nodes

– 100 meters between nodes

● Duration 10 minutes● Run with “./waf --run manet-2015”

OLSR UDP

Page 86: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

8 Steps of an ns-3 Simulation Script

1) Handle command line arguments

2) Set default attribute values and random seed

3) Create nodes

4) Configure physical and MAC layers

5) Set up network stack, routing and addresses

6) Configure and install applications

7) Set up initial positions and mobility

8) Schedule user-defined events andstart simulation

Simulation Scriptmain(){ <create sch, sa, ra, sn, rn, sq, rq and l> sch.schedule(sa.send(), 1s, 1450, 100); sch.schedule(sch.stop(), 60s); sch.eventLoop(); <clean up>}

Page 87: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 1: Command Line Arguments

● Enables parameterization of simulation from command line

int main (int argc, char *argv[]){  ...  // Obtain command line arguments  CommandLine cmd;  cmd.AddValue ("cols", "Columns of nodes", cols);  cmd.AddValue ("numnodes", "Number of nodes", numNodes);  cmd.AddValue ("spacing", "Spacing between neighbouring nodes", nodeSpacing);  cmd.AddValue ("duration", "Duration of simulation", duration);  cmd.AddValue ("seed", "Random seed for simulation", seed);  cmd.AddValue ("run", "Simulation run", run);  cmd.AddValue ("packetrate", "Packets transmitted per second", packetRate);  cmd.AddValue ("packetsize", "Packet size", packetSize);  cmd.AddValue ("sourcenode", "Number of source node", sourceNode);  cmd.AddValue ("destinationnode", "Number of destination node", destinationNode);  cmd.AddValue ("showtime", "show ... time ... (default = true)", showSimTime);  cmd.Parse (argc,argv);  ...

./waf –run “manet­2015 ­­nodespacing=50 ­­pktsize=100 ­­packetrate=500”

For instance:

Page 88: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 2: Set Attribute Values and Random Seed

● Use Config::­functions to set default parameter values

● Remember to change run number between runs!

  // Set default parameter values  Config::SetDefault("ns3::WifiRemoteStationManager::FragmentationThreshold",

StringValue ("2200"));  Config::SetDefault("ns3::WifiRemoteStationManager::RtsCtsThreshold",

StringValue ("2200"));

  // Set random seed and run number  SeedManager::SetSeed (seed);  SeedManager::SetRun (run);

$ for run in "1 2 3"; do ./waf –run “manet­2015 ­­run=$run”; done

Page 89: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 3: Create Nodes

● Most objects in Ns-3 managed by containers– Simulations consist of many objects of the same

type

– Later used by helper classes to install components

– Entities in containers obtained withcontainer­>get()

  // Create notes  NodeContainer c;  c.Create (numNodes);  ...  apps = client.Install (c.Get (sourceNode));

0 numNodes - 1

c

1

Page 90: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 4-7: Configure Nodes

● Nodes are initially empty hulls

Antenna and NIC

Protocols

Applications

Page 91: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 4: Physical Layer

● Helpers enable script-like C++ programs● Here:

– 802.11g in ad-hoc mode

– Automatic Rate Fallback (ARF)● Kamerman, Ad, and Leo Monteban. "WaveLAN®-II: a high-performance wireless LAN for the

unlicensed band." Bell Labs technical journal 2.3 (1997): 118-133.

● Elsewise: default values● Note that wifi.install uses node container c

  // Set up physical and mac layers  WifiHelper wifi = WifiHelper::Default ();  wifi.SetStandard (WIFI_PHY_STANDARD_80211g);  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();  wifiMac.SetType ("ns3::AdhocWifiMac");  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();  YansWifiPhyHelper phy = wifiPhy;  phy.SetChannel (wifiChannel.Create ());  NetDeviceContainer devices = wifi.Install (phy, wifiMac, c);

Page 92: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 4: Physical Layer

  // Set up physical and mac layers  WifiHelper wifi = WifiHelper::Default ();  wifi.SetStandard (WIFI_PHY_STANDARD_80211g);  wifi.SetRemoteStationManager ("ns3::ArfWifiManager");  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();  wifiMac.SetType ("ns3::AdhocWifiMac");  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();  YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();  YansWifiPhyHelper phy = wifiPhy;  phy.SetChannel (wifiChannel.Create ());  NetDeviceContainer devices = wifi.Install (phy, wifiMac, c);

……

● New container:devices

Page 93: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 5: Install Internet Stack and Routing Protocol

● Select routing protocol– Ns-3 currently supports OLSR, AODV and DSDV

– Used in example: OLSR

● Internet stack: IP, TCP, UDP, ARP and ICMP

// Routing and Internet stackns3::OlsrHelper olsr;InternetStackHelper internet;internet.SetRoutingHelper(olsr);internet.Install (c);

Page 94: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 5: Assign Addresses

● c­>Get(X) getsIP address 10.0.0.(X+1)

andMAC address 00:00:00:00:00:(X+1)

// Assign addressesIpv4AddressHelper address;address.SetBase ("10.0.0.0", "255.255.255.0");Ipv4InterfaceContainer interfaces = address.Assign (devices);

Page 95: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 6: Install Applications

● In example: simple UDP server and client● Set attributes● Specify when applications start and stop// Server/ReceiverUdpServerHelper server (4000);ApplicationContainer apps = server.Install (c.Get(destinationNode));apps.Start (Seconds (1));apps.Stop (Seconds (duration ­ 1));

// Client/SenderUdpClientHelper client (interfaces.GetAddress (destinationNode), 4000);client.SetAttribute ("MaxPackets", UintegerValue (100000000));client.SetAttribute ("Interval", TimeValue (Seconds(1 / ((double) packetRate))));client.SetAttribute ("PacketSize", UintegerValue (packetSize));apps = client.Install (c.Get (sourceNode));apps.Start (Seconds (1));apps.Stop (Seconds (duration ­ 1));

Page 96: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

The Ns-3 Node

● Node provides pointers to devices and applications

Ptr<Application> app = node­>GetApplication(0);Ptr<NetDevice> nic = node­>GetDevice(0);

● Aggregated with stack, mobility model and energy model

Ptr<Ipv4> ip = nodes.Get(0)­>GetObject<Ipv4>();Ipv4Address addr = ip­>GetAddress(1,0).GetLocal();

Page 97: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 7: Set up Initial Positions

● Several options available, including grid, disc, random placement and user-defined locations– Explained here: grid

// Set up mobilityMobilityHelper mobility;mobility.SetPositionAllocator (  "ns3::GridPositionAllocator",  "MinX", DoubleValue (1.0),  "MinY", DoubleValue (1.0),  "DeltaX", DoubleValue (nodeSpacing),  "DeltaY", DoubleValue (nodeSpacing),  "GridWidth", UintegerValue (cols));

nodeSpacing

cols

Page 98: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 7: Set Up Mobility Model

● Several alternatives– Random waypoint, random walk, user defined, …

● Used in Example: Random walk– Walk in random direction with random speed across fixed distance

● Reflect upon hitting scenario boundaries

– Speed defined with random variable

– Select new random direction

mobility.SetMobilityModel (  "ns3::RandomWalk2dMobilityModel",  "Bounds", RectangleValue    (Rectangle (0,(cols * nodeSpacing) + 1,       0,(rows * nodeSpacing) + 1)),  "Speed",    StringValue("ns3::UniformRandomVariable[Min=5.0,Max=10.0]"),  "Distance", DoubleValue(30));

mobility.Install (c);

Page 99: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Example Mobility, 10 minutes

Page 100: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 8: Schedule Initial Events and Start Simulation

● Can schedule our own events before simulation– Example: print virtual time once every simulated second

● Simulation duration should be set

// Print simulated timeif(showSimTime)

   Simulator::Schedule(Seconds(1), &PrintSeconds);

Simulator::Stop(Seconds(duration));Simulator::Run ();Simulator::Destroy ();

return 0;}

void PrintSeconds(void) {std::cerr << Simulator::Now() << std::endl;Simulator::Schedule(Seconds(1), &PrintSeconds);

}

Page 101: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Data Collection

● Four ways:

1) std::cout << “Manual collection” << std::endl;

2) Packet tracing

3) Trace points

4) Logging via the logging facility (see doc.)

Page 102: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Packet Tracing

● Part of data collection● One .pcap-file per node● Pass device container from Step 4

● Set prefix (here “MANET”)

  if(enablePcap)  wifiPhy.EnablePcap ("MANET", devices);

Page 103: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Packet Tracing

● Resulting files: <prefix>-<node>-<device>.pcapAUTHORS          MANET­17­0.pcap  routingtable­wireless.xmlbindings         MANET­18­0.pcap  scratchbuild            MANET­19­0.pcap  srcCHANGES.html     MANET­20­0.pcap  test.pydoc              MANET­2­0.pcap   testpy.suppdumbbell.xml     MANET­21­0.pcap  utilsexamples         MANET­22­0.pcap  utils.pyLICENSE          MANET­23­0.pcap  utils.pycMakefile         MANET­24­0.pcap  VERSIONMANET­0­0.pcap   MANET­3­0.pcap   wafMANET­10­0.pcap  MANET­4­0.pcap   waf.batMANET­1­0.pcap   MANET­5­0.pcap   waf­toolsMANET­11­0.pcap  MANET­6­0.pcap   wireless­animation.xmlMANET­12­0.pcap  MANET­7­0.pcap   wscriptMANET­13­0.pcap  MANET­8­0.pcap   wutils.pyMANET­14­0.pcap  MANET­9­0.pcap   wutils.pycMANET­15­0.pcap  READMEMANET­16­0.pcap  RELEASE_NOTES

Page 104: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Can be opened in, e.g., Wireshark

Page 105: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Trace Sources and Sinks

TypeId RoutingProtocol::GetTypeId (void){

...    .AddTraceSource ("RoutingTableChanged", "The OLSR routing table has changed.",                     MakeTraceSourceAccessor (&RoutingProtocol::m_routingTableChanged),                     "ns3::olsr::RoutingProtocol::TableChangeTracedCallback")

...

void RouteChange(std::string source, uint32_t size) {std::cout << "Routechange at " << source << ", new size: " << size << std::endl;

}

● Objects, attributes and trace sources can be located via textual paths via functions in the Config namespace (trace sources):

Config::Connect("/NodeList/*/$ns3::olsr::RoutingProtocol/RoutingTableChanged",MakeCallback (&RouteChange));

routingProtocolObject­>TraceConnect(“RoutingTableChanged”, “Context info”,MakeCallback(&RouteChange));

Page 106: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Trace Sources and Sinks

TypeId RoutingProtocol::GetTypeId (void){

...    .AddTraceSource ("RoutingTableChanged", "The OLSR routing table has changed.",                     MakeTraceSourceAccessor (&RoutingProtocol::m_routingTableChanged),                     "ns3::olsr::RoutingProtocol::TableChangeTracedCallback")

...

void RouteChange(std::string source, uint32_t size) {std::cout << "Routechange at " << source << ", new size: " << size << std::endl;

}

● Objects, attributes and trace sources can be located via textual paths via functions in the Config namespace (trace sources):

Config::Connect("/NodeList/*/$ns3::olsr::RoutingProtocol/RoutingTableChanged",MakeCallback (&RouteChange));

routingProtocolObject­>TraceConnect(“RoutingTableChanged”, “Source node”,MakeCallback(&RouteChange));

Routechange at /NodeList/2/$ns3::olsr::RoutingProtocol/RoutingTableChanged, new size: 8Routechange at /NodeList/11/$ns3::olsr::RoutingProtocol/RoutingTableChanged, new size: 13Routechange at /NodeList/15/$ns3::olsr::RoutingProtocol/RoutingTableChanged, new size: 9...

Routechange at Source node, new size: 5...

Page 107: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Extending Ns-3

● Prerequisite: C++ knowledge● Module-based● Create template with create-

module.py

● Creates five folders– Your model in “model”

● MUST reconfigure before re-compilation

ns-allinone-3.24

ns-3.24

src

ymcreate-module.py

doc examples helper model test

ym.cc ym.h

...

$ create­module.py ym

$ ./waf configure ­­enable­examples$ ./waf

Page 108: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Resulting .cc and .h files in

...#include "ym.h"

namespace ns3 {

/* ... */

}

...#ifndef YM_H#define YM_H

namespace ns3 {

/* ... */

}

#endif /* YM_H */

ym.cc ym.h

model

Page 109: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Resulting .cc and .h files in

...#include "inf5090­helper.h"

namespace ns3 {

/* ... */

}

...#ifndef INF5090_HELPER_H#define INF5090_HELPER_H

#include "ns3/inf5090.h"

namespace ns3 {

/* ... */

}

#endif /* INF5090_HELPER_H */

ym-helper.cc

helper

ym-helper.h

Page 110: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Resulting .cc and .h files in

/* ­*­ Mode:C++; c­file­style:"gnu"; indent­tabs­mode:nil; ­*­ */

#include "ns3/core­module.h"#include "ns3/ym­helper.h"

using namespace ns3;

int main (int argc, char *argv[]){  bool verbose = true;

  CommandLine cmd;  cmd.AddValue ("verbose", "Tell application to log if true", verbose);

  cmd.Parse (argc,argv);

  /* ... */

  Simulator::Run ();  Simulator::Destroy ();  return 0;}

example.cc:examples

Page 111: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

When Adding Files, Update wscript

ym

...def build(bld):    module = bld.create_ns3_module('ym', ['core'])    module.source = [        'model/ym.cc',        'helper/ym­helper.cc',        ]

    module_test = bld.create_ns3_module_test_library('ym')    module_test.source = [        'test/ym­test­suite.cc',        ]

    headers = bld(features='ns3header')    headers.module = 'ym'    headers.source = [        'model/ym.h',        'helper/ym­helper.h',        ]

    if bld.env.ENABLE_EXAMPLES:        bld.recurse('examples')

    # bld.ns3_python_bindings()

wscript

Page 112: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Summary

● Simulation is used when analysis and real experiments are unfeasible– Useful in other situations as well

● Discrete event simulation used for network simulation

1) Schedule initial events

2) Dequeue earliest event and update virtual time

3) Handle earliest event (update state + schedule new events)

– Repeat 2 and 3 until no more events or stopping time is exceeded

● Ns-3 object model enables easy, parameterization and data collection● Helpers and makes it possible to write “scripts” in C++● Four ways to collect data

Page 113: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Resources

Performance evaluation and simulation:● The Art of Computer Systems Performance Analysis, Raj Jain, Ch. 24● Discrete-Event System Simulation 4th Ed., Jerry Banks, Ch. 1-3

Ns-3● www.nsnam.org

– Esp.: https://www.nsnam.org/tutorials/ns-3-tutorial-Walid-Younes.pdf

● www.nsnam.org/wiki● www.nsnam.org/documentation

– Ns-3 manual

– Ns-3 tutorial

– Doxygen

– ...

● Examples in the source code

Page 114: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Summary of simulation conceptsStatic routesUser defined locationsConstant positionsThe Ns-3 logging facility

AppendixAppendix

Page 115: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Discrete-Event Simulation Concepts

Concept Network Simulation ExampleSystem The Internet, MANET, WSN, ...

Model C++ classes, math formulas, ...

Model state C++ objects, packets, node positions, ...

Entity Link, queue, packet, protocol, ...

Attributes Link capacity, queue size, packet type, ...

List Packets in a queue, nodes in a subnet, ...

Event Transmission/arrival of packet, packet drop, ...

Event notice Ns-3: Scheduler::Event (obj. w/ func. pointer)

Event list Ns-3: DefaultSimulatorImpl::m_events

Activity Transmission delay, part of movement, ...

Delay Queuing delay, end-to-end delay, ...

Clock Ns-3: DefaultSimulatorImpl::m_currentTs

Page 116: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 6: Static RoutingStep 6: Static RoutingSetting static routes

◦Use Ipv4StaticRoutingHelperWe provide a function to manipulate table

Ipv4StaticRoutingHelper staticRouting;InternetStackHelper internet;internet.SetRoutingHelper(staticRouting);internet.Install (nodes);

Page 117: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 6: Static RoutingStep 6: Static RoutingSetting static routes

◦Use Ipv4StaticRoutingHelperWe provide a function to manipulate table

void SetStaticRoute(Ptr<Node> n, const char* destination, const char* nextHop, uint32_t interface) { Ipv4StaticRoutingHelper staticRouting; Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> (); Ptr<Ipv4StaticRouting> a = staticRouting.GetStaticRouting (ipv4); a->AddHostRouteTo (Ipv4Address (destination), Ipv4Address (nextHop), interface);}

Page 118: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 6: Configuring Step 6: Configuring Static RoutesStatic RoutesSetting static routes:

// Set addresses

SetStaticRoute(nodes.Get(0), "10.0.0.3", "10.0.0.2", 1);SetStaticRoute(nodes.Get(0), "10.0.0.2", "10.0.0.2 ,1);SetStaticRoute(nodes.Get(1), "10.0.0.1", "10.0.0.1", 1);SetStaticRoute(nodes.Get(1), "10.0.0.3", "10.0.0.3", 1);SetStaticRoute(nodes.Get(2), "10.0.0.1", "10.0.0.2", 1);SetStaticRoute(nodes.Get(2), "10.0.0.2", "10.0.0.2", 1);

10.0.0.1 10.0.0.2 10.0.0.3

10.0.0.3 -> 10.0.0.2

10.0.0.2 -> 10.0.0.2

Page 119: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 6: Configuring Step 6: Configuring Static RoutesStatic RoutesSetting static routes:

// Set addresses

SetStaticRoute(nodes.Get(0), "10.0.0.3", "10.0.0.2", 1);SetStaticRoute(nodes.Get(0), "10.0.0.2", "10.0.0.2", 1);SetStaticRoute(nodes.Get(1), "10.0.0.1", "10.0.0.1", 1);SetStaticRoute(nodes.Get(1), "10.0.0.3", "10.0.0.3", 1);SetStaticRoute(nodes.Get(2), "10.0.0.1", "10.0.0.2", 1);SetStaticRoute(nodes.Get(2), "10.0.0.2", "10.0.0.2", 1);

10.0.0.1 10.0.0.2 10.0.0.3

10.0.0.1 -> 10.0.0.1 10.0.0.3 -> 10.0.0.3

Page 120: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 6: Configuring Step 6: Configuring Static RoutesStatic RoutesSetting static routes:

10.0.0.1 10.0.0.2 10.0.0.3

10.0.0.1 -> 10.0.0.2

10.0.0.2 -> 10.0.0.2

// Set addresses

SetStaticRoute(nodes.Get(0), "10.0.0.3", "10.0.0.2", 1);SetStaticRoute(nodes.Get(0), "10.0.0.2", "10.0.0.2", 1);SetStaticRoute(nodes.Get(1), "10.0.0.1", "10.0.0.1", 1);SetStaticRoute(nodes.Get(1), "10.0.0.3", "10.0.0.3", 1);SetStaticRoute(nodes.Get(2), "10.0.0.1", "10.0.0.2", 1);SetStaticRoute(nodes.Get(2), "10.0.0.2", "10.0.0.2", 1);

Page 121: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

Step 8: Explicit Locations and Step 8: Explicit Locations and Constant PositionsConstant Positions

MobilityHelper mobility;

Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();positionAlloc->Add(Vector(0.0, 0.0, 0.0));positionAlloc->Add(Vector(0.0, nodeSpacing, 0.0));mobility.SetPositionAllocator(positionAlloc);

nodeSpacing

[0,0,0] [nodeSpacing,0,0]

MobilityHelper mobility;

// Set positions

mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");

mobility.Install(nodes);

Page 122: Simulation and Ns-3 - Universitetet i Oslo · Simulation and Ns-3 Stein Kristiansen ... - Jerry Banks on “Simulation” System: “Entities that interact over time to accomplish

The logging facilityThe logging facility

Ns-3 has an extensive logging facilitySeven levels: error, warn, debug, info,

function, logic, all

Can activate component from script or from shell

LogComponentEnable (”MANET", LOG_LEVEL_INFO); $ export NS_LOG=”MANET=level_info”

NS_LOG_COMPONENT_DEFINE ("MANET");

NS_LOG_INFO("Area width: " << (rows - 1) * nodeSpacing);NS_LOG_INFO("Area height: " << (cols - 1) * nodeSpacing);