Change the protocol stack processing to pass packets by non-const
authorGeorge Riley<riley@ece.gatech.edu>
Fri, 24 Aug 2007 11:44:11 -0400
changeset 1303 9856d1175cbb
parent 1290 48ebb7788499
child 1304 642d6798feaa
Change the protocol stack processing to pass packets by non-const reference, rather than const reference and value as was previously done. Also change the queue semantics to return the packet on a deque, rather than requiring a packet as a parameter. The problem with the original approach was that packet UID's were getting skipped. The fix handles the uid properly, and we get sequential packet uid's on the trace file.
examples/wscript
samples/main-simple.cc
src/applications/onoff-application.cc
src/devices/csma/csma-net-device.cc
src/devices/csma/csma-net-device.h
src/devices/point-to-point/point-to-point-net-device.cc
src/devices/point-to-point/point-to-point-net-device.h
src/internet-node/arp-l3-protocol.cc
src/internet-node/arp-l3-protocol.h
src/internet-node/ipv4-end-point.cc
src/internet-node/ipv4-end-point.h
src/internet-node/ipv4-l3-protocol.cc
src/internet-node/ipv4-l3-protocol.h
src/internet-node/ipv4-static-routing.cc
src/internet-node/ipv4-static-routing.h
src/internet-node/udp-l4-protocol.cc
src/internet-node/udp-l4-protocol.h
src/internet-node/udp-socket.cc
src/internet-node/udp-socket.h
src/node/drop-tail-queue.cc
src/node/drop-tail-queue.h
src/node/ipv4.h
src/node/net-device.cc
src/node/net-device.h
src/node/node.cc
src/node/node.h
src/node/packet-socket.cc
src/node/packet-socket.h
src/node/queue.cc
src/node/queue.h
src/node/socket.h
--- a/examples/wscript	Wed Aug 22 12:02:42 2007 -0400
+++ b/examples/wscript	Fri Aug 24 11:44:11 2007 -0400
@@ -10,6 +10,10 @@
         ['point-to-point', 'internet-node'])
     obj.source = 'simple-point-to-point.cc'
 
+    obj = bld.create_ns3_program('really-simple-point-to-point',
+        ['point-to-point', 'internet-node'])
+    obj.source = 'really-simple-point-to-point.cc'
+
     obj = bld.create_ns3_program('csma-one-subnet',
         ['csma', 'internet-node'])
     obj.source = 'csma-one-subnet.cc'
--- a/samples/main-simple.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/samples/main-simple.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -14,7 +14,8 @@
 GenerateTraffic (Ptr<Socket> socket, uint32_t size)
 {
   std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl;
-  socket->Send (Packet (size));
+  Packet p(size);
+  socket->Send (p);
   if (size > 0)
     {
       Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50);
--- a/src/applications/onoff-application.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/applications/onoff-application.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -206,7 +206,8 @@
 void OnOffApplication::SendPacket()
 {
   NS_ASSERT (m_sendEvent.IsExpired ());
-  m_socket->Send(Packet (m_pktSize));
+  Packet p(m_pktSize);
+  m_socket->Send(p);
   m_totBytes += m_pktSize;
   m_lastStartTime = Simulator::Now();
   m_residualBits = 0;
--- a/src/devices/csma/csma-net-device.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/devices/csma/csma-net-device.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -274,13 +274,12 @@
 
 bool
 CsmaNetDevice::SendTo (
-  const Packet& packet, 
+  Packet& packet, 
   const Address& dest, 
   uint16_t protocolNumber)
 {
-  Packet p = packet;
-  NS_DEBUG ("CsmaNetDevice::SendTo (" << &p << ")");
-  NS_DEBUG ("CsmaNetDevice::SendTo (): UID is " << p.GetUid () << ")");
+  NS_DEBUG ("CsmaNetDevice::SendTo (" << &packet << ")");
+  NS_DEBUG ("CsmaNetDevice::SendTo (): UID is " << packet.GetUid () << ")");
 
   NS_ASSERT (IsLinkUp ());
 
@@ -289,10 +288,10 @@
     return false;
 
   Eui48Address destination = Eui48Address::ConvertFrom (dest);
-  AddHeader(p, destination, protocolNumber);
+  AddHeader(packet, destination, protocolNumber);
 
   // Place the packet to be sent on the send queue
-  if (m_queue->Enqueue(p) == false )
+  if (m_queue->Enqueue(packet) == false )
     {
       return false;
     }
@@ -301,11 +300,10 @@
   // transmission (see TransmitCompleteEvent)
   if (m_txMachineState == READY) 
     {
+      if (m_queue->IsEmpty()) return true; // Nothing else to do
       // Store the next packet to be transmitted
-      if (m_queue->Dequeue (m_currentPkt))
-        {
-          TransmitStart();
-        }
+      m_currentPkt = m_queue->Dequeue();
+      TransmitStart();
     }
   return true;
 }
@@ -389,9 +387,8 @@
             m_currentPkt.GetUid () << ")");
 
   // Try to transmit a new packet
-  bool found;
-  found = m_queue->Dequeue (m_currentPkt);
-  NS_ASSERT_MSG(found, "IsEmpty false but no Packet on queue?");
+  if (m_queue->IsEmpty()) return; //No packet to transmit
+  m_currentPkt = m_queue->Dequeue ();
   m_backoff.ResetBackoffTime();
   m_txMachineState = READY;
   TransmitStart ();
@@ -438,18 +435,10 @@
   NS_ASSERT_MSG(m_txMachineState == GAP, "Must be in interframe gap");
   m_txMachineState = READY;
 
+  if (m_queue->IsEmpty()) return; // No more to transmit, remain ready
   // Get the next packet from the queue for transmitting
-  if (m_queue->IsEmpty())
-    {
-      return;
-    }
-  else
-    {
-      bool found;
-      found = m_queue->Dequeue (m_currentPkt);
-      NS_ASSERT_MSG(found, "IsEmpty false but no Packet on queue?");
-      TransmitStart ();
-    }
+  m_currentPkt = m_queue->Dequeue ();
+  TransmitStart ();
 }
 
 TraceResolver *
