BasePSApp Class Reference

#include <BasePSApp.h>

Inheritance diagram for BasePSApp:
cSimpleModule cModule cComponent cDefaultList cNoncopyableOwnedObject cOwnedObject noncopyable cNamedObject cObject PEtherApp SEtherApp

List of all members.

Protected Types

typedef std::vector
< subscriptionItem >::iterator 
subscrIter
 The iterator for the Subscriptions' Table.

Protected Member Functions

virtual void initialize (int stage)
virtual int numInitStages () const
virtual void handleMessage (cMessage *msg)
virtual void finish ()
virtual bool cancelInformationItem (int type)
virtual InformationItemreturnMyRandII ()
virtual InformationItemreturnRandII ()
virtual void publishMetaDataPacket (subscriptionItem subItem)

Protected Attributes

long seqNum
 The sequence number of each transmitted packet.
long packetsSent
 Statistic for the packets sent.
long packetsReceived
 Statistic for packets received.
cOutVector eedVector
 End-to-end delay vector.
cStdDev eedStats
 End-to-end delay statistics.
std::vector< subscriptionItemsubscriptions
 The module's Subscriptions' Table.
IITableiit
 Pointer to the Information Item Table module.
cPardatarate
 The bitrate of every publication stream.

Detailed Description

The basic definition of the application used for publishing and subscribing in the publish-subscribe network. Because the is a high degree of overlap in the functionality of the publish and subscribe applications, this class is used to define some common operations and parameters.

The subscriptions of each applications are stored in an vector of subscription items. These items are represented by a complex struct containing the Information Item details, along with it's meta data. The meta data structure is used later only by publishers, but future implementation might include Subscriber usage as well.


Member Typedef Documentation

typedef std::vector<subscriptionItem>::iterator BasePSApp::subscrIter [protected]

The iterator for the Subscriptions' Table.


Member Function Documentation

bool BasePSApp::cancelInformationItem ( int  type  )  [protected, virtual]

Remove an Information Item from the relevant table of the module.

00066                                               {
00067 
00068         //Choose randomly a subscription, according to its popularity
00069         InformationItem *II=returnMyRandII();
00070 
00071         if(II==NULL) {
00072                 ev << "Tried to delete Information Item, but subscription list is empty!"  << endl;
00073         }
00074         else {
00075 
00076                 subscriptionItem subitem;
00077                 subitem.ii=II;
00078                 subscrIter iter=find(subscriptions.begin(),subscriptions.end(),subitem);
00079 
00080                 //Check if removing publication
00081                 if(type==UNPUBLISH_INFO) {
00082                         if(iit->removePubElement(II,this->getParentModule())) {
00083                                 subscriptions.erase(iter);
00084                                 return true;
00085                         }
00086                 }
00087                 //Check if removing subscription
00088                 else if(type==UNSUBSCRIBE_INFO) {
00089                         if(iit->removeSubElement(II,this->getParentModule())) {
00090                                 subscriptions.erase(iter);
00091                                 return true;
00092                         }
00093                 }
00094                 //If non of the above then we have an error
00095                 else {
00096                         ev << this->getFullName() << ": Wrong command was given while trying to remove Information Item!" << endl;
00097                 }
00098         }
00099 
00100         return false;
00101 }

void BasePSApp::finish (  )  [protected, virtual]

Called with finish() function is called for the whole simulation.

Reimplemented from cComponent.

Reimplemented in PEtherApp, and SEtherApp.

00052 {
00053         //Record Scalars
00054     recordScalar("packets sent", packetsSent);
00055     recordScalar("packets rcvd", packetsReceived);
00056     recordScalar("end-to-end delay mean", eedStats.getMean());
00057     recordScalar("end-to-end delay stddev", eedStats.getStddev());
00058     recordScalar("end-to-end delay min", eedStats.getMin());
00059     recordScalar("end-to-end delay max", eedStats.getMax());
00060 
00061     //Clear the subscriptions table;
00062     subscriptions.clear();
00063 }

void BasePSApp::handleMessage ( cMessage msg  )  [protected, virtual]

Handles a message received by this module. In this case it does nothing.

Reimplemented from cSimpleModule.

Reimplemented in PEtherApp, and SEtherApp.

00174 {
00175         //Nothing to do... deleting message
00176         delete msg;
00177 }

void BasePSApp::initialize ( int  stage  )  [protected, virtual]

Initialized the parameters of the class, like the statistic variables and the pointer to the Information Item Table.

Reimplemented from cComponent.

Reimplemented in PEtherApp, and SEtherApp.

00027 {
00028         if(stage==1) {
00029                 // parameters
00030                 seqNum = 0;
00031                 datarate= &par("datarate");
00032 
00033                 // statistics
00034                 packetsSent = packetsReceived = 0;
00035                 eedVector.setName("end-to-end delay");
00036                 eedStats.setName("end-to-end delay");
00037                 WATCH_VECTOR(subscriptions);
00038                 WATCH(packetsSent);
00039                 WATCH(packetsReceived);
00040                 WATCH(seqNum);
00041         }
00042         //The topology manager and IITable have been initialized at stage 2 so we access it now
00043         if(stage==3)
00044         {
00045                 //Get access to the Information Access tablet to bypass the TV need
00046                 iit=IITableAccess<IITable>("iiTable").get();
00047         }
00048 }

