SensorApplLayer.h

00001 /***************************************************************************
00002  * file:        SensorApplLayer.h
00003  *
00004  * author:      Amre El-Hoiydi, Jérôme Rousselot
00005  *
00006  * copyright:   (C) 2007 CSEM
00007  *
00008  *              This program is free software; you can redistribute it
00009  *              and/or modify it under the terms of the GNU General Public
00010  *              License as published by the Free Software Foundation; either
00011  *              version 2 of the License, or (at your option) any later
00012  *              version.
00013  *              For further information see file COPYING
00014  *              in the top level directory
00015  ***************************************************************************
00016  * part of:     framework implementation developed by tkn
00017  * description: Generate periodic traffic addressed to a sink
00018  **************************************************************************/
00019 
00020 
00021 #ifndef SENSOR_APPL_LAYER_H
00022 #define SENSOR_APPL_LAYER_H
00023 
00024 #include <map>
00025 #include "BaseUtility.h"
00026 #include "BaseModule.h"
00027 #include "BaseLayer.h"
00028 #include "NetwControlInfo.h"
00029 #include "Packet.h"
00030 #include "ApplPkt_m.h"
00031 #include "BaseApplLayer.h"
00032 #include "BaseWorldUtility.h"
00033 
00034 using namespace std;
00035 
00054 class SensorApplLayer:public BaseLayer
00055 {
00056 public:
00057 
00058 
00060   virtual void initialize(int);
00061   virtual void finish();
00062 
00063   ~SensorApplLayer();
00064   
00065   SensorApplLayer(): packet(100) {} // we must specify a packet length for Packet.h
00066 
00067   enum APPL_MSG_TYPES
00068   {
00069     SEND_DATA_TIMER,
00070     STOP_SIM_TIMER,
00071     DATA_MESSAGE
00072   };
00073 
00074   enum TRAFFIC_TYPES
00075   {
00076     UNKNOWN=0,
00077     PERIODIC,
00078     UNIFORM,
00079     EXPONENTIAL,
00080     NB_DISTRIBUTIONS,
00081   };
00082 
00083 protected:
00084   cMessage * delayTimer;
00085   int myAppAddr;
00086   int destAddr;
00087   int sentPackets;
00088   simtime_t initializationTime;
00089   simtime_t firstPacketGeneration;
00090   simtime_t lastPacketReception;
00091   // parameters:
00092   int trafficType;
00093   double trafficParam;
00094   int nbPackets;
00095   long nbPacketsSent;
00096   long nbPacketsReceived;
00097   bool stats;
00098   bool trace;
00099   bool debug;
00100   bool broadcastPackets;
00101   map < int, cStdDev > latencies;
00102   cStdDev latency;
00103   cOutVector latenciesRaw;
00104   Packet packet; // informs the simulation of the number of packets sent and received by this node.
00105   int catPacket;
00106   int hostID;
00107   int headerLength;
00108   BaseWorldUtility* world;
00109 
00110 protected:
00111     // gates
00112   int dataOut;
00113   int dataIn;
00114     int ctrlOut;
00115     int ctrlIn;
00116 
00118    virtual void handleSelfMsg(cMessage *);
00119 
00121   virtual void handleLowerMsg(cMessage *);
00122 
00123   virtual void handleLowerControl(cMessage * msg);
00124 
00125   virtual void handleUpperMsg(cMessage * m) { delete m; }
00126 
00127   virtual void handleUpperControl(cMessage * m) { delete m; }
00128 
00130   virtual void sendData();
00131 
00133   virtual void initializeDistribution(const char*);
00134 
00136   virtual void scheduleNextPacket();
00137 
00143   cStdDev& hostsLatency(int hostAddress);
00144 };
00145 
00146 #endif