IBR-DTNSuite  0.10
Configuration.h
Go to the documentation of this file.
1 /*
2  * Configuration.h
3  *
4  * Copyright (C) 2011 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #ifndef CONFIGURATION_H_
23 #define CONFIGURATION_H_
24 
26 #include "core/Node.h"
28 #include <ibrcommon/Exceptions.h>
30 #include <map>
31 #include <list>
32 #include <ibrcommon/thread/Timer.h>
33 
34 using namespace dtn::net;
35 using namespace dtn::core;
36 using namespace dtn::data;
37 
38 namespace dtn
39 {
40  namespace daemon
41  {
46  {
47  private:
48  Configuration();
49  virtual ~Configuration();
50 
51  public:
53  public:
54  virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf) throw () = 0;
55  };
56 
57  class NetConfig
58  {
59  public:
60  enum NetType
61  {
62  NETWORK_UNKNOWN = 0,
63  NETWORK_TCP = 1,
64  NETWORK_UDP = 2,
65  NETWORK_HTTP = 3,
66  NETWORK_LOWPAN = 4,
67  NETWORK_FILE = 5,
68  NETWORK_DGRAM_UDP = 6,
69  NETWORK_DGRAM_LOWPAN = 7,
70  NETWORK_DGRAM_ETHERNET = 8
71  };
72 
73  NetConfig(std::string name, NetType type, const std::string &url);
74  NetConfig(std::string name, NetType type, const ibrcommon::vinterface &iface, int port);
75  NetConfig(std::string name, NetType type, int port);
76  virtual ~NetConfig();
77 
78  std::string name;
80  std::string url;
82  int mtu;
83  int port;
84  };
85 
87  {
88  };
89 
91  {
92  };
93 
94  static Configuration &getInstance(bool reset = false);
95 
99  void load();
100  void load(string filename);
101 
102  void params(int argc, char *argv[]);
103 
107  std::string getNodename() const;
108 
114  int getTimezone() const;
115 
122  ibrcommon::File getPath(string name) const;
123 
128  bool doAPI() const;
129 
130  Configuration::NetConfig getAPIInterface() const;
131  ibrcommon::File getAPISocket() const;
132 
137  std::string version() const;
138 
143  std::string getStorage() const;
144 
148  bool enableTrafficStats() const;
149 
151  {
152  DEFAULT_ROUTING = 0,
153  EPIDEMIC_ROUTING = 1,
154  FLOOD_ROUTING = 2,
155  PROPHET_ROUTING = 3,
156  NO_ROUTING = 4
157  };
158 
164  dtn::data::Size getLimit(const std::string&) const;
165 
166  class Extension
167  {
168  protected:
169  virtual void load(const ibrcommon::ConfigFile &conf) = 0;
170  };
171 
173  {
174  friend class Configuration;
175  protected:
176  Discovery();
177  virtual ~Discovery();
178  void load(const ibrcommon::ConfigFile &conf);
179 
180  bool _enabled;
181  unsigned int _timeout;
183 
184  public:
185  bool enabled() const;
186  bool announce() const;
187  bool shortbeacon() const;
188  int version() const;
189  const std::set<ibrcommon::vaddress> address() const throw (ParameterNotFoundException);
190  int port() const;
191  unsigned int timeout() const;
192  bool enableCrosslayer() const;
193  };
194 
195  class Debug : public Configuration::Extension
196  {
197  friend class Configuration;
198  protected:
199  Debug();
200  virtual ~Debug();
201  void load(const ibrcommon::ConfigFile &conf);
202 
203  bool _enabled;
204  bool _quiet;
205  int _level;
206 
207  public:
211  int level() const;
212 
216  bool enabled() const;
217 
222  bool quiet() const;
223  };
224 
226  {
227  friend class Configuration;
228  protected:
229  Logger();
230  virtual ~Logger();
231  void load(const ibrcommon::ConfigFile &conf);
232 
233  bool _quiet;
234  unsigned int _options;
237  bool _verbose;
238 
239  public:
244  bool quiet() const;
245 
250  const ibrcommon::File& getLogfile() const;
251 
261  unsigned int options() const;
262 
266  std::ostream &output() const;
267 
271  bool display_timestamps() const;
272 
276  bool verbose() const;
277  };
278 
280  {
281  friend class Configuration;
282  public:
283  /* prophet routing parameters */
285  public:
287  : p_encounter_max(0), p_encounter_first(0), p_first_threshold(0), beta(0), gamma(0), delta(0),
288  time_unit(0), i_typ(0), next_exchange_timeout(0), forwarding_strategy(), gtmx_nf_max(0)
289  { }
290 
292 
296  float beta;
297  float gamma;
298  float delta;
302  std::string forwarding_strategy;
303  unsigned int gtmx_nf_max;
304  };
305  protected:
306  Network();
307  virtual ~Network();
308  void load(const ibrcommon::ConfigFile &conf);
309 
310  std::multimap<std::string, std::string> _static_routes;
311  std::list<Node> _nodes;
312  std::list<NetConfig> _interfaces;
313  std::string _routing;
324  std::set<ibrcommon::vinterface> _internet_devices;
325 
326  public:
330  const std::list<NetConfig>& getInterfaces() const;
331 
335  const std::list<Node>& getStaticNodes() const;
336 
340  const std::multimap<std::string, std::string>& getStaticRoutes() const;
341 
345  RoutingExtension getRoutingExtension() const;
346 
351  bool doForwarding() const;
352 
356  bool getTCPOptionNoDelay() const;
357 
361  dtn::data::Length getTCPChunkSize() const;
362 
366  dtn::data::Timeout getTCPIdleTimeout() const;
367 
371  dtn::data::Timeout getAutoConnect() const;
372 
376  bool doFragmentation() const;
377 
381  ProphetConfig getProphetConfig() const;
382 
386  bool doScheduling() const;
387 
391  std::set<ibrcommon::vinterface> getInternetDevices() const;
392  };
393 
395  {
396  friend class Configuration;
397  private:
398  bool _enabled;
399  bool _tlsEnabled;
400  bool _tlsRequired;
401  bool _tlsOptionalOnBadClock;
402 
403  protected:
404  Security();
405  virtual ~Security();
406  void load(const ibrcommon::ConfigFile &conf);
407 
408  public:
409  bool enabled() const;
410 
417  bool doTLS() const;
418 
424  bool TLSRequired() const;
425 
426  enum Level
427  {
428  SECURITY_LEVEL_NONE = 0,
429  SECURITY_LEVEL_AUTHENTICATED = 1,
430  SECURITY_LEVEL_ENCRYPTED = 2,
431  SECURITY_LEVEL_SIGNED = 4
432  };
433 
437  int getLevel() const;
438 
442  const ibrcommon::File& getPath() const;
443 
447  const ibrcommon::File& getBABDefaultKey() const;
448 
452  const ibrcommon::File& getCertificate() const;
453 
457  const ibrcommon::File& getKey() const;
458 
463  const ibrcommon::File& getTrustedCAPath() const;
464 
469  bool TLSEncryptionDisabled() const;
470 
471  private:
472  // security related files
473  ibrcommon::File _path;
474 
475  // security level
476  int _level;
477 
478  // local BAB key
479  ibrcommon::File _bab_default_key;
480 
481  // TLS certificate
482  ibrcommon::File _cert;
483 
484  // TLS private key
485  ibrcommon::File _key;
486 
487  // TLS trusted CA path
488  ibrcommon::File _trustedCAPath;
489 
490  // TLS encryption disabled?
491  bool _disableEncryption;
492  };
493 
495  {
496  friend class Configuration;
497  private:
498  bool _daemonize;
499  ibrcommon::File _pidfile;
500  bool _kill;
501  dtn::data::Size _threads;
502 
503  protected:
504  Daemon();
505  virtual ~Daemon();
506  void load(const ibrcommon::ConfigFile &conf);
507 
508  public:
509  bool daemonize() const;
510  const ibrcommon::File& getPidFile() const;
511  bool kill_daemon() const;
512  dtn::data::Size getThreads() const;
513  };
514 
516  {
517  friend class Configuration;
518  protected:
519  TimeSync();
520  virtual ~TimeSync();
521  void load(const ibrcommon::ConfigFile &conf);
522 
524  bool _sync;
526  float _sigma;
527  float _psi;
528  float _sync_level;
529 
530  public:
531  bool hasReference() const;
532  bool doSync() const;
533  bool sendDiscoveryAnnouncements() const;
534 
535  float getSigma() const;
536  float getPsi() const;
537  float getSyncLevel() const;
538  };
539 
541  {
542  friend class Configuration;
543  protected:
544  DHT();
545  virtual ~DHT();
546  void load(const ibrcommon::ConfigFile &conf);
547 
548  private:
549  bool _enabled;
550  int _port;
551  string _id;
552  string _ipv4bind;
553  string _ipv6bind;
554  std::vector<string> _bootstrappingdomains;
555  bool _dnsbootstrapping;
556  std::vector<string> _bootstrappingips;
557  string _nodesFilePath;
558  bool _ipv4;
559  bool _ipv6;
560  bool _blacklist;
561  bool _selfannounce;
562  std::vector<int> _portFilter;
563  int _minRating;
564  bool _allowNeighbourToAnnounceMe;
565  bool _allowNeighbourAnnouncement;
566  bool _ignoreDHTNeighbourInformations;
567 
568  public:
572  bool enabled() const;
573 
577  bool randomPort() const;
578 
582  unsigned int getPort() const;
583 
587  string getID() const;
588 
592  bool randomID() const;
593 
597  bool isDNSBootstrappingEnabled() const;
598 
602  std::vector<string> getDNSBootstrappingNames() const;
603 
607  bool isIPBootstrappingEnabled() const;
608 
612  std::vector<string> getIPBootstrappingIPs() const;
613 
617  string getIPv4Binding() const;
618 
622  string getIPv6Binding() const;
623 
631  string getPathToNodeFiles() const;
632 
636  bool isIPv4Enabled() const;
637 
641  bool isIPv6Enabled() const;
642 
646  std::vector<int> getPortFilter() const;
647 
651  bool isBlacklistEnabled() const;
652 
656  bool isSelfAnnouncingEnabled() const;
657 
661  int getMinimumRating() const;
662 
666  bool isNeighbourAnnouncementEnabled() const;
667 
671  bool isNeighbourAllowedToAnnounceMe() const;
672 
682  bool ignoreDHTNeighbourInformations() const;
683  };
684 
686  {
687  friend class Configuration;
688  protected:
689  P2P();
690  virtual ~P2P();
691  void load(const ibrcommon::ConfigFile &conf);
692 
693  std::string _ctrl_path;
694  bool _enabled;
695 
696  public:
697  const std::string getCtrlPath() const;
698  bool enabled() const;
699  };
700 
701  const Configuration::Discovery& getDiscovery() const;
702  const Configuration::Debug& getDebug() const;
703  const Configuration::Logger& getLogger() const;
704  const Configuration::Network& getNetwork() const;
705  const Configuration::Security& getSecurity() const;
706  const Configuration::Daemon& getDaemon() const;
707  const Configuration::TimeSync& getTimeSync() const;
708  const Configuration::DHT& getDHT() const;
709  const Configuration::P2P& getP2P() const;
710 
711  private:
712  ibrcommon::ConfigFile _conf;
715  Configuration::Logger _logger;
716  Configuration::Network _network;
717  Configuration::Security _security;
718  Configuration::Daemon _daemon;
719  Configuration::TimeSync _timesync;
720  Configuration::DHT _dht;
721  Configuration::P2P _p2p;
722 
723  std::string _filename;
724  bool _doapi;
725  };
726  }
727 }
728 
729 #endif /*CONFIGURATION_H_*/