Aggregation.h

00001 /***************************************************************************
00002  * file:        Aggregation.h
00003  *
00004  * author:      Jerome Rousselot <jerome.rousselot@csem.ch>
00005  *
00006  * copyright:   (C) 2010 CSEM SA, Neuchatel, Switzerland.
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  * description: this class aggregates the packets received from the application
00017  * layer and separates packet emissions by a time InterPacketDelay.
00018  ***************************************************************************/
00019 
00020 
00021 #ifndef AGGREGATION_H_
00022 #define AGGREGATION_H_
00023 
00024 #include "BaseLayer.h"
00025 #include "ApplPkt_m.h"
00026 #include <omnetpp.h>
00027 #include <map>
00028 #include <vector>
00029 #include <utility>
00030 
00031 
00032 using namespace std;
00033 
00039 class Aggregation: public BaseLayer {
00040 public:
00041   Aggregation();
00042   virtual void initialize(int);
00043   virtual void finish();
00044 protected:
00045       virtual void handleSelfMsg(cMessage* msg);
00046       virtual void handleUpperMsg(cMessage *msg);
00047       virtual void handleLowerMsg(cMessage *msg);
00048       virtual void handleLowerControl(cMessage *msg);
00049       virtual void handleUpperControl(cMessage *msg);
00050 private:
00051       // this type is used to store, for a network destination, the time
00052       // at which a packet was last sent to it, and the packets currently
00053       // queued for aggregation.
00054       typedef pair<simtime_t, list<ApplPkt*> > destInfo;
00055 
00056       // this map associates to each known netwok address
00057       // the time at which a packet was last sent to it, and a vector
00058       // of packets currently queued for it (waiting aggregation).
00059       map<int, destInfo> destInfos;
00060 
00061       // This message is used as a timer to perform aggregation
00062       cMessage* aggregationTimer;
00063 
00064       // This is the minimum time between two transmissions to a same network destination
00065       simtime_t interPacketDelay;
00066 
00067       // maximum number of packets to aggregate into a single unit.
00068       int nbMaxPacketsPerAggregation;
00069 
00070       // returns true if we can send now to this destination
00071       virtual bool isOkToSendNow(int dest);
00072 
00073       // sends aggregated packets to destination now
00074       void sendAggregatedPacketNow(int dest);
00075 
00076 
00077       // counters
00078       long nbAggrPktSentDown;
00079       long nbAggrPktReceived;
00080 };
00081 
00082 #endif /* AGGREGATION_H_ */