back out unfinished p2p changes
authorTom Henderson <tomh@tomh.org>
Fri, 15 Jun 2007 13:19:57 -0700
changeset 77318ad0b94e2ae
parent 767 c36570ed4f5e
child 774 d8b27eb4efc5
back out unfinished p2p changes
src/devices/p2p/p2p-channel.cc
src/devices/p2p/p2p-net-device.cc
src/devices/p2p/p2p-net-device.h
src/node/mac-address.cc
src/node/mac-address.h
     1.1 --- a/src/devices/p2p/p2p-channel.cc	Thu Jun 14 10:41:47 2007 +0200
     1.2 +++ b/src/devices/p2p/p2p-channel.cc	Fri Jun 15 13:19:57 2007 -0700
     1.3 @@ -135,14 +135,12 @@
     1.4  // The sender is going to free the packet as soon as it has been transmitted.
     1.5  // We need to copy it to get a reference so it won't e deleted.
     1.6  //
     1.7 -// Above is not correct (GFR).  The event scheduler makes a copy
     1.8 -// of the packet
     1.9 -//  Packet packet = p;
    1.10 +  Packet packet = p;
    1.11    NS_DEBUG ("PointToPointChannel::TransmitEnd (): Schedule event in " << 
    1.12              m_delay.GetSeconds () << "sec");
    1.13    Simulator::Schedule (m_delay,
    1.14                         &PointToPointChannel::PropagationCompleteEvent,
    1.15 -                       this, p, src);
    1.16 +                       this, packet, src);
    1.17    return true;
    1.18  }
    1.19  
     2.1 --- a/src/devices/p2p/p2p-net-device.cc	Thu Jun 14 10:41:47 2007 +0200
     2.2 +++ b/src/devices/p2p/p2p-net-device.cc	Fri Jun 15 13:19:57 2007 -0700
     2.3 @@ -16,8 +16,7 @@
     2.4   * along with this program; if not, write to the Free Software
     2.5   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.6   *
     2.7 - * Author:  Craig Dowell <craigdo@ee.washington.edu>
     2.8 - * Revised: George Riley <riley@ece.gatech.edu>
     2.9 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    2.10   */
    2.11  
    2.12  #include <iostream>
    2.13 @@ -33,17 +32,11 @@
    2.14  
    2.15  namespace ns3 {
    2.16  
    2.17 -DataRateDefaultValue PointToPointNetDevice::g_defaultRate(
    2.18 -           "PointToPointLinkDataRate", 
    2.19 -           "The default data rate for point to point links",
    2.20 -           DataRate ("10Mb/s"));
    2.21 -
    2.22 -  PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node,
    2.23 -                                                const DataRate& rate) 
    2.24 +PointToPointNetDevice::PointToPointNetDevice (Ptr<Node> node) 
    2.25  : 
    2.26 -  NetDevice(node, MacAddress (6)), 
    2.27 +  NetDevice(node, MacAddress ("00:00:00:00:00:00")), 
    2.28    m_txMachineState (READY),
    2.29 -  m_bps (rate),
    2.30 +  m_bps (DataRate (0xffffffff)),
    2.31    m_tInterframeGap (Seconds(0)),
    2.32    m_channel (0), 
    2.33    m_queue (0),
    2.34 @@ -108,25 +101,26 @@
    2.35  //
    2.36  // Assignment operator for PointToPointNetDevice.
    2.37  //
    2.38 +// This uses the non-obvious trick of taking the source net device passed by
    2.39 +// value instead of by reference.  This causes the copy constructor to be
    2.40 +// invoked (where the real work is done -- see above).  All we have to do
    2.41 +// here is to return the newly constructed net device.
    2.42  //
    2.43 -PointToPointNetDevice&
    2.44 -PointToPointNetDevice::operator= (const PointToPointNetDevice& nd)
    2.45 +  PointToPointNetDevice&
    2.46 +PointToPointNetDevice::operator= (const PointToPointNetDevice nd)
    2.47  {
    2.48    NS_DEBUG ("PointToPointNetDevice::operator= (" << &nd << ")");
    2.49 -  // FIXME.  Not sure what to do here
    2.50 -  // GFR Note.  I would suggest dis-allowing netdevice assignment,
    2.51 -  // as well as pass-by-value (ie. copy constructor).
    2.52    return *this;
    2.53  }
    2.54  
    2.55    void 
    2.56 -PointToPointNetDevice::SetDataRate(const DataRate& bps)
    2.57 +PointToPointNetDevice::SetDataRate(DataRate bps)
    2.58  {
    2.59    m_bps = bps;
    2.60  }
    2.61  
    2.62    void 
    2.63 -PointToPointNetDevice::SetInterframeGap(const Time& t)
    2.64 +PointToPointNetDevice::SetInterframeGap(Time t)
    2.65  {
    2.66    m_tInterframeGap = t;
    2.67  }
    2.68 @@ -139,23 +133,68 @@
    2.69  
    2.70    NS_ASSERT (IsLinkUp ());
    2.71  
    2.72 +#ifdef NOTYET
    2.73 +    struct NetDevicePacketDestAddress tag;
    2.74 +    tag.address = address;
    2.75 +    p.AddTag (tag);
    2.76 +#endif
    2.77 +
    2.78  //
    2.79  // This class simulates a point to point device.  In the case of a serial
    2.80  // link, this means that we're simulating something like a UART.  This is
    2.81  // not a requirement for a point-to-point link, but it's a typical model for
    2.82  // the device.  
    2.83  //
    2.84 +// Generally, a real device will have a list of pending packets to transmit.  
    2.85 +// An on-device CPU frees the main CPU(s) of the details of what is happening
    2.86 +// in the device and feeds the USART.  The main CPU basically just sees the 
    2.87 +// list of packets -- it puts packets into the list, and the device frees the
    2.88 +// packets when they are transmitted.
    2.89  //
    2.90 -// If there's a transmission in progress, we enque the packet for later
    2.91 -// trnsmission; otherwise we send it now.
    2.92 +// In the case of our virtual device here, the queue pointed to by m_queue
    2.93 +// corresponds to this list.  The main CPU adds packets to the list by 
    2.94 +// calling this method and when the device completes a send, the packets are
    2.95 +// freed in an "interrupt" service routine.
    2.96 +//
    2.97 +// We're going to do the same thing here.  So first of all, the incoming packet
    2.98 +// goes onto our queue if possible.  If the queue can't handle it, there's
    2.99 +// nothing to be done.
   2.100 +//
   2.101 +    if (m_queue->Enqueue(p) == false )
   2.102 +      {
   2.103 +        return false;
   2.104 +      }
   2.105 +//
   2.106 +// If there's a transmission in progress, the "interrupt" will keep the
   2.107 +// transmission process going.  If the device is idle, we need to start a
   2.108 +// transmission.
   2.109 +//
   2.110 +// In the real world, the USART runs until it finishes sending bits, and then
   2.111 +// pulls on the device's transmit complete interrupt wire.  At the same time,
   2.112 +// the electrons from the last wiggle of the wire are busy propagating down
   2.113 +// the wire.  In the case of a long speed-of-light delay in the wire, we could
   2.114 +// conceivably start transmitting the next packet before the end of the 
   2.115 +// previously sent data has even reached the end of the wire.  This situation
   2.116 +// is usually avoided (like the plague) and an "interframe gap" is introduced.
   2.117 +// This is usually the round-trip delay on the channel plus some hard-to-
   2.118 +// quantify receiver turn-around time (the time required for the receiver
   2.119 +// to process the last frame and prepare for reception of the next).
   2.120 +//
   2.121 +// So, if the transmit machine is ready, we need to schedule a transmit 
   2.122 +// complete event (at which time we tell the channel we're no longer sending
   2.123 +// bits).  A separate transmit ready event (at which time the transmitter 
   2.124 +// becomes ready to start sending bits again is scheduled there).  Finally, 
   2.125 +// we tell the channel (via TransmitStart ()) that we've started wiggling the 
   2.126 +// wire and bits are coming out.
   2.127 +//
   2.128 +// If the transmit machine is not ready, we just leave and the transmit ready
   2.129 +// event we know is coming will kick-start the transmit process.
   2.130 +//
   2.131      if (m_txMachineState == READY) 
   2.132        {
   2.133          return TransmitStart (p);
   2.134        }
   2.135 -    else
   2.136 -      {
   2.137 -        return m_queue->Enqueue(p);
   2.138 -      }
   2.139 +    return true;
   2.140  }
   2.141  
   2.142    bool
   2.143 @@ -167,25 +206,25 @@
   2.144  //
   2.145  // This function is called to start the process of transmitting a packet.
   2.146  // We need to tell the channel that we've started wiggling the wire and
   2.147 -// schedule an event that will be executed when the transmission is complete.
   2.148 +// schedule an event that will be executed when it's time to tell the 
   2.149 +// channel that we're done wiggling the wire.
   2.150  //
   2.151    NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit");
   2.152    m_txMachineState = BUSY;
   2.153 -  Time txCompleteTime = Seconds (m_bps.CalculateTxTime(p.GetSize())) + 
   2.154 -    m_tInterframeGap;
   2.155 +  Time tEvent = Seconds (m_bps.CalculateTxTime(p.GetSize()));
   2.156  
   2.157    NS_DEBUG ("PointToPointNetDevice::TransmitStart (): " <<
   2.158      "Schedule TransmitCompleteEvent in " << 
   2.159 -    txCompleteTime.GetSeconds () << "sec");
   2.160 -  // Schedule the tx complete event
   2.161 -  Simulator::Schedule (txCompleteTime, 
   2.162 -                       &PointToPointNetDevice::TransmitComplete, 
   2.163 +    tEvent.GetSeconds () << "sec");
   2.164 +
   2.165 +  Simulator::Schedule (tEvent, 
   2.166 +                       &PointToPointNetDevice::TransmitCompleteEvent, 
   2.167                         this);
   2.168 -  return m_channel->TransmitStart(p, this); 
   2.169 +  return m_channel->TransmitStart (p, this); 
   2.170  }
   2.171  
   2.172    void
   2.173 -PointToPointNetDevice::TransmitComplete (void)
   2.174 +PointToPointNetDevice::TransmitCompleteEvent (void)
   2.175  {
   2.176    NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent ()");
   2.177  //
   2.178 @@ -195,10 +234,49 @@
   2.179  // the transmitter after the interframe gap.
   2.180  //
   2.181    NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
   2.182 +  m_txMachineState = GAP;
   2.183 +  Packet p;
   2.184 +  bool found;
   2.185 +  found = m_queue->Dequeue (p);
   2.186 +  NS_ASSERT_MSG(found, "Packet must be on queue if transmitted");
   2.187 +  NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent (): Pkt UID is " << 
   2.188 +            p.GetUid () << ")");
   2.189 +  m_channel->TransmitEnd (p, this); 
   2.190 +
   2.191 +  NS_DEBUG (
   2.192 +    "PointToPointNetDevice::TransmitCompleteEvent (): " <<
   2.193 +    "Schedule TransmitReadyEvent in "
   2.194 +    << m_tInterframeGap.GetSeconds () << "sec");
   2.195 +
   2.196 +  Simulator::Schedule (m_tInterframeGap, 
   2.197 +                       &PointToPointNetDevice::TransmitReadyEvent, 
   2.198 +                       this);
   2.199 +}
   2.200 +
   2.201 +  void
   2.202 +PointToPointNetDevice::TransmitReadyEvent (void)
   2.203 +{
   2.204 +  NS_DEBUG ("PointToPointNetDevice::TransmitReadyEvent ()");
   2.205 +//
   2.206 +// This function is called to enable the transmitter after the interframe
   2.207 +// gap has passed.  If there are pending transmissions, we use this opportunity
   2.208 +// to start the next transmit.
   2.209 +//
   2.210 +  NS_ASSERT_MSG(m_txMachineState == GAP, "Must be in interframe gap");
   2.211    m_txMachineState = READY;
   2.212 -  Packet p;
   2.213 -  if (!m_queue->Dequeue(p)) return; // Nothing to do at this point
   2.214 -  TransmitStart(p);
   2.215 +
   2.216 +  if (m_queue->IsEmpty())
   2.217 +    {
   2.218 +      return;
   2.219 +    }
   2.220 +  else
   2.221 +    {
   2.222 +      Packet p;
   2.223 +      bool found;
   2.224 +      found = m_queue->Peek (p);
   2.225 +      NS_ASSERT_MSG(found, "IsEmpty false but no Packet on queue?");
   2.226 +      TransmitStart (p);
   2.227 +    }
   2.228  }
   2.229  
   2.230  TraceResolver *
     3.1 --- a/src/devices/p2p/p2p-net-device.h	Thu Jun 14 10:41:47 2007 +0200
     3.2 +++ b/src/devices/p2p/p2p-net-device.h	Fri Jun 15 13:19:57 2007 -0700
     3.3 @@ -30,7 +30,6 @@
     3.4  #include "ns3/callback-trace-source.h"
     3.5  #include "ns3/nstime.h"
     3.6  #include "ns3/data-rate.h"
     3.7 -#include "ns3/default-value.h"
     3.8  #include "ns3/ptr.h"
     3.9  
    3.10  namespace ns3 {
    3.11 @@ -81,8 +80,7 @@
    3.12     * @see PointToPointTopology::AddPointToPointLink ()
    3.13     * @param node the Node to which this device is connected.
    3.14     */
    3.15 -  PointToPointNetDevice (Ptr<Node> node,
    3.16 -                         const DataRate& = g_defaultRate.GetValue());
    3.17 +  PointToPointNetDevice (Ptr<Node> node);
    3.18    /**
    3.19     * Copy Construct a PointToPointNetDevice
    3.20     *
    3.21 @@ -107,7 +105,7 @@
    3.22     *
    3.23     * @param nd the object to be copied
    3.24     */
    3.25 -  PointToPointNetDevice& operator= (const PointToPointNetDevice& nd);
    3.26 +  PointToPointNetDevice& operator= (PointToPointNetDevice nd);
    3.27    /**
    3.28     * Set the Data Rate used for transmission of packets.  The data rate is
    3.29     * set in the Attach () method from the corresponding field in the channel
    3.30 @@ -116,7 +114,7 @@
    3.31     * @see Attach ()
    3.32     * @param bps the data rate at which this object operates
    3.33     */
    3.34 -  void SetDataRate(const DataRate& bps);
    3.35 +  void SetDataRate(DataRate bps);
    3.36    /**
    3.37     * Set the inteframe gap used to separate packets.  The interframe gap
    3.38     * defines the minimum space required between packets sent by this device.
    3.39 @@ -127,7 +125,7 @@
    3.40     * @see Attach ()
    3.41     * @param t the interframe gap time
    3.42     */
    3.43 -  void SetInterframeGap(const Time& t);
    3.44 +  void SetInterframeGap(Time t);
    3.45    /**
    3.46     * Attach the device to a channel.
    3.47     *
    3.48 @@ -192,19 +190,6 @@
    3.49     * @returns a pointer to the channel
    3.50     */
    3.51    virtual Ptr<Channel> DoGetChannel(void) const;
    3.52 -  /**
    3.53 -   * Set a new default data rate
    3.54 -   * @param Data rate to set for new default
    3.55 -   */
    3.56 -  static void SetDefaultRate(const DataRate&);
    3.57 -
    3.58 -  /** 
    3.59 -   * Get the current default rate.
    3.60 -   * @returns a const reference to current default
    3.61 -   */
    3.62 -
    3.63 -  static const DataRate& GetDefaultRate();
    3.64 -
    3.65  private:
    3.66    /**
    3.67     * Send a Packet Down the Wire.
    3.68 @@ -238,11 +223,33 @@
    3.69    /**
    3.70     * Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
    3.71     *
    3.72 -   * The TransmitComplete method is used internally to finish the process
    3.73 -   * of sending a packet out on the channel.
    3.74 +   * The TransmitCompleteEvent method is used internally to finish the process
    3.75 +   * of sending a packet out on the channel.  During execution of this method
    3.76 +   * the TransmitEnd method is called on the channel to let it know that the
    3.77 +   * physical device this class represents has virually finished sending 
    3.78 +   * signals.  The channel uses this event to begin its speed of light delay
    3.79 +   * timer after which it notifies the Net Device at the other end of the 
    3.80 +   * link that the bits have arrived.  During this method, the net device 
    3.81 +   * also schedules the TransmitReadyEvent at which time the transmitter 
    3.82 +   * becomes ready to send the next packet.
    3.83     *
    3.84 +   * @see PointToPointChannel::TransmitEnd ()
    3.85 +   * @see TransmitReadyEvent ()
    3.86 +   * @returns true if success, false on failure
    3.87     */
    3.88 -  void TransmitComplete(void);
    3.89 +  void TransmitCompleteEvent (void);
    3.90 +  /**
    3.91 +   * Cause the Transmitter to Become Ready to Send Another Packet.
    3.92 +   *
    3.93 +   * The TransmitReadyEvent method is used internally to re-enable the 
    3.94 +   * transmit machine of the net device.  It is scheduled after a suitable
    3.95 +   * interframe gap after the completion of the previous transmission.
    3.96 +   * The queue is checked at this time, and if there is a packet waiting on
    3.97 +   * the queue, the transmission process is begun.
    3.98 +   *
    3.99 +   * @see TransmitStart ()
   3.100 +   */
   3.101 +  void TransmitReadyEvent (void);
   3.102    /**
   3.103     * Create a Trace Resolver for events in the net device.
   3.104     *
   3.105 @@ -256,7 +263,8 @@
   3.106    enum TxMachineState
   3.107      {
   3.108        READY, /**< The transmitter is ready to begin transmission of a packet */
   3.109 -      BUSY   /**< The transmitter is busy transmitting a packet */
   3.110 +      BUSY,  /**< The transmitter is busy transmitting a packet */
   3.111 +      GAP    /**< The transmitter is in the interframe gap time */
   3.112      };
   3.113    /**
   3.114     * The state of the Net Device transmit state machine.
   3.115 @@ -297,11 +305,6 @@
   3.116     * @see class TraceResolver
   3.117     */
   3.118    CallbackTraceSource<Packet &> m_rxTrace;
   3.119 -  /** 
   3.120 -   * Default data rate.  Used for all newly created p2p net devices
   3.121 -   */
   3.122 -   static DataRateDefaultValue g_defaultRate;
   3.123 -
   3.124  };
   3.125  
   3.126  }; // namespace ns3
     4.1 --- a/src/node/mac-address.cc	Thu Jun 14 10:41:47 2007 +0200
     4.2 +++ b/src/node/mac-address.cc	Fri Jun 15 13:19:57 2007 -0700
     4.3 @@ -33,9 +33,6 @@
     4.4  
     4.5  namespace ns3 {
     4.6  
     4.7 -// Static variables
     4.8 -uint8_t MacAddress::g_nextAddress[MacAddress::MAX_LEN];
     4.9 -
    4.10  static char
    4.11  AsciiToLowCase (char c)
    4.12  {
    4.13 @@ -57,13 +54,6 @@
    4.14      }
    4.15  }
    4.16  
    4.17 -MacAddress::MacAddress(uint8_t len) : m_len(len)
    4.18 -{
    4.19 -  NS_ASSERT (len <= MacAddress::MAX_LEN);
    4.20 -  AdvanceAddress();
    4.21 -  memcpy(m_address, g_nextAddress, len);
    4.22 -}
    4.23 -
    4.24  MacAddress::MacAddress (uint8_t const *address, uint8_t len)
    4.25  {
    4.26    NS_ASSERT (len <= MacAddress::MAX_LEN);
    4.27 @@ -158,17 +148,6 @@
    4.28          m_len = len;
    4.29  }
    4.30  
    4.31 -// Static methods
    4.32 -void MacAddress::AdvanceAddress()
    4.33 -  {
    4.34 -    // Advance to next address, little end first
    4.35 -    for(size_t i = 0; i < MAX_LEN; ++i)
    4.36 -      {
    4.37 -        if (++g_nextAddress[i] != 0) break;
    4.38 -      }
    4.39 -  }
    4.40 -
    4.41 -// Non-member operators
    4.42  bool operator == (MacAddress const&a, MacAddress const&b)
    4.43  {
    4.44  	return a.IsEqual (b);
     5.1 --- a/src/node/mac-address.h	Thu Jun 14 10:41:47 2007 +0200
     5.2 +++ b/src/node/mac-address.h	Fri Jun 15 13:19:57 2007 -0700
     5.3 @@ -47,13 +47,6 @@
     5.4     */
     5.5    MacAddress (void);
     5.6    /**
     5.7 -   * \brief Construct a MacAddress using the next available
     5.8 -   * address.
     5.9 -   * \see MacAddres::Next
    5.10 -   * \param len length, in bytes, of the desired address
    5.11 -   */
    5.12 -  MacAddress(uint8_t len);
    5.13 -  /**
    5.14     * \brief Construct a MacAddress from a byte-array
    5.15     *
    5.16     * low byte should be first.
    5.17 @@ -104,14 +97,6 @@
    5.18     */
    5.19    void Set (uint8_t const ad[MAX_LEN], uint8_t len);
    5.20  
    5.21 -  // Static methods/members
    5.22 -  /**
    5.23 -   *
    5.24 -   * Advance the global to the next available mac address.
    5.25 -   */
    5.26 -  static void AdvanceAddress();
    5.27 -  static uint8_t g_nextAddress[MAX_LEN];
    5.28 -
    5.29  private:
    5.30    uint8_t m_address[MAX_LEN];
    5.31    uint8_t m_len;