Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

SimpleMacLayer Class Reference
[AnalogueModels example - Classes from the AnalogueModels example]

A simple Mac layer implementation which only shows how to create Signals, send them to Phy and receive the from the Phy layer. More...

#include <SimpleMacLayer.h>

Inherits BaseModule.

Collaboration diagram for SimpleMacLayer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void initialize (int stage)
 Basic initialization for all modules.
virtual void handleMessage (cMessage *msg)

Protected Types

enum  { TEST_MACPKT = 12121 }

Protected Member Functions

MappingcreateMapping (simtime_t time, simtime_t length, double freqFrom, double freqTo, double value)
 Creates a Mapping with the passed value at the passed position in freqency and time.
void handleMacPkt (MacPkt *pkt)
void handleTXOver ()
void broadCastPacket ()
 Sends the answer packet.
void sendDown (MacPkt *pkt)
MacPkt * createMacPkt (simtime_t length)
 Creates the answer packet.
void log (std::string msg)

Protected Attributes

MacToPhyInterfacephy
 Pointer to the phy module of this host.
int dataOut
 Omnet gates.
int dataIn
int myIndex
int nextReceiver
 The index of the host the next packet should be send to.
DimensionSet dimensions
 The dimensions for the signal this mac layer works with (frequency and time).

Detailed Description

A simple Mac layer implementation which only shows how to create Signals, send them to Phy and receive the from the Phy layer.

This Mac layer just sends an answer packet every time it receives a packet. Since both hosts do that in this simulation, it will only terminate if one packet gets lost (couldn't be received by the phy layer correctly).

Definition at line 21 of file SimpleMacLayer.h.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
TEST_MACPKT 

Used as Message kind to identify MacPackets.

Definition at line 35 of file SimpleMacLayer.h.

       {
    TEST_MACPKT = 12121
  };


Member Function Documentation

void SimpleMacLayer::initialize ( int  stage  )  [virtual]

Basic initialization for all modules.

Subscription to Blackboard should be in stage==0, and firing notifications in stage==1 or later.

NOTE: You have to call this in the initialize() function of the inherited class!

Reimplemented from BaseModule.

Definition at line 9 of file SimpleMacLayer.cc.

References DimensionSet::addDimension(), dataOut, dimensions, BaseModule::findHost(), Dimension::frequency, nextReceiver, phy, Radio::RX, MacToPhyInterface::setRadioState(), Dimension::time, and Radio::TX.

                                         {
  BaseModule::initialize(stage);

  if(stage == 0) {
    myIndex = findHost()->getIndex();

    dimensions.addDimension(Dimension::time);
    dimensions.addDimension(Dimension::frequency);

    dataOut = findGate("lowerGateOut");
    dataIn = findGate("lowerGateIn");

    phy = FindModule<MacToPhyInterface*>::findSubModule(this->getParentModule());

  } else if(stage == 1) {
    if(myIndex == 0){ //host with index 0 start with sending packets
      log("Switching radio to TX...");
      nextReceiver = 1;
      phy->setRadioState(Radio::TX); //to be able to send packets it has to switch to TX mode

    }else{ //every other host start in receiving mode
      log("Switching radio to RX...");
      phy->setRadioState(Radio::RX);
    }
    //switching the radio can take some time,
    //we will get a "RADIO_SWITCHING_OVER" message as soon as the radio has switched.
  }
}


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