Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

EtherAppSrv.cc

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 CTIE, Monash University
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include <stdio.h>
00020 #include <string.h>
00021 #include <omnetpp.h>
00022 
00023 #include "EtherCtrl_m.h"
00024 #include "EtherApp_m.h"
00025 #include "utils.h"
00026 
00027 
00028 #define MAX_REPLY_CHUNK_SIZE   1497
00029 
00030 
00034 class EtherAppSrv : public cSimpleModule
00035 {
00036   protected:
00037     int localSAP;
00038     int remoteSAP;
00039 
00040     long packetsSent;
00041     long packetsReceived;
00042     cOutVector eedVector;
00043     cStdDev eedStats;
00044 
00045   public:
00046     Module_Class_Members(EtherAppSrv,cSimpleModule,0);
00047 
00048     virtual void initialize();
00049     virtual void handleMessage(cMessage *msg);
00050     virtual void finish();
00051 
00052     void registerDSAP(int dsap);
00053     void sendPacket(cMessage *datapacket, const MACAddress& destAddr);
00054 };
00055 
00056 Define_Module (EtherAppSrv);
00057 
00058 void EtherAppSrv::initialize()
00059 {
00060     localSAP = ETHERAPP_SRV_SAP;
00061     remoteSAP = ETHERAPP_CLI_SAP;
00062 
00063     // statistics
00064     packetsSent = packetsReceived = 0;
00065     eedVector.setName("end-to-end delay");
00066     eedStats.setName("end-to-end delay");
00067     WATCH(packetsSent);
00068     WATCH(packetsReceived);
00069 
00070     registerDSAP(localSAP);
00071 }
00072 
00073 void EtherAppSrv::handleMessage(cMessage *msg)
00074 {
00075     EV << "Received packet `" << msg->name() << "'\n";
00076 
00077     packetsReceived++;
00078     simtime_t lastEED = simTime() - msg->creationTime();
00079     eedVector.record(lastEED);
00080     eedStats.collect(lastEED);
00081 
00082     EtherAppReq *req = check_and_cast<EtherAppReq *>(msg);
00083     EtherCtrl *ctrl = check_and_cast<EtherCtrl *>(req->removeControlInfo());
00084     MACAddress srcAddr = ctrl->getSrc();
00085     long requestId = req->getRequestId();
00086     long replyBytes = req->getResponseBytes();
00087     char msgname[30];
00088     strcpy(msgname,msg->name());
00089 
00090     delete msg;
00091     delete ctrl;
00092 
00093     // send back packets asked by EtherAppCli side
00094     int k = 0;
00095     strcat(msgname,"-resp-");
00096     char *s = msgname+strlen(msgname);
00097     while (replyBytes>0)
00098     {
00099         int l = replyBytes>MAX_REPLY_CHUNK_SIZE ? MAX_REPLY_CHUNK_SIZE : replyBytes;
00100         replyBytes -= l;
00101 
00102         sprintf(s,"%d",k);
00103 
00104         EV << "Generating packet `" << msgname << "'\n";
00105 
00106         EtherAppResp *datapacket = new EtherAppResp(msgname, ETHCTRL_DATA);
00107         datapacket->setRequestId(requestId);
00108         datapacket->setLength(8*l);
00109         sendPacket(datapacket, srcAddr);
00110         packetsSent++;
00111 
00112         k++;
00113     }
00114 
00115 }
00116 
00117 void EtherAppSrv::sendPacket(cMessage *datapacket, const MACAddress& destAddr)
00118 {
00119     EtherCtrl *etherctrl = new EtherCtrl();
00120     etherctrl->setSsap(localSAP);
00121     etherctrl->setDsap(remoteSAP);
00122     etherctrl->setDest(destAddr);
00123     M30(datapacket)->setControlInfo(etherctrl);
00124     send(datapacket, "out");
00125 }
00126 
00127 void EtherAppSrv::registerDSAP(int dsap)
00128 {
00129     EV << fullPath() << " registering DSAP " << dsap << "\n";
00130 
00131     EtherCtrl *etherctrl = new EtherCtrl();
00132     etherctrl->setDsap(dsap);
00133     cMessage30 *msg = new cMessage30("register_DSAP", ETHCTRL_REGISTER_DSAP);
00134     msg->setControlInfo(etherctrl);
00135 
00136     send(msg, "out");
00137 }
00138 
00139 void EtherAppSrv::finish()
00140 {
00141     if (par("writeScalars").boolValue())
00142     {
00143         recordScalar("packets sent", packetsSent);
00144         recordScalar("packets rcvd", packetsReceived);
00145         recordScalar("end-to-end delay mean", eedStats.mean());
00146         recordScalar("end-to-end delay stddev", eedStats.stddev());
00147         recordScalar("end-to-end delay min", eedStats.min());
00148         recordScalar("end-to-end delay max", eedStats.max());
00149     }
00150 }
00151 
00152 

Generated on Sat May 15 20:30:42 2004 for Ethernet by doxygen1.2.17