studies/performance/Performance-Code4/fifonet1_n.cpp
⇒
download file
1
2
3
4
5
6
7
8
9
10
11 #include <math.h>
12 #include "omnetpp.h"
13
14 #define check_error() \
15 {(void)0;}
16 #define check_memory() \
17 {if (memoryIsLow()) {throw new cException(eNOMEM); }}
18 #define check_module_count(num, mod, parentmod) \
19 {if ((int)num<=0) {throw new cException("Negative or zero module vector size %s[%d] in compound module %s", \
20 mod,(int)num,parentmod);}}
21 #define check_gate_count(num, mod, gate, parentmod) \
22 {if ((int)num<0) {throw new cException("Negative gate vector size %s.%s[%d] in compound module %s", \
23 mod,gate,(int)num,parentmod);}}
24 #define check_loop_bounds(lower, upper, parentmod) \
25 {if ((int)lower<0) \
26 {throw new cException("Bad loop bounds (%d..%d) in compound module %s", \
27 (int)lower,(int)upper,parentmod);}}
28 #define check_module_index(index,modvar,modname,parentmod) \
29 {if (index<0 || index>=modvar[0]->size()) {throw new cException("Bad submodule index %s[%d] in compound module %s", \
30 modname,(int)index,parentmod);}}
31 #define check_channel_params(delay, err, channel) \
32 {if ((double)delay<0.0) \
33 {throw new cException("Negative delay value %lf in channel %s",(double)delay,channel);} \
34 if ((double)err<0.0 || (double)err>1.0) \
35 {throw new cException("Incorrect error value %lf in channel %s",(double)err,channel);}}
36 #define check_modtype(modtype, modname) \
37 {if ((modtype)==NULL) {throw new cException("Simple module type definition %s not found", \
38 modname);}}
39 #define check_function(funcptr, funcname) \
40 {if ((funcptr)==NULL) {throw new cException("Function %s not found", \
41 funcname);}}
42 #define check_function_retnull(funcptr, funcname) \
43 {if ((funcptr)==NULL) {throw new cException("Function %s not found", \
44 funcname);return NULL;}}
45 #define check_gate(gateindex, modname, gatename) \
46 {if ((int)gateindex==-1) {throw new cException("Gate %s.%s not found",modname,gatename);}}
47 #define check_anc_param(ptr,parname,compoundmod) \
48 {if ((ptr)==NULL) {throw new cException("Unknown ancestor parameter named %s in compound module %s", \
49 parname,compoundmod);}}
50 #define check_param(ptr,parname) \
51 {if ((ptr)==NULL) {throw new cException("Unknown parameter named %s", \
52 parname);}}
53 #ifndef __cplusplus
54 # error Compile as C++!
55 #endif
56 #ifdef __BORLANDC__
57 # if !defined(__FLAT__) && !defined(__LARGE__)
58 # error Compile as 16-bit LARGE model or 32-bit DPMI!
59 # endif
60 #endif
61
62
63 #ifdef _MSC_VER
64 # pragma warning(disable:4101)
65 #endif
66 #ifdef __BORLANDC__
67 # pragma warn -waus
68 # pragma warn -wuse
69 #endif
70
71
72
73
74 #define NEDC_VERSION 0x0203
75 #if (NEDC_VERSION!=OMNETPP_VERSION)
76 # error Version mismatch! Probably this file was generated by an earlier version of nedc: 'make clean' should help.
77 #endif
78
79
80
81
82
83 ModuleInterface( FifoNet1 )
84 Machine( default )
85 EndInterface
86
87 Register_ModuleInterface( FifoNet1 )
88
89 class FifoNet1 : public cCompoundModule
90 {
91 public:
92 FifoNet1(const char *name, cModule *parentmod) :
93 cCompoundModule(name, parentmod) {}
94 protected:
95 virtual void doBuildInside();
96 };
97
98 Define_Module( FifoNet1 );
99
100 void FifoNet1::doBuildInside()
101 {
102 cModule *mod = this;
103
104 cPar value, *par;
105 cPar::ExprElem *expr_tab; int k;
106 cFunctionType *functype;
107 const char *type_name;
108 char b1[64], b2[64];
109 cArray machines;
110 bool islocal, do_this_block;
111 int n;
112
113
114 cModuleType *modtype = NULL;
115 long sub_nr = 0;
116 long sub_i = 0;
117
118
119 modtype = findModuleType( "FF2Generator" );
120 check_modtype( modtype, "FF2Generator" );
121 cModule *gen_mod;
122
123
124 par = new cPar();
125 *par = mod->machinePar("default");
126 machines.add( par );
127 check_error(); check_memory();
128
129
130 islocal = simulation.netInterface()==NULL ||
131 simulation.netInterface()->isLocalMachineIn( machines );
132 gen_mod = modtype->create( "gen", mod, islocal);
133 check_error(); check_memory();
134
135
136 gen_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() );
137 check_error(); check_memory();
138
139
140 value.cancelRedirection();
141 value = 0L;
142 value.setPrompt( NULL );
143 value.setInput( true );
144 par = &(gen_mod->par("num_messages"));
145 check_param(par, "num_messages");
146 *par = value;
147
148 value.cancelRedirection();
149 value = 0L;
150 value.setPrompt( NULL );
151 value.setInput( true );
152 par = &(gen_mod->par("ia_time"));
153 check_param(par, "ia_time");
154 *par = value;
155
156 value.cancelRedirection();
157 value = 0L;
158 value.setPrompt( NULL );
159 value.setInput( true );
160 par = &(gen_mod->par("msg_length"));
161 check_param(par, "msg_length");
162 *par = value;
163
164 n = gen_mod->params();
165 for(k=0;k<n;k++)
166 if(gen_mod->par(k).isInput())
167 {gen_mod->par(k).read();check_error();}
168
169 gen_mod->setDisplayString(dispSUBMOD, "p=76,78;i=gen" );
170
171
172 gen_mod->buildInside();
173 machines.clear();
174
175
176 modtype = findModuleType( "FF2PacketFifo" );
177 check_modtype( modtype, "FF2PacketFifo" );
178 cModule *fifo_mod;
179
180
181 par = new cPar();
182 *par = mod->machinePar("default");
183 machines.add( par );
184 check_error(); check_memory();
185
186
187 islocal = simulation.netInterface()==NULL ||
188 simulation.netInterface()->isLocalMachineIn( machines );
189 fifo_mod = modtype->create( "fifo", mod, islocal);
190 check_error(); check_memory();
191
192
193 fifo_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() );
194 check_error(); check_memory();
195
196
197 value.cancelRedirection();
198 value = 0L;
199 value.setPrompt( NULL );
200 value.setInput( true );
201 par = &(fifo_mod->par("service_time"));
202 check_param(par, "service_time");
203 *par = value;
204
205 n = fifo_mod->params();
206 for(k=0;k<n;k++)
207 if(fifo_mod->par(k).isInput())
208 {fifo_mod->par(k).read();check_error();}
209
210 fifo_mod->setDisplayString(dispSUBMOD, "p=164,78;i=queue" );
211
212
213 fifo_mod->buildInside();
214 machines.clear();
215
216
217 modtype = findModuleType( "FF2Sink" );
218 check_modtype( modtype, "FF2Sink" );
219 cModule *sink_mod;
220
221
222 par = new cPar();
223 *par = mod->machinePar("default");
224 machines.add( par );
225 check_error(); check_memory();
226
227
228 islocal = simulation.netInterface()==NULL ||
229 simulation.netInterface()->isLocalMachineIn( machines );
230 sink_mod = modtype->create( "sink", mod, islocal);
231 check_error(); check_memory();
232
233
234 sink_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() );
235 check_error(); check_memory();
236
237 n = sink_mod->params();
238 for(k=0;k<n;k++)
239 if(sink_mod->par(k).isInput())
240 {sink_mod->par(k).read();check_error();}
241
242 sink_mod->setDisplayString(dispSUBMOD, "p=244,78;i=sink" );
243
244
245 sink_mod->buildInside();
246 machines.clear();
247
248
249 cLinkType *link_p;
250 cPar *delay_p, *error_p, *datarate_p;
251 int gateL, gateR;
252 long mod_nr_L, mod_nr_R, gate_nr_L, gate_nr_R;
253
254 do_this_block = true;
255 if (do_this_block)
256 {
257 gateL = gen_mod->findGate( "out" );
258 check_gate( gateL, "gen", "out" );
259
260 gateR = fifo_mod->findGate( "in" );
261 check_gate( gateR, "fifo", "in" );
262
263 connect (gen_mod, gateL,
264 NULL,
265 fifo_mod, gateR);
266
267 check_error(); check_memory();
268 }
269
270
271 do_this_block = true;
272 if (do_this_block)
273 {
274 gateL = fifo_mod->findGate( "out" );
275 check_gate( gateL, "fifo", "out" );
276
277 gateR = sink_mod->findGate( "in" );
278 check_gate( gateR, "sink", "in" );
279
280 connect (fifo_mod, gateL,
281 NULL,
282 sink_mod, gateR);
283
284 check_error(); check_memory();
285 }
286
287 mod->checkInternalConnections();
288 check_error(); check_memory();
289 }
290
291 class fifonet1 : public cNetworkType
292 {
293 public:
294 fifonet1(const char *name) : cNetworkType(name) {}
295 fifonet1(const fifonet1& n) {setName(n.name());operator=(n);}
296 virtual void setupNetwork();
297 };
298
299 Define_Network( fifonet1 );
300
301 void fifonet1::setupNetwork()
302 {
303
304
305 cPar value, *par;
306 cPar::ExprElem *expr_tab; int k;
307 cFunctionType *functype;
308 const char *type_name;
309 char b1[64], b2[64];
310 cArray machines;
311 bool islocal, do_this_block;
312 int n;
313
314
315 par = new cPar();
316 *par = ev.getPhysicalMachineFor("default");
317 machines.add( par );
318 check_error(); check_memory();
319
320
321 cModuleType *modtype;
322 modtype = findModuleType( "FifoNet1" );
323 check_modtype( modtype, "FifoNet1" );
324 cModule *fifonet1_mod;
325
326
327 islocal = simulation.netInterface()==NULL ||
328 simulation.netInterface()->isLocalMachineIn( machines );
329 if (!islocal)
330 throw new cException("Local machine `%s' is not among machines specified for this network",
331 simulation.netInterface()->localhost());
332 fifonet1_mod = modtype->create( "fifonet1", NULL, islocal);
333 check_error(); check_memory();
334
335
336 fifonet1_mod->setMachinePar( "default", ev.getPhysicalMachineFor("default") );
337 check_error(); check_memory();
338
339 n = fifonet1_mod->params();
340 for(k=0;k<n;k++)
341 if(fifonet1_mod->par(k).isInput())
342 {fifonet1_mod->par(k).read();check_error();}
343
344
345 fifonet1_mod->buildInside();
346 machines.clear();
347
348 check_error(); check_memory();
349 }
350
351