TTEthernet Model for INET Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
TTEthernetModel::RCBuffer Class Reference

Base class for a rate-constrained buffer class. More...

#include <RCBuffer.h>

Inheritance diagram for TTEthernetModel::RCBuffer:
TTEthernetModel::CTBuffer TTEthernetModel::Buffer TTEthernetModel::RCDoubleBuffer TTEthernetModel::RCQueueBuffer

Public Member Functions

 RCBuffer ()
 Constructor. More...
 
virtual ~RCBuffer ()
 Destructor. More...
 
virtual void resetBag ()
 resets the bag for a destination gate. More...
 
- Public Member Functions inherited from TTEthernetModel::CTBuffer
 ~CTBuffer ()
 Destructor. More...
 
void putFrame (EtherFrame *frame)
 Wrapper function arround enqueue(). More...
 
- Public Member Functions inherited from TTEthernetModel::Buffer
 ~Buffer ()
 Destructor. More...
 
EtherFrame * getFrame ()
 Wrapper function arround dequeue(). More...
 
void putFrame (EtherFrame *frame)
 Wrapper function arround enqueue(). More...
 
void addReceiveCallback (Callback *cb, TTEApplicationBase *application)
 Adds a receive callback for an application to the buffer. More...
 
CallbackgetReceiveCallback (TTEApplicationBase *application)
 Returns the currently registered receive callback for an application. More...
 
void addTransmitCallback (Callback *cb, TTEApplicationBase *application)
 Adds a transmit callback for an application to the buffer. More...
 
CallbackgetTransmitCallback (TTEApplicationBase *application)
 Returns the currently registered transmit callback for an application. More...
 

Protected Member Functions

virtual void initialize (int stage)
 Initializes the timerMessage. More...
 
virtual int numInitStages () const
 Returns the numer of initializaiton stages this module needs. More...
 
virtual void handleMessage (cMessage *msg)
 handles the incoming and outgoing messages of the buffer. More...
 
virtual void handleParameterChange (const char *parname)
 Indicates a parameter has changed. More...
 
- Protected Member Functions inherited from TTEthernetModel::CTBuffer
void handleMessage (cMessage *msg)
 Is called when a new Frame is received in the buffer. More...
 
- Protected Member Functions inherited from TTEthernetModel::Buffer
void handleMessage (cMessage *msg)
 Is called when a new Frame is received in the buffer. More...
 
virtual void enqueue (EtherFrame *newFrame)
 Is called to store an EtherFrame in the buffer. More...
 
virtual EtherFrame * dequeue ()
 Is called to get an EtherFrame from the buffer. More...
 
void recordPacketSent ()
 Emits a statistics signal that a frame was sent from the buffer. More...
 
void setIsEmpty (bool empty)
 Sets the status of the Buffer to empty or non-empty. More...
 

Private Attributes

bool bagExpired
 Boolean indicating the bag already expired. More...
 
unsigned int numReset
 Number of reset messages by the destination Gates. More...
 
SchedulerTimerEventtimerMessage
 The timer Message is stored for reusage purpose. More...
 

Additional Inherited Members

- Protected Attributes inherited from TTEthernetModel::CTBuffer
uint32_t ctMask
 caches ct_mask parameter More...
 
uint32_t ctMarker
 caches ct_marker parameter More...
 
uint16_t ctId
 caches ct_id parameter More...
 
- Static Protected Attributes inherited from TTEthernetModel::Buffer
static simsignal_t txPkSignal = SIMSIGNAL_NULL
 Signal that is emitted every time a frame was sent. More...
 
static simsignal_t latencySignal = SIMSIGNAL_NULL
 Signal that contains the latency until the frame enters the buffer. More...
 

Detailed Description

Base class for a rate-constrained buffer class.

The Frame is stored and released immediately when the bag has expired previously. If the bag has not expired yet the frame is stored. The implementation uses a SchedulerTimerEvent that is registered at the TTEScheduler.

Use the implementations RCDoubleBuffer, RCQueueBuffer.

See Also
RCDoubleBuffer, RCQueueBuffer, CTBuffer

Definition at line 38 of file RCBuffer.h.

Constructor & Destructor Documentation

TTEthernetModel::RCBuffer::RCBuffer ( )

Constructor.

Definition at line 25 of file RCBuffer.cc.

26 {
27  bagExpired = true;
28  timerMessage = new SchedulerTimerEvent("RCBuffer Scheduler Event", TIMER_EVENT);
29 }
TTEthernetModel::RCBuffer::~RCBuffer ( )
virtual

Destructor.

Definition at line 31 of file RCBuffer.cc.

32 {
33  cancelEvent(timerMessage);
34  delete timerMessage;
35 }

Member Function Documentation

void TTEthernetModel::RCBuffer::handleMessage ( cMessage *  msg)
protectedvirtual

handles the incoming and outgoing messages of the buffer.

