bug 273: constify packet pointers.
--- a/src/devices/bridge/bridge-net-device.cc Mon Aug 25 09:05:41 2008 -0700
+++ b/src/devices/bridge/bridge-net-device.cc Mon Aug 25 09:13:05 2008 -0700
@@ -61,7 +61,7 @@
}
void
-BridgeNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<Packet> packet, uint16_t protocol,
+BridgeNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol,
Address const &src, Address const &dst, PacketType packetType)
{
NS_LOG_FUNCTION_NOARGS ();
@@ -97,7 +97,7 @@
}
void
-BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
+BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
uint16_t protocol, Mac48Address src, Mac48Address dst)
{
NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
@@ -130,7 +130,7 @@
}
void
-BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
+BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
uint16_t protocol, Mac48Address src, Mac48Address dst)
{
NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
--- a/src/devices/bridge/bridge-net-device.h Mon Aug 25 09:05:41 2008 -0700
+++ b/src/devices/bridge/bridge-net-device.h Mon Aug 25 09:13:05 2008 -0700
@@ -72,11 +72,11 @@
protected:
virtual void DoDispose (void);
- void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
+ void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
Address const &source, Address const &destination, PacketType packetType);
- void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
+ void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
uint16_t protocol, Mac48Address src, Mac48Address dst);
- void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
+ void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
uint16_t protocol, Mac48Address src, Mac48Address dst);
void Learn (Mac48Address source, Ptr<NetDevice> port);
Ptr<NetDevice> GetLearnedState (Mac48Address source);
--- a/src/internet-stack/arp-l3-protocol.cc Mon Aug 25 09:05:41 2008 -0700
+++ b/src/internet-stack/arp-l3-protocol.cc Mon Aug 25 09:13:05 2008 -0700
@@ -117,11 +117,13 @@
}
void
-ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from,
+ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
const Address &to, NetDevice::PacketType packetType)
{
NS_LOG_FUNCTION_NOARGS ();
+ Ptr<Packet> packet = p->Copy ();
+
Ptr<ArpCache> cache = FindCache (device);
ArpHeader arp;
packet->RemoveHeader (arp);
--- a/src/internet-stack/arp-l3-protocol.h Mon Aug 25 09:05:41 2008 -0700
+++ b/src/internet-stack/arp-l3-protocol.h Mon Aug 25 09:13:05 2008 -0700
@@ -54,7 +54,7 @@
/**
* \brief Receive a packet
*/
- void Receive(Ptr<NetDevice> device, Ptr<Packet> p, uint16_t protocol, const Address &from, const Address &to,
+ void Receive(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to,
NetDevice::PacketType packetType);
/**
* \brief Perform an ARP lookup
--- a/src/internet-stack/ipv4-l3-protocol.cc Mon Aug 25 09:05:41 2008 -0700
+++ b/src/internet-stack/ipv4-l3-protocol.cc Mon Aug 25 09:13:05 2008 -0700
@@ -449,13 +449,15 @@
}
void
-Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from,
+Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
const Address &to, NetDevice::PacketType packetType)
{
- NS_LOG_FUNCTION (this << &device << packet << protocol << from);
+ NS_LOG_FUNCTION (this << &device << p << protocol << from);
NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ());
+ Ptr<Packet> packet = p->Copy ();
+
uint32_t index = 0;
Ptr<Ipv4Interface> ipv4Interface;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
--- a/src/internet-stack/ipv4-l3-protocol.h Mon Aug 25 09:05:41 2008 -0700
+++ b/src/internet-stack/ipv4-l3-protocol.h Mon Aug 25 09:13:05 2008 -0700
@@ -83,7 +83,7 @@
* - implement a per-NetDevice ARP cache
* - send back arp replies on the right device
*/
- void Receive( Ptr<NetDevice> device, Ptr<Packet> p, uint16_t protocol, const Address &from,
+ void Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
const Address &to, NetDevice::PacketType packetType);
/**
--- a/src/node/net-device.h Mon Aug 25 09:05:41 2008 -0700
+++ b/src/node/net-device.h Mon Aug 25 09:13:05 2008 -0700
@@ -274,7 +274,7 @@
* \returns true if the callback could handle the packet successfully, false
* otherwise.
*/
- typedef Callback<bool,Ptr<NetDevice>,Ptr<Packet>,uint16_t,const Address &> ReceiveCallback;
+ typedef Callback<bool,Ptr<NetDevice>,Ptr<const Packet>,uint16_t,const Address &> ReceiveCallback;
/**
* \param cb callback to invoke whenever a packet has been received and must
@@ -296,7 +296,7 @@
* \returns true if the callback could handle the packet successfully, false
* otherwise.
*/
- typedef Callback< bool, Ptr<NetDevice>, Ptr<Packet>, uint16_t,
+ typedef Callback< bool, Ptr<NetDevice>, Ptr<const Packet>, uint16_t,
const Address &, const Address &, PacketType > PromiscReceiveCallback;
/**
--- a/src/node/node.cc Mon Aug 25 09:05:41 2008 -0700
+++ b/src/node/node.cc Mon Aug 25 09:13:05 2008 -0700
@@ -222,7 +222,7 @@
}
bool
-Node::PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
+Node::PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
const Address &from, const Address &to, NetDevice::PacketType packetType)
{
NS_LOG_FUNCTION(device->GetName ());
@@ -230,7 +230,7 @@
}
bool
-Node::NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
+Node::NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
const Address &from)
{
NS_LOG_FUNCTION(device->GetName ());
@@ -238,15 +238,11 @@
}
bool
-Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
+Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
const Address &from, const Address &to, NetDevice::PacketType packetType, bool promiscuous)
{
NS_LOG_FUNCTION(device->GetName ());
bool found = false;
- // if there are (potentially) multiple handlers, we need to copy the
- // packet before passing it to each handler, because handlers may
- // modify it.
- bool copyNeeded = (m_handlers.size () > 1);
for (ProtocolHandlerList::iterator i = m_handlers.begin ();
i != m_handlers.end (); i++)
@@ -259,7 +255,7 @@
{
if (promiscuous == i->promiscuous)
{
- i->handler (device, (copyNeeded ? packet->Copy () : packet), protocol, from, to, packetType);
+ i->handler (device, packet->Copy (), protocol, from, to, packetType);
found = true;
}
}
--- a/src/node/node.h Mon Aug 25 09:05:41 2008 -0700
+++ b/src/node/node.h Mon Aug 25 09:13:05 2008 -0700
@@ -145,7 +145,7 @@
* this value is only valid for promiscuous mode
* protocol handlers.
*/
- typedef Callback<void,Ptr<NetDevice>, Ptr<Packet>,uint16_t,const Address &,
+ typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
const Address &, NetDevice::PacketType> ProtocolHandler;
/**
* \param handler the handler to register
@@ -189,10 +189,10 @@
*/
virtual void NotifyDeviceAdded (Ptr<NetDevice> device);
- bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet>, uint16_t protocol, const Address &from);
- bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet>, uint16_t protocol,
+ bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, const Address &from);
+ bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
const Address &from, const Address &to, NetDevice::PacketType packetType);
- bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet>, uint16_t protocol,
+ bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
void Construct (void);
--- a/src/node/packet-socket.cc Mon Aug 25 09:05:41 2008 -0700
+++ b/src/node/packet-socket.cc Mon Aug 25 09:13:05 2008 -0700
@@ -344,7 +344,7 @@
}
void
-PacketSocket::ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet,
+PacketSocket::ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet,
uint16_t protocol, const Address &from,
const Address &to, NetDevice::PacketType packetType)
{
@@ -369,7 +369,7 @@
SocketAddressTag tag;
tag.SetAddress (address);
packet->AddTag (tag);
- m_deliveryQueue.push (packet);
+ m_deliveryQueue.push (packet->Copy ());
m_rxAvailable += packet->GetSize ();
NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this);
NotifyDataRecv ();
--- a/src/node/packet-socket.h Mon Aug 25 09:05:41 2008 -0700
+++ b/src/node/packet-socket.h Mon Aug 25 09:13:05 2008 -0700
@@ -103,7 +103,7 @@
Address &fromAddress);
private:
- void ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet,
+ void ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet,
uint16_t protocol, const Address &from, const Address &to,
NetDevice::PacketType packetType);
int DoBind (const PacketSocketAddress &address);