@@ -495,32 +484,31 @@
 }
 
 void
-CsmaNetDevice::Receive (const Packet& packet)
+CsmaNetDevice::Receive (Packet& packet)
 {
   EthernetHeader header (false);
   EthernetTrailer trailer;
   Eui48Address broadcast;
   Eui48Address destination;
-  Packet p = packet;
 
-  NS_DEBUG ("CsmaNetDevice::Receive UID is (" << p.GetUid() << ")");
+  NS_DEBUG ("CsmaNetDevice::Receive UID is (" << packet.GetUid() << ")");
 
   // Only receive if send side of net device is enabled
   if (!IsReceiveEnabled())
     {
-      m_dropTrace (p);
+      m_dropTrace (packet);
       return;
     }
 
   if (m_encapMode == RAW)
     {
       ForwardUp (packet, 0, GetBroadcast ());
-      m_dropTrace (p);
+      //m_dropTrace (packet);
       return;
     }
-  p.RemoveTrailer(trailer);
-  trailer.CheckFcs(p);
-  p.RemoveHeader(header);
+  packet.RemoveTrailer(trailer);
+  trailer.CheckFcs(packet);
+  packet.RemoveHeader(header);
 
   broadcast = Eui48Address::ConvertFrom (GetBroadcast ());
   destination = Eui48Address::ConvertFrom (GetAddress ());
@@ -528,11 +516,11 @@
       (header.GetDestination() != destination))
     {
       // not for us.
-      m_dropTrace (p);
+      m_dropTrace (packet);
       return;
     }
 
-  m_rxTrace (p);
+  m_rxTrace (packet);
 //
 // protocol must be initialized to avoid a compiler warning in the RAW
 // case that breaks the optimized build.
@@ -547,7 +535,7 @@
       break;
     case LLC: {
       LlcSnapHeader llc;
-      p.RemoveHeader (llc);
+      packet.RemoveHeader (llc);
       protocol = llc.GetType ();
     } break;
     case RAW:
@@ -555,7 +543,7 @@
       break;
     }
   
-  ForwardUp (p, protocol, header.GetSource ());
+  ForwardUp (packet, protocol, header.GetSource ());
   return;
 }
 
--- a/src/devices/csma/csma-net-device.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/devices/csma/csma-net-device.h	Fri Aug 24 11:44:11 2007 -0400
@@ -195,7 +195,7 @@
    * @see CsmaChannel
    * \param p a reference to the received packet
    */
-  void Receive (const Packet& p);
+  void Receive (Packet& p);
 
   bool IsSendEnabled (void);
   bool IsReceiveEnabled (void);
@@ -270,7 +270,7 @@
    * \param protocolNumber -- this parameter is not used here
    * \return true if success, false on failure
    */
