CommunicationLayer Class Reference

The communication layer class which is a superclass of classes implemented layers in the network stack. More...

#include <communication_layer.hpp>

Inheritance diagram for CommunicationLayer:

SimulationEndListener ApplicationLayer LinkLayer PhysicalLayer RfidReaderApp RfidTagApp RfidReaderPhy RfidTagPhy List of all members.

Public Types

typedef boost::shared_ptr<
CommunicationLayer
CommunicationLayerPtr
 Smart pointer that clients should use.
typedef boost::shared_ptr<
SimulationEndListener
SimulationEndListenerPtr
 Smart pointer that clients should use.
 Directions_Lower
 enum value Directions_Lower.
 Directions_Upper
 enum value Direction_Upper.
 Types_Physical
 enum value Types_Physical.
 Types_Link
 enum value Types_Link.
 Types_Network
 enum value Types_Network.
 Types_Transport
 enum value Types_Transport.
 Types_Application
 enum value Types_Application.
enum  Directions { Directions_Lower, Directions_Upper }
 Directions enum. More...
enum  Types {
  Types_Physical, Types_Link, Types_Network, Types_Transport,
  Types_Application
}
 Types enum. More...

Public Member Functions

virtual ~CommunicationLayer ()
 A destructor.
virtual SimulationEndListenerPtr thisSimulationEndListener ()=0
 Gives this pointer as a SimulationEndListener object.
void insertLowerLayer (CommunicationLayerPtr layerToInsert)
 Add a layer below this layer.
t_uint numberOfLayers (Directions direction) const
 The number of layers available in the given direction.
bool setDefaultLayer (Directions direction, t_uint newDefaultIdx)
 Set the layer being used as the default for communication.
t_uint getDefaultLayer (Directions direction) const
 Get the index of the layer being used as the default.
void setLayerDelay (Directions direction, const SimTime &delay)
 Set the time delay before a sent packet is received by the next layer.
SimTime getLayerDelay (Directions direction) const
 Get the time delay before a sent packet is received by the next layer.
bool sendToQueue (PacketPtr packet)
 Send a packet to the default lower layer using a queue.
bool sendToQueue (PacketPtr packet, t_uint lowerLayerIdx)
 Send a packet to the specified lower layer using a queue.
void unblockQueue ()
 Unblock this layer's packet queue so that it can resume sending.
void blockQueue ()
 Block this layer's packet queue so that it can no longer pass packet to lower layers.
bool getQueueIsBlocked () const
 Determine whether of not the queue is currently blocked.
void setMaxQueueLength (t_uint maxQueueLength)
 Set the maximum packet queue size.
t_uint getMaxQueueLength () const
 Get the maximum packet queue size.
bool sendToLayer (Directions direction, PacketPtr packet)
 Send a packet to the default next layer.
bool sendToLayer (Directions direction, PacketPtr packet, t_uint recvingLayerIdx)
 Send a packet to the specified next layer.
bool sendToAllLayers (Directions direction, PacketPtr packet)
 Send a packet to all adjacent layers.
bool recvFromLayer (Directions direction, PacketPtr packet, CommunicationLayerPtr sendingLayer)
 Receives a packet from a sending layer.
virtual bool recvFromLayer (Directions direction, PacketPtr packet, t_uint sendingLayerIdx)
 Receives a packet from a sending layer.
virtual Types getLayerType () const =0
 Get the layer type for an object.
NodeId getNodeId () const
 Get the node ID associated with this object.

Protected Member Functions

 CommunicationLayer (NodePtr node)
 A constructor.
NodePtr getNode () const
 Get the node that contains this object.
bool queueIsFull () const
 Check if the packet queue is full.
void blockUpperQueues ()
 Block the queues of each of our upper layers.
void unblockUpperQueues ()
 Unblock the queue of each upper layer or until the queue fills up.
void sendFromQueue ()
 Send a packets from the queue while it is not empty and not blocked.
void setLowerLayerRecvEventPending (bool isPending)
 Set whether or not their is a packet currently pending for the lower layer.
void removeLayerData (PacketPtr packet) const
 Remove the layer specific data from a packet.
CommunicationLayerPtr getLayer (Directions direction, t_uint sendingLayerIdx)
 Get a pointer to the specified communication layer object.
