Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / parsim / cnullmessageprot.h @ 81ad8b66

History | View | Annotate | Download (3.83 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  CNULLMESSAGEPROT.H - part of
3
//
4
//                  OMNeT++/OMNEST
5
//           Discrete System Simulation in C++
6
//
7
//  Author: Andras Varga, 2003
8
//          Dept. of Electrical and Computer Systems Engineering,
9
//          Monash University, Melbourne, Australia
10
//
11
//=========================================================================
12
13
/*--------------------------------------------------------------*
14
  Copyright (C) 2003-2008 Andras Varga
15
  Copyright (C) 2006-2008 OpenSim Ltd.
16

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20
21
#ifndef __CNULLMESSAGEPROT_H__
22
#define __CNULLMESSAGEPROT_H__
23
24
#include "cparsimprotocolbase.h"
25
#include "cmessage.h"  // MK_PARSIM_BEGIN
26
27
NAMESPACE_BEGIN
28
29
// forward declarations
30
class cCommBuffer;
31
class cNMPLookahead;
32
33
34
/**
35
 * Implements the "null message algorithm".
36
 * Lookahead calculation is encapsulated into a separate object,
37
 * subclassed from cNMPLookahead.
38
 *
39
 * @ingroup Parsim
40
 */
41
class SIM_API cNullMessageProtocol : public cParsimProtocolBase
42
{
43
  protected:
44
    struct PartitionInfo
45
    {
46
        cMessage *eitEvent;  // EIT received from partition
47
        cMessage *eotEvent;  // events which marks that a null message should be sent out
48
        simtime_t lastEotSent; // last EOT value that was sent
49
    };
50
51
    // partition information
52
    int numSeg;              // number of partitions
53
    PartitionInfo *segInfo;  // partition info array, size numSeg
54
55
    // controls null message resend frequency, 0<=laziness<=1
56
    double laziness;
57
58
    // internally used message kinds
59
    enum
60
    {
61
        MK_PARSIM_EIT =       MK_PARSIM_BEGIN - 1,
62
        MK_PARSIM_RESENDEOT = MK_PARSIM_BEGIN - 2
63
    };
64
65
    bool debug;
66
67
    cNMPLookahead *lookaheadcalc;
68
69
  protected:
70
    // process buffers coming from other partitions
71
    virtual void processReceivedBuffer(cCommBuffer *buffer, int tag, int sourceProcId);
72
73
    // processes a received EIT: reschedule partition's EIT message
74
    virtual void processReceivedEIT(int sourceProcId, simtime_t eit);
75
76
    // resend null message to this partition
77
    virtual void sendNullMessage(int procId, simtime_t now);
78
79
    // reschedule event in FES, to the given time
80
    virtual void rescheduleEvent(cMessage *msg, simtime_t t);
81
82
  public:
83
    /**
84
     * Constructor.
85
     */
86
    cNullMessageProtocol();
87
88
    /**
89
     * Destructor.
90
     */
91
    virtual ~cNullMessageProtocol();
92
93
    /**
94
     * Redefined beacause we have to pass the same data to the lookahead calculator object
95
     * (cNMPLookahead) too.
96
     */
97
    virtual void setContext(cSimulation *sim, cParsimPartition *seg, cParsimCommunications *co);
98
99
    /**
100
     * Sets null message resend laziness. Value is between 0 and 1 --
101
     * 0.0 means eager resend, 1.0 means lazy resend.
102
     *
103
     * (Probably should never be 1.0, otherwise floating point rounding errors
104
     * may cause obscure EIT-deadlocks on receiving side.)
105
     */
106
    void setLaziness(double d)  {laziness = d;}
107
108
    /**
109
     * Get laziness of null message resend.
110
     */
111
    double getLaziness()  {return laziness;}
112
113
    /**
114
     * Called at the beginning of a simulation run.
115
     */
116
    virtual void startRun();
117
118
    /**
119
     * Called at the end of a simulation run.
120
     */
121
    virtual void endRun();
122
123
    /**
124
     * Scheduler function. The null message algorithm is embedded here.
125
     */
126
    virtual cMessage *getNextEvent();
127
128
    /**
129
     * In addition to its normal task (sending out the cMessage to the
130
     * given partition), it also does lookahead calculation and optional
131
     * piggybacking of null message on the cMessage.
132
     */
133
    virtual void processOutgoingMessage(cMessage *msg, int procId, int moduleId, int gateId, void *data);
134
};
135
136
NAMESPACE_END
137
138
139
#endif