lowLevelPacket.cc

Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  LowLevelPacket.cc
00005  *
00006  *    Description:  
00007  *
00008  *        Version:  1.0
00009  *        Created:  02/09/2010 08:56:45 PM
00010  *       Revision:  none
00011  *       Compiler:  gcc
00012  *
00013  *         Author:  Mitchelle Rasquinha (), mitchelle.rasquinha@gatech.edu
00014  *        Company:  Georgia Institute of Technology
00015  *
00016  * =====================================================================================
00017  */
00018 
00019 #ifndef  _lowlevelpacket_cc_INC
00020 #define  _lowlevelpacket_cc_INC
00021 
00022 #include        "lowLevelPacket.h"
00023 
00024 using namespace std;
00025 
00026 /* LowLevelPacket Class Impl */
00027 LowLevelPacket::LowLevelPacket()
00028 {
00029     source = -1;
00030     destination = -1;
00031     transaction_id = -1;
00032     virtual_channel = 0;
00033     sent_time = 0;
00034     length = 0;
00035 
00036 }
00037 
00038 LowLevelPacket::~LowLevelPacket()
00039 {
00040     flits.clear();
00041     control_bits.clear();
00042     payload.clear();
00043 }               /* -----  end of function LowLevelPacket::~LowLevelPacket()  ----- */
00044 
00045 void LowLevelPacket::operator=( const LowLevelPacket* p )
00046 {
00047     source = p->source;
00048     destination = p->destination;
00049     transaction_id = p->transaction_id;
00050     pkt_cnt = p->pkt_cnt;
00051     virtual_channel = p->virtual_channel;
00052     sent_time = p->sent_time;
00053     msg_class = p->msg_class;
00054     length = p->length;
00055     for ( uint i=0; i<control_bits.size(); i++)
00056         this->control_bits.push_back(p->control_bits[i]); 
00057 
00058     for ( uint i=0; i<payload.size(); i++)
00059         this->payload.push_back(p->payload[i]); 
00060 }
00061 
00062 string
00063 LowLevelPacket::toString () const
00064 {
00065     stringstream str;
00066     str << "LowLevelPacket: " << endl;
00067     str << "\t Source: " << source 
00068         << "\t Destination: " << destination
00069         << "\t virtual_channel: " << virtual_channel 
00070         << "\t sent time: " << sent_time
00071         << "\t No of flits: " << flits.size()
00072         << "\t length: " << length
00073         << "\t msg_class: " << msg_class
00074         << "\t addr: " << addr << dec
00075         << "\t hop_count: " << hop_count
00076         << "\t network_latency: " << avg_network_latency
00077                 << "\t PacketCount: " << dec << pkt_cnt
00078         << "\t size: " << static_cast<HeadFlit*>(flits[0])->payload.size() 
00079         << endl;
00080     for ( uint i=0 ; i<flits.size() ; i++ )
00081         if( flits[i]->type == HEAD)
00082             str << static_cast<HeadFlit*>(flits[i])->toString();
00083         else if( flits[i]->type == BODY)
00084             str << static_cast<BodyFlit*>(flits[i])->toString();
00085         else if( flits[i]->type == TAIL)
00086             str << static_cast<TailFlit*>(flits[i])->toString();
00087         else
00088             str << " Error unk flit type" ;
00089 /* 
00090  * */
00091     return str.str();
00092 }               /* -----  end of function LoeLevelPacket::toString  ----- */
00093 
00094 bool
00095 LowLevelPacket::valid_packet ()
00096 {
00097     if( flits.size())
00098         return (flits.size() == static_cast<HeadFlit*>(flits[0])->length);
00099     else
00100         return false;
00101 
00102 }               /* -----  end of function LowLevelPacket::valid_packet  ----- */
00103 
00104 void
00105 LowLevelPacket::add ( Flit* ptr )
00106 {
00107     switch (ptr->type)
00108     {
00109         case HEAD:
00110             {
00111                 HeadFlit* hf = static_cast < HeadFlit*> (ptr);
00112 //                flits.push_back(hf);
00113                 this->source = hf->src_address;
00114                 this->destination = hf->dst_address;
00115                 this->transaction_id = hf->transaction_id;
00116                 this->virtual_channel = hf->vc;
00117                 this->length = hf->length;
00118                 this->msg_class = hf->msg_class;
00119                 this->sent_time = hf->packet_originated_time;
00120                 this->addr = hf->addr;
00121                 this->avg_network_latency = hf->avg_network_latency;
00122                 this->hop_count = hf->hop_count;
00123                 this->stat_memory_serviced_time = hf->stat_memory_serviced_time;
00124                 this->req_start_time = hf->req_start_time;
00125                 this->waiting_in_ni = hf->waiting_in_ni;
00126                 this->pkt_cnt = hf->pkt_cnt;
00127 
00128     for ( uint i=0; i<hf->control_bits.size(); i++)
00129         this->control_bits.push_back(hf->control_bits[i]); 
00130 
00131     for ( uint i=0; i<hf->payload.size(); i++)
00132         this->payload.push_back(hf->payload[i]); 
00133 
00134                 delete hf;
00135                 break;
00136             }
00137         case BODY:
00138             {
00139                 BodyFlit* bf = static_cast<BodyFlit*> (ptr);
00140     for ( uint i=0; i<bf->bf_data.size(); i++)
00141         this->payload.push_back(bf->bf_data[i]); 
00142 //                flits.push_back(bf);
00143                 delete bf;
00144                 break;
00145             }
00146         case TAIL:
00147             {
00148                 TailFlit* tf = static_cast<TailFlit*> (ptr);
00149 //                flits.push_back(tf);
00150                 this->sent_time = tf->packet_originated_time;
00151                 this->avg_network_latency = tf->avg_network_latency - this->avg_network_latency;
00152                 delete tf;
00153                 break;
00154             }
00155         default:
00156             fprintf(stdout,"ERROR Unk flit type");
00157             break;
00158     }
00159     return ;
00160 }               /* -----  end of function LowLevelPacket::add  ----- */
00161 
00162 Flit* LowLevelPacket::at(unsigned int index)
00163 {
00164     if(index > flits.size())
00165         fprintf(stdout," Error Index out of bounds in lowlevelpacket");
00166 
00167     return flits.at(index);
00168 }
00169 
00170 Flit* LowLevelPacket::get_next_flit()
00171 {
00172     Flit *ptr;
00173     ptr = flits.front();
00174     flits.pop_front();
00175     return ptr;
00176 }
00177 
00178 void
00179 LowLevelPacket::clear ()
00180 {
00181     flits.clear();
00182     return;
00183 }               /* -----  end of function LowLevelPacket::clear  ----- */
00184 
00185 uint
00186 LowLevelPacket::size ()
00187 {
00188     return flits.size();
00189 }               /* -----  end of function LowLevelPacket::size  ----- */
00190 
00191 #endif   /* ----- #ifndef _lowlevelpacket_cc_INC  ----- */
00192 

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