00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "BurstApplLayerBattery.h"
00024
00025 Define_Module(BurstApplLayerBattery);
00026
00027
00028 void BurstApplLayerBattery::initialize(int stage)
00029 {
00030 BurstApplLayer::initialize(stage);
00031
00032 if(stage==0) {
00033 bcastOut = replyOut = replyIn = 0;
00034 }
00035 }
00036
00037 void BurstApplLayerBattery::handleSelfMsg(cMessage *msg)
00038 {
00039 switch(msg->getKind()) {
00040 case SEND_BROADCAST_TIMER:
00041 for(int i=0; i<burstSize; i++) {
00042 bcastOut += 1;
00043 debugEV << "bcastQueued = " << bcastOut << endl;
00044 sendBroadcast();
00045 }
00046 break;
00047 default:
00048 EV <<" Unkown selfmessage! kind: "<<msg->getKind() << endl;
00049 break;
00050 }
00051 }
00052
00053 void BurstApplLayerBattery::handleLowerMsg( cMessage* msg )
00054 {
00055 ApplPkt *m;
00056
00057 switch( msg->getKind() ) {
00058 case BROADCAST_MESSAGE:
00059 m = static_cast<ApplPkt *>(msg);
00060 debugEV << "Received a broadcast packet from host["<<m->getSrcAddr()<<"] -> sending reply\n";
00061 replyOut += 1;
00062 debugEV << simTime() << ": replyOut = " << replyOut << endl;
00063 sendReply(m);
00064 break;
00065 case BROADCAST_REPLY_MESSAGE:
00066 m = static_cast<ApplPkt *>(msg);
00067 debugEV << "Received reply from host["<<m->getSrcAddr()<<"]; delete msg\n";
00068 replyIn += 1;
00069 debugEV << simTime() << ": replyIn = " << replyIn << endl;
00070 delete msg;
00071 break;
00072 default:
00073 EV <<"Error! got packet with unknown kind: " << msg->getKind()<<endl;
00074 break;
00075 }
00076 }
00077
00078 void BurstApplLayerBattery::handleHostState(const HostState& state)
00079 {
00080 HostState::States hostState = state.get();
00081
00082 switch (hostState) {
00083 case HostState::FAILED:
00084 debugEV << "t = " << simTime() << " host state FAILED" << endl;
00085 recordScalar("HostState::FAILED", simTime());
00086
00087
00088
00089
00090
00091
00092
00093 if (delayTimer->isScheduled()) {
00094 debugEV << "canceling frame burst" << endl;
00095 cancelEvent(delayTimer);
00096 }
00097 break;
00098 default:
00099
00100 break;
00101 }
00102 }
00103
00104 void BurstApplLayerBattery::finish()
00105 {
00106 BurstApplLayer::finish();
00107 recordScalar("broadcast queued", bcastOut);
00108 recordScalar("replies sent", replyOut);
00109 recordScalar("replies received", replyIn);
00110 }