Implement GetRxAvailable ()

This commit is contained in:
Tom Henderson
2008-05-02 10:55:07 -07:00
parent bfe0533aa3
commit daddd90d07
7 changed files with 59 additions and 8 deletions

View File

@@ -78,7 +78,8 @@ TcpSocket::GetTypeId ()
m_nextRxSequence (0),
m_pendingData (0),
m_rtt (0),
m_lastMeasuredRtt (Seconds(0.0))
m_lastMeasuredRtt (Seconds(0.0)),
m_rxAvailable (0)
{
NS_LOG_FUNCTION (this);
@@ -122,7 +123,8 @@ TcpSocket::TcpSocket(const TcpSocket& sock)
m_rtt (0),
m_lastMeasuredRtt (Seconds(0.0)),
m_cnTimeout (sock.m_cnTimeout),
m_cnCount (sock.m_cnCount)
m_cnCount (sock.m_cnCount),
m_rxAvailable (0)
{
NS_LOG_FUNCTION_NOARGS ();
NS_LOG_LOGIC("Invoked the copy constructor");
@@ -450,9 +452,10 @@ TcpSocket::Recv (uint32_t maxSize, uint32_t flags)
return 0;
}
Ptr<Packet> p = m_deliveryQueue.front ();
if (p->GetSize() <= maxSize)
if (p->GetSize () <= maxSize)
{
m_deliveryQueue.pop ();
m_rxAvailable -= p->GetSize ();
}
else
{
@@ -461,6 +464,14 @@ TcpSocket::Recv (uint32_t maxSize, uint32_t flags)
return p;
}
uint32_t
TcpSocket::GetRxAvailable (void) const
{
// We separately maintain this state to avoid walking the queue
// every time this might be called
return m_rxAvailable;
}
void
TcpSocket::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
{
@@ -979,6 +990,7 @@ void TcpSocket::NewRx (Ptr<Packet> p,
tag.SetAddress (fromAddress);
p->AddTag (tag);
m_deliveryQueue.push (p);
m_rxAvailable += p->GetSize ();
NotifyDataRecv ();
if (m_closeNotified)
{
@@ -1035,6 +1047,7 @@ void TcpSocket::NewRx (Ptr<Packet> p,
tag.SetAddress (fromAddress);
p1->AddTag (tag);
m_deliveryQueue.push (p1);
m_rxAvailable += p->GetSize ();
NotifyDataRecv ();
NS_LOG_LOGIC ("TcpSocket " << this << " adv rxseq1 by " << s1 );

View File

@@ -71,6 +71,7 @@ public:
virtual int Listen(uint32_t queueLimit);
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
private:
friend class Tcp;
@@ -175,6 +176,7 @@ private:
// Temporary queue for delivering data to application
std::queue<Ptr<Packet> > m_deliveryQueue;
uint32_t m_rxAvailable;
};
}//namespace ns3

View File

@@ -40,7 +40,8 @@ UdpSocket::UdpSocket ()
m_errno (ERROR_NOTERROR),
m_shutdownSend (false),
m_shutdownRecv (false),
m_connected (false)
m_connected (false),
m_rxAvailable (0)
{
NS_LOG_FUNCTION_NOARGS ();
}
@@ -333,9 +334,10 @@ UdpSocket::Recv (uint32_t maxSize, uint32_t flags)
return 0;
}
Ptr<Packet> p = m_deliveryQueue.front ();
if (p->GetSize() <= maxSize)
if (p->GetSize () <= maxSize)
{
m_deliveryQueue.pop ();
m_rxAvailable -= p->GetSize ();
}
else
{
@@ -344,6 +346,14 @@ UdpSocket::Recv (uint32_t maxSize, uint32_t flags)
return p;
}
uint32_t
UdpSocket::GetRxAvailable (void) const
{
// We separately maintain this state to avoid walking the queue
// every time this might be called
return m_rxAvailable;
}
void
UdpSocket::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
{
@@ -358,6 +368,7 @@ UdpSocket::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
tag.SetAddress (address);
packet->AddTag (tag);
m_deliveryQueue.push (packet);
m_rxAvailable += packet->GetSize ();
NotifyDataRecv ();
}
@@ -410,12 +421,16 @@ void UdpSocketTest::ReceivePacket2 (Ptr<Socket> socket, Ptr<Packet> packet, cons
void UdpSocketTest::ReceivePkt (Ptr<Socket> socket)
{
uint32_t availableData = socket->GetRxAvailable ();
m_receivedPacket = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
NS_ASSERT (availableData == m_receivedPacket->GetSize ());
}
void UdpSocketTest::ReceivePkt2 (Ptr<Socket> socket)
{
uint32_t availableData = socket->GetRxAvailable ();
m_receivedPacket2 = socket->Recv (std::numeric_limits<uint32_t>::max(), 0);
NS_ASSERT (availableData == m_receivedPacket2->GetSize ());
}
bool

View File

@@ -58,6 +58,7 @@ public:
virtual int SendTo(const Address &address,Ptr<Packet> p);
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
private:
friend class Udp;
@@ -82,6 +83,7 @@ private:
bool m_connected;
std::queue<Ptr<Packet> > m_deliveryQueue;
uint32_t m_rxAvailable;
};
}//namespace ns3

View File

@@ -29,7 +29,7 @@ NS_LOG_COMPONENT_DEFINE ("PacketSocket");
namespace ns3 {
PacketSocket::PacketSocket ()
PacketSocket::PacketSocket () : m_rxAvailable (0)
{
NS_LOG_FUNCTION_NOARGS ();
m_state = STATE_OPEN;
@@ -305,6 +305,7 @@ PacketSocket::ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet,
tag.SetAddress (address);
packet->AddTag (tag);
m_deliveryQueue.push (packet);
m_rxAvailable += packet->GetSize ();
NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this);
NotifyDataRecv ();
}
@@ -317,9 +318,10 @@ PacketSocket::Recv (uint32_t maxSize, uint32_t flags)
return 0;
}
Ptr<Packet> p = m_deliveryQueue.front ();
if (p->GetSize() <= maxSize)
if (p->GetSize () <= maxSize)
{
m_deliveryQueue.pop ();
m_rxAvailable -= p->GetSize ();
}
else
{
@@ -328,4 +330,12 @@ PacketSocket::Recv (uint32_t maxSize, uint32_t flags)
return p;
}
uint32_t
PacketSocket::GetRxAvailable (void) const
{
// We separately maintain this state to avoid walking the queue
// every time this might be called
return m_rxAvailable;
}
}//namespace ns3

View File

@@ -89,6 +89,7 @@ public:
virtual int SendTo(const Address &address,Ptr<Packet> p);
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
virtual uint32_t GetRxAvailable (void) const;
private:
@@ -114,6 +115,8 @@ private:
Address m_destAddr; /// Default destination address
std::queue<Ptr<Packet> > m_deliveryQueue;
uint32_t m_rxAvailable;
};
}//namespace ns3

View File

@@ -273,7 +273,13 @@ public:
* 0 if the socket cannot return a next in-sequence packet.
*/
Ptr<Packet> Recv (void);
/**
* Return number of bytes which can be returned from one or
* multiple calls to Recv.
* Must be possible to call this method from the Recv callback.
*/
virtual uint32_t GetRxAvailable (void) const = 0;
protected:
void NotifyCloseCompleted (void);
void NotifyConnectionSucceeded (void);