bug 273: constify packet pointers.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon Aug 25 09:13:05 2008 -0700 (17 months ago)
changeset 3568e5ab96db540e
parent 3567 e60083af704c
child 3569 4eaf02702f17
bug 273: constify packet pointers.
src/devices/bridge/bridge-net-device.cc
src/devices/bridge/bridge-net-device.h
src/internet-stack/arp-l3-protocol.cc
src/internet-stack/arp-l3-protocol.h
src/internet-stack/ipv4-l3-protocol.cc
src/internet-stack/ipv4-l3-protocol.h
src/node/net-device.h
src/node/node.cc
src/node/node.h
src/node/packet-socket.cc
src/node/packet-socket.h
     1.1 --- a/src/devices/bridge/bridge-net-device.cc	Mon Aug 25 09:05:41 2008 -0700
     1.2 +++ b/src/devices/bridge/bridge-net-device.cc	Mon Aug 25 09:13:05 2008 -0700
     1.3 @@ -61,7 +61,7 @@
     1.4  }
     1.5  
     1.6  void
     1.7 -BridgeNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<Packet> packet, uint16_t protocol,
     1.8 +BridgeNetDevice::ReceiveFromDevice (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet, uint16_t protocol,
     1.9                                      Address const &src, Address const &dst, PacketType packetType)
    1.10  {
    1.11    NS_LOG_FUNCTION_NOARGS ();
    1.12 @@ -97,7 +97,7 @@
    1.13  }
    1.14  
    1.15  void
    1.16 -BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
    1.17 +BridgeNetDevice::ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
    1.18                                   uint16_t protocol, Mac48Address src, Mac48Address dst)
    1.19  {
    1.20    NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
    1.21 @@ -130,7 +130,7 @@
    1.22  }
    1.23  
    1.24  void
    1.25 -BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
    1.26 +BridgeNetDevice::ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
    1.27                                          uint16_t protocol, Mac48Address src, Mac48Address dst)
    1.28  {
    1.29    NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName ()
     2.1 --- a/src/devices/bridge/bridge-net-device.h	Mon Aug 25 09:05:41 2008 -0700
     2.2 +++ b/src/devices/bridge/bridge-net-device.h	Mon Aug 25 09:13:05 2008 -0700
     2.3 @@ -72,11 +72,11 @@
     2.4  protected:
     2.5    virtual void DoDispose (void);
     2.6  
     2.7 -  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
     2.8 +  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
     2.9                            Address const &source, Address const &destination, PacketType packetType);
    2.10 -  void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
    2.11 +  void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
    2.12                         uint16_t protocol, Mac48Address src, Mac48Address dst);
    2.13 -  void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<Packet> packet,
    2.14 +  void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
    2.15                           uint16_t protocol, Mac48Address src, Mac48Address dst);
    2.16    void Learn (Mac48Address source, Ptr<NetDevice> port);
    2.17    Ptr<NetDevice> GetLearnedState (Mac48Address source);
     3.1 --- a/src/internet-stack/arp-l3-protocol.cc	Mon Aug 25 09:05:41 2008 -0700
     3.2 +++ b/src/internet-stack/arp-l3-protocol.cc	Mon Aug 25 09:13:05 2008 -0700
     3.3 @@ -117,11 +117,13 @@
     3.4  }
     3.5  
     3.6  void 
     3.7 -ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from,
     3.8 +ArpL3Protocol::Receive(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
     3.9                         const Address &to, NetDevice::PacketType packetType)
    3.10  {
    3.11    NS_LOG_FUNCTION_NOARGS ();
    3.12  
    3.13 +  Ptr<Packet> packet = p->Copy ();
    3.14 +
    3.15    Ptr<ArpCache> cache = FindCache (device);
    3.16    ArpHeader arp;
    3.17    packet->RemoveHeader (arp);
     4.1 --- a/src/internet-stack/arp-l3-protocol.h	Mon Aug 25 09:05:41 2008 -0700
     4.2 +++ b/src/internet-stack/arp-l3-protocol.h	Mon Aug 25 09:13:05 2008 -0700
     4.3 @@ -54,7 +54,7 @@
     4.4    /**
     4.5     * \brief Receive a packet
     4.6     */
     4.7 -  void Receive(Ptr<NetDevice> device, Ptr<Packet> p, uint16_t protocol, const Address &from, const Address &to,
     4.8 +  void Receive(Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to,
     4.9                 NetDevice::PacketType packetType);
    4.10    /**
    4.11     * \brief Perform an ARP lookup
     5.1 --- a/src/internet-stack/ipv4-l3-protocol.cc	Mon Aug 25 09:05:41 2008 -0700
     5.2 +++ b/src/internet-stack/ipv4-l3-protocol.cc	Mon Aug 25 09:13:05 2008 -0700
     5.3 @@ -449,13 +449,15 @@
     5.4  }  
     5.5  
     5.6  void 
     5.7 -Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol, const Address &from,
     5.8 +Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
     5.9                           const Address &to, NetDevice::PacketType packetType)
    5.10  {
    5.11 -  NS_LOG_FUNCTION (this << &device << packet << protocol <<  from);
    5.12 +  NS_LOG_FUNCTION (this << &device << p << protocol <<  from);
    5.13  
    5.14    NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ());
    5.15  
    5.16 +  Ptr<Packet> packet = p->Copy ();
    5.17 +
    5.18    uint32_t index = 0;
    5.19    Ptr<Ipv4Interface> ipv4Interface;
    5.20    for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
     6.1 --- a/src/internet-stack/ipv4-l3-protocol.h	Mon Aug 25 09:05:41 2008 -0700
     6.2 +++ b/src/internet-stack/ipv4-l3-protocol.h	Mon Aug 25 09:13:05 2008 -0700
     6.3 @@ -83,7 +83,7 @@
     6.4     *    - implement a per-NetDevice ARP cache
     6.5     *    - send back arp replies on the right device
     6.6     */
     6.7 -  void Receive( Ptr<NetDevice> device, Ptr<Packet> p, uint16_t protocol, const Address &from,
     6.8 +  void Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from,
     6.9                  const Address &to, NetDevice::PacketType packetType);
    6.10  
    6.11    /**
     7.1 --- a/src/node/net-device.h	Mon Aug 25 09:05:41 2008 -0700
     7.2 +++ b/src/node/net-device.h	Mon Aug 25 09:13:05 2008 -0700
     7.3 @@ -274,7 +274,7 @@
     7.4     * \returns true if the callback could handle the packet successfully, false
     7.5     *          otherwise.
     7.6     */
     7.7 -  typedef Callback<bool,Ptr<NetDevice>,Ptr<Packet>,uint16_t,const Address &> ReceiveCallback;
     7.8 +  typedef Callback<bool,Ptr<NetDevice>,Ptr<const Packet>,uint16_t,const Address &> ReceiveCallback;
     7.9  
    7.10    /**
    7.11     * \param cb callback to invoke whenever a packet has been received and must
    7.12 @@ -296,7 +296,7 @@
    7.13     * \returns true if the callback could handle the packet successfully, false
    7.14     *          otherwise.
    7.15     */
    7.16 -  typedef Callback< bool, Ptr<NetDevice>, Ptr<Packet>, uint16_t,
    7.17 +  typedef Callback< bool, Ptr<NetDevice>, Ptr<const Packet>, uint16_t,
    7.18                      const Address &, const Address &, PacketType > PromiscReceiveCallback;
    7.19  
    7.20    /**
     8.1 --- a/src/node/node.cc	Mon Aug 25 09:05:41 2008 -0700
     8.2 +++ b/src/node/node.cc	Mon Aug 25 09:13:05 2008 -0700
     8.3 @@ -222,7 +222,7 @@
     8.4  }
     8.5  
     8.6  bool
     8.7 -Node::PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
     8.8 +Node::PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
     8.9                                  const Address &from, const Address &to, NetDevice::PacketType packetType)
    8.10  {
    8.11    NS_LOG_FUNCTION(device->GetName ());
    8.12 @@ -230,7 +230,7 @@
    8.13  }
    8.14  
    8.15  bool
    8.16 -Node::NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
    8.17 +Node::NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
    8.18                                     const Address &from)
    8.19  {
    8.20    NS_LOG_FUNCTION(device->GetName ());
    8.21 @@ -238,15 +238,11 @@
    8.22  }
    8.23  
    8.24  bool
    8.25 -Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet> packet, uint16_t protocol,
    8.26 +Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
    8.27                           const Address &from, const Address &to, NetDevice::PacketType packetType, bool promiscuous)
    8.28  {
    8.29    NS_LOG_FUNCTION(device->GetName ());
    8.30    bool found = false;
    8.31 -  // if there are (potentially) multiple handlers, we need to copy the
    8.32 -  // packet before passing it to each handler, because handlers may
    8.33 -  // modify it.
    8.34 -  bool copyNeeded = (m_handlers.size () > 1);
    8.35  
    8.36    for (ProtocolHandlerList::iterator i = m_handlers.begin ();
    8.37         i != m_handlers.end (); i++)
    8.38 @@ -259,7 +255,7 @@
    8.39              {
    8.40                if (promiscuous == i->promiscuous)
    8.41                  {
    8.42 -                  i->handler (device, (copyNeeded ? packet->Copy () : packet), protocol, from, to, packetType);
    8.43 +                  i->handler (device, packet->Copy (), protocol, from, to, packetType);
    8.44                    found = true;
    8.45                  }
    8.46              }
     9.1 --- a/src/node/node.h	Mon Aug 25 09:05:41 2008 -0700
     9.2 +++ b/src/node/node.h	Mon Aug 25 09:13:05 2008 -0700
     9.3 @@ -145,7 +145,7 @@
     9.4     *                   this value is only valid for promiscuous mode
     9.5     *                   protocol handlers.
     9.6     */
     9.7 -  typedef Callback<void,Ptr<NetDevice>, Ptr<Packet>,uint16_t,const Address &,
     9.8 +  typedef Callback<void,Ptr<NetDevice>, Ptr<const Packet>,uint16_t,const Address &,
     9.9                     const Address &, NetDevice::PacketType> ProtocolHandler;
    9.10    /**
    9.11     * \param handler the handler to register
    9.12 @@ -189,10 +189,10 @@
    9.13     */
    9.14    virtual void NotifyDeviceAdded (Ptr<NetDevice> device);
    9.15  
    9.16 -  bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet>, uint16_t protocol, const Address &from);
    9.17 -  bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet>, uint16_t protocol,
    9.18 +  bool NonPromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol, const Address &from);
    9.19 +  bool PromiscReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
    9.20                                   const Address &from, const Address &to, NetDevice::PacketType packetType);
    9.21 -  bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<Packet>, uint16_t protocol,
    9.22 +  bool ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet>, uint16_t protocol,
    9.23                            const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc);
    9.24  
    9.25    void Construct (void);
    10.1 --- a/src/node/packet-socket.cc	Mon Aug 25 09:05:41 2008 -0700
    10.2 +++ b/src/node/packet-socket.cc	Mon Aug 25 09:13:05 2008 -0700
    10.3 @@ -344,7 +344,7 @@
    10.4  }
    10.5  
    10.6  void 
    10.7 -PacketSocket::ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet, 
    10.8 +PacketSocket::ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet, 
    10.9                           uint16_t protocol, const Address &from,
   10.10                           const Address &to, NetDevice::PacketType packetType)
   10.11  {
   10.12 @@ -369,7 +369,7 @@
   10.13        SocketAddressTag tag;
   10.14        tag.SetAddress (address);
   10.15        packet->AddTag (tag);
   10.16 -      m_deliveryQueue.push (packet);
   10.17 +      m_deliveryQueue.push (packet->Copy ());
   10.18        m_rxAvailable += packet->GetSize ();
   10.19        NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this);
   10.20        NotifyDataRecv ();
    11.1 --- a/src/node/packet-socket.h	Mon Aug 25 09:05:41 2008 -0700
    11.2 +++ b/src/node/packet-socket.h	Mon Aug 25 09:13:05 2008 -0700
    11.3 @@ -103,7 +103,7 @@
    11.4      Address &fromAddress);
    11.5  
    11.6  private:
    11.7 -  void ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet, 
    11.8 +  void ForwardUp (Ptr<NetDevice> device, Ptr<const Packet> packet, 
    11.9                    uint16_t protocol, const Address &from, const Address &to,
   11.10                    NetDevice::PacketType packetType);
   11.11    int DoBind (const PacketSocketAddress &address);