virtual int BasePSApp::numInitStages (  )  const [inline, protected, virtual]

Returns the number of initialization stages.

Reimplemented from cComponent.

Reimplemented in PEtherApp, and SEtherApp.

00108 {return 4;};

void BasePSApp::publishMetaDataPacket ( subscriptionItem  subItem  )  [protected, virtual]

00180                                                               {
00181         //Increase sequence number
00182         seqNum++;
00183 
00184         // Generate Message name
00185         char msgname[30];
00186         sprintf(msgname, "MetaDataMsg-%d-%ld", getId(), seqNum);
00187         ev << "Generating packet `" << msgname << "'\n";
00188 
00189         //Create Message
00190         MetaDataPacket *metadatapacket = new MetaDataPacket(msgname);
00191 
00192         //Set packet size
00193         metadatapacket->setByteLength(/*type*/ 1  + /*ID*/ 1 + /*scopeLen*/ (PURSUIT_ID_LEN)*(subItem.ii->scopeSize()) + /*QoSList*/ (subItem.qos.size())*(QoS_ITEM_SIZE));
00194 
00195         //Set Message Parameters
00196         metadatapacket->setID(*subItem.ii);
00197         metadatapacket->setType(PUB_METADATA);
00198         metadatapacket->setItemNum(subItem.qos.size());
00199         metadatapacket->setIIStatus(subItem.qos);
00200 
00201         //Send the message to the Topology Manager
00202         this->sendDirect(metadatapacket,simulation.getModuleByPath("tm"),simulation.getModuleByPath("tm")->findGate("TMin"));
00203 }

InformationItem * BasePSApp::returnMyRandII (  )  [protected, virtual]

Is used by nodes to choose an Information Item, from the subscriptions table. The choices are made according to the popularity of each subscriptions.

00141                                            {
00142 
00143         double propArray[subscriptions.size()];
00144         InformationItem *II=NULL;
00145         double sum=0;
00146 
00147         //Define iterator
00148         subscrIter iter;
00149 
00150         //Check all subscriptions made in the IITable and their popularity
00151         //Afterwards create a matrix defining the popularity boundaries
00152         for(unsigned int i=0;i<subscriptions.size();i++) {
00153                 propArray[i]=sum+subscriptions[i].ii->getPop();
00154                 sum+=subscriptions[i].ii->getPop();
00155         }
00156 
00157         //Randomly choose one Information Item to return
00158         double choice=dblrand()*sum;
00159 
00160         //Find out the choice made, between all existing Information Items
00161         for(unsigned int i=0;i<subscriptions.size();i++) {
00162                 if(choice<propArray[i]) {
00163                         II=subscriptions[i].ii;
00164                         return II;
00165                 }
00166                 i++;
00167         }
00168 
00169         return II;
00170 }

InformationItem * BasePSApp::returnRandII (  )  [protected, virtual]

Is used by publishers to choose an Information Item, requested by a subscription from this node. This way subscriptions can be met and increase their number of publishers and subscribers per Information Item.

00104                                          {
00105 
00106         double propArray[iit->getNumOfRendezvous()];
00107         InformationItem *II=NULL;
00108         unsigned int i=0;
00109         double sum=0;
00110 
00111         //Define iterator
00112         IITable::RVVectorIt iter;
00113 
00114         //Check all subscriptions made in the IITable and their popularity
00115         //Afterwards create a matrix defining the popularity boundaries
00116         for(iter=iit->rendezvous.begin();iter!=iit->rendezvous.end();iter++) {
00117                 propArray[i]=sum+iter->first->getPop();
00118                 sum+=iter->first->getPop();
00119                 i++;
00120         }
00121 
00122         //Randomly choose one Information Item to return
00123         double choice=dblrand()*sum;
00124 
00125         //Reinitialize array counter
00126         i=0;
00127 
00128         //Find out the choice made, between all existing Information Items
00129         for(iter=iit->rendezvous.begin();iter!=iit->rendezvous.end();iter++) {
00130                 if(choice<propArray[i]) {
00131                         II=iter->first;
00132                         return II;
00133                 }
00134                 i++;
00135         }
00136 
00137         return II;
00138 }


Member Data Documentation

cPar* BasePSApp::datarate [protected]

The bitrate of every publication stream.

End-to-end delay statistics.

End-to-end delay vector.

IITable* BasePSApp::iit [protected]

Pointer to the Information Item Table module.

long BasePSApp::packetsReceived [protected]

Statistic for packets received.

long BasePSApp::packetsSent [protected]

Statistic for the packets sent.

long BasePSApp::seqNum [protected]

The sequence number of each transmitted packet.

std::vector<subscriptionItem> BasePSApp::subscriptions [protected]

The module's Subscriptions' Table.


The documentation for this class was generated from the following files:
Generated on Thu Jun 14 17:12:42 2012 for PAL by  doxygen 1.6.3