Communication Networks

Stochastic Simulation of Communication Networks SS2011 Part 4 Prof. Dr. C. Görg www.comnets.uni-bremen.de VSIM 2 - 1 Table of Contents 1 2 3 4 5 ...
Author: Suzanna May
1 downloads 2 Views 131KB Size
Stochastic Simulation of Communication Networks SS2011 Part 4

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 1

Table of Contents 1 2 3 4 5 6 7 8

Prof. Dr. C. Görg

General Introduction Random Number Generation S i i lE Statistical Evaluation l i ComNets Class Library (CNCL) OPNET Network Simulator (ns) SDL Simulation Speed-Up Methods

www.comnets.uni-bremen.de

VSIM 2 - 2

CNCL: Communication Networks Class Library • Class Library in C++ with the following characteristics: – tree like class structure – run time type information and test – weak typing and general container classes – general class library with basic data types – portability p y

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 3

Main Components for Simulation • Random Numbers: g efficient & flexible generation • Statistical Evaluation • (Pure) (P ) Event E t oriented i t d scheduling h d li • Spec Special a co construct st uct to implement pe e t SDL structures

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 4

Class Diagram

Association Inheritance Using Has by value by reference Instantiation

CNCL Class Diagram

CNCL

runtime type information

CNClass

CNObject j A

CNParam object bj t A management

CNRNG

... Prof. Dr. C. Görg

...

...

CNString

...

...

... www.comnets.uni-bremen.de

VSIM 2 - 5

Base Classes • CNCL highest class of the hierarchy static member functions and error handling • CNObject main root of the hierarchy, hierarchy all classes are derived directly/indirectly from CNObject • CNClass C C ass every class in the CNCL hierarchy is described by an object of this type (run time type information) • CNParam generic parameter object (not used) Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 6

Random Number Generators • See also Part 2 • Combination of previous tools and libg++ • 2 class hierarchies: – 6 Base generators (CNRNG) – 20 Distributions (CNRandom) ( )

• All combinations possible

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 7

Class Diagram

Association Inheritance Using

CNRndInt

1

CNRNG

Has by value by reference Instantiation

1 n 1

1

1

A

CNRandom

CNRandomMix

2

A

CNACG

CNFiboG

CNB t CNBeta

CNH CNHyperExp E

CNBinomial

CNHyperGeom

CNCL Random Number Generators Prof. Dr. C. Görg

CNSSMP2

CNWeibull CNW ib ll

CNLCG

CNDiracTab

CNMLCG

CNTab

CNDeterm CNFileG

1

CNMDeterm CNInterTab

CNTausG CNNormal CNDiscUniform

CNNegExp

CNLogNormal CNErlang

CNPoisson

CNRayleigh CNRice

CNGeometric

CNUniform

www.comnets.uni-bremen.de

VSIM 2 - 8

Statistical Evaluation • S See also l P Partt 3 • Evaluation of a sequence q of random values: – CNMoments (first 3 moments, min, max, ...) – CNBatchMeans (mean, variance and cdf with confidence intervals, equidistant intervals x-axis) – CNLRE (cdf with relative error and local correlation coefficient, equidistant intervals y-axis) Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 9

CNCL Event Handling • A simulation consists of Event Handlers • Event Handlers communicate by sending Events • Events E t are managed db by a Scheduler, S h d l that th t receives the Events and sends them to the appropriate Event Handler at the specified time

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 10

Event Handler (CNEventHandler) • A An Event E t Handler H dl is i an object bj t receiving, processing and sending Events to other Event Handlers • Finite state machine • The Th only l communication i ti mechanism h i b between t Event Handlers is the generation of Events, which are sent via the Event Scheduler • The functionality of resuming an Event Handler after a certain time has to be implemented by using timer events (process oriented: e.g. sleep) Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 11

EVENT Handler Attributes • state • current (model) time • calling scheduler Event Handler is a base class from which the user has to derive the specific Event Handlers needed for the sim simulation lation model

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 12

Class Hierarchy Event Handler

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 13

Sending Events CNEventID CNEventHandler::send ( CNEvent * ev ) [protected] Send an event to the scheduler. M b Members lleft ft uninitialized i iti li d iin th the eventt are sett tto d default f lt values (scheduled time = current time, addressed event handler = this event handler, sending event handler = thi eventt h this handler) dl ) Returns the event's ID CNEventID CNEventHandler::send_delay ( CNEvent * ev, double dt) [protected] S d an eventt to Send t the th scheduler, h d l same as send_event(), d t() but scheduled time is set to the current time plus a time delay dt Returns the event's ID Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 14

CNEventID CNEventHandler::send_event CNEventHandler::send event ( CNEvent * ev ) [protected] Send an event to the scheduler. M b Members lleft ft uninitialized i iti li d iin th the eventt are sett tto d default f lt values (scheduled time = current time, addressed event handler = this event handler, sending event handler = thi eventt h this handler) dl ) Returns the event's ID CNEventID CNEventHandler::send_now ( CNEvent * ev ) [protected] S d an eventt to Send t the th scheduler. h d l Same as send_event(), but scheduled time is set to the current time Returns the event's ID Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 15

CNCL Events (CNEvent) • C Central t l communication i ti object bj t with ith th the ffollowing ll i attributes: – – – – – – – –

unique ID priority type defined by the user ( d l) ti (model) time, when h th the eventt was sentt (model) time, for which the event has been scheduled sending g event handler receiving event handler pointer to any CNCL object

• E Events t always l addressed dd d ffrom one Event E t Handler H dl to t another Event Handler (optionally with priorities)

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 16

