Download Simulating Queueing Networks with OMNeT++
Transcript
4.2 The .ned Files Each entity in a simulation needs to communicate via messages with itself and other entities. Messages can be used for various purposes. One is to represent jobs that need service at queues. Another is to convey information of the entity’s state to itself in the future, or to other entities. Specifically, the fifo example contains three entities: a source module, a fifo module and a sink module. The source module generates messages that represent jobs. These job-messages are sent to the fifo module. This in turn delays the messages according to the present queue, then services them, and finally sends the messages to the sink module. The sink module processes these messages to extract some final statistics. The sink is where the messages leave the queueing network. The sink module releases as well the memory allocated to the job messages. Clearly, all these modules need in- and output gates to receive and send messages. The .ned file specifies these gates. In our example, the fifo module has an input and an output gate. Furthermore these modules may need parameters such as service rate, queue size, etc. These parameters need be declared in the .ned files too. The definition of the parameters, i.e., giving them a value, takes place when the simulation starts. The next step is to glue all the modules together to form a network. This should be done by means of another .ned file that defines a compound module. This new module uses the simple modules and connects them into networks. Besides this, it passes parameter values on to them during the simulation. Finally it gives some directives on where on the canvas the simple modules should appear. To state this in terms of the fifo queue, FifoNet, defined in fifonet.ned, connects the output of the source to the input of the fifo queue, and the output gate of the queue to the sink. Consult fifonet.ned for all details. Take especially notice of the syntax, and be aware of when to use a comma ‘,’, and a semicolon ‘;’. I made some time consuming errors by not using them in the appropriate way. Note that this hierarchy of modules—simple modules forming compound modules, forming in turn other compound modules–provides a very efficient way to build large, complex queueing networks. Start by building the parts, and then connect these parts to larger compound modules up to entire networks. 4.3 The .cc and .h Files Now we have defined all entities that take part in the process cycle of job-messages, and specified the routing between these entities in the compound modules, we should tell how each entity should process job-messages. In concrete terms, the generator should generate jobs with certain interarrival times distributed according to some specified probability distribution. These jobs are represented by a message, so that in fact the generator generates messages. Then it sends these messages out of its output gate. If you will have a look at gen.cc you will see that it will produce in total fifonet.gen.num messages messages, each separated some time ia time apart. These two parameters are defined in the file omnetpp.ini. fifo.cc contains the heart of the simulation. Once you understand this code, which may be a bit hard at first, you have mastered the most important aspects of OMNeT++. Once the jobs arrive at the fifo queue they will be queued or not, depending on whether the server is idle or not. These arriving jobs are handled in the function Fifo::handleMessage. Lets see what it does. Suppose the server is busy. Then the event stack of the simulator should contain an event that indicates when the job’s service is supposed to be finished. If you think a bit about how to implement such events, taking into account that all events are related to messages, you will understand that the server should send itself an endService message at the moment a job’s service starts, to indicate when this job’s service should stop. This endService message will be put on the event stack by the event scheduler (not to be confused with the queueing scheduler!). At some point in time, the event scheduler will remove this message from the stack, and will give it to the fifo module. Once this module receives the endService message, it knows that the job’s service has ended, and that it should send it to the sink. When the queue is empty after the departure, the server should just wait. On the other hand, if there are jobs in queue, it should take the job in front of the queue, and start another service period. Now have a look at fifo.cc and think deeply about it until you understand what is exactly going on. Remember well that a simulation entity has no other means to communicate with itself in the future than via self-messages, and that these messages have to be put on the internal event stack. fifo.cc contains four more functions. The functionality of Fifo::initialize should be clear from its implementation. The function Fifo::finish processes part of the simulation results when the simulation has finished. The other two functions Fifo::serviceRequirement and endService enable you to specify what to do when a job starts service—here only a random service duration is generated—and when it 7