|
24 |
|
24 |
|
25 |
#define NSC_VERSION 0x000500 |
25 |
#define NSC_VERSION 0x000500 |
26 |
|
26 |
|
|
|
27 |
/** |
28 |
* \ingroup nsctcp |
29 |
* \brief Struct interface to NSC stack |
30 |
*/ |
27 |
struct INetStack |
31 |
struct INetStack |
28 |
{ |
32 |
{ |
29 |
virtual ~INetStack() {} |
33 |
virtual ~INetStack() {} |
30 |
|
34 |
|
|
|
35 |
/** |
36 |
* \brief Initialize the stack |
37 |
* \param hz timer_interrupt frequency |
38 |
*/ |
31 |
virtual void init (int hz) = 0; |
39 |
virtual void init (int hz) = 0; |
32 |
|
40 |
|
|
|
41 |
/** |
42 |
* \brief Deliver complete packet to the NSC network stack |
43 |
* \param if_id interface ID |
44 |
* \param data data |
45 |
* \param datalen data length |
46 |
*/ |
33 |
virtual void if_receive_packet (int if_id, const void *data, int datalen) = 0; |
47 |
virtual void if_receive_packet (int if_id, const void *data, int datalen) = 0; |
34 |
|
48 |
/** |
|
|
49 |
* \brief Send complete packet to the NSC network stack |
50 |
* \param data data |
51 |
* \param datalen data length |
52 |
*/ |
35 |
virtual void if_send_packet (const void *data, int datalen) = 0; |
53 |
virtual void if_send_packet (const void *data, int datalen) = 0; |
|
|
54 |
/** |
55 |
* \brief Signal the completion of send procedure to the NSC network stack |
56 |
* \param if_id interface ID |
57 |
*/ |
36 |
virtual void if_send_finish (int if_id) = 0; |
58 |
virtual void if_send_finish (int if_id) = 0; |
37 |
|
59 |
|
|
|
60 |
/** |
61 |
* \brief Attach an interface to the stack |
62 |
* \param addr address |
63 |
* \param mask network mask |
64 |
* \param mtu MTU |
65 |
*/ |
38 |
virtual void if_attach (const char *addr, const char *mask, int mtu) = 0; |
66 |
virtual void if_attach (const char *addr, const char *mask, int mtu) = 0; |
|
|
67 |
/** |
68 |
* \brief Add a default gateway to the interface |
69 |
* \param addr gateway address |
70 |
*/ |
39 |
virtual void add_default_gateway (const char *addr) = 0; |
71 |
virtual void add_default_gateway (const char *addr) = 0; |
40 |
|
72 |
|
41 |
/** Purely for debugging/diagnostic purposes. This returns the internal id |
73 |
/** |
42 |
* of the stack instance. |
74 |
* \brief Returns the internal id of the stack instance. |
|
|
75 |
* |
76 |
* Purely for debugging/diagnostic purposes. |
77 |
* \return internal stack id |
43 |
*/ |
78 |
*/ |
44 |
virtual int get_id () = 0; |
79 |
virtual int get_id () = 0; |
45 |
|
80 |
|
46 |
/** Should return a short one-word name of the stack. Eg. Linux 2.4.x -> |
81 |
/** |
|
|
82 |
* \brief Return a short one-word name of the stack |
83 |
* |
84 |
* Should return a short one-word name of the stack. Eg. Linux 2.4.x -> |
47 |
* linux24, FreeBSD 5.x -> freebsd5. This can be used to identify output |
85 |
* linux24, FreeBSD 5.x -> freebsd5. This can be used to identify output |
48 |
* from a stack, for example a packet trace file. */ |
86 |
* from a stack, for example a packet trace file. |
|
|
87 |
* \return short one-word name of the stack |
88 |
*/ |
49 |
virtual const char *get_name () = 0; |
89 |
virtual const char *get_name () = 0; |
50 |
|
90 |
|
51 |
/** This is used so the simulator can call the stack timer_interrupt function |
91 |
/** |
|
|
92 |
* \brief Get the timer_interrupt frequency |
93 |
* |
94 |
* This is used so the simulator can call the stack timer_interrupt function |
52 |
* the correct amount of times per second. For example, lwip has a hz of 10, |
95 |
* the correct amount of times per second. For example, lwip has a hz of 10, |
53 |
* which it returns here to say that it's timer_interrupt should be called |
96 |
* which it returns here to say that it's timer_interrupt should be called |
54 |
* 10 times a second. FreeBSD uses 100, as does Linux 2.4, while Linux 2.6 |
97 |
* 10 times a second. FreeBSD uses 100, as does Linux 2.4, while Linux 2.6 |
55 |
* uses 1000. (This is often configurable in the kernel in question, also.) |
98 |
* uses 1000. (This is often configurable in the kernel in question, also.) |
|
|
99 |
* |
100 |
* \return frequency |
56 |
*/ |
101 |
*/ |
57 |
virtual int get_hz () = 0; |
102 |
virtual int get_hz () = 0; |
58 |
|
103 |
|
|
|
104 |
/** |
105 |
* \brief The stack timer_interrupt function |
106 |
*/ |
59 |
virtual void timer_interrupt () = 0; |
107 |
virtual void timer_interrupt () = 0; |
|
|
108 |
|
109 |
/** |
110 |
* \brief Increment the time ticks |
111 |
*/ |
60 |
virtual void increment_ticks () = 0; |
112 |
virtual void increment_ticks () = 0; |
61 |
|
113 |
|
|
|
114 |
/** |
115 |
* \brief Set the buffer size |
116 |
*/ |
62 |
virtual void buffer_size (int size) = 0; |
117 |
virtual void buffer_size (int size) = 0; |
63 |
|
118 |
|
|
|
119 |
/** |
120 |
* \brief Create a new UDP socket |
121 |
*/ |
64 |
virtual struct INetDatagramSocket *new_udp_socket () { return NULL; } |
122 |
virtual struct INetDatagramSocket *new_udp_socket () { return NULL; } |
|
|
123 |
/** |
124 |
* \brief Create a new TCP socket |
125 |
*/ |
65 |
virtual struct INetStreamSocket *new_tcp_socket () { return NULL; } |
126 |
virtual struct INetStreamSocket *new_tcp_socket () { return NULL; } |
|
|
127 |
/** |
128 |
* \brief Create a new SCTP socket |
129 |
*/ |
66 |
virtual struct INetStreamSocket *new_sctp_socket () { return NULL; } |
130 |
virtual struct INetStreamSocket *new_sctp_socket () { return NULL; } |
67 |
|
131 |
|
68 |
// The following I've made optional to implement for now. Eases |
132 |
// The following I've made optional to implement for now. Eases |
69 |
// integration of new features. |
133 |
// integration of new features. |
|
|
134 |
/** |
135 |
* \brief use sysctl to modify system parameters |
136 |
* \param sysctl_name name of the parameter to modify |
137 |
* \param oldval old value |
138 |
* \param oldlenp old value length |
139 |
* \param newval new value |
140 |
* \param newlen new value length |
141 |
* \returns |
142 |
*/ |
70 |
virtual int sysctl (const char *sysctl_name, void *oldval, size_t *oldlenp, |
143 |
virtual int sysctl (const char *sysctl_name, void *oldval, size_t *oldlenp, |
71 |
void *newval, size_t newlen) |
144 |
void *newval, size_t newlen) |
72 |
{ |
145 |
{ |
|
77 |
// to convert the string-value to something that the stack can handle. |
150 |
// to convert the string-value to something that the stack can handle. |
78 |
// The idea here is that this is a front-end to the sysctl(2) call, |
151 |
// The idea here is that this is a front-end to the sysctl(2) call, |
79 |
// much like the sysctl(8) program. |
152 |
// much like the sysctl(8) program. |
|
|
153 |
/** |
154 |
* \brief Set system parameters using sysctl |
155 |
* \param name name of the parameter to modify |
156 |
* \param value new value |
157 |
* \returns |
158 |
*/ |
80 |
virtual int sysctl_set (const char *name, const char *value) |
159 |
virtual int sysctl_set (const char *name, const char *value) |
81 |
{ |
160 |
{ |
82 |
return -1; |
161 |
return -1; |
|
85 |
// same as above, cradle code is expected to convert the sysctl value |
164 |
// same as above, cradle code is expected to convert the sysctl value |
86 |
// into a string. |
165 |
// into a string. |
87 |
// returns length of the string in value, i.e. retval > len: 'output truncated'. |
166 |
// returns length of the string in value, i.e. retval > len: 'output truncated'. |
|
|
167 |
/** |
168 |
* \brief Get system parameters using sysctl |
169 |
* \param name name of the parameter to modify |
170 |
* \param value value |
171 |
* \param len value length |
172 |
* \returns length of the string in value, i.e. retval > len: 'output truncated'. |
173 |
*/ |
88 |
virtual int sysctl_get (const char *name, char *value, size_t len) |
174 |
virtual int sysctl_get (const char *name, char *value, size_t len) |
89 |
{ |
175 |
{ |
90 |
return -1; |
176 |
return -1; |
91 |
} |
177 |
} |
92 |
|
178 |
|
93 |
// this tells the cradle code to put the name of sysctl number 'idx' |
179 |
/** |
94 |
// into name[]. |
180 |
* \brief Tell the cradle code to put the name of sysctl number 'idx' into name[]. |
95 |
// The idea is that this can be used to get a list of all available sysctls: |
181 |
* |
96 |
// char buf[256] |
182 |
* The idea is that this can be used to get a list of all available sysctls: |
97 |
// for (i=0; sysctl_getnum(i, buf, sizeof(buf)) > 0 ;i++) |
183 |
* \verbatim |
98 |
// puts(buf); |
184 |
char buf[256] |
99 |
// returns -1 if idx is out of range and the length of the sysctl name otherwise. |
185 |
for (i=0; sysctl_getnum(i, buf, sizeof(buf)) > 0 ;i++) |
|
|
186 |
puts(buf); |
187 |
\endverbatim |
188 |
* |
189 |
* \param idx index |
190 |
* \param name sysctl name |
191 |
* \param len sysctl length |
192 |
* \returns -1 if idx is out of range and the length of the sysctl name otherwise. |
193 |
*/ |
100 |
virtual int sysctl_getnum (size_t idx, char *name, size_t len) |
194 |
virtual int sysctl_getnum (size_t idx, char *name, size_t len) |
101 |
{ |
195 |
{ |
102 |
return -1; |
196 |
return -1; |
103 |
} |
197 |
} |
104 |
|
198 |
|
|
|
199 |
/** |
200 |
* \brief Show the NSC configuration |
201 |
*/ |
105 |
virtual void show_config () |
202 |
virtual void show_config () |
106 |
{ |
203 |
{ |
107 |
; |
204 |
; |
108 |
} |
205 |
} |
109 |
|
206 |
|
110 |
/* Optional functions used to get and set variables for this stack */ |
207 |
/** |
|
|
208 |
* \brief Optional function to get variables for this stack |
209 |
* \param var the variable |
210 |
* \param result the result |
211 |
* \param result_len result length |
212 |
* \returns true on success |
213 |
*/ |
111 |
virtual bool get_var (const char *var, char *result, int result_len) |
214 |
virtual bool get_var (const char *var, char *result, int result_len) |
112 |
{ |
215 |
{ |
113 |
return false; |
216 |
return false; |
114 |
} |
217 |
} |
115 |
|
218 |
|
|
|
219 |
/** |
220 |
* \brief Optional function to set variables for this stack |
221 |
* \param var the variable |
222 |
* \param val the new value |
223 |
* \returns true on success |
224 |
*/ |
116 |
virtual bool set_var (const char *var, const char *val) |
225 |
virtual bool set_var (const char *var, const char *val) |
117 |
{ |
226 |
{ |
118 |
return false; |
227 |
return false; |
119 |
} |
228 |
} |
120 |
|
229 |
|
121 |
/** The level of debugging or diagnostic information to print out. This |
230 |
/** |
122 |
* normally means kernel messages printed out during initialisation but |
231 |
* \brief Set the level of debugging or diagnostic information to print out. |
123 |
* may also include extra debugging messages that are part of NSC. */ |
232 |
* |
|
|
233 |
* This normally means kernel messages printed out during initialisation but |
234 |
* may also include extra debugging messages that are part of NSC. |
235 |
* |
236 |
* \param level debugging/diagnostic level |
237 |
*/ |
124 |
virtual void set_diagnostic (int level) {} |
238 |
virtual void set_diagnostic (int level) {} |
125 |
|
239 |
|
126 |
/** Simple interface to support sending any textual command to a stack |
240 |
/** |
|
|
241 |
* \brief Simple interface to support sending any textual command to a stack |
127 |
* |
242 |
* |
128 |
* @returns 0 on success |
243 |
* @returns 0 on success |
129 |
*/ |
244 |
*/ |
|
133 |
} |
248 |
} |
134 |
}; |
249 |
}; |
135 |
|
250 |
|
|
|
251 |
/** |
252 |
* \ingroup nsctcp |
253 |
* \brief Struct interface to NSC Stream (i.e., TCP) Sockets |
254 |
*/ |
136 |
struct INetStreamSocket |
255 |
struct INetStreamSocket |
137 |
{ |
256 |
{ |
138 |
virtual ~INetStreamSocket() {} |
257 |
virtual ~INetStreamSocket() {} |
139 |
|
258 |
|
|
|
259 |
/** |
260 |
* \brief Connect to a remote peer |
261 |
*/ |
140 |
virtual void connect (const char *, int) = 0; |
262 |
virtual void connect (const char *, int) = 0; |
|
|
263 |
/** |
264 |
* \brief Disconnect from a remote peer |
265 |
*/ |
141 |
virtual void disconnect () = 0; |
266 |
virtual void disconnect () = 0; |
|
|
267 |
/** |
268 |
* \brief Put the socket in Listening state on a port |
269 |
*/ |
142 |
virtual void listen (int) = 0; |
270 |
virtual void listen (int) = 0; |
|
|
271 |
/** |
272 |
* \brief Accept an incoming connection |
273 |
*/ |
143 |
virtual int accept (INetStreamSocket **) = 0; |
274 |
virtual int accept (INetStreamSocket **) = 0; |
|
|
275 |
/** |
276 |
* \brief Send some data |
277 |
* \param data the data |
278 |
* \param datalen data length |
279 |
* \return the number of data sent or -1 on error |
280 |
*/ |
144 |
virtual int send_data (const void *data, int datalen) = 0; |
281 |
virtual int send_data (const void *data, int datalen) = 0; |
|
|
282 |
/** |
283 |
* \brief Read some data |
284 |
* \param buf the buffer to store the data |
285 |
* \param buflen buffer length |
286 |
* \return the number of data read or -1 on error |
287 |
*/ |
145 |
virtual int read_data (void *buf, int *buflen) = 0; |
288 |
virtual int read_data (void *buf, int *buflen) = 0; |
146 |
/* We need to pass the option name in as a string here. The reason for |
289 |
/** |
|
|
290 |
* \brief Set the socket options |
291 |
* |
292 |
* We need to pass the option name in as a string here. The reason for |
147 |
* this is that different operating systems you compile on will have |
293 |
* this is that different operating systems you compile on will have |
148 |
* different numbers defined for the constants SO_SNDBUF and so on. */ |
294 |
* different numbers defined for the constants SO_SNDBUF and so on. |
|
|
295 |
* |
296 |
* \param optname name of the option |
297 |
* \param val option value |
298 |
* \param valsize size of the option value |
299 |
* \returns |
300 |
*/ |
149 |
virtual int setsockopt (char *optname, void *val, size_t valsize) = 0; |
301 |
virtual int setsockopt (char *optname, void *val, size_t valsize) = 0; |
|
|
302 |
/** |
303 |
* \brief Print the socket state |
304 |
*/ |
150 |
virtual void print_state (FILE *) = 0; |
305 |
virtual void print_state (FILE *) = 0; |
|
|
306 |
/** |
307 |
* \brief Check the connection state |
308 |
* \returns true if socket is in connected state |
309 |
*/ |
151 |
virtual bool is_connected () = 0; |
310 |
virtual bool is_connected () = 0; |
|
|
311 |
/** |
312 |
* \brief Check the listening state |
313 |
* \returns true if socket is in listening state |
314 |
*/ |
152 |
virtual bool is_listening () = 0; |
315 |
virtual bool is_listening () = 0; |
153 |
|
316 |
/** |
|
|
317 |
* \brief Get the peer name |
318 |
* |
319 |
* \note not implemented |
320 |
* |
321 |
* \param sa sockaddr structure to fill |
322 |
* \param salen sockaddr structure length |
323 |
* \returns -1 on error (always returns -1) |
324 |
*/ |
154 |
virtual int getpeername (struct sockaddr *sa, size_t *salen) { |
325 |
virtual int getpeername (struct sockaddr *sa, size_t *salen) { |
155 |
return -1; |
326 |
return -1; |
156 |
} |
327 |
} |
|
|
328 |
/** |
329 |
* \brief Get the socket local name |
330 |
* |
331 |
* \note not implemented |
332 |
* |
333 |
* \param sa sockaddr structure to fill |
334 |
* \param salen sockaddr structure length |
335 |
* \returns -1 on error (always returns -1) |
336 |
*/ |
157 |
virtual int getsockname (struct sockaddr *sa, size_t *salen) { |
337 |
virtual int getsockname (struct sockaddr *sa, size_t *salen) { |
158 |
return -1; |
338 |
return -1; |
159 |
} |
339 |
} |
160 |
/* Optional functions used to get and set variables for this TCP |
340 |
/** |
161 |
* connection. */ |
341 |
* \brief Optional function used to get variables for this TCP connection. |
|
|
342 |
* |
343 |
* \note not implemented |
344 |
* |
345 |
* \param var variable requested |
346 |
* \param result result result |
347 |
* \param result_len result length |
348 |
* \return always false |
349 |
*/ |
162 |
virtual bool get_var (const char *var, char *result, int result_len) |
350 |
virtual bool get_var (const char *var, char *result, int result_len) |
163 |
{ |
351 |
{ |
164 |
return false; |
352 |
return false; |
165 |
} |
353 |
} |
166 |
|
354 |
/** |
|
|
355 |
* \brief Optional function used to set variables for this TCP connection. |
356 |
* |
357 |
* \note not implemented |
358 |
* |
359 |
* \param var variable to set |
360 |
* \param val value to set |
361 |
* \return always false |
362 |
*/ |
167 |
virtual bool set_var (const char *var, const char *val) |
363 |
virtual bool set_var (const char *var, const char *val) |
168 |
{ |
364 |
{ |
169 |
return false; |
365 |
return false; |
170 |
} |
366 |
} |
171 |
}; |
367 |
}; |
172 |
|
368 |
|
|
|
369 |
/** |
370 |
* \ingroup nsctcp |
371 |
* \brief Struct interface to NSC Datagram (i.e., UDP) Sockets |
372 |
*/ |
173 |
struct INetDatagramSocket |
373 |
struct INetDatagramSocket |
174 |
{ |
374 |
{ |
175 |
virtual ~INetDatagramSocket() {} |
375 |
virtual ~INetDatagramSocket() {} |
176 |
|
376 |
|
|
|
377 |
/** |
378 |
* \brief Set the destination address and port |
379 |
*/ |
177 |
virtual void set_destination (const char *, int) = 0; |
380 |
virtual void set_destination (const char *, int) = 0; |
|
|
381 |
/** |
382 |
* \brief Send a datagram |
383 |
* \param data the data |
384 |
* \param datalen data length |
385 |
*/ |
178 |
virtual void send_data (const void *data, int datalen) = 0; |
386 |
virtual void send_data (const void *data, int datalen) = 0; |
179 |
}; |
387 |
}; |
|
|
388 |
|
389 |
/** |
390 |
* \ingroup nsctcp |
391 |
* \brief Struct interface to NSC send capabilities |
392 |
*/ |
180 |
struct ISendCallback |
393 |
struct ISendCallback |
181 |
{ |
394 |
{ |
182 |
virtual ~ISendCallback() {} |
395 |
virtual ~ISendCallback() {} |
183 |
|
396 |
|
|
|
397 |
/** |
398 |
* \brief Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3. |
399 |
*/ |
184 |
virtual void send_callback (const void *data, int datalen) = 0; |
400 |
virtual void send_callback (const void *data, int datalen) = 0; |
185 |
}; |
401 |
}; |
186 |
|
402 |
|
|
|
403 |
/** |
404 |
* \ingroup nsctcp |
405 |
* \brief Struct interface to NSC soft interrupt capabilities |
406 |
*/ |
187 |
struct IInterruptCallback |
407 |
struct IInterruptCallback |
188 |
{ |
408 |
{ |
189 |
virtual ~IInterruptCallback() {} |
409 |
virtual ~IInterruptCallback() {} |
190 |
|
410 |
|
|
|
411 |
/** |
412 |
* \brief Called by the NSC stack whenever something of interest has happened |
413 |
*/ |
191 |
virtual void wakeup () = 0; |
414 |
virtual void wakeup () = 0; |
|
|
415 |
/** |
416 |
* \brief Get the actual time |
417 |
*/ |
192 |
virtual void gettime (unsigned int *, unsigned int *) = 0; |
418 |
virtual void gettime (unsigned int *, unsigned int *) = 0; |
193 |
}; |
419 |
}; |
194 |
|
420 |
|