void insertLayer (Directions direction, CommunicationLayerPtr layerToInsert)
 Add an adjacent layer in the specified direction.

Protected Attributes

bool m_lowerLayerRecvEventPending
 Determines if a lower layer receive event has been scheduled.

Friends

class Node
class LayerRecvEvent

Detailed Description

The communication layer class which is a superclass of classes implemented layers in the network stack.

This is the superclass for each of the layers in the network stack in a node. A communiation layer follows the OSI model where layers communicate with layers adjacent to it both above and below. Our class supports multiple adjacent layers. This allows, for example, a MAC layer to have multiple interfaces (PHY layers) with which it can communicate or multiple applications to share lower layers.

Definition at line 35 of file communication_layer.hpp.


Member Enumeration Documentation

enum CommunicationLayer::Directions

Directions enum.

Used to specify which direction an operation should operate on.

Enumerator:
Directions_Lower  enum value Directions_Lower.
Directions_Upper  enum value Direction_Upper.

Definition at line 54 of file communication_layer.hpp.

enum CommunicationLayer::Types

Types enum.

Used to classify the type of a CommunicationLayer object.

Enumerator:
Types_Physical  enum value Types_Physical.
Types_Link  enum value Types_Link.
Types_Network  enum value Types_Network.
Types_Transport  enum value Types_Transport.
Types_Application  enum value Types_Application.

Definition at line 63 of file communication_layer.hpp.


Constructor & Destructor Documentation

CommunicationLayer::~CommunicationLayer (  )  [virtual]

A destructor.

A virtual destructor is recommended since the class has virtual functions.

Definition at line 18 of file communication_layer.cpp.

CommunicationLayer::CommunicationLayer ( NodePtr  node  )  [protected]

A constructor.

Parameters:
node the container of this object.
See also:
getNode()

Definition at line 9 of file communication_layer.cpp.


Member Function Documentation

t_uint CommunicationLayer::getDefaultLayer ( Directions  direction  )  const [inline]

Get the index of the layer being used as the default.

Parameters:
direction the direction being queried.
Returns:
the index of the default communication layer.

Definition at line 538 of file communication_layer.hpp.

References Directions_Lower, and Directions_Upper.

Referenced by LinkLayer::channelIsBusy(), sendToLayer(), and sendToQueue().

CommunicationLayerPtr CommunicationLayer::getLayer ( Directions  direction,
t_uint  sendingLayerIdx 
) [inline, protected]

Get a pointer to the specified communication layer object.

Parameters:
direction the direction the packet was sent.
sendingLayerIdx the index of the layer that sent the packet.
Returns:
a pointer to the communication layer.

Definition at line 479 of file communication_layer.hpp.

References Directions_Lower, Directions_Upper, and numberOfLayers().

Referenced by LinkLayer::channelIsBusy().

SimTime CommunicationLayer::getLayerDelay ( Directions  direction  )  const [inline]

Get the time delay before a sent packet is received by the next layer.

Parameters:
direction the direction being queried.
Returns:
the time delay.

Definition at line 569 of file communication_layer.hpp.

References Directions_Lower, and Directions_Upper.

Referenced by sendToLayer().

virtual Types CommunicationLayer::getLayerType (  )  const [pure virtual]

Get the layer type for an object.

Returns:
the type of the layer.

Implemented in ApplicationLayer, LinkLayer, and PhysicalLayer.

Referenced by recvFromLayer(), removeLayerData(), and sendToLayer().

t_uint CommunicationLayer::getMaxQueueLength (  )  const [inline]

Get the maximum packet queue size.

Returns:
the maximum number of packet that the queue can hold.

Definition at line 474 of file communication_layer.hpp.

NodeId CommunicationLayer::getNodeId (  )  const

Get the node ID associated with this object.

Returns:
the node ID.

Definition at line 191 of file communication_layer.cpp.

References getNode().

Referenced by PhysicalLayer::captureSignal(), WirelessChannel::getRecvdStrength(), recvFromLayer(), PhysicalLayer::recvPendingSignal(), sendToLayer(), and RfidReaderApp::simulationEndHandler().

