A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
27
struct
INetStack
28
{
29
virtual
~INetStack
() {}
30
31
virtual
void
init
(
int
hz) = 0;
32
33
virtual
void
if_receive_packet
(
int
if_id,
const
void
*
data
,
int
datalen) = 0;
34
35
virtual
void
if_send_packet
(
const
void
*
data
,
int
datalen) = 0;
36
virtual
void
if_send_finish
(
int
if_id) = 0;
37
38
virtual
void
if_attach
(
const
char
*addr,
const
char
*mask,
int
mtu) = 0;
39
virtual
void
add_default_gateway
(
const
char
*addr) = 0;
40
44
virtual
int
get_id
() = 0;
45
49
virtual
const
char
*
get_name
() = 0;
50
57
virtual
int
get_hz
() = 0;
58
59
virtual
void
timer_interrupt
() = 0;
60
virtual
void
increment_ticks
() = 0;
61
62
virtual
void
buffer_size
(
int
size) = 0;
63
64
virtual
struct
INetDatagramSocket
*
new_udp_socket
() {
return
NULL; }
65
virtual
struct
INetStreamSocket
*
new_tcp_socket
() {
return
NULL; }
66
virtual
struct
INetStreamSocket
*
new_sctp_socket
() {
return
NULL; }
67
68
// The following I've made optional to implement for now. Eases
69
// integration of new features.
70
virtual
int
sysctl
(
const
char
*sysctl_name,
void
*oldval,
size_t
*oldlenp,
71
void
*newval,
size_t
newlen)
72
{
73
return
-1;
74
}
75
76
// alternate, simpler interface. the stack cradle code is expected
77
// 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,
79
// much like the sysctl(8) program.
80
virtual
int
sysctl_set
(
const
char
*name,
const
char
*value)
81
{
82
return
-1;
83
}
84
85
// same as above, cradle code is expected to convert the sysctl value
86
// into a string.
87
// returns length of the string in value, i.e. retval > len: 'output truncated'.
88
virtual
int
sysctl_get
(
const
char
*name,
char
*value,
size_t
len)
89
{
90
return
-1;
91
}
92
93
// this tells the cradle code to put the name of sysctl number 'idx'
94
// into name[].
95
// The idea is that this can be used to get a list of all available sysctls:
96
// char buf[256]
97
// for (i=0; sysctl_getnum(i, buf, sizeof(buf)) > 0 ;i++)
98
// puts(buf);
99
// returns -1 if idx is out of range and the length of the sysctl name otherwise.
100
virtual
int
sysctl_getnum
(
size_t
idx,
char
*name,
size_t
len)
101
{
102
return
-1;
103
}
104
105
virtual
void
show_config
()
106
{
107
;
108
}
109
110
/* Optional functions used to get and set variables for this stack */
111
virtual
bool
get_var
(
const
char
*var,
char
*result,
int
result_len)
112
{
113
return
false
;
114
}
115
116
virtual
bool
set_var
(
const
char
*var,
const
char
*val)
117
{
118
return
false
;
119
}
120
124
virtual
void
set_diagnostic
(
int
level) {}
125
130
virtual
int
cmd
(
const
char
*)
131
{
132
return
1;
133
}
134
};
135
136
struct
INetStreamSocket
137
{
138
virtual
~INetStreamSocket
() {}
139
140
virtual
void
connect
(
const
char
*,
int
) = 0;
141
virtual
void
disconnect
() = 0;
142
virtual
void
listen
(
int
) = 0;
143
virtual
int
accept
(
INetStreamSocket
**) = 0;
144
virtual
int
send_data
(
const
void
*
data
,
int
datalen) = 0;
145
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
147
* this is that different operating systems you compile on will have
148
* different numbers defined for the constants SO_SNDBUF and so on. */
149
virtual
int
setsockopt
(
char
*optname,
void
*val,
size_t
valsize) = 0;
150
virtual
void
print_state
(FILE *) = 0;
151
virtual
bool
is_connected
() = 0;
152
virtual
bool
is_listening
() = 0;
153
154
virtual
int
getpeername
(
struct
sockaddr *sa,
size_t
*salen) {
155
return
-1;
156
}
157
virtual
int
getsockname
(
struct
sockaddr *sa,
size_t
*salen) {
158
return
-1;
159
}
160
/* Optional functions used to get and set variables for this TCP
161
* connection. */
162
virtual
bool
get_var
(
const
char
*var,
char
*result,
int
result_len)
163
{
164
return
false
;
165
}
166
167
virtual
bool
set_var
(
const
char
*var,
const
char
*val)
168
{
169
return
false
;
170
}
171
};
172
173
struct
INetDatagramSocket
174
{
175
virtual
~INetDatagramSocket
() {}
176
177
virtual
void
set_destination
(
const
char
*,
int
) = 0;
178
virtual
void
send_data
(
const
void
*
data
,
int
datalen) = 0;
179
};
180
struct
ISendCallback
181
{
182
virtual
~ISendCallback
() {}
183
184
virtual
void
send_callback
(
const
void
*
data
,
int
datalen) = 0;
185
};
186
187
struct
IInterruptCallback
188
{
189
virtual
~IInterruptCallback
() {}
190
191
virtual
void
wakeup
() = 0;
192
virtual
void
gettime
(
unsigned
int
*,
unsigned
int
*) = 0;
193
};
194
195
typedef
int (*
FRandom
)();
196
typedef
INetStack
*(*FCreateStack)(
ISendCallback
*,
IInterruptCallback
*,
197
FRandom
);
198
199
#define CREATE_STACK_FUNC(a,b,c) extern "C" INetStack *nsc_create_stack ( \
200
ISendCallback *a, IInterruptCallback *b, FRandom c)
201
202
#endif
/* NSC_SIM_INTERFACE_H */
src
internet
model
sim_interface.h
Generated on Tue May 14 2013 11:08:23 for ns-3 by
1.8.1.2