#include <SEtherApp.h>
Protected Member Functions | |
virtual void | initialize (int stage) |
virtual int | numInitStages () const |
virtual void | handleMessage (cMessage *msg) |
virtual void | finish () |
virtual void | choosePublication () |
virtual bool | genInformationItem () |
Protected Attributes | |
double | psProportion |
The proportion between publishing and subscribing (future use). |
The Subscribe Ethernet Application class header The Subscribe Ethernet Application. This simple application acts more like a sink, apart from the fact that it is able to subscribe to Information Items existing or not in the Information Item Table of the simulation ground.
void SEtherApp::choosePublication | ( | ) | [protected, virtual] |
Chooses a random publication from the Information Item Table, according to the popularity of each element. Afterwards, the application module tries to subscribe to this publication (although it might be already subscribed).
00108 { 00109 00110 //Try to receive a published request for an Information Item 00111 InformationItem *publication=returnRandII(); 00112 if(publication!=NULL) { 00113 00114 //Inform the Global Information Item Table 00115 if(iit->addSubElement(publication,this->getParentModule())) { 00116 00117 ev << this->getParentModule()->getFullName() << ": Existing Information Item met with new subscription!" << endl; 00118 00119 subscriptionItem subitem; 00120 subitem.ii=publication; 00121 subscriptions.push_back(subitem); 00122 } 00123 } 00124 //If non returned for any reason print an error message 00125 else { 00126 ev << this->getParentModule()->getFullName() << ": Tried to find publication but list was empty!" << endl; 00127 } 00128 }
void SEtherApp::finish | ( | ) | [protected, virtual] |
The finish function of the application. Just calls the finish function of the base class.
Reimplemented from BasePSApp.
00049 { 00050 BasePSApp::finish(); 00051 }
bool SEtherApp::genInformationItem | ( | ) | [protected, virtual] |
It generates a information Item and places it into the subscriptions table of the subscriber, and informs the Information Item Table module, if exists.
00131 { 00132 //Create subscription item 00133 subscriptionItem subitem; 00134 00135 /************Cancel afterwards!!!*************/ 00136 //Generate random ID 00137 char ID[PURSUIT_ID_LEN+1]; 00138 for(int i=0;i<PURSUIT_ID_LEN;i++) 00139 { 00140 ID[i]=(char)(1+intrand(255)); 00141 } 00142 //Put string end character 00143 ID[PURSUIT_ID_LEN] = '\0'; 00144 00145 InformationItem *II=new InformationItem("0457A0B220ABF100",ID); 00146 //InformationItem *II=new InformationItem("0457A0B220ABF100","BGA%£FD"); 00147 00148 //Assign the successfully created Information Item in the subscription 00149 subitem.ii=II; 00150 00151 //Create randomly Meta-data for the future Information Item 00152 //TODO: Find a method for generating these metadata 00153 subitem.qos[QoS_BW_M]=(uint16_t)datarate->doubleValue(); 00154 subitem.qos[QoS_FLOW]=1; 00155 00156 /* First the Topology Manager has to be informed of the new Information Item 00157 * and it's meta data. This happens to avoid finding paths without being 00158 * informed of the QoS requirements of each item. If there is a mistake, 00159 * such as the Information Item already exists, the Topology Manager will 00160 * not accept the packet. The same information lies on the rendezvous table.*/ 00161 publishMetaDataPacket(subitem); 00162 00163 /***Inform the Global Information Item Table***/ 00164 if(iit->addSubElement(II,this->getParentModule())) { 00165 //Add the successfully created Information Item 00166 subitem.ii=II; 00167 00168 subscriptions.push_back(subitem); 00169 return true; 00170 } 00171 /**********************************************/ 00172 00173 return false; 00174 }
void SEtherApp::handleMessage | ( | cMessage * | msg | ) | [protected, virtual] |
Handles incoming messages for the subscriber application. It actually only records their statistics and deletes them.
Reimplemented from BasePSApp.
00055 { 00056 if (msg->isSelfMessage()) 00057 { 00058 //Self message to create or delete a new subscription 00059 if(strcmp(msg->getFullName(),"choosePublisher")==0) { 00060 //Decide whether to make new subscription 00061 double now=simTime().dbl(); 00062 //Get a random variable according the the Gaussian distribution 00063 double subPeak=normal(this->par("actPeak").doubleValue(),PEAK_DEV); 00064 00065 //Try to create a new subscription, if the random variable is close enough to the current time. 00066 //To create a periodical functionality, the modulo of the current time is taken for the time 00067 //period equal to three times the mean value of the Gaussian random variable. 00068 if(subPeak-(2*PEAK_DEV+1)<fmod(now,3*subPeak) && subPeak+(2*PEAK_DEV+1)>fmod(now,3*subPeak)) { 00069 if(dblrand()<0.8) { 00070 choosePublication(); 00071 } 00072 else { 00073 genInformationItem(); 00074 } 00075 } 00076 //Or delete an old one if the current time is close enough the the double of the Gaussian mean. 00077 //Notice that a bit more space is given to the removing of subscriptions, since it creates 00078 //better results. 00079 else if(2*subPeak-(2*PEAK_DEV+2)<fmod(now,3*subPeak) && 2*subPeak+(2*PEAK_DEV+2)>fmod(now,3*subPeak)) { 00080 cancelInformationItem(UNSUBSCRIBE_INFO); 00081 } 00082 00083 simtime_t st = par("subInterval").doubleValue(); 00084 // Send packet with a small jitter 00085 simtime_t jitter = dblrand() * MAXJITTER; 00086 scheduleAt(simTime()+st+jitter, msg); 00087 } 00088 } 00089 else { 00090 EV << "Received packet `" << msg->getName() << "'\n"; 00091 00092 packetsReceived++; 00093 simtime_t lastEED = simTime() - msg->getCreationTime(); 00094 eedVector.record(lastEED); 00095 eedStats.collect(lastEED); 00096 00097 //Left here for future use 00098 PSEtherAppMsg *req = check_and_cast<PSEtherAppMsg *>(msg); 00099 Ieee802Ctrl *ctrl = check_and_cast<Ieee802Ctrl *>(req->removeControlInfo()); 00100 //MACAddress srcAddr = ctrl->getSrc(); 00101 00102 delete ctrl; 00103 delete req; 00104 } 00105 }
void SEtherApp::initialize | ( | int | stage | ) | [protected, virtual] |
Initialization function of the subscriber application. Schedules the initial self messages and is able to create some initial subscriptions.
Reimplemented from BasePSApp.
00030 { 00031 BasePSApp::initialize(stage); 00032 if(stage==1) { 00033 //Read the proportion of choosing publishers against adding subscribers 00034 psProportion = simulation.getSystemModule()->par("PubSubProportion"); 00035 if(psProportion<0 || psProportion>1) 00036 psProportion=0.5; 00037 00038 //Generate self message for choosing a subscriber to publish for 00039 cMessage *choosePubmsg = new cMessage("choosePublisher"); 00040 simtime_t st = par("subInterval").doubleValue(); 00041 // Send packet with a small jitter 00042 simtime_t jitter = dblrand() * MAXJITTER; 00043 scheduleAt(simTime()+st+jitter, choosePubmsg); 00044 } 00045 }
virtual int SEtherApp::numInitStages | ( | ) | const [inline, protected, virtual] |
double SEtherApp::psProportion [protected] |
The proportion between publishing and subscribing (future use).