--- a/samples/main-simple.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/samples/main-simple.cc Wed Aug 29 09:35:53 2007 +0200
@@ -14,8 +14,7 @@
GenerateTraffic (Ptr<Socket> socket, uint32_t size)
{
std::cout << "at=" << Simulator::Now ().GetSeconds () << "s, tx bytes=" << size << std::endl;
- Packet p(size);
- socket->Send (p);
+ socket->Send (Packet (size));
if (size > 0)
{
Simulator::Schedule (Seconds (0.5), &GenerateTraffic, socket, size - 50);
--- a/src/applications/onoff-application.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/applications/onoff-application.cc Wed Aug 29 09:35:53 2007 +0200
@@ -206,8 +206,7 @@
void OnOffApplication::SendPacket()
{
NS_ASSERT (m_sendEvent.IsExpired ());
- Packet p(m_pktSize);
- m_socket->Send(p);
+ m_socket->Send(Packet (m_pktSize));
m_totBytes += m_pktSize;
m_lastStartTime = Simulator::Now();
m_residualBits = 0;
--- a/src/devices/csma/csma-net-device.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/devices/csma/csma-net-device.cc Wed Aug 29 09:35:53 2007 +0200
@@ -274,12 +274,13 @@
bool
CsmaNetDevice::SendTo (
- Packet& packet,
+ const Packet& packet,
const Address& dest,
uint16_t protocolNumber)
{
- NS_DEBUG ("CsmaNetDevice::SendTo (" << &packet << ")");
- NS_DEBUG ("CsmaNetDevice::SendTo (): UID is " << packet.GetUid () << ")");
+ Packet p = packet;
+ NS_DEBUG ("CsmaNetDevice::SendTo (" << &p << ")");
+ NS_DEBUG ("CsmaNetDevice::SendTo (): UID is " << p.GetUid () << ")");
NS_ASSERT (IsLinkUp ());
@@ -288,10 +289,10 @@
return false;
Eui48Address destination = Eui48Address::ConvertFrom (dest);
- AddHeader(packet, destination, protocolNumber);
+ AddHeader(p, destination, protocolNumber);
// Place the packet to be sent on the send queue
- if (m_queue->Enqueue(packet) == false )
+ if (m_queue->Enqueue(p) == false )
{
return false;
}
@@ -300,10 +301,11 @@
// transmission (see TransmitCompleteEvent)
if (m_txMachineState == READY)
{
- if (m_queue->IsEmpty()) return true; // Nothing else to do
// Store the next packet to be transmitted
- m_currentPkt = m_queue->Dequeue();
- TransmitStart();
+ if (m_queue->Dequeue (m_currentPkt))
+ {
+ TransmitStart();
+ }
}
return true;
}
@@ -387,8 +389,9 @@
m_currentPkt.GetUid () << ")");
// Try to transmit a new packet
- if (m_queue->IsEmpty()) return; //No packet to transmit
- m_currentPkt = m_queue->Dequeue ();
+ bool found;
+ found = m_queue->Dequeue (m_currentPkt);
+ NS_ASSERT_MSG(found, "IsEmpty false but no Packet on queue?");
m_backoff.ResetBackoffTime();
m_txMachineState = READY;
TransmitStart ();
@@ -435,10 +438,18 @@
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
- m_currentPkt = m_queue->Dequeue ();
- TransmitStart ();
+ 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 ();
+ }
}
TraceResolver *
@@ -484,31 +495,32 @@
}
void
-CsmaNetDevice::Receive (Packet& packet)
+CsmaNetDevice::Receive (const Packet& packet)
{
EthernetHeader header (false);
EthernetTrailer trailer;
Eui48Address broadcast;
Eui48Address destination;
+ Packet p = packet;
- NS_DEBUG ("CsmaNetDevice::Receive UID is (" << packet.GetUid() << ")");
+ NS_DEBUG ("CsmaNetDevice::Receive UID is (" << p.GetUid() << ")");
// Only receive if send side of net device is enabled
if (!IsReceiveEnabled())
{
- m_dropTrace (packet);
+ m_dropTrace (p);
return;
}
if (m_encapMode == RAW)
{
ForwardUp (packet, 0, GetBroadcast ());
- //m_dropTrace (packet);
+ m_dropTrace (p);
return;
}
- packet.RemoveTrailer(trailer);
- trailer.CheckFcs(packet);
- packet.RemoveHeader(header);
+ p.RemoveTrailer(trailer);
+ trailer.CheckFcs(p);
+ p.RemoveHeader(header);
broadcast = Eui48Address::ConvertFrom (GetBroadcast ());
destination = Eui48Address::ConvertFrom (GetAddress ());
@@ -516,11 +528,11 @@
(header.GetDestination() != destination))
{
// not for us.
- m_dropTrace (packet);
+ m_dropTrace (p);
return;
}
- m_rxTrace (packet);
+ m_rxTrace (p);
//
// protocol must be initialized to avoid a compiler warning in the RAW
// case that breaks the optimized build.
@@ -535,7 +547,7 @@
break;
case LLC: {
LlcSnapHeader llc;
- packet.RemoveHeader (llc);
+ p.RemoveHeader (llc);
protocol = llc.GetType ();
} break;
case RAW:
@@ -543,7 +555,7 @@
break;
}
- ForwardUp (packet, protocol, header.GetSource ());
+ ForwardUp (p, protocol, header.GetSource ());
return;
}
--- a/src/devices/csma/csma-net-device.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/devices/csma/csma-net-device.h Wed Aug 29 09:35:53 2007 +0200
@@ -195,7 +195,7 @@
* @see CsmaChannel
* \param p a reference to the received packet
*/
- void Receive (Packet& p);
+ void Receive (const 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 (Packet& p, const Address& dest, uint16_t protocolNumber);
+ virtual bool SendTo (const 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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/devices/point-to-point/point-to-point-net-device.cc Wed Aug 29 09:35:53 2007 +0200
@@ -117,17 +117,18 @@
m_tInterframeGap = t;
}
-bool PointToPointNetDevice::SendTo (Packet& packet, const Address& dest,
+bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest,
uint16_t protocolNumber)
{
- NS_DEBUG ("PointToPointNetDevice::SendTo (" << &packet << ", " << &dest << ")");
- NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << packet.GetUid () << ")");
+ Packet p = packet;
+ NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")");
+ NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.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(packet, protocolNumber);
+ AddHeader(p, protocolNumber);
//
// This class simulates a point to point device. In the case of a serial
@@ -138,16 +139,16 @@
// trnsmission; otherwise we send it now.
if (m_txMachineState == READY)
{
- return TransmitStart (packet);
+ return TransmitStart (p);
}
else
{
- return m_queue->Enqueue(packet);
+ return m_queue->Enqueue(p);
}
}
bool
-PointToPointNetDevice::TransmitStart (Packet& p)
+PointToPointNetDevice::TransmitStart (Packet &p)
{
NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")");
NS_DEBUG (
@@ -183,8 +184,8 @@
//
NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
m_txMachineState = READY;
- if (m_queue->IsEmpty()) return; // Nothing to do at this point
- Packet p = m_queue->Dequeue();
+ Packet p;
+ if (!m_queue->Dequeue(p)) return; // Nothing to do at this point
TransmitStart(p);
}
@@ -235,9 +236,11 @@
{
NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")");
uint16_t protocol = 0;
- m_rxTrace (p);
- ProcessHeader(p, protocol);
- ForwardUp (p, protocol, GetBroadcast ());
+ Packet packet = p;
+
+ m_rxTrace (packet);
+ ProcessHeader(packet, protocol);
+ ForwardUp (packet, protocol, GetBroadcast ());
}
Ptr<Queue> PointToPointNetDevice::GetQueue(void) const
--- a/src/devices/point-to-point/point-to-point-net-device.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/devices/point-to-point/point-to-point-net-device.h Wed Aug 29 09:35:53 2007 +0200
@@ -211,7 +211,7 @@
* @param protocolNumber Protocol Number used to find protocol touse
* @returns true if success, false on failure
*/
- virtual bool SendTo (Packet& p, const Address& dest,
+ virtual bool SendTo (const Packet& p, const Address& dest,
uint16_t protocolNumber);
/**
* Start Sending a Packet Down the Wire.
--- a/src/internet-node/arp-l3-protocol.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/arp-l3-protocol.cc Wed Aug 29 09:35:53 2007 +0200
@@ -84,11 +84,12 @@
}
void
-ArpL3Protocol::Receive(Ptr<NetDevice> device, Packet& p, uint16_t protocol, const Address &from)
+ArpL3Protocol::Receive(Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from)
{
ArpCache *cache = FindCache (device);
ArpHeader arp;
- p.RemoveHeader (arp);
+ Packet packet = p;
+ packet.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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/arp-l3-protocol.h Wed Aug 29 09:35:53 2007 +0200
@@ -53,7 +53,7 @@
/**
* \brief Recieve a packet
*/
- void Receive(Ptr<NetDevice> device, Packet& p, uint16_t protocol, const Address &from);
+ void Receive(Ptr<NetDevice> device, const Packet& p, uint16_t protocol, const Address &from);
/**
* \brief Perform an ARP lookup
* \param p
--- a/src/internet-node/ipv4-end-point.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/ipv4-end-point.cc Wed Aug 29 09:35:53 2007 +0200
@@ -65,7 +65,7 @@
}
void
-Ipv4EndPoint::SetRxCallback (Callback<void, Packet&, Ipv4Address, uint16_t> callback)
+Ipv4EndPoint::SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback)
{
m_rxCallback = callback;
}
@@ -77,7 +77,7 @@
}
void
-Ipv4EndPoint::ForwardUp (Packet &p, Ipv4Address saddr, uint16_t sport)
+Ipv4EndPoint::ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport)
{
if (!m_rxCallback.IsNull ())
{
--- a/src/internet-node/ipv4-end-point.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/ipv4-end-point.h Wed Aug 29 09:35:53 2007 +0200
@@ -43,17 +43,17 @@
void SetPeer (Ipv4Address address, uint16_t port);
- void SetRxCallback (Callback<void, Packet&, Ipv4Address, uint16_t> callback);
+ void SetRxCallback (Callback<void,const Packet &, Ipv4Address, uint16_t> callback);
void SetDestroyCallback (Callback<void> callback);
- void ForwardUp (Packet &p, Ipv4Address saddr, uint16_t sport);
+ void ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport);
private:
Ipv4Address m_localAddr;
uint16_t m_localPort;
Ipv4Address m_peerAddr;
uint16_t m_peerPort;
- Callback<void, Packet&, Ipv4Address, uint16_t> m_rxCallback;
+ Callback<void,const Packet &, Ipv4Address, uint16_t> m_rxCallback;
Callback<void> m_destroyCallback;
};
--- a/src/internet-node/ipv4-l3-protocol.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/ipv4-l3-protocol.cc Wed Aug 29 09:35:53 2007 +0200
@@ -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, Packet& p, uint16_t protocol, const Address &from)
+Ipv4L3Protocol::Receive( Ptr<NetDevice> device, const 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,25 +322,26 @@
}
index++;
}
+ Packet packet = p;
Ipv4Header ipHeader;
- p.RemoveHeader (ipHeader);
+ packet.RemoveHeader (ipHeader);
if (!ipHeader.IsChecksumOk ())
{
return;
}
- if (Forwarding (p, ipHeader, device))
+ if (Forwarding (packet, ipHeader, device))
{
return;
}
- ForwardUp (p, ipHeader);
+ ForwardUp (packet, ipHeader);
}
void
-Ipv4L3Protocol::Send (Packet& packet,
+Ipv4L3Protocol::Send (Packet const &packet,
Ipv4Address source,
Ipv4Address destination,
uint8_t protocol)
@@ -364,10 +365,12 @@
ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++)
{
Ipv4Interface *outInterface = *ifaceIter;
- NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
- packet.AddHeader (ipHeader);
- m_txTrace (packet, ifaceIndex);
- outInterface->Send (packet, destination);
+ Packet packetCopy = packet;
+
+ NS_ASSERT (packetCopy.GetSize () <= outInterface->GetMtu ());
+ packetCopy.AddHeader (ipHeader);
+ m_txTrace (packetCopy, ifaceIndex);
+ outInterface->Send (packetCopy, destination);
}
}
else
@@ -388,7 +391,7 @@
void
Ipv4L3Protocol::SendRealOut (bool found,
Ipv4Route const &route,
- Packet& packet,
+ Packet packet,
Ipv4Header const &ipHeader)
{
if (!found)
@@ -413,7 +416,7 @@
bool
-Ipv4L3Protocol::Forwarding (Packet& packet, Ipv4Header &ipHeader, Ptr<NetDevice> device)
+Ipv4L3Protocol::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetDevice> device)
{
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
i != m_interfaces.end (); i++)
@@ -468,7 +471,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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/ipv4-l3-protocol.h Wed Aug 29 09:35:53 2007 +0200
@@ -118,7 +118,7 @@
* - implement a per-NetDevice ARP cache
* - send back arp replies on the right device
*/
- void Receive( Ptr<NetDevice> device, Packet& p, uint16_t protocol, const Address &from);
+ void Receive( Ptr<NetDevice> device, const 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& packet, Ipv4Address source,
+ void Send (Packet const &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& packet, Ipv4Header &ipHeader, Ptr<NetDevice> device);
- void ForwardUp (Packet& p, Ipv4Header const&ip);
+ bool Forwarding (Packet const &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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/ipv4-static-routing.cc Wed Aug 29 09:35:53 2007 +0200
@@ -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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/ipv4-static-routing.h Wed Aug 29 09:35:53 2007 +0200
@@ -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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/udp-l4-protocol.cc Wed Aug 29 09:35:53 2007 +0200
@@ -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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/udp-l4-protocol.h Wed Aug 29 09:35:53 2007 +0200
@@ -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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/udp-socket.cc Wed Aug 29 09:35:53 2007 +0200
@@ -155,7 +155,7 @@
return 0;
}
int
-UdpSocket::Send (Packet &p)
+UdpSocket::Send (const Packet &p)
{
if (!m_connected)
{
@@ -165,7 +165,7 @@
return DoSendTo (p, m_defaultAddress, m_defaultPort);
}
int
-UdpSocket::DoSendTo (Packet &p, const Address &address)
+UdpSocket::DoSendTo (const 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 (Packet& p, Ipv4Address ipv4, uint16_t port)
+UdpSocket::DoSendTo (const Packet &p, Ipv4Address ipv4, uint16_t port)
{
if (m_endPoint == 0)
{
@@ -195,7 +195,7 @@
return 0;
}
int
-UdpSocket::SendTo(const Address &address, Packet &p)
+UdpSocket::SendTo(const Address &address, const Packet &p)
{
if (m_connected)
{
@@ -209,7 +209,7 @@
}
void
-UdpSocket::ForwardUp (Packet &packet, Ipv4Address ipv4, uint16_t port)
+UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port)
{
if (m_shutdownRecv)
{
@@ -217,7 +217,8 @@
}
Address address = InetSocketAddress (ipv4, port);
- NotifyDataReceived (packet, address);
+ Packet p = packet;
+ NotifyDataReceived (p, address);
}
}//namespace ns3
--- a/src/internet-node/udp-socket.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/internet-node/udp-socket.h Wed Aug 29 09:35:53 2007 +0200
@@ -51,8 +51,8 @@
virtual int ShutdownSend (void);
virtual int ShutdownRecv (void);
virtual int Connect(const Address &address);
- virtual int Send (Packet &p);
- virtual int SendTo(const Address &address,Packet &p);
+ virtual int Send (const Packet &p);
+ virtual int SendTo(const Address &address,const Packet &p);
private:
@@ -60,10 +60,10 @@
friend class Udp;
// invoked by Udp class
int FinishBind (void);
- void ForwardUp (Packet &p, Ipv4Address ipv4, uint16_t port);
+ void ForwardUp (const Packet &p, Ipv4Address ipv4, uint16_t port);
void Destroy (void);
- int DoSendTo (Packet &p, const Address &daddr);
- int DoSendTo (Packet &p, Ipv4Address daddr, uint16_t dport);
+ int DoSendTo (const Packet &p, const Address &daddr);
+ int DoSendTo (const Packet &p, Ipv4Address daddr, uint16_t dport);
Ipv4EndPoint *m_endPoint;
Ptr<Node> m_node;
--- a/src/node/drop-tail-queue.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/drop-tail-queue.cc Wed Aug 29 09:35:53 2007 +0200
@@ -73,26 +73,39 @@
return true;
}
-Packet
-DropTailQueue::DoDequeue ()
+bool
+DropTailQueue::DoDequeue (Packet& p)
{
- NS_DEBUG("DropTailQueue::DoDequeue ( )");
- NS_ASSERT(!IsEmpty());
- Packet p = m_packets.front ();
+ NS_DEBUG("DropTailQueue::DoDequeue (" << &p << ")");
+
+ if (m_packets.empty())
+ {
+ NS_DEBUG("DropTailQueue::DoDequeue (): Queue empty");
+ return false;
+ }
+
+ p = m_packets.front ();
m_packets.pop ();
NS_DEBUG("DropTailQueue::DoDequeue (): Popped " << &p << " <= true");
- return p;
+ return true;
}
-Packet
-DropTailQueue::DoPeek ()
+bool
+DropTailQueue::DoPeek (Packet& p)
{
- NS_DEBUG("DropTailQueue::DoPeek ( )");
- NS_ASSERT(!IsEmpty());
+ NS_DEBUG("DropTailQueue::DoPeek (" << &p << ")");
- return m_packets.front ();
+ if (m_packets.empty())
+ {
+ NS_DEBUG("DropTailQueue::DoPeek (): Queue empty");
+ return false;
+ }
+
+ p = m_packets.front ();
+
+ return true;
}
}; // namespace ns3
--- a/src/node/drop-tail-queue.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/drop-tail-queue.h Wed Aug 29 09:35:53 2007 +0200
@@ -58,8 +58,8 @@
private:
virtual bool DoEnqueue (const Packet& p);
- virtual Packet DoDequeue ();
- virtual Packet DoPeek ();
+ virtual bool DoDequeue (Packet &p);
+ virtual bool DoPeek (Packet &p);
private:
std::queue<Packet> m_packets;
--- a/src/node/ipv4.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/ipv4.h Wed Aug 29 09:35:53 2007 +0200
@@ -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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/net-device.cc Wed Aug 29 09:35:53 2007 +0200
@@ -171,7 +171,7 @@
// Receive packet from above
bool
-NetDevice::Send(Packet& p, const Address& dest, uint16_t protocolNumber)
+NetDevice::Send(const Packet& p, const Address& dest, uint16_t protocolNumber)
{
if (m_isUp)
{
@@ -197,7 +197,7 @@
// Receive packets from below
bool
-NetDevice::ForwardUp(Packet& p, uint16_t param, const Address &from)
+NetDevice::ForwardUp(const Packet& p, uint16_t param, const Address &from)
{
bool retval = false;
--- a/src/node/net-device.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/net-device.h Wed Aug 29 09:35:53 2007 +0200
@@ -158,7 +158,7 @@
*
* \return whether the Send operation succeeded
*/
- bool Send(Packet& p, const Address& dest, uint16_t protocolNumber);
+ bool Send(const 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>,Packet &,uint16_t,const Address &> ReceiveCallback;
+ typedef Callback<bool,Ptr<NetDevice>,const 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 (Packet& p, uint16_t param, const Address &address);
+ bool ForwardUp (const Packet& p, uint16_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 (Packet& p, const Address &dest, uint16_t protocolNumber) = 0;
+ virtual bool SendTo (const 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 Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/node.cc Wed Aug 29 09:35:53 2007 +0200
@@ -213,7 +213,7 @@
}
bool
-Node::ReceiveFromDevice (Ptr<NetDevice> device, Packet &packet,
+Node::ReceiveFromDevice (Ptr<NetDevice> device, const Packet &packet,
uint16_t protocol, const Address &from)
{
bool found = false;
--- a/src/node/node.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/node.h Wed Aug 29 09:35:53 2007 +0200
@@ -158,7 +158,7 @@
/**
* A protocol handler
*/
- typedef Callback<void,Ptr<NetDevice>, Packet &,uint16_t,const Address &> ProtocolHandler;
+ typedef Callback<void,Ptr<NetDevice>, const 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, Packet &packet,
+ bool ReceiveFromDevice (Ptr<NetDevice> device, const Packet &packet,
uint16_t protocol, const Address &from);
void Construct (void);
TraceResolver *CreateDevicesTraceResolver (const TraceContext &context);
--- a/src/node/packet-socket.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/packet-socket.cc Wed Aug 29 09:35:53 2007 +0200
@@ -186,7 +186,7 @@
}
int
-PacketSocket::Send (Packet &p)
+PacketSocket::Send (const Packet &p)
{
if (m_state == STATE_OPEN ||
m_state == STATE_BOUND)
@@ -198,7 +198,7 @@
}
int
-PacketSocket::SendTo(const Address &address, Packet &p)
+PacketSocket::SendTo(const Address &address, const Packet &p)
{
PacketSocketAddress ad;
if (m_state == STATE_CLOSED)
@@ -262,7 +262,7 @@
}
void
-PacketSocket::ForwardUp (Ptr<NetDevice> device, Packet &packet,
+PacketSocket::ForwardUp (Ptr<NetDevice> device, const 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 (packet, address);
+ NotifyDataReceived (p, address);
}
}//namespace ns3
--- a/src/node/packet-socket.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/packet-socket.h Wed Aug 29 09:35:53 2007 +0200
@@ -82,15 +82,15 @@
virtual int ShutdownSend (void);
virtual int ShutdownRecv (void);
virtual int Connect(const Address &address);
- virtual int Send (Packet &p);
- virtual int SendTo(const Address &address,Packet &p);
+ virtual int Send (const Packet &p);
+ virtual int SendTo(const Address &address,const Packet &p);
private:
private:
void Init (void);
- void ForwardUp (Ptr<NetDevice> device, Packet &packet,
+ void ForwardUp (Ptr<NetDevice> device, const Packet &packet,
uint16_t protocol, const Address &from);
int DoBind (const PacketSocketAddress &address);
virtual void DoDispose (void);
--- a/src/node/queue.cc Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/queue.cc Wed Aug 29 09:35:53 2007 +0200
@@ -49,7 +49,7 @@
{
return m_type == ENQUEUE;
}
-bool
+bool
QueueTraceType::IsDequeue (void) const
{
return m_type == DEQUEUE;
@@ -122,25 +122,28 @@
return retval;
}
-Packet
-Queue::Dequeue ()
+bool
+Queue::Dequeue (Packet &p)
{
- NS_ASSERT(!IsEmpty());
- NS_DEBUG("Queue::Dequeue ( )");
+ NS_DEBUG("Queue::Dequeue (" << &p << ")");
- Packet p = DoDequeue ();
+ bool retval = DoDequeue (p);
- m_nBytes -= p.GetSize ();
- m_nPackets--;
-
- NS_ASSERT (m_nBytes >= 0);
- NS_ASSERT (m_nPackets >= 0);
-
- NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
+ if (retval)
+ {
+ m_nBytes -= p.GetSize ();
+ m_nPackets--;
+
+ NS_ASSERT (m_nBytes >= 0);
+ NS_ASSERT (m_nPackets >= 0);
- m_traceDequeue (p);
+ NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
- return p;
+ const Packet packet = p;
+ m_traceDequeue (packet);
+ }
+
+ return retval;
}
void
@@ -151,13 +154,12 @@
NS_ASSERT (!"Don't know what to do with dequeued packets!");
}
-Packet
-Queue::Peek ()
+bool
+Queue::Peek (Packet &p)
{
- NS_ASSERT(!IsEmpty());
- NS_DEBUG("Queue::Peek ( )");
+ NS_DEBUG("Queue::Peek (" << &p << ")");
- return DoPeek ();
+ return DoPeek (p);
}
--- a/src/node/queue.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/queue.h Wed Aug 29 09:35:53 2007 +0200
@@ -83,16 +83,14 @@
bool Enqueue (const Packet& p);
/**
* Remove a packet from the front of the Queue
- * Must not be called on an empty queue.
- * \return The packet removed from the queue
+ * \return True if the operation was successful; false otherwise
*/
- Packet Dequeue ();
+ bool Dequeue (Packet &p);
/**
* Get a copy of the item at the front of the queue without removing it
- * Must NOT be called on an empty queue
- * \return The packet at the head of the queue.
+ * \return True if the operation was successful; false otherwise
*/
- Packet Peek ();
+ bool Peek (Packet &p);
/**
* XXX Doesn't do anything right now, think its supposed to flush the queue
@@ -165,8 +163,8 @@
private:
virtual bool DoEnqueue (const Packet& p) = 0;
- virtual Packet DoDequeue () = 0;
- virtual Packet DoPeek () = 0;
+ virtual bool DoDequeue (Packet &p) = 0;
+ virtual bool DoPeek (Packet &p) = 0;
protected:
// called by subclasses to notify parent of packet drops.
--- a/src/node/socket.h Tue Aug 28 10:20:13 2007 -0400
+++ b/src/node/socket.h Wed Aug 29 09:35:53 2007 +0200
@@ -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 (Packet &p) = 0;
+ virtual int Send (const 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,Packet &p) = 0;
+ virtual int SendTo(const Address &address,const Packet &p) = 0;
protected:
void NotifyCloseCompleted (void);