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     /* Do this in setup with the address or node_ip appended */
00012 //    out_filename = "traceOut.tr";
00013     last_vc = 0;
00014     interface_connections.resize(1);
00015     seed = 10;
00016 }               /* -----  end of function GenericRPG::GenericRPG  ----- */
00017 
00018 GenericRPG::~GenericRPG ()
00019 {
00020 }               /* -----  end of function GenericRPG::~GenericRPG  ----- */
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 }               /* -----  end of function GenericRPG::init_generator  ----- */
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     /* Need to init these variables. Using default for now */
00053     /*  lambda, out_filename, distribution,  */
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 //    setup();
00083     packets = 0;
00084     address = myId();
00085     only_sink = false;
00086     
00087     // send ready events for each virtual channel
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 //        Simulator::Schedule(Simulator::Now()+1, &NetworkComponent::process_event, interface_connections[0], event);
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     // open the output trace file
00104     /*
00105     stringstream str;
00106     str << "rpg_" << node_ip << "_trace_out.tr";
00107     out_filename = str.str();
00108     out_file.open(out_filename.c_str());
00109     if( !out_file.is_open() )
00110     {
00111         stringstream stream;
00112         stream << "Could not open output trace file " << out_filename << ".\n";
00113         timed_cout(stream.str());
00114     }   
00115      */
00116     return ;
00117 }               /* -----  end of function GenericRPG::setup  ----- */
00118 
00119 void
00120 GenericRPG::finish ()
00121 {
00122 //    out_file.close();
00123     return ;
00124 }               /* -----  end of function GenericRPG::finish  ----- */
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 }               /* -----  end of function GenericRPG::process_event  ----- */
00146 
00147 void
00148 GenericRPG::handle_new_packet_event ( IrisEvent* e)
00149 {
00150     // get the packet data
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     // write out the packet data to the output trace file
00155     /*
00156     if( !out_file.is_open() )   
00157         out_file.open( out_filename.c_str(), std::ios_base::app );              
00158 
00159     if( !out_file.is_open() )
00160     {
00161         cout << "Could not open output trace file " << out_filename << ".\n";
00162     }
00163         
00164         out_file << hlp->toString();
00165         out_file << "\tPkt latency: " << Simulator::Now() - hlp->sent_time << endl;
00166      */
00167 
00168 //        delete(hlp);
00169     // send back a ready event
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 //    delete e;
00178     return ;
00179 }               /* -----  end of function GenericRPG::handle_new_packet_event  ----- */
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         hlp->destination = MIN( generator.address(), MAX_ADDRESS);
00212         if( hlp->destination == node_ip )
00213             hlp->destination = (hlp->destination + 1) % (MAX_ADDRESS + 1);
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; //generator.length();
00220 //        hlp->length = MIN( hlp->length, MAX_LENGTH);
00221 //        hlp->length = MAX( hlp->length, MIN_LENGTH);
00222         hlp->sent_time = Simulator::Now() ; //MAX(generator.delay() , 1);
00223         for ( uint i=0 ; i < hlp->data_payload_length ; i++ )
00224             hlp->data.push_back(true);
00225 
00226         /* Need to generate the transaction id */
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; /* Making a copy so we dont depend on hlp deletionMaking a copy so we dont depend on hlp deletion. May be needed later if the functions are broken. */
00240         Simulator::Schedule( hlp->sent_time, &NetworkComponent::process_event, interface_connections[0], event );
00241                 
00242         /*  Check for an empty vc and call yourself as long as it is not the
00243          *  MAX_SIM_TIME or last packet. If you were to do Run() till all
00244          *  events in the system are complete. This will probably determine
00245          *  the end of the simulation */
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 //    delete e;
00270     return ;
00271 }               /* -----  end of function GenericRPG::handle_out_pull_event  ----- */
00272 
00273 void
00274 GenericRPG::handle_ready_event ( IrisEvent* e)
00275 {
00276 #ifdef _DEBUG
00277     _DBG_NOARG("handle_ready_event");
00278 #endif
00279 
00280     // send the next packet if it is less than the current time
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         /* Need to be careful with the same cycles scheduling. Can result in
00290          * events of the past. Need to test this. */
00291         Simulator::Schedule(Simulator::Now()+1, &NetworkComponent::process_event, this, event); 
00292         sending = true;
00293     }
00294 
00295 //    delete e;
00296     return ;
00297 }               /* -----  end of function GenericRPG::handle_ready_event  ----- */
00298 
00299 void
00300 GenericRPG::init ()
00301 {
00302                 
00303     return ;
00304 }               /* -----  end of function GenericRPG::init  ----- */
00305 
00306 string
00307 GenericRPG::toString () const
00308 {
00309     stringstream str;
00310     str << "GenericRPG";
00311     return str.str();
00312 }               /* -----  end of function GenericRPG::toString  ----- */
00313 
00314 #endif   /* ----- #ifndef _genericrpg_cc_INC  ----- */
00315 

Generated on Tue Oct 19 17:22:00 2010 for IRIS by  doxygen 1.5.8