NetworkLine.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2005-01-17 22:34:01 -0600 (Mon, 17 Jan 2005) $
00011  * Version:       $Revision: 16635 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef _VPR_SIM_NETWORK_LINE_H_
00043 #define _VPR_SIM_NETWORK_LINE_H_
00044 
00045 #include <vpr/vprConfig.h>
00046 
00047 #include <stdlib.h>
00048 #include <math.h>
00049 #include <string>
00050 #include <deque>
00051 #include <vector>
00052 #include <utility>
00053 #include <vpr/vpr.h>
00054 #include <vpr/Util/Interval.h>
00055 
00056 #include <vpr/md/SIM/Network/MessagePtr.h>
00057 
00058 
00059 namespace vpr
00060 {
00061 
00062 namespace sim
00063 {
00064 
00073 class VPR_CLASS_API NetworkLine
00074 {
00075 public:
00076    enum LineDirection
00077    {
00078       FORWARD,
00079       REVERSE
00080    };
00081 
00082    enum NetworkType
00083    {
00084       LAN,
00085       MAN,
00086       WAN,
00087       LOOPBACK
00088    };
00089 
00093    NetworkLine()
00094       : mLength(0.0f)
00095       , mCapacity(0.0f)
00096       , mDelay(0.0f)
00097       , mNetworkType(LAN)
00098       , mNetworkID(0)
00099       , mNetworkIP(0)
00100       , mLatency(0.0f)
00101    {
00102       /* Do nothing. */ ;
00103    }
00104 
00105    NetworkLine(const double miles, const double Mbps, const double delay,
00106                const std::string& netType, const vpr::Uint8 netID,
00107                const std::string& netIP);
00108 
00114    int getWeight() const
00115    {
00116       return (int) mLength;
00117    }
00118 
00122    double getLength() const
00123    {
00124       return mLength;
00125    }
00126 
00127    void setLength(const double miles)
00128    {
00129       mLength  = miles;
00130       mLatency = 5.0f * miles;
00131    }
00132 
00133    double getCapacity() const
00134    {
00135       return mCapacity;
00136    }
00137 
00138    void setCapacity(const double Mbps)
00139    {
00140       mCapacity = Mbps;
00141    }
00142 
00143    double getPropagationDelay() const
00144    {
00145       return mLatency;
00146    }
00147 
00152    vpr::Interval getWireAccessTime(const vpr::Uint32 bits) const
00153    {
00154       // This gets the number of microseconds required to transmit the given
00155       // number of bits.  This works because mCapacity is measured in
00156       // _megabits_ per second but the given argument is simply bits.
00157       double microsec = ((double) bits / mCapacity);
00158 
00159       // Round up since vpr::Interval objects deal in whole numbers.
00160       double time = ceil(microsec);
00161 
00162       return vpr::Interval((vpr::Uint32) time, vpr::Interval::Usec);
00163    }
00164 
00165    const std::string& getNetworkAddressString() const
00166    {
00167       return mNetworkIPStr;
00168    }
00169 
00174    vpr::Interval getBitTransmissionTime() const
00175    {
00176       // Round up since vpr::Interval objects deal in whole numbers.
00177       return vpr::Interval((vpr::Uint32) ceil(getPropagationDelay()),
00178                            vpr::Interval::Usec);
00179    }
00180 
00181    void calculateMessageEventTimes(vpr::sim::MessagePtr msg,
00182                                    const vpr::Interval& curTime,
00183                                    const LineDirection direction)
00184    {
00185       switch (direction)
00186       {
00187          case FORWARD:
00188             calculateMessageEventTimes(msg, curTime, mForwardLineQueue);
00189             break;
00190          case REVERSE:
00191             calculateMessageEventTimes(msg, curTime, mReverseLineQueue);
00192             break;
00193       }
00194    }
00195 
00199    void addMessage(vpr::sim::MessagePtr msg, const LineDirection direction)
00200    {
00201       switch (direction)
00202       {
00203          case FORWARD:
00204             addMessageToQueue(msg, mForwardLineQueue);
00205             break;
00206          case REVERSE:
00207             addMessageToQueue(msg, mReverseLineQueue);
00208             break;
00209       }
00210    }
00211 
00212    void removeActiveMessages(const vpr::SocketImplSIM* sock,
00213                              std::vector<vpr::Interval>& eventTimes,
00214                              const LineDirection direction)
00215    {
00216       switch (direction)
00217       {
00218          case FORWARD:
00219             removeMessagesFromQueue(sock, eventTimes, mForwardLineQueue);
00220             break;
00221          case REVERSE:
00222             removeMessagesFromQueue(sock, eventTimes, mReverseLineQueue);
00223             break;
00224       }
00225    }
00226 
00229    vpr::ReturnStatus getArrivedMessage(const vpr::Interval& eventTime,
00230                                        vpr::sim::MessagePtr& msg,
00231                                        const LineDirection direction)
00232    {
00233       vpr::ReturnStatus status;
00234 
00235       if ( direction == FORWARD )
00236       {
00237          status = getArrivedMessageFromQueue(eventTime, msg, mForwardLineQueue);
00238       }
00239       else
00240       {
00241          status = getArrivedMessageFromQueue(eventTime, msg, mReverseLineQueue);
00242       }
00243 
00244       return status;
00245    }
00246 
00247 private:
00248    typedef std::pair<vpr::Interval, vpr::sim::MessagePtr> msg_queue_entry_t;
00249    typedef std::deque<msg_queue_entry_t> msg_queue_t;
00250 
00251    vpr::ReturnStatus getArrivedMessageFromQueue(const vpr::Interval& eventTime,
00252                                                 vpr::sim::MessagePtr& msg,
00253                                                 msg_queue_t& queue);
00254 
00255    void calculateMessageEventTimes(vpr::sim::MessagePtr msg,
00256                                    const vpr::Interval& curTime,
00257                                    msg_queue_t& queue);
00258 
00259    void addMessageToQueue(vpr::sim::MessagePtr msg, msg_queue_t& queue);
00260 
00261    void removeMessagesFromQueue(const vpr::SocketImplSIM* sock,
00262                                 std::vector<vpr::Interval>& eventTimes,
00263                                 msg_queue_t& queue);
00264 
00265    double      mLength;       
00266    double      mCapacity;     
00267    double      mDelay;
00268    NetworkType mNetworkType;  
00269    vpr::Uint8  mNetworkID;    
00270    vpr::Uint32 mNetworkIP;
00271    std::string mNetworkIPStr;
00272 
00273    double mLatency;       
00275    msg_queue_t mForwardLineQueue;
00276    msg_queue_t mReverseLineQueue;
00277 };
00278 
00279 } // End of sim namespace
00280 
00281 } // End of vpr namespace
00282 
00283 
00284 #endif /* _VPR_SIM_NETWORK_LINE_H_ */

Generated on Thu Jan 4 10:52:10 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1