Scheduler (CNEventScheduler) • Realizes the central control for simulations in CNCL • Maintains arriving Events in a list and calls the addressed Event Handler at the appropriate time • Events are sorted into the list according to their time and priority

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 17

Main task of the scheduler • take first Event from the list • update model time • call specified Event Handler

• Events can also be deleted by the scheduler, e.g. for the realization of timers

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 18

CNCL and SDL Mapping SDL programs to CNCL: • Signals g ⇒ Events • SDL states ⇒ CNCL states • SDL process ⇒ CNCL Event Handler (special mapping)

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 19

Example: G/G/1 • 2 Event Handlers: – Generator: g generates jjobs with a random interarrival time and sends these to the Server onlyy one state – Server: manages arriving jobs in a queue and serves them with a random service time 2 states: Waiting (Server is free) Serving (Server is occupied, serving a job)

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 20

G/G/1 Events • TIMER_G: timer for arrivals in the Generator • TIMER_S: timer for the service time in the Server • JOB: sending a job from the Generator to the Server

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 21

G/G/1 Model M d l scheduler JOB

JOB

TIMER_G

TIMER_S

server

generator queue

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 22

Class Diagram

Association Inheritance Using Has by value by reference Instantiation

CNEvent Handler

CNEvent

A

Server F F

CNEvent Scheduler CNDLObject

F

... Generator

CNEventList user implemented event handlers for the simulation model

CNDLList

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 23

Legend:

Event Handler Generator Generate Event TIMER_G; JOB JOB;

TIMER_G

JOBJServer

Choose next time of arrival

Status

Transmit event

Waiting for event

Common actions

TIMER_G J Generator Inquiry Generate Figure: G/G/1-Simulation: CNCL Generator Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 24

Event Handler Server Event JOB, TIMER_S;

Waiting

JOB

Choose processing i titime

TIMER_S TIMER S JServer

Serving

JOB

TIMER_S

Queue.put(Job);

Serving

Queue.empty

Job:=queue.get(); Choose Processing time

Waiting

TIMER_S JServer Serving g

Serving Prof. Dr. C. Görg

Figure: G/G/1-Simulation: CNCL Server www.comnets.uni-bremen.de

VSIM 2 - 25

CNCL Program: #include #include #include #include #include #include #include #include #include #include #include "Job.h“ // CNEvent types for M/M/1 simulation enum { EV_JOB, EV_TIMER_G, EV_TIMER_S };

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 26

class Server : public CNEventHandler { private: Job *job; j ; // Served jjob CNQueueFIFO queue; // CNQueue CNRandom &rnd_b; // Distribution of service time b CNMoments t_w; // Evaluation tau_w with moments CNLREF t_w_lre; // Evaluation tau_w with LRE algorithm enum { ST_WAITING, ST_SERVING }; ready; // flag for LRE evaluation ofstream lre_outfile; public: virtual void event_handler(const CNEvent *ev);

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 27

void id print_results(); i t lt () void eval_job(Job *job); Server(CNRandom &rnd, char* fn) : rnd_b(rnd), rnd b(rnd) job(NIL) job(NIL), tt_w( w("tau tau_w w")), t_w_lre(0.01,0.99,0.01,100,CNLRE::LIN,0,"LREevaluation"), ) lre_outfile(fn) { state(ST_WAITING); ready = FALSE; } };

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 28

class Generator : public CNEventHandler { private: CNRandom &rnd_a;; // Distribution of arrival time a Server *server; // Connected queue/server CNMoments t_a; double value; public: virtual void event_handler(const CNEvent *ev); void print_results(); Generator(CNRandom G (CNR d & &rnd, d S Server **serv)) : rnd_a(rnd), d ( d) server(serv), t_a("tau_a") {} }; Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 29

void Generator::event Generator::event_handler(const handler(const CNEvent *ev) ev) { // Incoming g event -> g generate new Job send_now(new CNEvent(EV_JOB, server, new Job)); // CNRandom delay value = rnd_a(); send delay(new CNEvent(EV_TIMER_G), send_delay(new CNEvent(EV TIMER G) value); t_a.put(value); } void Generator::print_results() { cout type()) { case EV_JOB: // Incoming job, put into queue { Job *job; j b = (J job (Job b *) *)ev->object(); > bj t() job->in = now(); queue.put(job); } break; case EV_TIMER_S: // Timer event, event service time run down job->out = now(); // Evaluate job eval job(job); eval_job(job); delete job; Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 31

job = NIL; if ((readyy == TRUE)) scheduler()->stop(); () p() // Get new job from queue if(!queue.empty()) { job = (Job *)queue.get(); job->start = now(); // CNRandom service time send_delay(new CNEvent(EV_TIMER_S), rnd_b()); state(ST_SERVING); } else l { state(ST_WAITING); } break; default: error("mm1: error( mm1: ", "illegal illegal event in state ST ST_SERVING SERVING"); ); break; } break; Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 32

case ST_WAITING: switch(ev->type()) ( yp ()) { case EV_JOB: // Incoming job job = (Job *)ev->object(); job->in = now(); job->start = now(); // CNRandom service time send_delay(new CNEvent(EV_TIMER_S), rnd_b()); state(ST_SERVING); t t (ST SERVING) break; default: error("mm1: error( mm1: ", "illegal illegal event in state ST ST_WAITING WAITING"); ); break; } break; default: error("mm1: ", "illegal state"); break; } }

Prof. Dr. C. Görg

www.comnets.uni-bremen.de

VSIM 2 - 33

void Server::eval_job(Job *job) { t_w.put(job->start - job->in); t w lre put(job->start - job->in); t_w_lre.put(job->start if (t_w_lre.status() == CNStatistics::END) ready = TRUE; }

void Server::print_results() S () { cout