If message arrived on in, it is queued by calling Buffer::handleMessage(cMessage *msg). Afterwards the message is directly send when the bag already expired. When the scheduler message arrives (schedulerIn) a pending message is transferred. If there is no message waiting the bagExpired state is saved.

Parameters
msgincoming EtherFrame for the Buffer or SchedulerTimerEvent message.

Definition at line 56 of file RCBuffer.cc.

57 {
59 
60  if(destinationGates.size() > 0)
61  {
62  if (msg->arrivedOn("in"))
63  {
64  if (bagExpired)
65  {
66  cMessage *outgoingMessage = getFrame();
67  if(outgoingMessage){
68  bagExpired = false;
69  numReset = 0;
70  //Send Message
71  for (std::list<cGate*>::iterator dgate = destinationGates.begin(); dgate != destinationGates.end(); ++dgate)
72  {
73  sendDirect(outgoingMessage->dup(),0,0, *dgate);
74  }
75  if(gate("out")->isConnected()){
76  send(outgoingMessage->dup(),"out");
77  }
79  delete outgoingMessage;
80  }
81  }
82  }
83  else if (msg->arrivedOn("schedulerIn") && msg->getKind() == TIMER_EVENT)
84  {
85  cMessage *outgoingMessage = getFrame();
86  if (outgoingMessage)
87  {
88  bagExpired = false;
89  numReset = 0;
90  //Send Message
91  for (std::list<cGate*>::iterator gate = destinationGates.begin(); gate != destinationGates.end(); ++gate)
92  {
93  sendDirect(outgoingMessage->dup(), *gate);
94  }
96  delete outgoingMessage;
97  }
98  else
99  {
100  bagExpired = true;
101  getDisplayString().setTagArg("i2", 0, "");
102  }
103  }
104  }
105 }
void TTEthernetModel::RCBuffer::handleParameterChange ( const char *  parname)
protectedvirtual

Indicates a parameter has changed.

Parameters
parnameName of the changed parameter or NULL if multiple parameter changed.

Reimplemented from TTEthernetModel::CTBuffer.

Definition at line 107 of file RCBuffer.cc.

107  {
109 
110  timerMessage->setTimer(par("bag").doubleValue());
111 }
void TTEthernetModel::RCBuffer::initialize ( int  stage)
protectedvirtual

Initializes the timerMessage.

Parameters
stagethe stages. Module initializes when stage==0

Reimplemented from TTEthernetModel::Buffer.

Definition at line 45 of file RCBuffer.cc.

46 {
47  CTBuffer::initialize(stage);
48  if(stage==0){
49  timerMessage->setDestinationGate(gate("schedulerIn"));
50 
51  //Update displaystring
52  setIsEmpty(true);
53  }
54 }
int TTEthernetModel::RCBuffer::numInitStages ( ) const
protectedvirtual

Returns the numer of initializaiton stages this module needs.

Returns
always returns 1

Reimplemented from TTEthernetModel::Buffer.

Definition at line 37 of file RCBuffer.cc.

38 {
40  return CTBuffer::numInitStages();
41  else
42  return 1;
43 }
void TTEthernetModel::RCBuffer::resetBag ( )
virtual

resets the bag for a destination gate.

This method must be invoked only once by each destination gate to indicate the message left the interface. The method executes the transmit callbacks and registers a SchedulerTimerEvent that indicates the beginning of a new bag

Definition at line 113 of file RCBuffer.cc.

Referenced by TTEthernetModel::TTEOutput::handleMessage(), and TTEthernetModel::TTEOutput::requestPacket().

114 {
115  Enter_Method("resetBag()");
116  //This is the moment when the message was transmitted execute transmit callbacks if there are some
117  for(std::map<TTEApplicationBase*,Callback*>::const_iterator iter = transmitCallbacks.begin();
118  iter != transmitCallbacks.end(); ++iter){
119  iter->first->executeCallback(iter->second);
120  }
121 
122  //Set icon:
123  getDisplayString().setTagArg("i2", 0, "status/hourglass");
124 
125  numReset++;
126  if (numReset == destinationGates.size())
127  {
128  //Reregister scheduler
129  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
130  tteScheduler->registerEvent(timerMessage);
131  }
132 }

Member Data Documentation

bool TTEthernetModel::RCBuffer::bagExpired
private

Boolean indicating the bag already expired.

Definition at line 44 of file RCBuffer.h.

Referenced by handleMessage(), and RCBuffer().

unsigned int TTEthernetModel::RCBuffer::numReset
private

Number of reset messages by the destination Gates.

The bag is only reseted when all gates invoked resetBag().

Definition at line 51 of file RCBuffer.h.

Referenced by handleMessage(), and resetBag().

SchedulerTimerEvent* TTEthernetModel::RCBuffer::timerMessage
private

The timer Message is stored for reusage purpose.

Definition at line 56 of file RCBuffer.h.

Referenced by handleParameterChange(), initialize(), RCBuffer(), resetBag(), and ~RCBuffer().


The documentation for this class was generated from the following files: