User Manual, Developers Guide and API Documentation

TrafficSpec.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <WNS/distribution/Distribution.hpp>
00029 #include <WNS/pyconfig/View.hpp>
00030 #include <WNS/pyconfig/Parser.hpp>
00031 
00032 
00033 #ifndef WNS_MARKOVCHAIN_TRAFFICSPEC_HPP
00034 #define WNS_MARKOVCHAIN_TRAFFICSPEC_HPP
00035 namespace wns { namespace markovchain {
00036 
00044     class TrafficSpec {
00045     public:
00049         TrafficSpec()
00050         {
00051         }
00052 
00058         TrafficSpec(std::string _iatpdf,
00059                 double _arg0,
00060                 double _arg1) :
00061             interArrivalTimeDistribution(NULL),
00062             packetSizeDistribution(NULL),
00063             meanRate(0.0)
00064         {
00065             wns::pyconfig::Parser config;
00066             std::string iatDistName = convertGdfDistributionName2wns(_iatpdf, _arg0, _arg1);
00067             config.loadString(
00068                 "import openwns.distribution\n"
00069                 "packetSize = openwns.distribution.Fixed(1024)\n" // there's no better way now
00070                 "iat = openwns.distribution." + iatDistName + "\n"
00071                 );
00072                 initializeGenerators(config);
00073         }
00074 
00078         TrafficSpec(const wns::pyconfig::View& pyco) :
00079             interArrivalTimeDistribution(NULL),
00080             packetSizeDistribution(NULL),
00081             meanRate(0.0)
00082         {
00083             initializeGenerators(pyco);
00084         }
00085 
00089         ~TrafficSpec()
00090         {
00091         }
00092 
00096         wns::distribution::Distribution*
00097         getInterArrivalTimeDistribution() const
00098         {
00099             return interArrivalTimeDistribution;
00100         }
00101 
00105         wns::distribution::Distribution*
00106         getPacketSizeDistribution() const
00107         {
00108             return packetSizeDistribution;
00109         }
00110 
00112         double getMeanRate() const
00113         {
00114             return meanRate; // without scaling
00115         }
00116 
00117     private:
00118 
00122         std::string
00123         stringify(double x) const
00124         {
00125             std::ostringstream o;
00126             o << x;
00127             return o.str();
00128         }
00129 
00135         std::string
00136         convertGdfDistributionName2wns(std::string _pdf, double _arg0, double _arg1) const
00137         {
00138             std::string DistName;
00139             if (_pdf == "constant") {
00140                 DistName = "Fixed(" + stringify(_arg0) + ")";
00141             } else if (_pdf == "exponential") {
00142                 DistName = "NegExp(" + stringify(_arg0) +")";
00143             } else if (_pdf == "uniform") {
00144                 DistName = "Uniform(" + stringify(_arg0) + "," + stringify(_arg1) +")";
00145             } else { // WNS name allowed in gdf file
00146                 DistName = _pdf + "(" + stringify(_arg0) + ")";
00147             }
00148             return DistName;
00149         }
00150 
00151         friend class MarkovContinuousTimeTrafficTest;
00152         friend class MarkovDiscreteTimeTrafficTest;
00153 
00159         void
00160         initializeGenerators(const wns::pyconfig::View& pyco)
00161         {
00162             wns::pyconfig::View iatConfig(pyco, "iat");
00163             std::string iatName = iatConfig.get<std::string>("__plugin__");
00164             interArrivalTimeDistribution =
00165                 wns::distribution::DistributionFactory::creator(iatName)->create(iatConfig);
00166             wns::pyconfig::View packetConfig(pyco, "packetSize");
00167             std::string psName = packetConfig.get<std::string>("__plugin__");
00168             packetSizeDistribution =
00169                 wns::distribution::DistributionFactory::creator(psName)->create(packetConfig);
00170             //std::cout << "iat=" << interArrivalTimeDistribution->paramString()
00171             //    << ", packetSize=" <<
00172             //    packetSizeDistribution->paramString() << std::endl;
00173             double meanIAT;
00174             meanIAT = 
00175                 dynamic_cast<wns::distribution::IHasMean*>(interArrivalTimeDistribution)
00176                     ->getMean();
00177             assure(meanIAT>0.0,"zero meanIAT");
00178             meanRate =  
00179                 dynamic_cast<wns::distribution::IHasMean*>(packetSizeDistribution)
00180                     ->getMean()/meanIAT;
00181         }
00182 
00183     protected:
00185         wns::distribution::Distribution* interArrivalTimeDistribution;
00187         wns::distribution::Distribution* packetSizeDistribution;
00189         double meanRate; // without scaling
00190     }; // class TrafficSpec
00191 
00192 }//markovchain
00193 }//wns
00194 #endif // WNS_MARKOVCHAIN_TRAFFICSPEC_HPP
00195 
00196 

Generated on Sat May 26 03:31:45 2012 for openWNS by  doxygen 1.5.5