-  virtual bool SendTo (const Packet& p, const Address& dest, uint16_t protocolNumber);
+  virtual bool SendTo (Packet& p, const Address& dest, uint16_t protocolNumber);
 
   /**
    * Start Sending a Packet Down the Wire.
--- a/src/devices/point-to-point/point-to-point-net-device.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/devices/point-to-point/point-to-point-net-device.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -117,18 +117,17 @@
   m_tInterframeGap = t;
 }
 
-bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest, 
+bool PointToPointNetDevice::SendTo (Packet& packet, const Address& dest, 
                                     uint16_t protocolNumber)
 {
-  Packet p = packet;
-  NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")");
-  NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")");
+  NS_DEBUG ("PointToPointNetDevice::SendTo (" << &packet << ", " << &dest << ")");
+  NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << packet.GetUid () << ")");
 
   // GFR Comment. Why is this an assertion? Can't a link legitimately
   // "go down" during the simulation?  Shouldn't we just wait for it
   // to come back up?
   NS_ASSERT (IsLinkUp ());
-  AddHeader(p, protocolNumber);
+  AddHeader(packet, protocolNumber);
 
 //
 // This class simulates a point to point device.  In the case of a serial
@@ -139,16 +138,16 @@
 // trnsmission; otherwise we send it now.
   if (m_txMachineState == READY) 
     {
-      return TransmitStart (p);
+      return TransmitStart (packet);
     }
   else
     {
-      return m_queue->Enqueue(p);
+      return m_queue->Enqueue(packet);
     }
 }
 
   bool
-PointToPointNetDevice::TransmitStart (Packet &p)
+PointToPointNetDevice::TransmitStart (Packet& p)
 {
   NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")");
   NS_DEBUG (
@@ -184,8 +183,8 @@
 //
   NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
   m_txMachineState = READY;
-  Packet p;
-  if (!m_queue->Dequeue(p)) return; // Nothing to do at this point
+  if (m_queue->IsEmpty()) return; // Nothing to do at this point
+  Packet p = m_queue->Dequeue();
   TransmitStart(p);
 }
 
@@ -236,11 +235,9 @@
 {
   NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")");
   uint16_t protocol = 0;
-  Packet packet = p;
-
-  m_rxTrace (packet);
-  ProcessHeader(packet, protocol);
-  ForwardUp (packet, protocol, GetBroadcast ());
+  m_rxTrace (p);
+  ProcessHeader(p, protocol);
+  ForwardUp (p, protocol, GetBroadcast ());
 }
 
 Ptr<Queue> PointToPointNetDevice::GetQueue(void) const 
--- a/src/devices/point-to-point/point-to-point-net-device.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/devices/point-to-point/point-to-point-net-device.h	Fri Aug 24 11:44:11 2007 -0400
@@ -211,7 +211,7 @@
    * @param protocolNumber Protocol Number used to find protocol touse
    * @returns true if success, false on failure
    */
