//----------------------------------------- // // Generated by NEDC version 2.3b2 // date: Sat Jun 21 13:41:37 2003 // // Input file: generator.ned // Output file: generator_n.cpp //----------------------------------------- #include #include "omnetpp.h" #define check_error() \ {(void)0;} #define check_memory() \ {if (memoryIsLow()) {throw new cException(eNOMEM); }} #define check_module_count(num, mod, parentmod) \ {if ((int)num<=0) {throw new cException("Negative or zero module vector size %s[%d] in compound module %s", \ mod,(int)num,parentmod);}} #define check_gate_count(num, mod, gate, parentmod) \ {if ((int)num<0) {throw new cException("Negative gate vector size %s.%s[%d] in compound module %s", \ mod,gate,(int)num,parentmod);}} #define check_loop_bounds(lower, upper, parentmod) \ {if ((int)lower<0) \ {throw new cException("Bad loop bounds (%d..%d) in compound module %s", \ (int)lower,(int)upper,parentmod);}} #define check_module_index(index,modvar,modname,parentmod) \ {if (index<0 || index>=modvar[0]->size()) {throw new cException("Bad submodule index %s[%d] in compound module %s", \ modname,(int)index,parentmod);}} #define check_channel_params(delay, err, channel) \ {if ((double)delay<0.0) \ {throw new cException("Negative delay value %lf in channel %s",(double)delay,channel);} \ if ((double)err<0.0 || (double)err>1.0) \ {throw new cException("Incorrect error value %lf in channel %s",(double)err,channel);}} #define check_modtype(modtype, modname) \ {if ((modtype)==NULL) {throw new cException("Simple module type definition %s not found", \ modname);}} #define check_function(funcptr, funcname) \ {if ((funcptr)==NULL) {throw new cException("Function %s not found", \ funcname);}} #define check_function_retnull(funcptr, funcname) \ {if ((funcptr)==NULL) {throw new cException("Function %s not found", \ funcname);return NULL;}} #define check_gate(gateindex, modname, gatename) \ {if ((int)gateindex==-1) {throw new cException("Gate %s.%s not found",modname,gatename);}} #define check_anc_param(ptr,parname,compoundmod) \ {if ((ptr)==NULL) {throw new cException("Unknown ancestor parameter named %s in compound module %s", \ parname,compoundmod);}} #define check_param(ptr,parname) \ {if ((ptr)==NULL) {throw new cException("Unknown parameter named %s", \ parname);}} #ifndef __cplusplus # error Compile as C++! #endif #ifdef __BORLANDC__ # if !defined(__FLAT__) && !defined(__LARGE__) # error Compile as 16-bit LARGE model or 32-bit DPMI! # endif #endif // Disable warnings about unused variables: #ifdef _MSC_VER # pragma warning(disable:4101) #endif #ifdef __BORLANDC__ # pragma warn -waus # pragma warn -wuse #endif // for GCC, seemingly there's no way to emulate the -Wunused command-line // flag from a source file... // Version check #define NEDC_VERSION 0x0203 #if (NEDC_VERSION!=OMNETPP_VERSION) # error Version mismatch! Probably this file was generated by an earlier version of nedc: 'make clean' should help. #endif //-------------------------------------------- // Following code generated from: servicenet.ned //-------------------------------------------- ModuleInterface( Selector ) Machine( default ) Parameter( server_count, ParType_Numeric ) Gate( out[], GateDir_Output ) Gate( in, GateDir_Input ) EndInterface Register_ModuleInterface( Selector ) // class Selector : public cSimpleModule // { // Module_Class_Members(Selector,cSimpleModule,8192) // virtual void activity(); // // Add you own member functions here! // }; // // Define_Module( Selector ) // // void Selector::activity() // { // // Put code for simple module activity here! // } // ModuleInterface( ServiceNet ) Machine( default ) Parameter( server_count, ParType_Numeric ParType_Const ) Parameter( selector_type, ParType_String ) Parameter( generator_rate, ParType_Numeric ParType_Const ) Parameter( generator_rg, ParType_Numeric ParType_Const ) Parameter( sample_count, ParType_Numeric ParType_Const ) EndInterface Register_ModuleInterface( ServiceNet ) class ServiceNet : public cCompoundModule { public: ServiceNet(const char *name, cModule *parentmod) : cCompoundModule(name, parentmod) {} protected: virtual void doBuildInside(); }; Define_Module( ServiceNet ); void ServiceNet::doBuildInside() { cModule *mod = this; // temporary variables: cPar value, *par; cPar::ExprElem *expr_tab; int k; cFunctionType *functype; const char *type_name; char b1[64], b2[64]; cArray machines; bool islocal, do_this_block; int n; // const parameters: // Submodules: cModuleType *modtype = NULL; long sub_nr = 0; long sub_i = 0; // server modtype = findModuleType( "Server" ); check_modtype( modtype, "Server" ); sub_nr = mod->par( "server_count" ); check_module_count(sub_nr,"server","ServiceNet"); cModule **server_mod = new cModule *[sub_nr]; for (sub_i=0; sub_imachinePar("default"); machines.add( par ); check_error(); check_memory(); // module creation: islocal = simulation.netInterface()==NULL || simulation.netInterface()->isLocalMachineIn( machines ); server_mod[sub_i] = modtype->create( "server", mod, islocal); check_error(); check_memory(); server_mod[sub_i]->setIndex(sub_i, sub_nr); // set machine list: server_mod[sub_i]->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); check_error(); check_memory(); // 'parameters:' section par = &(server_mod[sub_i]->par("address")); check_param(par, "address"); *par = (long)sub_i; n = server_mod[sub_i]->params(); for(k=0;kpar(k).isInput()) {server_mod[sub_i]->par(k).read();check_error();} // build function call: server_mod[sub_i]->buildInside(); } machines.clear(); // selector par = &mod->par("selector_type"); check_param(par,"selector_type"); type_name = (const char *)par; type_name = mod->par("selector_type"); modtype = findModuleType( type_name ); check_modtype( modtype, type_name ); cModule *selector_mod; // an empty actual machine list for the next module par = new cPar(); *par = mod->machinePar("default"); machines.add( par ); check_error(); check_memory(); // module creation: islocal = simulation.netInterface()==NULL || simulation.netInterface()->isLocalMachineIn( machines ); selector_mod = modtype->create( "selector", mod, islocal); check_error(); check_memory(); // set machine list: selector_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); check_error(); check_memory(); // 'parameters:' section par = &(selector_mod->par("server_count")); check_param(par, "server_count"); *par = mod->par( "server_count" ); n = selector_mod->params(); for(k=0;kpar(k).isInput()) {selector_mod->par(k).read();check_error();} // 'gatesizes:' section n = mod->par( "server_count" ); check_gate_count( n, "selector","out","ServiceNet"); selector_mod->setGateSize("out", n ); // build function call: selector_mod->buildInside(); machines.clear(); // sink modtype = findModuleType( "Sink" ); check_modtype( modtype, "Sink" ); cModule *sink_mod; // an empty actual machine list for the next module par = new cPar(); *par = mod->machinePar("default"); machines.add( par ); check_error(); check_memory(); // module creation: islocal = simulation.netInterface()==NULL || simulation.netInterface()->isLocalMachineIn( machines ); sink_mod = modtype->create( "sink", mod, islocal); check_error(); check_memory(); // set machine list: sink_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); check_error(); check_memory(); // 'parameters:' section par = &(sink_mod->par("sample_count")); check_param(par, "sample_count"); *par = mod->par( "sample_count" ); n = sink_mod->params(); for(k=0;kpar(k).isInput()) {sink_mod->par(k).read();check_error();} // 'gatesizes:' section n = mod->par( "server_count" ); check_gate_count( n, "sink","in","ServiceNet"); sink_mod->setGateSize("in", n ); // build function call: sink_mod->buildInside(); machines.clear(); // generator modtype = findModuleType( "Generator" ); check_modtype( modtype, "Generator" ); cModule *generator_mod; // an empty actual machine list for the next module par = new cPar(); *par = mod->machinePar("default"); machines.add( par ); check_error(); check_memory(); // module creation: islocal = simulation.netInterface()==NULL || simulation.netInterface()->isLocalMachineIn( machines ); generator_mod = modtype->create( "generator", mod, islocal); check_error(); check_memory(); // set machine list: generator_mod->setMachinePar( "default", ((cPar *)machines[0])->stringValue() ); check_error(); check_memory(); // 'parameters:' section par = &(generator_mod->par("rate")); check_param(par, "rate"); *par = mod->par( "generator_rate" ); par = &(generator_mod->par("random_generator")); check_param(par, "random_generator"); *par = mod->par( "generator_rg" ); n = generator_mod->params(); for(k=0;kpar(k).isInput()) {generator_mod->par(k).read();check_error();} // build function call: generator_mod->buildInside(); machines.clear(); // Connections: cLinkType *link_p; cPar *delay_p, *error_p, *datarate_p; int gateL, gateR; long mod_nr_L, mod_nr_R, gate_nr_L, gate_nr_R; { // for i loop: long i_index; long i_begin = 0; expr_tab = new cPar::ExprElem[3]; k=0; expr_tab[k++] = mod->par( "server_count" ); expr_tab[k++] = 1; expr_tab[k++] = '-'; value.cancelRedirection(); value.setDoubleValue(expr_tab,k); long i_end = value; check_loop_bounds(i_begin, i_end, "ServiceNet"); for (i_index=i_begin; i_index<=i_end; i_index++) { do_this_block = true; // no "if" condition if (do_this_block) // "if" in NED { gate_nr_L = i_index; gateL = selector_mod->findGate( "out", gate_nr_L ); check_gate( gateL, "selector", indexedname(b1,"out",gate_nr_L) ); mod_nr_R = i_index; check_module_index(mod_nr_R,server_mod,"server", "ServiceNet"); gateR = server_mod[mod_nr_R]->findGate( "in" ); check_gate( gateR, "server", "in" ); connect (selector_mod, gateL, NULL, server_mod[mod_nr_R], gateR); check_error(); check_memory(); } // end-if do_this_block = true; // no "if" condition if (do_this_block) // "if" in NED { mod_nr_L = i_index; check_module_index(mod_nr_L,server_mod,"server", "ServiceNet"); gateL = server_mod[mod_nr_L]->findGate( "out" ); check_gate( gateL, "server", "out" ); gate_nr_R = i_index; gateR = sink_mod->findGate( "in", gate_nr_R ); check_gate( gateR, "sink", indexedname(b1,"in",gate_nr_R) ); connect (server_mod[mod_nr_L], gateL, NULL, sink_mod, gateR); check_error(); check_memory(); } // end-if } // end for i } do_this_block = true; // no "if" condition if (do_this_block) // "if" in NED { gateL = generator_mod->findGate( "out" ); check_gate( gateL, "generator", "out" ); gateR = selector_mod->findGate( "in" ); check_gate( gateR, "selector", "in" ); connect (generator_mod, gateL, NULL, selector_mod, gateR); check_error(); check_memory(); } // end-if mod->checkInternalConnections(); delete[] server_mod; check_error(); check_memory(); } class servicenet : public cNetworkType { public: servicenet(const char *name) : cNetworkType(name) {} servicenet(const servicenet& n) {setName(n.name());operator=(n);} virtual void setupNetwork(); }; Define_Network( servicenet ); void servicenet::setupNetwork() { // temporary variables: cPar value, *par; cPar::ExprElem *expr_tab; int k; cFunctionType *functype; const char *type_name; char b1[64], b2[64]; cArray machines; bool islocal, do_this_block; int n; // an empty actual machine list for the next module par = new cPar(); *par = ev.getPhysicalMachineFor("default"); machines.add( par ); check_error(); check_memory(); // system module creation cModuleType *modtype; modtype = findModuleType( "ServiceNet" ); check_modtype( modtype, "ServiceNet" ); cModule *servicenet_mod; // module creation: islocal = simulation.netInterface()==NULL || simulation.netInterface()->isLocalMachineIn( machines ); if (!islocal) throw new cException("Local machine `%s' is not among machines specified for this network", simulation.netInterface()->localhost()); servicenet_mod = modtype->create( "servicenet", NULL, islocal); check_error(); check_memory(); // set machine list: servicenet_mod->setMachinePar( "default", ev.getPhysicalMachineFor("default") ); check_error(); check_memory(); n = servicenet_mod->params(); for(k=0;kpar(k).isInput()) {servicenet_mod->par(k).read();check_error();} // build function call: servicenet_mod->buildInside(); machines.clear(); check_error(); check_memory(); }