genericRPG.cc
Go to the documentation of this file.00001
00002 #ifndef _genericrpg_cc_INC
00003 #define _genericrpg_cc_INC
00004 #define MAX_SIM_TIME 2000000000
00005 #include "genericRPG.h"
00006
00007 GenericRPG::GenericRPG ()
00008 {
00009 name = "GenericRPG";
00010 sending = false;
00011
00012
00013 last_vc = 0;
00014 interface_connections.resize(1);
00015 seed = 10;
00016 }
00017
00018 GenericRPG::~GenericRPG ()
00019 {
00020 }
00021
00022 void
00023 GenericRPG::init_generator ()
00024 {
00025 generator.seed(seed);
00026
00027 generator.addressRange( 0, MAX_ADDRESS + 1 );
00028 generator.delayRange( MIN_DELAY, MAX_DELAY );
00029 generator.lengthRange( MIN_LENGTH, MAX_LENGTH);
00030
00031 generator.addressHotSpotRange( 0, MAX_ADDRESS + 1, HOT_SPOTS);
00032 generator.delayHotSpotRange( MIN_DELAY, MAX_DELAY, HOT_SPOTS );
00033 generator.lengthHotSpotRange( MIN_LENGTH, MAX_LENGTH, HOT_SPOTS );
00034
00035 generator.addressDistribution( destination_type );
00036 generator.lengthDistribution( length_type );
00037 generator.delayDistribution( delay_type );
00038 return ;
00039 }
00040
00041 void
00042 GenericRPG::set_no_vcs( uint v )
00043 {
00044 vcs = v;
00045 }
00046
00047 void
00048 GenericRPG::setup (uint n, uint v, uint time)
00049 {
00050 vcs = v;
00051 max_sim_time = time;
00052
00053
00054 if( run_destination_type.compare("poisson")==0 )
00055 {
00056 destination_type = libRandom::randomNumberGenerator::poisson;
00057 length_type = libRandom::randomNumberGenerator::poisson;
00058 delay_type = libRandom::randomNumberGenerator::poisson;
00059 }
00060 else if( run_destination_type.compare("gaussian") == 0)
00061 {
00062 destination_type = libRandom::randomNumberGenerator::gaussian;
00063 length_type = libRandom::randomNumberGenerator::gaussian;
00064 delay_type = libRandom::randomNumberGenerator::gaussian;
00065 }
00066 else if( run_destination_type.compare("hotSpot") == 0 )
00067 {
00068 destination_type = libRandom::randomNumberGenerator::hotSpot;
00069 length_type = libRandom::randomNumberGenerator::hotSpot;
00070 delay_type = libRandom::randomNumberGenerator::hotSpot;
00071 }
00072 else
00073 {
00074 destination_type = libRandom::randomNumberGenerator::uniform;
00075 length_type = libRandom::randomNumberGenerator::uniform;
00076 delay_type = libRandom::randomNumberGenerator::uniform;
00077 }
00078
00079 ready.resize( vcs );
00080 ready.insert( ready.begin(), ready.size(), false );
00081 init_generator();
00082
00083 packets = 0;
00084 address = myId();
00085 only_sink = false;
00086
00087
00088 for( unsigned int i = 0; i < vcs; i++ )
00089 {
00090 IrisEvent* event = new IrisEvent();
00091 VirtualChannelDescription* vc = new VirtualChannelDescription();
00092 event->type = READY_EVENT;
00093 event->vc = i;
00094 vc->vc = i;
00095 event->event_data.push_back(vc);
00096
00097 Simulator::Schedule(Simulator::Now()+1, &NetworkComponent::process_event, this, event);
00098 }
00099
00100 for(unsigned int i = 0; i < ready.size(); i++)
00101 ready[i] = true;
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 return ;
00117 }
00118
00119 void
00120 GenericRPG::finish ()
00121 {
00122
00123 return ;
00124 }
00125
00126 void
00127 GenericRPG::process_event (IrisEvent* e)
00128 {
00129 switch(e->type)
00130 {
00131 case NEW_PACKET_EVENT:
00132 handle_new_packet_event(e);
00133 break;
00134 case OUT_PULL_EVENT:
00135 handle_out_pull_event(e);
00136 break;
00137 case READY_EVENT:
00138 handle_ready_event(e);
00139 break;
00140 default:
00141 cout << "\nRPG: " << address << "process_event: UNK event type" << endl;
00142 break;
00143 }
00144 return ;
00145 }
00146
00147 void
00148 GenericRPG::handle_new_packet_event ( IrisEvent* e)
00149 {
00150
00151 HighLevelPacket* hlp = static_cast< HighLevelPacket* >( e->event_data.at(0));
00152 _DBG( "-------------- GOT NEW PACKET ---------------\n pkt_latency: %d", (int)( Simulator::Now() - hlp->sent_time));
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 IrisEvent* event = new IrisEvent();
00171 event->type = READY_EVENT;
00172 VirtualChannelDescription* vc = new VirtualChannelDescription();
00173 vc->vc = hlp->virtual_channel;
00174 event->event_data.push_back(vc);
00175 Simulator::Schedule( Simulator::Now()+1, &NetworkComponent::process_event, interface_connections[0], event);
00176
00177
00178 return ;
00179 }
00180
00181 void
00182 GenericRPG::handle_out_pull_event ( IrisEvent* e )
00183 {
00184 bool found = false;
00185 for( unsigned int i = last_vc ; i < ready.size(); i++ )
00186 if( ready[i] )
00187 {
00188 found = true;
00189 last_vc= i;
00190 break;
00191 }
00192
00193 if(!found )
00194 for( unsigned int i = 0; i < last_vc ; i++ )
00195 if( ready[i] )
00196 {
00197 found = true;
00198 last_vc = i;
00199 break;
00200 }
00201
00202 if( found && !only_sink)
00203 {
00204 packets++;
00205 unsigned int current_packet_time = 0;
00206 HighLevelPacket* hlp = new HighLevelPacket();
00207 hlp->virtual_channel = last_vc;
00208 last_vc++;
00209 hlp->source = address;
00210
00211
00212
00213
00214
00215 hlp->destination = 0;
00216 if( node_ip == 0 )
00217 hlp->destination = 1;
00218
00219 hlp->data_payload_length= 1*max_phy_link_bits;
00220
00221
00222 hlp->sent_time = Simulator::Now() ;
00223 for ( uint i=0 ; i < hlp->data_payload_length ; i++ )
00224 hlp->data.push_back(true);
00225
00226
00227 hlp->transaction_id = generator.length();
00228 seed++;
00229
00230 stringstream str;
00231 str << "GenericRPG " << address << " Sending packet : " << hlp->toString();
00232 str << "\n No of packets: " << packets;
00233 timed_cout(str.str());
00234
00235 ready[ hlp->virtual_channel ] = false;
00236 IrisEvent* event = new IrisEvent();
00237 event->type = NEW_PACKET_EVENT;
00238 event->event_data.push_back(hlp);
00239 current_packet_time = hlp->sent_time;
00240 Simulator::Schedule( hlp->sent_time, &NetworkComponent::process_event, interface_connections[0], event );
00241
00242
00243
00244
00245
00246 found = false;
00247 for( unsigned int i = 0; i < ready.size(); i++ )
00248 if( ready[i] && current_packet_time < MAX_SIM_TIME )
00249 {
00250 found = true;
00251 break;
00252 }
00253
00254 if( found )
00255 {
00256 IrisEvent* event = new IrisEvent();
00257 event->type = OUT_PULL_EVENT;
00258 event->vc = e->vc;
00259 Simulator::Schedule( Simulator::Now()+1, &NetworkComponent::process_event, this, event);
00260 sending = true;
00261 }
00262 else
00263 sending = false;
00264
00265 }
00266 else
00267 sending = false;
00268
00269
00270 return ;
00271 }
00272
00273 void
00274 GenericRPG::handle_ready_event ( IrisEvent* e)
00275 {
00276 #ifdef _DEBUG
00277 _DBG_NOARG("handle_ready_event");
00278 #endif
00279
00280
00281 VirtualChannelDescription* vc = static_cast<VirtualChannelDescription*>(e->event_data.at(0));
00282 ready[vc->vc] = true;
00283
00284 if( !sending && Simulator::Now() < MAX_SIM_TIME )
00285 {
00286 IrisEvent* event = new IrisEvent();
00287 event->type = OUT_PULL_EVENT;
00288 event->vc = e->vc;
00289
00290
00291 Simulator::Schedule(Simulator::Now()+1, &NetworkComponent::process_event, this, event);
00292 sending = true;
00293 }
00294
00295
00296 return ;
00297 }
00298
00299 void
00300 GenericRPG::init ()
00301 {
00302
00303 return ;
00304 }
00305
00306 string
00307 GenericRPG::toString () const
00308 {
00309 stringstream str;
00310 str << "GenericRPG";
00311 return str.str();
00312 }
00313
00314 #endif
00315