-  virtual bool SendTo (const Packet& p, const Address& dest, 
+  virtual bool SendTo (Packet& p, const Address& dest, 
                        uint16_t protocolNumber);
   /**
    * Start Sending a Packet Down the Wire.
--- a/src/internet-node/arp-l3-protocol.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/arp-l3-protocol.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -84,12 +84,11 @@
 }
 
 void 
-ArpL3Protocol::Receive(Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from)
+ArpL3Protocol::Receive(Ptr<NetDevice> device, Packet& p, uint16_t protocol, const Address &from)
 {
   ArpCache *cache = FindCache (device);
   ArpHeader arp;
-  Packet packet = p;
-  packet.RemoveHeader (arp);
+  p.RemoveHeader (arp);
   
   NS_DEBUG ("ARP: received "<< (arp.IsRequest ()? "request" : "reply") <<
             " node="<<m_node->GetId ()<<", got request from " <<
--- a/src/internet-node/arp-l3-protocol.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/arp-l3-protocol.h	Fri Aug 24 11:44:11 2007 -0400
@@ -53,7 +53,7 @@
   /**
    * \brief Recieve a packet
    */
-  void Receive(Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from);
+  void Receive(Ptr<NetDevice> device, Packet& p, uint16_t protocol, const Address &from);
   /**
    * \brief Perform an ARP lookup
    * \param p
--- a/src/internet-node/ipv4-end-point.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/ipv4-end-point.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -65,7 +65,7 @@
 }
 
 void 
-Ipv4EndPoint::SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback)
+Ipv4EndPoint::SetRxCallback (Callback<void, Packet&, Ipv4Address, uint16_t> callback)
 {
   m_rxCallback = callback;
 }
@@ -77,7 +77,7 @@
 }
 
 void 
-Ipv4EndPoint::ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport)
+Ipv4EndPoint::ForwardUp (Packet &p, Ipv4Address saddr, uint16_t sport)
 {
   if (!m_rxCallback.IsNull ())
   {
--- a/src/internet-node/ipv4-end-point.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/ipv4-end-point.h	Fri Aug 24 11:44:11 2007 -0400
@@ -43,17 +43,17 @@
 
   void SetPeer (Ipv4Address address, uint16_t port);
 
-  void SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback);
+  void SetRxCallback (Callback<void, Packet&, Ipv4Address, uint16_t> callback);
   void SetDestroyCallback (Callback<void> callback);
 
-  void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport);
+  void ForwardUp (Packet &p, Ipv4Address saddr, uint16_t sport);
 
 private:
   Ipv4Address m_localAddr;
   uint16_t m_localPort;
   Ipv4Address m_peerAddr;
   uint16_t m_peerPort;
-  Callback<void,const Packet &, Ipv4Address, uint16_t> m_rxCallback;
+  Callback<void, Packet&, Ipv4Address, uint16_t> m_rxCallback;
   Callback<void> m_destroyCallback;
 };
 
--- a/src/internet-node/ipv4-l3-protocol.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/ipv4-l3-protocol.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -221,7 +221,7 @@
 
 void
 Ipv4L3Protocol::Lookup (Ipv4Header const &ipHeader,
-                        Packet packet,
+                        Packet& packet,
                         Ipv4RoutingProtocol::RouteReplyCallback routeReply)
 {
   for (Ipv4RoutingProtocolList::const_iterator rprotoIter = m_routingProtocols.begin ();
@@ -310,7 +310,7 @@
 }  
 
 void 
-Ipv4L3Protocol::Receive( Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from)
+Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Packet& p, uint16_t protocol, const Address &from)
 {
   uint32_t index = 0;
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
@@ -322,26 +322,25 @@
         }
       index++;
     }
-  Packet packet = p;
   Ipv4Header ipHeader;
-  packet.RemoveHeader (ipHeader);
+  p.RemoveHeader (ipHeader);
 
   if (!ipHeader.IsChecksumOk ()) 
     {
       return;
     }
 
-  if (Forwarding (packet, ipHeader, device)) 
+  if (Forwarding (p, ipHeader, device)) 
     {
       return;
     }
 
-  ForwardUp (packet, ipHeader);
+  ForwardUp (p, ipHeader);
 }
 
 
 void 
-Ipv4L3Protocol::Send (Packet const &packet, 
+Ipv4L3Protocol::Send (Packet& packet, 
             Ipv4Address source, 
             Ipv4Address destination,
             uint8_t protocol)
@@ -365,12 +364,10 @@
            ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
         {
           Ipv4Interface *outInterface = *ifaceIter;
-          Packet packetCopy = packet;
-
-          NS_ASSERT (packetCopy.GetSize () <= outInterface->GetMtu ());
-          packetCopy.AddHeader (ipHeader);
-          m_txTrace (packetCopy, ifaceIndex);
-          outInterface->Send (packetCopy, destination);
+          NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
+          packet.AddHeader (ipHeader);
+          m_txTrace (packet, ifaceIndex);
+          outInterface->Send (packet, destination);
         }
     }
   else
@@ -391,7 +388,7 @@
 void
 Ipv4L3Protocol::SendRealOut (bool found,
                              Ipv4Route const &route,
-                             Packet packet,
+                             Packet& packet,
                              Ipv4Header const &ipHeader)
 {
   if (!found)
@@ -416,7 +413,7 @@
 
 
 bool
-Ipv4L3Protocol::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetDevice> device)
+Ipv4L3Protocol::Forwarding (Packet& packet, Ipv4Header &ipHeader, Ptr<NetDevice> device)
 {
   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
        i != m_interfaces.end (); i++) 
@@ -471,7 +468,7 @@
 
 
 void
-Ipv4L3Protocol::ForwardUp (Packet p, Ipv4Header const&ip)
+Ipv4L3Protocol::ForwardUp (Packet& p, Ipv4Header const&ip)
 {
   Ptr<Ipv4L4Demux> demux = m_node->QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
   Ptr<Ipv4L4Protocol> protocol = demux->GetProtocol (ip.GetProtocol ());
--- a/src/internet-node/ipv4-l3-protocol.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/ipv4-l3-protocol.h	Fri Aug 24 11:44:11 2007 -0400
@@ -118,7 +118,7 @@
    *    - implement a per-NetDevice ARP cache
    *    - send back arp replies on the right device
    */
-  void Receive( Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from);
+  void Receive( Ptr<NetDevice> device, Packet& p, uint16_t protocol, const Address &from);
 
   /**
    * \param packet packet to send
@@ -129,7 +129,7 @@
    * Higher-level layers call this method to send a packet
    * down the stack to the MAC and PHY layers.
    */
-  void Send (Packet const &packet, Ipv4Address source, 
+  void Send (Packet& packet, Ipv4Address source, 
 	     Ipv4Address destination, uint8_t protocol);
 
 
@@ -151,7 +151,7 @@
                         uint32_t interface);
 
   void Lookup (Ipv4Header const &ipHeader,
-               Packet packet,
+               Packet& packet,
                Ipv4RoutingProtocol::RouteReplyCallback routeReply);
 
   uint32_t GetNRoutes (void);
@@ -183,10 +183,10 @@
 
   void SendRealOut (bool found,
                     Ipv4Route const &route,
-                    Packet packet,
+                    Packet& packet,
                     Ipv4Header const &ipHeader);
-  bool Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetDevice> device);
-  void ForwardUp (Packet p, Ipv4Header const&ip);
+  bool Forwarding (Packet& packet, Ipv4Header &ipHeader, Ptr<NetDevice> device);
+  void ForwardUp (Packet& p, Ipv4Header const&ip);
   uint32_t AddIpv4Interface (Ipv4Interface *interface);
   void SetupLoopback (void);
   TraceResolver *InterfacesCreateTraceResolver (TraceContext const &context) const;
