genericSink.cc

Go to the documentation of this file.
00001 #ifndef  _genericsink_cc_INC
00002 #define  _genericsink_cc_INC
00003 
00004 #include        "genericSink.h"
00005 
00006 /*
00007  *--------------------------------------------------------------------------------------
00008  *       Class:  GenericSink
00009  *      Method:  GenericSink
00010  * Description:  constructor
00011  *--------------------------------------------------------------------------------------
00012  */
00013 GenericSink::GenericSink ()
00014 {
00015     out_filename = "sink_trace_.tr";
00016     name = "GenericSink";
00017 }  /* -----  end of method GenericSink::GenericSink  (constructor)  ----- */
00018 
00019 void
00020 GenericSink::setup (uint n, uint v, uint time)
00021 {
00022     vcs =v;
00023     no_nodes = n;
00024     max_sim_time = time;
00025     address = myId();
00026     node_ip = address/3;
00027     last_vc = 0;
00028 
00029     stat_packets_in = 0;
00030     stat_min_pkt_latency = 9999999;
00031     stat_last_packet_out_cycle = 0;
00032     stat_total_lat = 0;
00033     stat_hop_count = 0;
00034 
00035     ready.resize(vcs);
00036 
00037     ready.resize( vcs );
00038     ready.insert( ready.begin(), ready.size(), false );
00039 
00040     for( uint i = 0; i < vcs; i++ )
00041     {
00042         IrisEvent* e = new IrisEvent();
00043         e->type = READY_EVENT;
00044         e->vc = i;
00045         Simulator::Schedule(Simulator::Now()+1, &NetworkComponent::process_event,this, e);
00046     }
00047         return;
00048 }               /* -----  end of function GenericSink  ----- */
00049 
00050 void
00051 GenericSink::set_output_path( string name)
00052 {
00053     stringstream str;
00054     str << name << "/tpg_" << node_ip << "_trace_out.tr";
00055     out_filename = str.str();
00056 }
00057 
00058 void
00059 GenericSink::process_event (IrisEvent* e)
00060 {
00061     switch(e->type)
00062     {
00063         case NEW_PACKET_EVENT:
00064             handle_new_packet_event(e);
00065             break;
00066         case OUT_PULL_EVENT:
00067             handle_out_pull_event(e);
00068             break;
00069         case READY_EVENT:
00070             handle_ready_event(e);
00071             break;
00072         default:
00073             cout << "\nSINK: Unk event type" <<endl;
00074             break;
00075     }
00076 
00077     return ;
00078 }               /* -----  end of function GenericSink::process_event  ----- */
00079 
00080 void
00081 GenericSink::handle_new_packet_event ( IrisEvent* e )
00082 {
00083     ni_recv = false;
00084     // get the packet data
00085     HighLevelPacket* hlp = static_cast< HighLevelPacket* >( e->event_data.at(0));
00086     ullint lat = Simulator::Now() - hlp->sent_time;
00087     if( stat_min_pkt_latency > lat)
00088         stat_min_pkt_latency = lat;
00089 
00090     stat_last_packet_in_cycle = Simulator::Now();
00091     stat_packets_in++;
00092     stat_hop_count += hlp->hop_count;
00093     stat_total_lat += lat;
00094 
00095 #ifdef DEBUG
00096     _DBG( "-------------- GENERIC_SINK GOT NEW PACKET --------------- pkt_latency: %f", lat);
00097     // write out the packet data to the output trace file
00098     if( !out_file.is_open() )
00099         out_file.open( out_filename.c_str(), std::ios_base::app );
00100 
00101     out_file << hlp->toString();
00102     out_file << "\tPkt latency: " << lat << endl;
00103 #endif
00104 
00105     delete hlp;
00106 
00107     // send back a ready event
00108     IrisEvent* event2 = new IrisEvent();
00109     event2->type = READY_EVENT;
00110     event2->vc = hlp->virtual_channel;
00111     Simulator::Schedule( Simulator::Now()+1, &NetworkComponent::process_event, interface_connections[0], event2);
00112 
00113 
00114     delete e;
00115     return ;
00116 }               /* -----  end of function GenericSink::handle_new_packet_event  ----- */
00117 
00118 void
00119 GenericSink::handle_out_pull_event ( IrisEvent* e )
00120 {
00121 
00122     delete e;
00123     return ;
00124 }               /* -----  end of function GenericSink::handle_outpull_event  ----- */
00125 
00126 void
00127 GenericSink::handle_ready_event ( IrisEvent* e )
00128 {
00129     if ( e->vc > vcs )
00130     {
00131         _DBG(" Got ready for vc %d no_vcs %d ", e->vc, vcs);
00132         exit(1);
00133     }
00134 
00135     ready[e->vc] = true;
00136 
00137 
00138     delete e;
00139     return ;
00140 }               /* -----  end of function GenericSink::handle_ready_event  ----- */
00141 
00142 string
00143 GenericSink::toString () const
00144 {
00145     stringstream str;
00146     str << "GenericSink" 
00147         << "\t addr: " << address
00148         << "\toutput file = " << out_filename;
00149     return str.str();
00150 }               /* -----  end of function GenericSink::toString  ----- */
00151 
00152 string
00153 GenericSink::print_stats() const
00154 {
00155     stringstream str;
00156     str << "\n sink[" << node_ip << "] packets_out: " << stat_packets_out
00157         << "\n sink[" << node_ip << "] packets_in: " << stat_packets_in
00158         << "\n sink[" << node_ip << "] min_pkt_latency: " << stat_min_pkt_latency
00159         << "\n sink[" << node_ip << "] last_packet_out_cycle: " << stat_last_packet_out_cycle
00160         << "\n sink[" << node_ip << "] last_packet_in_cycle: " << stat_last_packet_in_cycle
00161         << "\n sink[" << node_ip << "] avg_latency: " << (stat_total_lat+0.0)/stat_packets_in
00162         << "\n sink[" << node_ip << "] avg_hop_count: " << (stat_hop_count+0.0)/stat_packets_in
00163         << endl;
00164     return str.str();
00165 } /* ----- end of function GenericGenericSink::toString ----- */
00166 #endif   /* ----- #ifndef _genericsink_cc_INC  ----- */
00167 

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