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

Base class for all buffer classes. More...

#include <Buffer.h>

Inheritance diagram for TTEthernetModel::Buffer:
TTEthernetModel::BGBuffer TTEthernetModel::CTBuffer TTEthernetModel::DoubleBuffer TTEthernetModel::QueueBuffer TTEthernetModel::BGQueueBuffer TTEthernetModel::RCBuffer TTEthernetModel::TTBuffer TTEthernetModel::RCDoubleBuffer TTEthernetModel::TTDoubleBuffer TTEthernetModel::BGQueueBuffer TTEthernetModel::RCQueueBuffer TTEthernetModel::TTQueueBuffer

Public Member Functions

 ~Buffer ()
 Destructor. More...
 
virtual void handleParameterChange (const char *parname)
 Indicates a parameter has changed. 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 module. More...
 
virtual int numInitStages () const
 Returns the numer of initializaiton stages this module needs. More...
 
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...
 

Protected Attributes

std::list< cGate * > destinationGates
 Stores the Gates to that the messages are delivered. More...
 
std::map< TTEApplicationBase
*, Callback * > 
receiveCallbacks
 Stores the callbacks that are executed when a frame is added to the buffer. More...
 
std::map< TTEApplicationBase
*, Callback * > 
transmitCallbacks
 Stores the callbacks that are executed when a frame is removed from the buffer. More...
 

Static Protected Attributes

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...
 

Private Member Functions

void initializeStatistics ()
 caches ct_mask parameter More...
 

Detailed Description

Base class for all buffer classes.

Buffer, although packed with buffer-related functionality, does not do anything useful by itself: one has to subclass from it and redefine one or more virtual member functions to make it do useful work. These functions are:

  • void enqueue(EtherFrame <em>newFrame)
  • EtherFrame dequeue()

enqueue(EtherFrame *newFrame) is called to queue a message in the buffer. It must be implemented according to the correct buffer behaviour.

dequeue() is called to get a frame from the buffer.

Definition at line 47 of file Buffer.h.

Constructor & Destructor Documentation

Buffer::~Buffer ( )

Destructor.

Definition at line 29 of file Buffer.cc.

29  {
30  destinationGates.clear();
31  receiveCallbacks.clear();
32  transmitCallbacks.clear();
33 }

Member Function Documentation

void Buffer::addReceiveCallback ( Callback cb,
TTEApplicationBase application 
)

Adds a receive callback for an application to the buffer.

The callback is registered for a specific application. Each application is allowed to only register one receive callback per buffer. Further calls overwrite the registered callback.

Parameters
cbthe receive callback to be added.
thecorresponding application that registers the callback

Definition at line 75 of file Buffer.cc.

Referenced by TTEthernetModel::TTEAPIApplicationBase::tte_set_buf_var().

76 {
77  receiveCallbacks[application]=cb;
78 }
void Buffer::addTransmitCallback ( Callback cb,
TTEApplicationBase application 
)

Adds a transmit callback for an application to the buffer.

The callback is registered for a specific application. Each application is allowed to only register one transmit callback per buffer. Further calls overwrite the registered callback.

Parameters
cbthe transmit callback to be added.
thecorresponding application that registers the callback

Definition at line 87 of file Buffer.cc.

Referenced by TTEthernetModel::TTEAPIApplicationBase::tte_set_buf_var().

88 {
89  transmitCallbacks[application]=cb;
90 }
EtherFrame * Buffer::dequeue ( )
protectedvirtual

Is called to get an EtherFrame from the buffer.

This method must be implemented according to the buffer strategy.

Returns
a pointer to the next EtherFrame from the buffer. Returns null if there is no EtherFrame in the buffer

Reimplemented in TTEthernetModel::QueueBuffer, and TTEthernetModel::DoubleBuffer.

Definition at line 154 of file Buffer.cc.

Referenced by getFrame(), and TTEthernetModel::BGBuffer::handleMessage().

155 {
156  ev << "Buffer::dequeue not implemented" << endl;
157  throw;
158 }
void Buffer::enqueue ( EtherFrame *  newFrame)
protectedvirtual

Is called to store an EtherFrame in the buffer.

This method must be implemented according to the buffer strategy.

Parameters
newFramea pointer to the new EtherFrame to be saved in the buffer

Reimplemented in TTEthernetModel::QueueBuffer, and TTEthernetModel::DoubleBuffer.

Definition at line 148 of file Buffer.cc.

