• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

daemon/src/Configuration.h

Go to the documentation of this file.
00001 #ifndef CONFIGURATION_H_
00002 #define CONFIGURATION_H_
00003 
00004 #include "ibrcommon/data/ConfigFile.h"
00005 #include "core/Node.h"
00006 #include "routing/StaticRoutingExtension.h"
00007 #include <ibrcommon/Exceptions.h>
00008 #include <ibrcommon/net/vinterface.h>
00009 
00010 using namespace dtn::net;
00011 using namespace dtn::core;
00012 using namespace dtn::data;
00013 
00014 namespace dtn
00015 {
00016         namespace daemon
00017         {
00021                 class Configuration
00022                 {
00023                 private:
00024                         Configuration();
00025                         virtual ~Configuration();
00026 
00027                 public:
00028                         class NetConfig
00029                         {
00030                         public:
00031                                 enum NetType
00032                                 {
00033                                         NETWORK_UNKNOWN = 0,
00034                                         NETWORK_TCP = 1,
00035                                         NETWORK_UDP = 2,
00036                                         NETWORK_HTTP = 3,
00037                                         NETWORK_LOWPAN = 4
00038                                 };
00039 
00040                                 NetConfig(std::string name, NetType type, const std::string &url, bool discovery = true);
00041                                 NetConfig(std::string name, NetType type, const ibrcommon::vaddress &address, int port, bool discovery = true);
00042                                 NetConfig(std::string name, NetType type, const ibrcommon::vinterface &iface, int port, bool discovery = true);
00043                                 NetConfig(std::string name, NetType type, int port, bool discovery = true);
00044                                 virtual ~NetConfig();
00045 
00046                                 std::string name;
00047                                 NetType type;
00048                                 std::string url;
00049                                 ibrcommon::vinterface interface;
00050                                 ibrcommon::vaddress address;
00051                                 int port;
00052                                 bool discovery;
00053                         };
00054 
00055                         class ParameterNotSetException : ibrcommon::Exception
00056                         {
00057                         };
00058 
00059                         class ParameterNotFoundException : ibrcommon::Exception
00060                         {
00061                         };
00062 
00063                         static Configuration &getInstance();
00064 
00068                         void load();
00069                         void load(string filename);
00070 
00071                         void params(int argc, char *argv[]);
00072 
00076                         string getNodename();
00077 
00083                         int getTimezone();
00084 
00091                         ibrcommon::File getPath(string name);
00092 
00099                         unsigned int getUID();
00100 
00107                         unsigned int getGID();
00108 
00113                         bool doAPI();
00114 
00115                         Configuration::NetConfig getAPIInterface();
00116                         ibrcommon::File getAPISocket();
00117 
00122                         std::string version();
00123 
00130                         std::string getNotifyCommand();
00131 
00136                         std::string getStorage() const;
00137 
00138                         enum RoutingExtension
00139                         {
00140                                 DEFAULT_ROUTING = 0,
00141                                 EPIDEMIC_ROUTING = 1,
00142                                 FLOOD_ROUTING = 2
00143                         };
00144 
00150                         size_t getLimit(std::string);
00151 
00152                         class Extension
00153                         {
00154                         protected:
00155                                 virtual void load(const ibrcommon::ConfigFile &conf) = 0;
00156                         };
00157 
00158                         class Discovery : public Configuration::Extension
00159                         {
00160                                 friend class Configuration;
00161                         protected:
00162                                 Discovery();
00163                                 virtual ~Discovery();
00164                                 void load(const ibrcommon::ConfigFile &conf);
00165 
00166                                 bool _enabled;
00167                                 unsigned int _timeout;
00168 
00169                         public:
00170                                 bool enabled() const;
00171                                 bool announce() const;
00172                                 bool shortbeacon() const;
00173                                 char version() const;
00174                                 const ibrcommon::vaddress address() const throw (ParameterNotFoundException);
00175                                 int port() const;
00176                                 unsigned int timeout() const;
00177                         };
00178 
00179                         class Statistic : public Configuration::Extension
00180                         {
00181                                 friend class Configuration;
00182                         protected:
00183                                 Statistic();
00184                                 virtual ~Statistic();
00185                                 void load(const ibrcommon::ConfigFile &conf);
00186 
00187                         public:
00191                                 bool enabled() const;
00192 
00196                                 ibrcommon::File logfile() const throw (ParameterNotSetException);
00197 
00201                                 std::string type() const;
00202 
00206                                 unsigned int interval() const;
00207 
00211                                 std::string address() const;
00212 
00216                                 unsigned int port() const;
00217                         };
00218 
00219                         class Debug : public Configuration::Extension
00220                         {
00221                                 friend class Configuration;
00222                         protected:
00223                                 Debug();
00224                                 virtual ~Debug();
00225                                 void load(const ibrcommon::ConfigFile &conf);
00226 
00227                                 bool _enabled;
00228                                 bool _quiet;
00229                                 int _level;
00230 
00231                         public:
00235                                 int level() const;
00236 
00240                                 bool enabled() const;
00241 
00246                                 bool quiet() const;
00247                         };
00248 
00249                         class Logger : public Configuration::Extension
00250                         {
00251                                 friend class Configuration;
00252                         protected:
00253                                 Logger();
00254                                 virtual ~Logger();
00255                                 void load(const ibrcommon::ConfigFile &conf);
00256 
00257                                 bool _quiet;
00258                                 unsigned int _options;
00259                                 bool _timestamps;
00260 
00261                         public:
00266                                 bool quiet() const;
00267 
00277                                 unsigned int options() const;
00278 
00282                                 std::ostream &output() const;
00283 
00287                                 bool display_timestamps() const;
00288                         };
00289 
00290                         class Network :  public Configuration::Extension
00291                         {
00292                                 friend class Configuration;
00293                         protected:
00294                                 Network();
00295                                 virtual ~Network();
00296                                 void load(const ibrcommon::ConfigFile &conf);
00297 
00298                                 std::list<dtn::routing::StaticRoutingExtension::StaticRoute> _static_routes;
00299                                 std::list<Node> _nodes;
00300                                 std::list<NetConfig> _interfaces;
00301                                 std::string _routing;
00302                                 bool _forwarding;
00303                                 bool _tcp_nodelay;
00304                                 size_t _tcp_chunksize;
00305                                 ibrcommon::vinterface _default_net;
00306                                 bool _use_default_net;
00307 
00308                         public:
00312                                 const std::list<NetConfig>& getInterfaces() const;
00313 
00317                                 const std::list<Node>& getStaticNodes() const;
00318 
00322                                 const list<dtn::routing::StaticRoutingExtension::StaticRoute>& getStaticRoutes() const;
00323 
00327                                 RoutingExtension getRoutingExtension() const;
00328 
00333                                 bool doForwarding() const;
00334 
00338                                 bool getTCPOptionNoDelay() const;
00339 
00343                                 size_t getTCPChunkSize() const;
00344                         };
00345 
00346                         class Security : public Configuration::Extension
00347                         {
00348                                 friend class Configuration;
00349                         private:
00350                                 bool _enabled;
00351 
00352                         protected:
00353                                 Security();
00354                                 virtual ~Security();
00355                                 void load(const ibrcommon::ConfigFile &conf);
00356 
00357                         public:
00358                                 bool enabled() const;
00359 
00360 #ifdef WITH_BUNDLE_SECURITY
00361                                 enum Level
00362                                 {
00363                                         SECURITY_LEVEL_NONE = 0,
00364                                         SECURITY_LEVEL_AUTHENTICATED = 1,
00365                                         SECURITY_LEVEL_ENCRYPTED = 2
00366                                 };
00367 
00368                                 Level getLevel() const;
00369 
00370                                 const ibrcommon::File& getPath() const;
00371 
00372                                 const ibrcommon::File& getCA() const;
00373 
00374                                 const ibrcommon::File& getKey() const;
00375 
00376                                 const ibrcommon::File& getBABDefaultKey() const;
00377 
00378                         private:
00379                                 ibrcommon::File _path;
00380                                 Level _level;
00381                                 ibrcommon::File _ca;
00382                                 ibrcommon::File _key;
00383                                 ibrcommon::File _bab_default_key;
00384 #endif
00385                         };
00386 
00387                         class Daemon : public Configuration::Extension
00388                         {
00389                                 friend class Configuration;
00390                         private:
00391                                 bool _daemonize;
00392                                 ibrcommon::File _pidfile;
00393                                 bool _kill;
00394 
00395                         protected:
00396                                 Daemon();
00397                                 virtual ~Daemon();
00398                                 void load(const ibrcommon::ConfigFile &conf);
00399 
00400                         public:
00401                                 bool daemonize() const;
00402                                 const ibrcommon::File& getPidFile() const;
00403                                 bool kill_daemon() const;
00404                         };
00405 
00406                         const Configuration::Discovery& getDiscovery() const;
00407                         const Configuration::Statistic& getStatistic() const;
00408                         const Configuration::Debug& getDebug() const;
00409                         const Configuration::Logger& getLogger() const;
00410                         const Configuration::Network& getNetwork() const;
00411                         const Configuration::Security& getSecurity() const;
00412                         const Configuration::Daemon& getDaemon() const;
00413 
00414                 private:
00415                         ibrcommon::ConfigFile _conf;
00416                         Configuration::Discovery _disco;
00417                         Configuration::Statistic _stats;
00418                         Configuration::Debug _debug;
00419                         Configuration::Logger _logger;
00420                         Configuration::Network _network;
00421                         Configuration::Security _security;
00422                         Configuration::Daemon _daemon;
00423 
00424                         std::string _filename;
00425                         bool _doapi;
00426                 };
00427         }
00428 }
00429 
00430 #endif /*CONFIGURATION_H_*/

Generated on Wed Mar 30 2011 11:11:49 for IBR-DTNSuite by  doxygen 1.7.1