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.
This commit is contained in:
George Riley
2007-08-24 11:44:11 -04:00
parent 08bcb4249d
commit 391b3eef11
31 changed files with 152 additions and 179 deletions

View File

@@ -10,6 +10,10 @@ def build(bld):
['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'

View File

@@ -14,7 +14,8 @@ static void
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);

View File

@@ -206,7 +206,8 @@ void OnOffApplication::ScheduleStopEvent()
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;

View File

@@ -274,13 +274,12 @@ CsmaNetDevice::DoNeedsArp (void) const
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 @@ CsmaNetDevice::SendTo (
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 @@ CsmaNetDevice::SendTo (
// 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 @@ CsmaNetDevice::TransmitAbort (void)
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 @@ CsmaNetDevice::TransmitReadyEvent (void)
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 @@ CsmaNetDevice::AddQueue (Ptr<Queue> q)
}
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 @@ CsmaNetDevice::Receive (const Packet& packet)
(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 @@ CsmaNetDevice::Receive (const Packet& packet)
break;
case LLC: {
LlcSnapHeader llc;
p.RemoveHeader (llc);
packet.RemoveHeader (llc);
protocol = llc.GetType ();
} break;
case RAW:
@@ -555,7 +543,7 @@ CsmaNetDevice::Receive (const Packet& packet)
break;
}
ForwardUp (p, protocol, header.GetSource ());
ForwardUp (packet, protocol, header.GetSource ());
return;
}

View File

@@ -195,7 +195,7 @@ enum CsmaEncapsulationMode {
* @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 @@ private:
* \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.

View File

@@ -117,18 +117,17 @@ void PointToPointNetDevice::SetInterframeGap(const Time& t)
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 @@ bool PointToPointNetDevice::SendTo (const Packet& packet, const Address& dest,
// 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 @@ void PointToPointNetDevice::TransmitComplete (void)
//
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 @@ void PointToPointNetDevice::Receive (Packet& p)
{
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

View File

@@ -211,7 +211,7 @@ private:
* @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.

View File

@@ -84,12 +84,11 @@ ArpL3Protocol::FindCache (Ptr<NetDevice> device)
}
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 " <<

View File

@@ -53,7 +53,7 @@ public:
/**
* \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

View File

@@ -65,7 +65,7 @@ Ipv4EndPoint::SetPeer (Ipv4Address address, uint16_t port)
}
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 @@ Ipv4EndPoint::SetDestroyCallback (Callback<void> callback)
}
void
Ipv4EndPoint::ForwardUp (const Packet &p, Ipv4Address saddr, uint16_t sport)
Ipv4EndPoint::ForwardUp (Packet &p, Ipv4Address saddr, uint16_t sport)
{
if (!m_rxCallback.IsNull ())
{

View File

@@ -43,17 +43,17 @@ public:
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;
};

View File

@@ -221,7 +221,7 @@ Ipv4L3Protocol::SetDefaultRoute (Ipv4Address nextHop,
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 @@ Ipv4L3Protocol::FindInterfaceForDevice (Ptr<const NetDevice> device)
}
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 @@ Ipv4L3Protocol::Receive( Ptr<NetDevice> device, const Packet& p, uint16_t protoc
}
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 @@ Ipv4L3Protocol::Send (Packet const &packet,
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 @@ Ipv4L3Protocol::Send (Packet const &packet,
void
Ipv4L3Protocol::SendRealOut (bool found,
Ipv4Route const &route,
Packet packet,
Packet& packet,
Ipv4Header const &ipHeader)
{
if (!found)
@@ -416,7 +413,7 @@ Ipv4L3Protocol::SendRealOut (bool found,
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 @@ Ipv4L3Protocol::Forwarding (Packet const &packet, Ipv4Header &ipHeader, Ptr<NetD
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 ());

View File

@@ -118,7 +118,7 @@ public:
* - 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 @@ public:
* 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 @@ public:
uint32_t interface);
void Lookup (Ipv4Header const &ipHeader,
Packet packet,
Packet& packet,
Ipv4RoutingProtocol::RouteReplyCallback routeReply);
uint32_t GetNRoutes (void);
@@ -183,10 +183,10 @@ private:
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;

View File

@@ -210,7 +210,7 @@ Ipv4StaticRouting::RemoveRoute (uint32_t index)
bool
Ipv4StaticRouting::RequestRoute (Ipv4Header const &ipHeader,
Packet packet,
Packet& packet,
RouteReplyCallback routeReply)
{
Ipv4Route *route = LookupStatic (ipHeader.GetDestination ());

View File

@@ -52,7 +52,7 @@ public:
Ipv4StaticRouting () : m_defaultRoute (0) {}
virtual bool RequestRoute (Ipv4Header const &ipHeader,
Packet packet,
Packet& packet,
RouteReplyCallback routeReply);

View File

@@ -122,7 +122,7 @@ UdpL4Protocol::Receive(Packet& packet,
}
void
UdpL4Protocol::Send (Packet packet,
UdpL4Protocol::Send (Packet& packet,
Ipv4Address saddr, Ipv4Address daddr,
uint16_t sport, uint16_t dport)
{

View File

@@ -74,7 +74,7 @@ public:
* \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);
/**

View File

@@ -155,7 +155,7 @@ UdpSocket::Connect(const Address & address)
return 0;
}
int
UdpSocket::Send (const Packet &p)
UdpSocket::Send (Packet &p)
{
if (!m_connected)
{
@@ -165,7 +165,7 @@ UdpSocket::Send (const Packet &p)
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 @@ UdpSocket::DoSendTo (const Packet &p, const Address &address)
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 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address ipv4, uint16_t port)
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 @@ UdpSocket::SendTo(const Address &address, const Packet &p)
}
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 @@ UdpSocket::ForwardUp (const Packet &packet, Ipv4Address ipv4, uint16_t port)
}
Address address = InetSocketAddress (ipv4, port);
Packet p = packet;
NotifyDataReceived (p, address);
NotifyDataReceived (packet, address);
}
}//namespace ns3

View File

@@ -51,8 +51,8 @@ public:
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 @@ private:
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;

View File

@@ -73,39 +73,26 @@ DropTailQueue::DoEnqueue (const Packet& p)
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

View File

@@ -58,8 +58,8 @@ public:
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;

View File

@@ -46,7 +46,7 @@ class Ipv4Header; // FIXME: ipv4-header.h needs to move from module
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 @@ public:
* 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 @@ public:
* insert any extra header.
*/
virtual bool RequestRoute (const Ipv4Header &ipHeader,
Packet packet,
Packet& packet,
RouteReplyCallback routeReply) = 0;
};

View File

@@ -171,7 +171,7 @@ NetDevice::DisablePointToPoint (void)
// 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 @@ NetDevice::GetChannel (void) const
// 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;

View File

@@ -158,7 +158,7 @@ public:
*
* \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 @@ public:
* \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 @@ public:
* 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 @@ public:
* 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.

View File

@@ -213,7 +213,7 @@ Node::UnregisterProtocolHandler (ProtocolHandler handler)
}
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;

