|
1 /* |
|
2 * Copyright 2004-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 _CONVERGENCE_LAYER_H_ |
|
18 #define _CONVERGENCE_LAYER_H_ |
|
19 |
|
20 #include <string> |
|
21 #include <vector> |
|
22 #include <oasys/util/Singleton.h> |
|
23 #include <oasys/serialize/Serialize.h> |
|
24 |
|
25 #include "contacts/Link.h" |
|
26 #include "contacts/Contact.h" |
|
27 #include "contacts/Interface.h" |
|
28 #include "contacts/NamedAttribute.h" |
|
29 |
|
30 // forward declaration |
|
31 namespace oasys { |
|
32 class StringBuffer; |
|
33 } |
|
34 |
|
35 namespace dtn { |
|
36 |
|
37 /** |
|
38 * The abstract interface for a convergence layer. |
|
39 */ |
|
40 class ConvergenceLayer : public oasys::Logger { |
|
41 public: |
|
42 /** |
|
43 * Constructor. |
|
44 */ |
|
45 ConvergenceLayer(const char* classname, |
|
46 const char* name) |
|
47 : Logger(classname, "/dtn/cl/%s", name), |
|
48 name_(name) |
|
49 { |
|
50 } |
|
51 |
|
52 /** |
|
53 * Destructor. |
|
54 */ |
|
55 virtual ~ConvergenceLayer(); |
|
56 |
|
57 /** |
|
58 * Set CL-specific options. |
|
59 */ |
|
60 virtual bool set_cla_parameters(AttributeVector ¶ms); |
|
61 |
|
62 /** |
|
63 * Set default interface options. |
|
64 */ |
|
65 virtual bool set_interface_defaults(int argc, const char* argv[], |
|
66 const char** invalidp); |
|
67 |
|
68 /** |
|
69 * Set default link options. |
|
70 */ |
|
71 virtual bool set_link_defaults(int argc, const char* argv[], |
|
72 const char** invalidp); |
|
73 |
|
74 /** |
|
75 * Bring up a new interface. |
|
76 */ |
|
77 virtual bool interface_up(Interface* iface, |
|
78 int argc, const char* argv[]); |
|
79 |
|
80 /** |
|
81 * Bring down the interface. |
|
82 */ |
|
83 virtual bool interface_down(Interface* iface); |
|
84 |
|
85 /** |
|
86 * Dump out CL specific interface information. |
|
87 */ |
|
88 virtual void dump_interface(Interface* iface, oasys::StringBuffer* buf); |
|
89 |
|
90 /** |
|
91 * Create any CL-specific components of the Link. |
|
92 */ |
|
93 virtual bool init_link(const LinkRef& link, int argc, const char* argv[]); |
|
94 |
|
95 /** |
|
96 * Delete any CL-specific components of the link (requests pertaining |
|
97 * to this link must be ignored gracefully by the CL in the future). |
|
98 */ |
|
99 virtual void delete_link(const LinkRef& link); |
|
100 |
|
101 /** |
|
102 * Dump out CL specific link information. |
|
103 */ |
|
104 virtual void dump_link(const LinkRef& link, oasys::StringBuffer* buf); |
|
105 |
|
106 /** |
|
107 * Post-initialization, parse any CL-specific options for the link. |
|
108 */ |
|
109 virtual bool reconfigure_link(const LinkRef& link, |
|
110 int argc, const char* argv[]); |
|
111 |
|
112 virtual void reconfigure_link(const LinkRef& link, |
|
113 AttributeVector& params); |
|
114 |
|
115 /** |
|
116 * Open a new contact for the given link. The implementation will |
|
117 * create a new Contact object (or find one that already exists), |
|
118 * establish any CL specific connections, then post a |
|
119 * ContactUpEvent when the contact is successfully initiated. |
|
120 */ |
|
121 virtual bool open_contact(const ContactRef& contact) = 0; |
|
122 |
|
123 /** |
|
124 * Close the open contact. |
|
125 * |
|
126 * Mainly used to clean the state that is associated with this |
|
127 * contact. This is called by the link->close() function. |
|
128 * |
|
129 * Note that this function should NOT post a ContactDownEvent, as |
|
130 * this function is only called to clean up the contact state |
|
131 * after it has been closed (i.e. after the ContactDownEvent has |
|
132 * been generated by some other part of the system). |
|
133 */ |
|
134 virtual bool close_contact(const ContactRef& contact); |
|
135 |
|
136 /** |
|
137 * Notify the convergence layer that a bundle was queued on the |
|
138 * link. |
|
139 * |
|
140 * In some cases (e.g. TCP) this just kicks the other thread to |
|
141 * notice that there are bundles to send out. In others (e.g. UDP) |
|
142 * there is no per-contact thread, so this callback is used to |
|
143 * send the bundle. |
|
144 */ |
|
145 virtual void bundle_queued(const LinkRef& link, const BundleRef& bundle) = 0; |
|
146 |
|
147 /** |
|
148 * Try to cancel transmission of a given bundle on the link. |
|
149 */ |
|
150 virtual void cancel_bundle(const LinkRef& link, const BundleRef& bundle); |
|
151 |
|
152 /** |
|
153 * Report if the given endpoint is reachable via the given interface. |
|
154 */ |
|
155 virtual void is_eid_reachable(const std::string& query_id, |
|
156 Interface* iface, |
|
157 const std::string& endpoint); |
|
158 |
|
159 /** |
|
160 * Report the values of the given link attributes. |
|
161 */ |
|
162 virtual void query_link_attributes(const std::string& query_id, |
|
163 const LinkRef& link, |
|
164 const AttributeNameVector& attributes); |
|
165 |
|
166 /** |
|
167 * Report the values of the given interface attributes. |
|
168 */ |
|
169 virtual void query_iface_attributes(const std::string& query_id, |
|
170 Interface* iface, |
|
171 const AttributeNameVector& attributes); |
|
172 |
|
173 /** |
|
174 * Report the values of the convergence layer parameters. |
|
175 */ |
|
176 virtual void query_cla_parameters(const std::string& query_id, |
|
177 const AttributeNameVector& parameters); |
|
178 |
|
179 /** |
|
180 * Perform any necessary shutdown procedures. |
|
181 */ |
|
182 virtual void shutdown() { } |
|
183 |
|
184 /** |
|
185 * Boot-time initialization and registration of statically defined |
|
186 * convergence layers. |
|
187 */ |
|
188 static void init_clayers(); |
|
189 static void add_clayer(ConvergenceLayer* cl); |
|
190 |
|
191 /** |
|
192 * Find the appropriate convergence layer for the given |
|
193 * string. |
|
194 */ |
|
195 static ConvergenceLayer* find_clayer(const char* proto); |
|
196 |
|
197 /** |
|
198 * Shutdown all registerd convergence layers. |
|
199 */ |
|
200 static void shutdown_clayers(); |
|
201 |
|
202 /** |
|
203 * Accessor for the convergence layer name. |
|
204 */ |
|
205 const char* name() { return name_; } |
|
206 |
|
207 /** |
|
208 * Magic number used for DTN convergence layers |
|
209 */ |
|
210 static const u_int32_t MAGIC = 0x64746e21; //'DTN!' |
|
211 |
|
212 protected: |
|
213 /** |
|
214 * The unique name of this convergence layer. |
|
215 */ |
|
216 const char* name_; |
|
217 |
|
218 }; |
|
219 |
|
220 /** |
|
221 * Use a singleton vector to enumerate the convergence layers that |
|
222 * are currently implemented. |
|
223 */ |
|
224 class CLVector : public oasys::Singleton<CLVector>, |
|
225 public std::vector<ConvergenceLayer*> { |
|
226 public: |
|
227 virtual ~CLVector(); |
|
228 }; |
|
229 |
|
230 /** |
|
231 * Abstract base class for convergence layer specific state stored in |
|
232 * an interface / contact / link. |
|
233 */ |
|
234 class CLInfo : public oasys::SerializableObject { |
|
235 public: |
|
236 virtual ~CLInfo() {} |
|
237 |
|
238 /** |
|
239 * Virtual from SerializableObject |
|
240 */ |
|
241 virtual void serialize( oasys::SerializeAction *) {} |
|
242 }; |
|
243 |
|
244 } // namespace dtn |
|
245 |
|
246 #endif /* _CONVERGENCE_LAYER_H_ */ |