Cut over UDP applications to use the new receive API

This commit is contained in:
Tom Henderson
2008-04-25 14:29:28 -07:00
parent d7a038431f
commit 288d193daa
12 changed files with 230 additions and 23 deletions

View File

@@ -301,15 +301,30 @@ PacketSocket::ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet,
address.SetSingleDevice (device->GetIfIndex ());
address.SetProtocol (protocol);
SocketRxAddressTag tag;
tag.SetAddress (address);
packet->AddTag (tag);
m_deliveryQueue.push (packet);
NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this);
NotifyDataReceived (packet, address);
NotifyDataRecv ();
}
Ptr<Packet>
PacketSocket::Recv (uint32_t maxSize, uint32_t flags)
{
if (m_deliveryQueue.empty() )
{
return 0;
}
Ptr<Packet> p = m_deliveryQueue.front ();
m_deliveryQueue.pop ();
if (p->GetSize() <= maxSize)
{
m_deliveryQueue.pop ();
}
else
{
p = 0;
}
return p;
}

View File

@@ -246,4 +246,53 @@ Socket::NotifyDataRecv (void)
m_receivedData_ (this);
}
}
SocketRxAddressTag::SocketRxAddressTag ()
{
}
uint32_t
SocketRxAddressTag::GetUid (void)
{
static uint32_t uid = ns3::Tag::AllocateUid<SocketRxAddressTag> ("SocketRxAddressTag.ns3");
return uid;
}
void
SocketRxAddressTag::Print (std::ostream &os) const
{
os << "address="<< m_address;
}
uint32_t
SocketRxAddressTag::GetSerializedSize (void) const
{
return 0;
}
void
SocketRxAddressTag::Serialize (Buffer::Iterator i) const
{
// for local use in stack only
}
uint32_t
SocketRxAddressTag::Deserialize (Buffer::Iterator i)
{
// for local use in stack only
return 0;
}
void
SocketRxAddressTag::SetAddress (Address addr)
{
m_address = addr;
}
Address
SocketRxAddressTag::GetAddress (void) const
{
return m_address;
}
}//namespace ns3

View File

@@ -25,12 +25,14 @@
#include "ns3/callback.h"
#include "ns3/ptr.h"
#include "ns3/tag.h"
#include "ns3/object.h"
#include "address.h"
#include <stdint.h>
namespace ns3 {
class Node;
class Packet;
@@ -257,6 +259,14 @@ public:
*/
int SendTo (const Address &address, const uint8_t* buf, uint32_t size);
/**
* \brief Read a single packet from the socket
* \param maxSize reader will accept packet up to maxSize
* \param flags Socket recv flags
* \returns Ptr<Packet> of the next in-sequence packet. Returns
* 0 if the socket cannot return a next in-sequence packet conforming
* to the maxSize and flags.
*/
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags) = 0;
protected:
@@ -285,6 +295,26 @@ protected:
Callback<void, Ptr<Socket> > m_receivedData_;
};
/**
* \brief This class implements a tag that carries the source address
* of a packet across the receiving socket interface.
*/
class SocketRxAddressTag : public Tag
{
public:
SocketRxAddressTag ();
static uint32_t GetUid (void);
void Print (std::ostream &os) const;
uint32_t GetSerializedSize (void) const;
void Serialize (Buffer::Iterator i) const;
uint32_t Deserialize (Buffer::Iterator i);
void SetAddress (Address addr);
Address GetAddress (void) const;
private:
Address m_address;
};
} //namespace ns3
#endif /* SOCKET_H */