View File

@@ -158,7 +158,7 @@ public:
/**
* 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 @@ private:
*/
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);

View File

@@ -186,7 +186,7 @@ PacketSocket::Connect(const Address &ad)
}
int
PacketSocket::Send (const Packet &p)
PacketSocket::Send (Packet &p)
{
if (m_state == STATE_OPEN ||
m_state == STATE_BOUND)
@@ -198,7 +198,7 @@ PacketSocket::Send (const Packet &p)
}
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 @@ PacketSocket::SendTo(const Address &address, const Packet &p)
}
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 @@ PacketSocket::ForwardUp (Ptr<NetDevice> device, const Packet &packet,
return;
}
Packet p = packet;
//Packet p = packet; ?
PacketSocketAddress address;
address.SetPhysicalAddress (from);
@@ -279,7 +279,7 @@ PacketSocket::ForwardUp (Ptr<NetDevice> device, const Packet &packet,
NS_DEBUG ("PacketSocket::ForwardUp: UID is " << packet.GetUid()
<< " PacketSocket " << this);
NotifyDataReceived (p, address);
NotifyDataReceived (packet, address);
}
}//namespace ns3

View File

@@ -82,15 +82,15 @@ public:
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);

View File

@@ -49,7 +49,7 @@ QueueTraceType::IsEnqueue (void) const
{
return m_type == ENQUEUE;
}
bool
bool
QueueTraceType::IsDequeue (void) const
{
return m_type == DEQUEUE;
@@ -122,28 +122,25 @@ Queue::Enqueue (const Packet& p)
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--;
m_nBytes -= p.GetSize ();
m_nPackets--;
NS_ASSERT (m_nBytes >= 0);
NS_ASSERT (m_nPackets >= 0);
NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
NS_ASSERT (m_nBytes >= 0);
NS_ASSERT (m_nPackets >= 0);
m_traceDequeue (p);
NS_DEBUG("Queue::Dequeue (): m_traceDequeue (p)");
const Packet packet = p;
m_traceDequeue (packet);
}
return retval;
return p;
}
void
@@ -154,12 +151,13 @@ Queue::DequeueAll (void)
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 ();
}

View File

@@ -83,14 +83,16 @@ public:
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 @@ public:
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.

View File

@@ -173,7 +173,7 @@ public:
* \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 @@ public:
* \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);