bool CommunicationLayer::getQueueIsBlocked (  )  const [inline]

Determine whether of not the queue is currently blocked.

Returns:
true if the queue is blocked.

Definition at line 457 of file communication_layer.hpp.

void CommunicationLayer::insertLayer ( Directions  direction,
CommunicationLayerPtr  layerToInsert 
) [inline, protected]

Add an adjacent layer in the specified direction.

The layer being inserted must be owned by the same node as this object.

Parameters:
direction the direction of the action.
layerToInsert a pointer to the neighboring layer.

Definition at line 413 of file communication_layer.hpp.

References Directions_Lower, Directions_Upper, getNode(), numberOfLayers(), and setDefaultLayer().

Referenced by insertLowerLayer().

void CommunicationLayer::insertLowerLayer ( CommunicationLayerPtr  layerToInsert  )  [inline]

Add a layer below this layer.

This object will be inserted as the upper layer for layerToInsert. The layer being inserted must be owned by the same node as this object.

Parameters:
layerToInsert a pointer to the lower layer.

Definition at line 403 of file communication_layer.hpp.

References Directions_Lower, Directions_Upper, getNode(), and insertLayer().

t_uint CommunicationLayer::numberOfLayers ( Directions  direction  )  const [inline]

The number of layers available in the given direction.

Parameters:
direction the direction being queried.
Returns:
the number of layers.

Definition at line 501 of file communication_layer.hpp.

References Directions_Lower, and Directions_Upper.

Referenced by getLayer(), insertLayer(), recvFromLayer(), sendToAllLayers(), sendToLayer(), and setDefaultLayer().

bool CommunicationLayer::queueIsFull (  )  const [inline, protected]

Check if the packet queue is full.

Returns:
true if the packet queue is full.

Definition at line 462 of file communication_layer.hpp.

Referenced by sendFromQueue(), sendToQueue(), and unblockUpperQueues().

bool CommunicationLayer::recvFromLayer ( Directions  direction,
PacketPtr  packet,
t_uint  sendingLayerIdx 
) [virtual]

Receives a packet from a sending layer.

This is the function that subclasses should override to receive packets since it specifies the index of the sending layer rather than a pointer.

Parameters:
direction the direction the packet was sent.
packet a pointer to the received packet.
sendingLayerIdx the index of the layer that sent the packet.
Returns:
true if the specified layer was able to receive the packet.

Reimplemented in ApplicationLayer, LinkLayer, and PhysicalLayer.

Definition at line 166 of file communication_layer.cpp.

References Directions_Lower, Directions_Upper, numberOfLayers(), and sendToLayer().

bool CommunicationLayer::recvFromLayer ( Directions  direction,
PacketPtr  packet,
CommunicationLayerPtr  sendingLayer 
)

Receives a packet from a sending layer.

Parameters:
direction the direction the packet was sent.
packet a pointer to the received packet.
sendingLayer a pointer to the layer that sent the packet.
Returns:
true if the specified layer was able to receive the packet.

Definition at line 129 of file communication_layer.cpp.

References Directions_Lower, Directions_Upper, getLayerType(), getNodeId(), LogStreamManager::instance(), and numberOfLayers().

void CommunicationLayer::removeLayerData ( PacketPtr  packet  )  const [protected]

Remove the layer specific data from a packet.

Parameters:
packet a pointer to the packet whose layer data will be removed.

Definition at line 198 of file communication_layer.cpp.

References Packet::DataTypes_Application, Packet::DataTypes_Link, Packet::DataTypes_Network, Packet::DataTypes_Physical, Packet::DataTypes_Transport, getLayerType(), Types_Application, Types_Link, Types_Network, Types_Physical, and Types_Transport.

Referenced by sendToLayer().

bool CommunicationLayer::sendToAllLayers ( Directions  direction,
PacketPtr  packet 
)

Send a packet to all adjacent layers.

Parameters:
direction the direction of the action.
packet a pointer to the packet being sent.
Returns:
true if the packet was successfully scheduled to be sent to all layers.

Definition at line 85 of file communication_layer.cpp.

References numberOfLayers(), and sendToLayer().

bool CommunicationLayer::sendToLayer ( Directions  direction,
PacketPtr  packet,
t_uint  recvingLayerIdx 
)