--- a/src/internet-node/ipv4-static-routing.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/ipv4-static-routing.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -210,7 +210,7 @@
 
 bool
 Ipv4StaticRouting::RequestRoute (Ipv4Header const &ipHeader,
-                                 Packet packet,
+                                 Packet& packet,
                                  RouteReplyCallback routeReply)
 {
   Ipv4Route *route = LookupStatic (ipHeader.GetDestination ());
--- a/src/internet-node/ipv4-static-routing.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/ipv4-static-routing.h	Fri Aug 24 11:44:11 2007 -0400
@@ -52,7 +52,7 @@
   Ipv4StaticRouting () : m_defaultRoute (0) {}
 
   virtual bool RequestRoute (Ipv4Header const &ipHeader,
-                             Packet packet,
+                             Packet& packet,
                              RouteReplyCallback routeReply);
 
 
--- a/src/internet-node/udp-l4-protocol.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/udp-l4-protocol.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -122,7 +122,7 @@
 }
 
 void
-UdpL4Protocol::Send (Packet packet, 
+UdpL4Protocol::Send (Packet& packet, 
            Ipv4Address saddr, Ipv4Address daddr, 
            uint16_t sport, uint16_t dport)
 {
--- a/src/internet-node/udp-l4-protocol.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/udp-l4-protocol.h	Fri Aug 24 11:44:11 2007 -0400
@@ -74,7 +74,7 @@
    * \param sport The source port number
    * \param dport The destination port number
    */
-  void Send (Packet packet,
+  void Send (Packet& packet,
              Ipv4Address saddr, Ipv4Address daddr, 
              uint16_t sport, uint16_t dport);
   /**
--- a/src/internet-node/udp-socket.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/udp-socket.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -155,7 +155,7 @@
   return 0;
 }
 int 
-UdpSocket::Send (const Packet &p)
+UdpSocket::Send (Packet &p)
 {
   if (!m_connected)
     {
@@ -165,7 +165,7 @@
   return DoSendTo (p, m_defaultAddress, m_defaultPort);
 }
 int
-UdpSocket::DoSendTo (const Packet &p, const Address &address)
+UdpSocket::DoSendTo (Packet &p, const Address &address)
 {
   InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
   Ipv4Address ipv4 = transport.GetIpv4 ();
@@ -173,7 +173,7 @@
   return DoSendTo (p, ipv4, port);
 }
 int
-UdpSocket::DoSendTo (const Packet &p, Ipv4Address ipv4, uint16_t port)
+UdpSocket::DoSendTo (Packet& p, Ipv4Address ipv4, uint16_t port)
 {
   if (m_endPoint == 0)
     {
@@ -195,7 +195,7 @@
   return 0;
 }
 int 
-UdpSocket::SendTo(const Address &address, const Packet &p)
+UdpSocket::SendTo(const Address &address, Packet &p)
 {
   if (m_connected)
     {
@@ -209,7 +209,7 @@
 }
 
 void 
-UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port)
+UdpSocket::ForwardUp (Packet &packet, Ipv4Address ipv4, uint16_t port)
 {
   if (m_shutdownRecv)
     {
@@ -217,8 +217,7 @@
     }
   
   Address address = InetSocketAddress (ipv4, port);
-  Packet p = packet;
-  NotifyDataReceived (p, address);
+  NotifyDataReceived (packet, address);
 }
 
 }//namespace ns3
--- a/src/internet-node/udp-socket.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/internet-node/udp-socket.h	Fri Aug 24 11:44:11 2007 -0400
@@ -51,8 +51,8 @@
   virtual int ShutdownSend (void);
   virtual int ShutdownRecv (void);
   virtual int Connect(const Address &address);
-  virtual int Send (const Packet &p);
-  virtual int SendTo(const Address &address,const Packet &p);
+  virtual int Send (Packet &p);
+  virtual int SendTo(const Address &address,Packet &p);
 
 private:
 
@@ -60,10 +60,10 @@
   friend class Udp;
   // invoked by Udp class
   int FinishBind (void);
-  void ForwardUp (const Packet &p, Ipv4Address ipv4, uint16_t port);
+  void ForwardUp (Packet &p, Ipv4Address ipv4, uint16_t port);
   void Destroy (void);
-  int DoSendTo (const Packet &p, const Address &daddr);
-  int DoSendTo (const Packet &p, Ipv4Address daddr, uint16_t dport);
+  int DoSendTo (Packet &p, const Address &daddr);
+  int DoSendTo (Packet &p, Ipv4Address daddr, uint16_t dport);
 
   Ipv4EndPoint *m_endPoint;
   Ptr<Node> m_node;
--- a/src/node/drop-tail-queue.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/drop-tail-queue.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -73,39 +73,26 @@
   return true;
 }
 
-bool
-DropTailQueue::DoDequeue (Packet& p)
+Packet
+DropTailQueue::DoDequeue ()
 {
-  NS_DEBUG("DropTailQueue::DoDequeue (" << &p << ")");
-
-  if (m_packets.empty()) 
-    {
-      NS_DEBUG("DropTailQueue::DoDequeue (): Queue empty");
-      return false;
-    }
-
-  p = m_packets.front ();
+  NS_DEBUG("DropTailQueue::DoDequeue ( )");
+  NS_ASSERT(!IsEmpty());
+  Packet p = m_packets.front ();
   m_packets.pop ();
 
   NS_DEBUG("DropTailQueue::DoDequeue (): Popped " << &p << " <= true");
 
-  return true;
+  return p;
 }
 
-bool
-DropTailQueue::DoPeek (Packet& p)
+Packet
+DropTailQueue::DoPeek ()
 {
-  NS_DEBUG("DropTailQueue::DoPeek (" << &p << ")");
+  NS_DEBUG("DropTailQueue::DoPeek ( )");
+  NS_ASSERT(!IsEmpty());
 
-  if (m_packets.empty()) 
-    {
-      NS_DEBUG("DropTailQueue::DoPeek (): Queue empty");
-      return false;
-    }
-
-  p = m_packets.front ();
-
-  return true;
+  return m_packets.front ();
 }
 
 }; // namespace ns3
--- a/src/node/drop-tail-queue.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/drop-tail-queue.h	Fri Aug 24 11:44:11 2007 -0400
@@ -58,8 +58,8 @@
 
 private:
   virtual bool DoEnqueue (const Packet& p);
-  virtual bool DoDequeue (Packet &p);
-  virtual bool DoPeek (Packet &p);
+  virtual Packet DoDequeue ();
+  virtual Packet DoPeek ();
 
 private:
   std::queue<Packet> m_packets;
--- a/src/node/ipv4.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/ipv4.h	Fri Aug 24 11:44:11 2007 -0400
@@ -46,7 +46,7 @@
 class Ipv4RoutingProtocol : public Object
 {
 public:
-  // void (*RouteReply) (bool found, Ipv4Route route, Packet packet, Ipv4Header const &ipHeader);
+  // void (*RouteReply) (bool found, Ipv4Route route, Packet& packet, Ipv4Header const &ipHeader);
 
 
   /**
@@ -65,7 +65,7 @@
    * inserted and consequently the protocol type has to change).
    *
    */
-  typedef Callback<void, bool, const Ipv4Route&, Packet, const Ipv4Header&> RouteReplyCallback;
+  typedef Callback<void, bool, const Ipv4Route&, Packet&, const Ipv4Header&> RouteReplyCallback;
 
   /**
    * \brief Asynchronously requests a route for a given packet and IP header
@@ -100,7 +100,7 @@
    * insert any extra header.
    */
   virtual bool RequestRoute (const Ipv4Header &ipHeader,
-                             Packet packet,
+                             Packet& packet,
                              RouteReplyCallback routeReply) = 0;
 };
 
--- a/src/node/net-device.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/net-device.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -171,7 +171,7 @@
 
 // Receive packet from above
 bool 
-NetDevice::Send(const Packet& p, const Address& dest, uint16_t protocolNumber)
+NetDevice::Send(Packet& p, const Address& dest, uint16_t protocolNumber)
 {
   if (m_isUp)
     {
@@ -197,7 +197,7 @@
 
 // Receive packets from below
 bool
-NetDevice::ForwardUp(const Packet& p, uint32_t param, const Address &from)
+NetDevice::ForwardUp( Packet& p, uint32_t param, const Address &from)
 {
   bool retval = false;
 
--- a/src/node/net-device.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/net-device.h	Fri Aug 24 11:44:11 2007 -0400
@@ -158,7 +158,7 @@
    * 
    * \return whether the Send operation succeeded 
    */
-  bool Send(const Packet& p, const Address& dest, uint16_t protocolNumber);
+  bool Send(Packet& p, const Address& dest, uint16_t protocolNumber);
   /**
    * \returns the node base class which contains this network
    *          interface.
@@ -187,7 +187,7 @@
    * \returns true if the callback could handle the packet successfully, false
    *          otherwise.
    */
-  typedef Callback<bool,Ptr<NetDevice>,const Packet &,uint16_t,const Address &> ReceiveCallback;
+  typedef Callback<bool,Ptr<NetDevice>,Packet &,uint16_t,const Address &> ReceiveCallback;
 
   /**
    * \param cb callback to invoke whenever a packet has been received and must
@@ -251,7 +251,7 @@
    * forwards it to the higher layers by calling this method
    * which is responsible for passing it up to the Rx callback.
    */
-  bool ForwardUp (const Packet& p, uint32_t param, const Address &address);
+  bool ForwardUp (Packet& p, uint32_t param, const Address &address);
 
 
   /**
@@ -274,7 +274,7 @@
    * method.  When the link is Up, this method is invoked to ask 
    * subclasses to forward packets. Subclasses MUST override this method.
    */
-  virtual bool SendTo (const Packet& p, const Address &dest, uint16_t protocolNumber) = 0;
+  virtual bool SendTo (Packet& p, const Address &dest, uint16_t protocolNumber) = 0;
   /**
    * \returns true if this NetDevice needs the higher-layers
    *          to perform ARP over it, false otherwise.
--- a/src/node/node.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/node.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -213,7 +213,7 @@
 }
 
 bool
-Node::ReceiveFromDevice (Ptr<NetDevice> device, const Packet &packet, 
+Node::ReceiveFromDevice (Ptr<NetDevice> device, Packet &packet, 
                          uint16_t protocol, const Address &from)
 {
   bool found = false;
--- a/src/node/node.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/node.h	Fri Aug 24 11:44:11 2007 -0400
@@ -158,7 +158,7 @@
   /**
    * A protocol handler
    */
-  typedef Callback<void,Ptr<NetDevice>, const Packet &,uint16_t,const Address &> ProtocolHandler;
+  typedef Callback<void,Ptr<NetDevice>, Packet &,uint16_t,const Address &> ProtocolHandler;
   /**
    * \param handler the handler to register
    * \param protocolType the type of protocol this handler is 
@@ -210,7 +210,7 @@
    */
   virtual void NotifyDeviceAdded (Ptr<NetDevice> device);
 
-  bool ReceiveFromDevice (Ptr<NetDevice> device, const Packet &packet, 
+  bool ReceiveFromDevice (Ptr<NetDevice> device, Packet &packet, 
                           uint16_t protocol, const Address &from);
   void Construct (void);
   TraceResolver *CreateDevicesTraceResolver (const TraceContext &context);
--- a/src/node/packet-socket.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/packet-socket.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -186,7 +186,7 @@
 }
 
 int
-PacketSocket::Send (const Packet &p)
+PacketSocket::Send (Packet &p)
 {
   if (m_state == STATE_OPEN ||
       m_state == STATE_BOUND)
@@ -198,7 +198,7 @@
 }
 
 int
-PacketSocket::SendTo(const Address &address, const Packet &p)
+PacketSocket::SendTo(const Address &address, Packet &p)
 {
   PacketSocketAddress ad;
   if (m_state == STATE_CLOSED)
@@ -262,7 +262,7 @@
 }
 
 void 
-PacketSocket::ForwardUp (Ptr<NetDevice> device, const Packet &packet, 
+PacketSocket::ForwardUp (Ptr<NetDevice> device, Packet &packet, 
                          uint16_t protocol, const Address &from)
 {
   if (m_shutdownRecv)
@@ -270,7 +270,7 @@
       return;
     }
 
-  Packet p = packet;
+  //Packet p = packet; ? 
 
   PacketSocketAddress address;
   address.SetPhysicalAddress (from);
@@ -279,7 +279,7 @@
 
   NS_DEBUG ("PacketSocket::ForwardUp: UID is " << packet.GetUid()
             << " PacketSocket " << this);
-  NotifyDataReceived (p, address);
+  NotifyDataReceived (packet, address);
 }
 
 }//namespace ns3
--- a/src/node/packet-socket.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/packet-socket.h	Fri Aug 24 11:44:11 2007 -0400
@@ -82,15 +82,15 @@
   virtual int ShutdownSend (void);
   virtual int ShutdownRecv (void);
   virtual int Connect(const Address &address);
-  virtual int Send (const Packet &p);
-  virtual int SendTo(const Address &address,const Packet &p);
+  virtual int Send (Packet &p);
+  virtual int SendTo(const Address &address,Packet &p);
 
 
 private:
 
 private:
   void Init (void);
-  void ForwardUp (Ptr<NetDevice> device, const Packet &packet, 
+  void ForwardUp (Ptr<NetDevice> device, Packet &packet, 
                   uint16_t protocol, const Address &from);
   int DoBind (const PacketSocketAddress &address);
   virtual void DoDispose (void);
--- a/src/node/queue.cc	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/queue.cc	Fri Aug 24 11:44:11 2007 -0400
@@ -49,7 +49,7 @@
 {
   return m_type == ENQUEUE;
 }
-bool 
+bool
 QueueTraceType::IsDequeue (void) const
 {
   return m_type == DEQUEUE;
@@ -122,28 +122,25 @@
   return retval;
 }
 
-bool
-Queue::Dequeue (Packet &p)
+Packet
+Queue::Dequeue ()
 {
-  NS_DEBUG("Queue::Dequeue (" << &p << ")");
+  NS_ASSERT(!IsEmpty());
+  NS_DEBUG("Queue::Dequeue ( )");
 
-  bool retval = DoDequeue (p);
+  Packet p = DoDequeue ();
 
-  if (retval)
-    {
-      m_nBytes -= p.GetSize ();
-      m_nPackets--;
-
-      NS_ASSERT (m_nBytes >= 0);
-      NS_ASSERT (m_nPackets >= 0);
+  m_nBytes -= p.GetSize ();
+  m_nPackets--;
+  
+  NS_ASSERT (m_nBytes >= 0);
+  NS_ASSERT (m_nPackets >= 0);
+  
+  NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
 
-      NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
+  m_traceDequeue (p);
 
-      const Packet packet = p;
-      m_traceDequeue (packet);
-    }
-
-  return retval;
+  return p;
 }
 
 void
@@ -154,12 +151,13 @@
   NS_ASSERT (!"Don't know what to do with dequeued packets!");
 }
 
-bool
-Queue::Peek (Packet &p)
+Packet
+Queue::Peek ()
 {
-  NS_DEBUG("Queue::Peek (" << &p << ")");
+  NS_ASSERT(!IsEmpty());
+  NS_DEBUG("Queue::Peek ( )");
 
-  return DoPeek (p);
+  return DoPeek ();
 }
 
 
--- a/src/node/queue.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/queue.h	Fri Aug 24 11:44:11 2007 -0400
@@ -83,14 +83,16 @@
   bool Enqueue (const Packet& p);
   /**
    * Remove a packet from the front of the Queue
-   * \return True if the operation was successful; false otherwise
+   * Must not be called on an empty queue.
+   * \return The packet removed from the queue
    */
-  bool Dequeue (Packet &p);
+  Packet Dequeue ();
   /**
    * Get a copy of the item at the front of the queue without removing it
-   * \return True if the operation was successful; false otherwise
+   * Must NOT be called on an empty queue
+   * \return The packet at the head of the queue.
    */
-  bool Peek (Packet &p);
+  Packet Peek ();
 
   /**
    * XXX Doesn't do anything right now, think its supposed to flush the queue
@@ -163,8 +165,8 @@
 private:
 
   virtual bool DoEnqueue (const Packet& p) = 0;
-  virtual bool DoDequeue (Packet &p) = 0;
-  virtual bool DoPeek (Packet &p) = 0;
+  virtual Packet DoDequeue () = 0;
+  virtual Packet DoPeek () = 0;
 
 protected:
   // called by subclasses to notify parent of packet drops.
--- a/src/node/socket.h	Wed Aug 22 12:02:42 2007 -0400
+++ b/src/node/socket.h	Fri Aug 24 11:44:11 2007 -0400
@@ -173,7 +173,7 @@
    * \returns -1 in case of error or the number of bytes copied in the 
    *          internal buffer and accepted for transmission.
    */
-  virtual int Send (const Packet &p) = 0;
+  virtual int Send (Packet &p) = 0;
   
   /**
    * \brief Send data to a specified peer.
@@ -182,7 +182,7 @@
    * \returns -1 in case of error or the number of bytes copied in the 
    *          internal buffer and accepted for transmission.
    */
-  virtual int SendTo(const Address &address,const Packet &p) = 0;
+  virtual int SendTo(const Address &address,Packet &p) = 0;
 
 protected:
   void NotifyCloseCompleted (void);