A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sim_interface.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  Network Simulation Cradle
4  Copyright (C) 2003-2005 Sam Jansen
5 
6  This program is free software; you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by the Free
8  Software Foundation; either version 2 of the License, or (at your option)
9  any later version.
10 
11  This program is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc., 59
18  Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 */
21 
22 #ifndef NSC_SIM_INTERFACE_H
23 #define NSC_SIM_INTERFACE_H
24 
25 #define NSC_VERSION 0x000500
26 
31 struct INetStack
32 {
33  virtual ~INetStack() {}
34 
39  virtual void init (int hz) = 0;
40 
47  virtual void if_receive_packet (int if_id, const void *data, int datalen) = 0;
53  virtual void if_send_packet (const void *data, int datalen) = 0;
58  virtual void if_send_finish (int if_id) = 0;
59 
66  virtual void if_attach (const char *addr, const char *mask, int mtu) = 0;
71  virtual void add_default_gateway (const char *addr) = 0;
72 
79  virtual int get_id () = 0;
80 
89  virtual const char *get_name () = 0;
90 
102  virtual int get_hz () = 0;
103 
107  virtual void timer_interrupt () = 0;
108 
112  virtual void increment_ticks () = 0;
113 
117  virtual void buffer_size (int size) = 0;
118 
122  virtual struct INetDatagramSocket *new_udp_socket () { return NULL; }
126  virtual struct INetStreamSocket *new_tcp_socket () { return NULL; }
130  virtual struct INetStreamSocket *new_sctp_socket () { return NULL; }
131 
132  // The following I've made optional to implement for now. Eases
133  // integration of new features.
143  virtual int sysctl (const char *sysctl_name, void *oldval, size_t *oldlenp,
144  void *newval, size_t newlen)
145  {
146  return -1;
147  }
148 
149  // alternate, simpler interface. the stack cradle code is expected
150  // to convert the string-value to something that the stack can handle.
151  // The idea here is that this is a front-end to the sysctl(2) call,
152  // much like the sysctl(8) program.
159  virtual int sysctl_set (const char *name, const char *value)
160  {
161  return -1;
162  }
163 
164  // same as above, cradle code is expected to convert the sysctl value
165  // into a string.
166  // returns length of the string in value, i.e. retval > len: 'output truncated'.
174  virtual int sysctl_get (const char *name, char *value, size_t len)
175  {
176  return -1;
177  }
178 
194  virtual int sysctl_getnum (size_t idx, char *name, size_t len)
195  {
196  return -1;
197  }
198 
202  virtual void show_config ()
203  {
204  ;
205  }
206 
214  virtual bool get_var (const char *var, char *result, int result_len)
215  {
216  return false;
217  }
218 
225  virtual bool set_var (const char *var, const char *val)
226  {
227  return false;
228  }
229 
238  virtual void set_diagnostic (int level) {}
239 
245  virtual int cmd (const char *)
246  {
247  return 1;
248  }
249 };
250 
256 {
257  virtual ~INetStreamSocket() {}
258 
262  virtual void connect (const char *, int) = 0;
266  virtual void disconnect () = 0;
270  virtual void listen (int) = 0;
274  virtual int accept (INetStreamSocket **) = 0;
281  virtual int send_data (const void *data, int datalen) = 0;
288  virtual int read_data (void *buf, int *buflen) = 0;
301  virtual int setsockopt (char *optname, void *val, size_t valsize) = 0;
305  virtual void print_state (FILE *) = 0;
310  virtual bool is_connected () = 0;
315  virtual bool is_listening () = 0;
325  virtual int getpeername (struct sockaddr *sa, size_t *salen) {
326  return -1;
327  }
337  virtual int getsockname (struct sockaddr *sa, size_t *salen) {
338  return -1;
339  }
350  virtual bool get_var (const char *var, char *result, int result_len)
351  {
352  return false;
353  }
363  virtual bool set_var (const char *var, const char *val)
364  {
365  return false;
366  }
367 };
368 
374 {
375  virtual ~INetDatagramSocket() {}
376 
380  virtual void set_destination (const char *, int) = 0;
386  virtual void send_data (const void *data, int datalen) = 0;
387 };
388 
394 {
395  virtual ~ISendCallback() {}
396 
400  virtual void send_callback (const void *data, int datalen) = 0;
401 };
402 
408 {
409  virtual ~IInterruptCallback() {}
410 
414  virtual void wakeup () = 0;
418  virtual void gettime (unsigned int *, unsigned int *) = 0;
419 };
420 
421 typedef int (*FRandom)();
422 typedef INetStack *(*FCreateStack)(ISendCallback *, IInterruptCallback *,
423  FRandom);
424 
425 #define CREATE_STACK_FUNC(a,b,c) extern "C" INetStack *nsc_create_stack ( \
426  ISendCallback *a, IInterruptCallback *b, FRandom c)
427 
428 #endif /* NSC_SIM_INTERFACE_H */
virtual void if_receive_packet(int if_id, const void *data, int datalen)=0
Deliver complete packet to the NSC network stack.
virtual bool is_listening()=0
Check the listening state.
virtual void show_config()
Show the NSC configuration.
virtual void set_destination(const char *, int)=0
Set the destination address and port.
virtual ~INetDatagramSocket()
virtual bool get_var(const char *var, char *result, int result_len)
Optional function to get variables for this stack.
virtual int accept(INetStreamSocket **)=0
Accept an incoming connection.
virtual int setsockopt(char *optname, void *val, size_t valsize)=0
Set the socket options.
virtual ~INetStreamSocket()
virtual bool get_var(const char *var, char *result, int result_len)
Optional function used to get variables for this TCP connection.
virtual void if_send_packet(const void *data, int datalen)=0
Send complete packet to the NSC network stack.
virtual void connect(const char *, int)=0
Connect to a remote peer.
virtual void increment_ticks()=0
Increment the time ticks.
Struct interface to NSC send capabilities.
virtual void wakeup()=0
Called by the NSC stack whenever something of interest has happened.
virtual int get_hz()=0
Get the timer_interrupt frequency.
uint8_t data[writeSize]
virtual void send_callback(const void *data, int datalen)=0
Invoked by NSCs 'ethernet driver' to re-inject a packet into ns-3.
virtual const char * get_name()=0
Return a short one-word name of the stack.
virtual int send_data(const void *data, int datalen)=0
Send some data.
Struct interface to NSC stack.
Definition: sim_interface.h:31
virtual void send_data(const void *data, int datalen)=0
Send a datagram.
virtual void buffer_size(int size)=0
Set the buffer size.
virtual bool is_connected()=0
Check the connection state.
virtual void print_state(FILE *)=0
Print the socket state.
virtual int sysctl_set(const char *name, const char *value)
Set system parameters using sysctl.
Struct interface to NSC soft interrupt capabilities.
virtual void timer_interrupt()=0
The stack timer_interrupt function.
virtual void set_diagnostic(int level)
Set the level of debugging or diagnostic information to print out.
virtual struct INetStreamSocket * new_sctp_socket()
Create a new SCTP socket.
virtual int sysctl_getnum(size_t idx, char *name, size_t len)
Tell the cradle code to put the name of sysctl number 'idx' into name[].
virtual void gettime(unsigned int *, unsigned int *)=0
Get the actual time.
virtual void add_default_gateway(const char *addr)=0
Add a default gateway to the interface.
virtual int getpeername(struct sockaddr *sa, size_t *salen)
Get the peer name.
virtual int getsockname(struct sockaddr *sa, size_t *salen)
Get the socket local name.
int(* FRandom)()
virtual void listen(int)=0
Put the socket in Listening state on a port.
virtual bool set_var(const char *var, const char *val)
Optional function used to set variables for this TCP connection.
virtual int sysctl(const char *sysctl_name, void *oldval, size_t *oldlenp, void *newval, size_t newlen)
use sysctl to modify system parameters
virtual ~IInterruptCallback()
virtual void if_attach(const char *addr, const char *mask, int mtu)=0
Attach an interface to the stack.
Struct interface to NSC Stream (i.e., TCP) Sockets.
virtual void disconnect()=0
Disconnect from a remote peer.
Struct interface to NSC Datagram (i.e., UDP) Sockets.
virtual void if_send_finish(int if_id)=0
Signal the completion of send procedure to the NSC network stack.
virtual int read_data(void *buf, int *buflen)=0
Read some data.
virtual struct INetStreamSocket * new_tcp_socket()
Create a new TCP socket.
virtual void init(int hz)=0
Initialize the stack.
virtual bool set_var(const char *var, const char *val)
Optional function to set variables for this stack.
virtual ~INetStack()
Definition: sim_interface.h:33
virtual ~ISendCallback()
virtual int cmd(const char *)
Simple interface to support sending any textual command to a stack.
virtual int get_id()=0
Returns the internal id of the stack instance.
virtual struct INetDatagramSocket * new_udp_socket()
Create a new UDP socket.
virtual int sysctl_get(const char *name, char *value, size_t len)
Get system parameters using sysctl.