genericFlatMc.cc
Go to the documentation of this file.00001
00019 #ifndef _genericflatmc_cc_INC
00020 #define _genericflatmc_cc_INC
00021
00022 #include "genericFlatMc.h"
00023
00024 using namespace std;
00025
00026 GenericFlatMc::GenericFlatMc ()
00027 {
00028 name = "GenericFlatMc";
00029 sending = false;
00030 ni_recv = false;
00031 }
00032
00033 GenericFlatMc::~GenericFlatMc ()
00034 {
00035 pending_packets.clear();
00036 pending_packets_time.clear();
00037 out_file.close();
00038 return ;
00039 }
00040
00041 void
00042 GenericFlatMc::setup (uint n, uint v, uint time)
00043 {
00044 vcs =v;
00045 max_sim_time = time;
00046 no_nodes = n;
00047 address = myId();
00048
00049 min_pkt_latency = 999999999;
00050 packets_out = 0;
00051 packets_in = 0;
00052 last_packet_in_cycle = 0;
00053 last_packet_out_cycle = 0;
00054 packets_pending = 0;
00055
00056 ready.resize( vcs );
00057 ready.insert( ready.begin(), ready.size(), true );
00058 for(unsigned int i = 0; i < ready.size(); i++)
00059 ready[i] = true;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 return ;
00072 }
00073
00074 void
00075 GenericFlatMc::set_output_path( string name)
00076 {
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 return;
00089 }
00090
00091 void
00092 GenericFlatMc::finish ()
00093 {
00094 }
00095
00096 void
00097 GenericFlatMc::process_event (IrisEvent* e)
00098 {
00099 switch(e->type)
00100 {
00101 case NEW_PACKET_EVENT:
00102 handle_new_packet_event(e);
00103 break;
00104 case OUT_PULL_EVENT:
00105 handle_out_pull_event(e);
00106 break;
00107 case READY_EVENT:
00108 handle_ready_event(e);
00109 break;
00110 default:
00111 cout << "\nTPG: " << address << "process_event: UNK event type" << endl;
00112 break;
00113 }
00114 return ;
00115 }
00116
00117 void
00118 GenericFlatMc::handle_new_packet_event ( IrisEvent* e)
00119 {
00120 ni_recv = false;
00121
00122 HighLevelPacket* hlp = static_cast< HighLevelPacket* >( e->event_data.at(0));
00123 double lat = Simulator::Now() - hlp->sent_time;
00124 if( min_pkt_latency > lat)
00125 min_pkt_latency = lat;
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 IrisEvent* event2 = new IrisEvent();
00145 event2->type = READY_EVENT;
00146 event2->vc = hlp->virtual_channel;
00147 Simulator::Schedule( Simulator::Now()+1, &NetworkComponent::process_event, interface_connections[0], event2);
00148
00149
00150 packets_pending++;
00151 pending_packets_time.push_back(Simulator::Now()+200);
00152 pending_packets.push_back(hlp);
00153
00154
00155
00156 packets_in++;
00157 last_packet_in_cycle = Simulator::Now();
00158
00159
00160 IrisEvent* event = new IrisEvent();
00161 event->type = OUT_PULL_EVENT;
00162 event->vc = 0;
00163
00164 Simulator::Schedule(Simulator::Now()+199, &NetworkComponent::process_event, this, event);
00165 sending = true;
00166
00167
00168 delete e;
00169 return ;
00170 }
00171
00172 void
00173 GenericFlatMc::handle_out_pull_event ( IrisEvent* e )
00174 {
00175 bool found = false;
00176 uint sending_vc = -1;
00177 for( uint i=last_vc+1; i<vcs; i++)
00178 if( ready[i])
00179 {
00180 found = true;
00181 sending_vc = i;
00182 last_vc = i;
00183 break;
00184 }
00185 if ( !found)
00186 {
00187 for ( uint i=0; i<=last_vc; i++)
00188 if( ready[i])
00189 {
00190 found = true;
00191 sending_vc = i;
00192 last_vc = i;
00193 break;
00194 }
00195 }
00196 if( found && packets_pending > 0)
00197 {
00198
00199 packets_out++;
00200 last_packet_out_cycle= Simulator::Now();
00201
00202 packets_pending--;
00203 HighLevelPacket* hlp = pending_packets.front();
00204 hlp->virtual_channel = sending_vc;
00205
00206 hlp->transaction_id = 1000;
00207 hlp->msg_class = RESPONSE_PKT;
00208 hlp->destination = hlp->source;
00209 hlp->source = node_ip;
00210 hlp->sent_time = pending_packets_time.front();
00211 pending_packets_time.pop_front();
00212 pending_packets.pop_front();
00213
00214
00215
00216 hlp->data_payload_length = mc_response_pkt_payload_length;
00217
00218 hlp->sent_time += (Simulator::Now()-hlp->sent_time);
00219 hlp->hop_count++;
00220
00221 ready[sending_vc] = false;
00222 IrisEvent* event = new IrisEvent();
00223 event->type = NEW_PACKET_EVENT;
00224 event->event_data.push_back(hlp);
00225 Simulator::Schedule( hlp->sent_time, &NetworkComponent::process_event, interface_connections[0], event );
00226
00227 sending = false;
00228 }
00229
00230 delete e;
00231 return ;
00232 }
00233
00234 void
00235 GenericFlatMc::handle_ready_event ( IrisEvent* e)
00236 {
00237
00238
00239 ready[e->vc] = true;
00240 #ifdef _DEBUG_TPG
00241 _DBG_NOARG(" handle_ready_event ");
00242 #endif
00243
00244 if( !sending && Simulator::Now() < max_sim_time )
00245 {
00246 IrisEvent* event = new IrisEvent();
00247 event->type = OUT_PULL_EVENT;
00248 event->vc = e->vc;
00249 Simulator::Schedule(Simulator::Now()+1, &NetworkComponent::process_event, this, event);
00250 sending = true;
00251 }
00252 delete e;
00253 return ;
00254 }
00255
00256 string
00257 GenericFlatMc::toString () const
00258 {
00259 stringstream str;
00260 str << "\nGenericFlatMc: "
00261 << "\t vcs: " << ready.size()
00262 << "\t address: " <<address
00263 << "\t node_ip: " << node_ip
00264 ;
00265 return str.str();
00266 }
00267
00268 string
00269 GenericFlatMc::print_stats() const
00270 {
00271 stringstream str;
00272 str << toString()
00273 << "\n packets_out:\t " << packets_out
00274 << "\n last_packet_out_cycle :\t " << last_packet_out_cycle
00275 << "\n packets_in:\t " << packets_in
00276 << "\n last_packet_in_cycle :\t " << last_packet_in_cycle
00277 << "\n min_pkt_latency:\t" << min_pkt_latency
00278 ;
00279 return str.str();
00280 }
00281
00282 #endif