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

Base class for a time-triggered buffer class. More...

#include <TTBuffer.h>

Inheritance diagram for TTEthernetModel::TTBuffer:
TTEthernetModel::CTBuffer TTEthernetModel::Buffer TTEthernetModel::TTDoubleBuffer TTEthernetModel::TTQueueBuffer

Public Member Functions

 TTBuffer ()
 Constructor. More...
 
 ~TTBuffer ()
 Destructor. 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 SchedulerActionTimeEvent. 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

SchedulerActionTimeEventactionTimeEvent
 Event indicating the actionTime. 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 time-triggered buffer class.

The Frame is stored and released time-triggered using a previously registered SchedulerActionTimeEvent. The Buffer interacts with the TTEScheduler.

Use the implementations TTDoubleBuffer, TTQueueBuffer.

See Also
TTDoubleBuffer, TTQueueBuffer, CTBuffer

Definition at line 37 of file TTBuffer.h.

Constructor & Destructor Documentation

TTBuffer::TTBuffer ( )

Constructor.

Definition at line 25 of file TTBuffer.cc.

26 {
27  actionTimeEvent = new SchedulerActionTimeEvent("TTBuffer Scheduler Event", ACTION_TIME_EVENT);
28 }
TTBuffer::~TTBuffer ( )

Destructor.

Definition at line 30 of file TTBuffer.cc.

31 {
32  cancelEvent(actionTimeEvent);
33  delete actionTimeEvent;
34 }

Member Function Documentation

void TTBuffer::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). When a SchedulerActionTimeEvent message arrives the previously stored message is released and the callbacks are executed. When there is no message to send a TTBufferEmpty message is transmitted. This allowes the receiving application to use the bandwidth for other messages.

Parameters
msgincoming EtherFrame for the Buffer or SchedulerActionTimeEvent message.

Definition at line 62 of file TTBuffer.cc.

63 {
64  bool arrivedOnSchedulerIn = msg->arrivedOn("schedulerIn");
65 
67 
68  if (arrivedOnSchedulerIn && msg->getKind() == ACTION_TIME_EVENT && destinationGates.size() > 0)
69  {
70  cMessage *outgoingMessage = getFrame();
71  //Send Message
72  for (std::list<cGate*>::iterator destGate = destinationGates.begin(); destGate != destinationGates.end(); ++destGate)
73  {
74  if (outgoingMessage)
75  {
76  sendDirect(outgoingMessage->dup(), *destGate);
77  }
78  else
79  {
80  sendDirect(new TTBufferEmpty("TT Buffer Empty"), *destGate);
81  }
82  }
83  if(gate("out")->isConnected()){
84  if (outgoingMessage){
85  send(outgoingMessage->dup(),"out");
86  }
87  else{
88  send(new TTBufferEmpty("TT Buffer Empty"),"out");
89  }
90  }
91  if (outgoingMessage)
92  {
94  delete outgoingMessage;
95 
96  // Now execute transmit callbacks if there are some
97  for(std::map<TTEApplicationBase*,Callback*>::const_iterator iter = transmitCallbacks.begin();
98  iter != transmitCallbacks.end(); ++iter){
99  iter->first->executeCallback(iter->second);
100  }
101  }
102  //Reregister scheduler
103  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
104  tteScheduler->registerEvent(static_cast<SchedulerActionTimeEvent *>(msg), true);
105  }
106 }
void TTBuffer::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 108 of file TTBuffer.cc.

108  {
110 
111  if(actionTimeEvent)
112  actionTimeEvent->setAction_time(par("sendWindowStart").doubleValue());
113 }
void TTBuffer::initialize ( int  stage)
protectedvirtual

Initializes the SchedulerActionTimeEvent.

Parameters
stagethe stages. Module registers events when stage==1

Reimplemented from TTEthernetModel::Buffer.

Definition at line 41 of file TTBuffer.cc.

42 {
43  CTBuffer::initialize(stage);
44  if(stage==1)
45  {
46  ev << "Initialize TTBuffer" << endl;
47 
48  //Register Event
49  TTEScheduler *tteScheduler = (TTEScheduler*) getParentModule()->getSubmodule("tteScheduler");
50  //Dirty FIX
51  //TODO find out what is wrong here!
52  if(actionTimeEvent->isScheduled())
53  cancelEvent(actionTimeEvent);
54  actionTimeEvent->setDestinationGate(gate("schedulerIn"));
55  tteScheduler->registerEvent(actionTimeEvent);
56 
57  setIsEmpty(true);
58  return;
59  }
60 }
int TTBuffer::numInitStages ( ) const
protectedvirtual

Returns the numer of initializaiton stages this module needs.

Returns
returns TTEScheduler::numInitStages()+1 or Buffer::numInitStages() (depending on which is higher)

Reimplemented from TTEthernetModel::Buffer.

Definition at line 36 of file TTBuffer.cc.

37 {
38  return 2;
39 }

Member Data Documentation

SchedulerActionTimeEvent* TTEthernetModel::TTBuffer::actionTimeEvent
private

Event indicating the actionTime.

Definition at line 44 of file TTBuffer.h.

Referenced by handleParameterChange(), initialize(), TTBuffer(), and ~TTBuffer().


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