|
1 /* |
|
2 * Copyright 2005-2006 Intel Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifndef _CONNECTIVITY_H_ |
|
18 #define _CONNECTIVITY_H_ |
|
19 |
|
20 #include "SimEventHandler.h" |
|
21 #include <oasys/debug/DebugUtils.h> |
|
22 #include <oasys/debug/Logger.h> |
|
23 #include <oasys/util/StringUtils.h> |
|
24 |
|
25 namespace dtnsim { |
|
26 |
|
27 class Node; |
|
28 |
|
29 |
|
30 /** |
|
31 * Helper struct to store the current connectivity settings |
|
32 * between a pair (or set) of nodes. |
|
33 */ |
|
34 struct ConnState { |
|
35 /** |
|
36 * Default constructor, also implicitly the default connectivity |
|
37 * state. |
|
38 */ |
|
39 ConnState(): open_(true), bw_(100000), latency_(0.01) {} |
|
40 |
|
41 /** |
|
42 * Constructor with explicit settings. |
|
43 */ |
|
44 ConnState(bool open, int bw, int latency) |
|
45 : open_(open), bw_(bw), latency_(latency) {} |
|
46 |
|
47 /** |
|
48 * Utility function to parse a time specification. |
|
49 */ |
|
50 bool parse_time(const char* time_str, double* time); |
|
51 |
|
52 /** |
|
53 * Utility function to fill in the values from a set of options |
|
54 * (e.g. bw=10kbps, latency=10ms). |
|
55 */ |
|
56 bool parse_options(int argc, const char** argv, const char** invalidp); |
|
57 |
|
58 bool open_; |
|
59 u_int64_t bw_; // in bps |
|
60 double latency_; // in seconds |
|
61 }; |
|
62 |
|
63 /** |
|
64 * Base class for the underlying connectivity management between nodes |
|
65 * in the simulation. |
|
66 */ |
|
67 class Connectivity : public oasys::Logger { |
|
68 public: |
|
69 /** |
|
70 * Singleton accessor. |
|
71 */ |
|
72 static Connectivity* instance() |
|
73 { |
|
74 if (!instance_) { |
|
75 ASSERT(type_ != ""); // type must be set; |
|
76 instance_ = create_conn(); |
|
77 } |
|
78 |
|
79 return instance_; |
|
80 } |
|
81 |
|
82 /** |
|
83 * Constructor. |
|
84 */ |
|
85 Connectivity(); |
|
86 |
|
87 /** |
|
88 * Destructor. |
|
89 */ |
|
90 virtual ~Connectivity() {} |
|
91 |
|
92 /** |
|
93 * Get the current connectivity state between two nodes. |
|
94 */ |
|
95 const ConnState* lookup(Node* n1, Node* n2); |
|
96 |
|
97 protected: |
|
98 friend class ConnCommand; |
|
99 |
|
100 /** |
|
101 * The state structures are stored in a table indexed by strings |
|
102 * of the form NODE1,NODE2. Defaults can be set in the config with |
|
103 * a node name of '*' (and are stored in the table as such). |
|
104 */ |
|
105 typedef oasys::StringHashMap<ConnState> StateTable; |
|
106 StateTable state_; |
|
107 |
|
108 /** |
|
109 * Static bootstrap initializer. |
|
110 */ |
|
111 static Connectivity* create_conn(); |
|
112 |
|
113 /** |
|
114 * Set the current connectivity state. |
|
115 */ |
|
116 void set_state(const char* n1, const char* n2, const ConnState& s); |
|
117 |
|
118 static std::string type_; ///< The module type |
|
119 static Connectivity* instance_; ///< Singleton instance |
|
120 }; |
|
121 |
|
122 } // namespace dtnsim |
|
123 |
|
124 #endif /* _CONNECTIVITY_H_ */ |