Send a packet to the specified next layer.

Packets send to upper layers will have their header data removed.

Parameters:
direction the direction of the action.
packet a pointer to the packet being sent.
recvingLayerIdx the index of the layer to which the packet is being sent.
Returns:
true if the packet was successfully scheduled to be sent to the next layer.

Definition at line 96 of file communication_layer.cpp.

References LayerRecvEvent::create(), Directions_Lower, Directions_Upper, getLayerDelay(), getLayerType(), getNodeId(), LogStreamManager::instance(), LogStreamManager::logPktSendItem(), numberOfLayers(), removeLayerData(), and setLowerLayerRecvEventPending().

bool CommunicationLayer::sendToLayer ( Directions  direction,
PacketPtr  packet 
)

Send a packet to the default next layer.

Packets send to upper layers will have their header data removed.

Parameters:
direction the direction of the action.
packet a pointer to the packet being sent.
Returns:
true if the packet was successfully scheduled to be sent to the next layer.

Definition at line 79 of file communication_layer.cpp.

References getDefaultLayer().

Referenced by recvFromLayer(), LinkLayer::recvFromMacProtocol(), PhysicalLayer::recvPendingSignal(), sendFromQueue(), and sendToAllLayers().

bool CommunicationLayer::sendToQueue ( PacketPtr  packet,
t_uint  lowerLayerIdx 
)

Send a packet to the specified lower layer using a queue.

Parameters:
packet a pointer to the packet being sent.
lowerLayerIdx the index of the lower layer to which we are sending.
Returns:
true if the packet was successfully queued.

Definition at line 59 of file communication_layer.cpp.

References blockUpperQueues(), queueIsFull(), and sendFromQueue().

bool CommunicationLayer::sendToQueue ( PacketPtr  packet  ) 

Send a packet to the default lower layer using a queue.

Parameters:
packet a pointer to the packet being sent.
Returns:
true if the packet was successfully queued.

Definition at line 53 of file communication_layer.cpp.

References Directions_Lower, and getDefaultLayer().

bool CommunicationLayer::setDefaultLayer ( Directions  direction,
t_uint  newDefaultIdx 
) [inline]

Set the layer being used as the default for communication.

Parameters:
direction the direction of the action.
newDefaultIdx the index of the layer to be used as the default.
Returns:
true if the desired layer was set as the default.

Definition at line 517 of file communication_layer.hpp.

References Directions_Lower, Directions_Upper, and numberOfLayers().

Referenced by insertLayer().

void CommunicationLayer::setLayerDelay ( Directions  direction,
const SimTime delay 
) [inline]

Set the time delay before a sent packet is received by the next layer.

Parameters:
direction the direction of the action.
delay the time delay.

Definition at line 554 of file communication_layer.hpp.

References Directions_Lower, and Directions_Upper.

void CommunicationLayer::setLowerLayerRecvEventPending ( bool  isPending  )  [inline, protected]

Set whether or not their is a packet currently pending for the lower layer.

For example, if their is a layer delay then this will be pending until the lower layer actually receives the packet.

Parameters:
isPending whether of not such an event is pending.

Definition at line 446 of file communication_layer.hpp.

References m_lowerLayerRecvEventPending, and sendFromQueue().

Referenced by sendToLayer().

void CommunicationLayer::setMaxQueueLength ( t_uint  maxQueueLength  )  [inline]

Set the maximum packet queue size.

Parameters:
maxQueueLength the maximimum number of packets that the queue can hold.

Definition at line 468 of file communication_layer.hpp.

Referenced by LinkLayer::LinkLayer(), and PhysicalLayer::PhysicalLayer().

virtual SimulationEndListenerPtr CommunicationLayer::thisSimulationEndListener (  )  [pure virtual]

Gives this pointer as a SimulationEndListener object.

This is used to deal with shared_ptr's, this, and inheritance.

Returns:
a pointer to this object.

Implemented in LinkLayer, RfidReaderApp, RfidReaderPhy, RfidTagApp, and RfidTagPhy.


The documentation for this class was generated from the following files:
Generated on Tue Dec 12 17:04:39 2006 for rfidsim by  doxygen 1.4.7