Referenced by TTEthernetModel::CTBuffer::putFrame(), and putFrame().

149 {
150  ev << "Buffer::enqueue not implemented" << endl;
151  throw;
152 }
EtherFrame * Buffer::getFrame ( )

Wrapper function arround dequeue().

Returns
a pointer to the next EtherFrame from the buffer. Returns null if there is no EtherFrame in the buffer
See Also
dequeue();

Definition at line 99 of file Buffer.cc.

Referenced by TTEthernetModel::TTBuffer::handleMessage(), TTEthernetModel::RCBuffer::handleMessage(), and TTEthernetModel::TTEAPIApplicationBase::tte_open_input_buf().

99  {
100  return dequeue();
101 }
Callback * Buffer::getReceiveCallback ( TTEApplicationBase application)

Returns the currently registered receive callback for an application.

Parameters
thecorresponding application that registered callbacks
Returns
The callback that is currently registered. Null if there is no receive callback registered

Definition at line 80 of file Buffer.cc.

Referenced by TTEthernetModel::TTEAPIApplicationBase::tte_get_buf_var(), and TTEthernetModel::TTEAPIApplicationBase::tte_set_buf_var().

81 {
82  if(receiveCallbacks.find(application) == receiveCallbacks.end())
83  return NULL;
84  return receiveCallbacks[application];
85 }
Callback * Buffer::getTransmitCallback ( TTEApplicationBase application)

Returns the currently registered transmit callback for an application.

Parameters
thecorresponding application that registered callbacks
Returns
The callback that is currently registered. Null if there is no transmit callback registered

Definition at line 92 of file Buffer.cc.

Referenced by TTEthernetModel::TTEAPIApplicationBase::tte_get_buf_var(), and TTEthernetModel::TTEAPIApplicationBase::tte_set_buf_var().

93 {
94  if(transmitCallbacks.find(application) == transmitCallbacks.end())
95  return NULL;
96  return transmitCallbacks[application];
97 }
void Buffer::handleMessage ( cMessage *  msg)
protected

Is called when a new Frame is received in the buffer.

When a frame is received on the in-Gate it is processed. If the destination address is unspecified it is set according to the ct marker of the buffer. Afterwards it is enqueued using the buffer specific enqueue(EtherFrame *newFrame) method. In the end all registered receive callbacks are executed.

Parameters
msgThe incoming message

Definition at line 107 of file Buffer.cc.

Referenced by TTEthernetModel::BGBuffer::handleMessage(), and TTEthernetModel::CTBuffer::handleMessage().

108 {
109  if (msg->arrivedOn("in"))
110  {
111  EtherFrame *frame = check_and_cast<EtherFrame *>(msg);
112  emit(latencySignal, simTime()-msg->getCreationTime());
113  putFrame((EtherFrame*) frame);
114  // Now execute callbacks if there are some
115  for(std::map<TTEApplicationBase*,Callback*>::const_iterator iter = receiveCallbacks.begin();
116  iter != receiveCallbacks.end(); ++iter){
117  iter->first->executeCallback(iter->second);
118  }
119  }
120 }
void Buffer::handleParameterChange ( const char *  parname)
virtual

Indicates a parameter has changed.

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

Reimplemented in TTEthernetModel::RCBuffer, TTEthernetModel::TTBuffer, and TTEthernetModel::CTBuffer.

Definition at line 122 of file Buffer.cc.

Referenced by TTEthernetModel::CTBuffer::handleParameterChange().

122  {
123  destinationGates.clear();
124  if(ev.isGUI()){
125  //TODO check why this does not work
126  //getDisplayString().setTagArg("i2", 0, "");
127  //getDisplayString().setTagArg("tt", 0, "");
128  }
129  std::string destinationGatesString = par("destination_gates").stdstringValue();
130  std::vector<std::string> destinationGatePaths;
131  split(destinationGatesString,',',destinationGatePaths);
132  for(std::vector<std::string>::iterator destinationGatePath = destinationGatePaths.begin();
133  destinationGatePath!=destinationGatePaths.end();destinationGatePath++){
134  cGate* gate = gateByFullPath((*destinationGatePath));
135  if(gate){
136  destinationGates.push_back(gate);
137  }
138  else{
139  if(ev.isGUI()){
140  ev<<"Configuration problem: Gate "<<(*destinationGatePath)<<" could not be resolved!"<<endl;
141  getDisplayString().setTagArg("i2", 0, "status/excl3");
142  getDisplayString().setTagArg("tt", 0, "WARNING: Configuration Problem outgoing gate!");
143  }
144  }
145  }
146 }
void Buffer::initialize ( int  stage)
protectedvirtual

Initializes the module.

Parameters
stagethe stages. Module initializes when stage==0

Reimplemented in TTEthernetModel::RCBuffer, and TTEthernetModel::TTBuffer.

Definition at line 40 of file Buffer.cc.

Referenced by TTEthernetModel::TTBuffer::initialize(), and TTEthernetModel::RCBuffer::initialize().

41 {
42  if(stage==0){
43  ev << "Initialize Buffer" << endl;
45  }
46 }
void Buffer::initializeStatistics ( )
private

caches ct_mask parameter

caches ct_marker parameter caches ct_id parameter Initializes the statistics for the module

Definition at line 48 of file Buffer.cc.

Referenced by initialize().

49 {
50  txPkSignal = registerSignal("txPk");
51  latencySignal = registerSignal("latency");
52 }
int Buffer::numInitStages ( ) const
protectedvirtual

Returns the numer of initializaiton stages this module needs.

Returns
always returns 1

Reimplemented in TTEthernetModel::RCBuffer, and TTEthernetModel::TTBuffer.

Definition at line 35 of file Buffer.cc.

Referenced by TTEthernetModel::RCBuffer::numInitStages().

36 {
37  return 1;
38 }
void Buffer::putFrame ( EtherFrame *  frame)

Wrapper function arround enqueue().

Parameters
framethe EtherFrame to put in the buffer.
See Also
enqueue();

Definition at line 103 of file Buffer.cc.

Referenced by handleMessage().

103  {
104  enqueue(frame);
105 }
void Buffer::recordPacketSent ( )
protected

Emits a statistics signal that a frame was sent from the buffer.

Definition at line 54 of file Buffer.cc.

Referenced by TTEthernetModel::BGBuffer::handleMessage(), TTEthernetModel::TTBuffer::handleMessage(), and TTEthernetModel::RCBuffer::handleMessage().

55 {
56  emit(txPkSignal, 1L);
57 }
void Buffer::setIsEmpty ( bool  empty)
protected

Sets the status of the Buffer to empty or non-empty.

This method changes the GUI according to the buffer status.

Definition at line 59 of file Buffer.cc.

Referenced by TTEthernetModel::QueueBuffer::dequeue(), TTEthernetModel::QueueBuffer::enqueue(), TTEthernetModel::BGBuffer::initialize(), TTEthernetModel::TTBuffer::initialize(), and TTEthernetModel::RCBuffer::initialize().

60 {
61  if(ev.isGUI()){
62  if (empty)
63  {
64  getDisplayString().setTagArg("i", 1, "black");
65  getDisplayString().setTagArg("tt", 0, "Buffer is empty");
66  }
67  else
68  {
69  getDisplayString().setTagArg("i", 1, "");
70  getDisplayString().setTagArg("tt", 0, "");
71  }
72  }
73 }

Member Data Documentation

std::list<cGate*> TTEthernetModel::Buffer::destinationGates
protected
simsignal_t Buffer::latencySignal = SIMSIGNAL_NULL
staticprotected

Signal that contains the latency until the frame enters the buffer.

Definition at line 224 of file Buffer.h.

Referenced by handleMessage(), and initializeStatistics().

std::map<TTEApplicationBase*, Callback*> TTEthernetModel::Buffer::receiveCallbacks
protected

Stores the callbacks that are executed when a frame is added to the buffer.

Definition at line 70 of file Buffer.h.

Referenced by addReceiveCallback(), getReceiveCallback(), handleMessage(), and ~Buffer().

std::map<TTEApplicationBase*, Callback*> TTEthernetModel::Buffer::transmitCallbacks
protected

Stores the callbacks that are executed when a frame is removed from the buffer.

Definition at line 74 of file Buffer.h.

Referenced by addTransmitCallback(), getTransmitCallback(), TTEthernetModel::BGBuffer::handleMessage(), TTEthernetModel::TTBuffer::handleMessage(), TTEthernetModel::RCBuffer::resetBag(), and ~Buffer().

simsignal_t Buffer::txPkSignal = SIMSIGNAL_NULL
staticprotected

Signal that is emitted every time a frame was sent.

Definition at line 219 of file Buffer.h.

Referenced by initializeStatistics(), and recordPacketSent().


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