bug 210: must take device mtu into account.
1.1 --- a/src/node/packet-socket.cc Wed Jun 04 10:47:34 2008 -0700
1.2 +++ b/src/node/packet-socket.cc Wed Jun 04 10:59:30 2008 -0700
1.3 @@ -27,6 +27,8 @@
1.4 #include "ns3/uinteger.h"
1.5 #include "ns3/trace-source-accessor.h"
1.6
1.7 +#include <algorithm>
1.8 +
1.9 NS_LOG_COMPONENT_DEFINE ("PacketSocket");
1.10
1.11 namespace ns3 {
1.12 @@ -240,11 +242,35 @@
1.13 return SendTo (p, m_destAddr);
1.14 }
1.15
1.16 -// XXX must limit it to interface MTU
1.17 +uint32_t
1.18 +PacketSocket::GetMinMtu (PacketSocketAddress ad) const
1.19 +{
1.20 + if (ad.IsSingleDevice ())
1.21 + {
1.22 + Ptr<NetDevice> device = m_node->GetDevice (ad.GetSingleDevice ());
1.23 + return device->GetMtu ();
1.24 + }
1.25 + else
1.26 + {
1.27 + uint32_t minMtu = 0xffff;
1.28 + for (uint32_t i = 0; i < m_node->GetNDevices (); i++)
1.29 + {
1.30 + Ptr<NetDevice> device = m_node->GetDevice (i);
1.31 + minMtu = std::min (minMtu, (uint32_t)device->GetMtu ());
1.32 + }
1.33 + return minMtu;
1.34 + }
1.35 +}
1.36 +
1.37 uint32_t
1.38 PacketSocket::GetTxAvailable (void) const
1.39 {
1.40 - // Use 65536 for now
1.41 + if (m_state == STATE_CONNECTED)
1.42 + {
1.43 + PacketSocketAddress ad = PacketSocketAddress::ConvertFrom (m_destAddr);
1.44 + return GetMinMtu (ad);
1.45 + }
1.46 + // If we are not connected, we return a 'safe' value by default.
1.47 return 0xffff;
1.48 }
1.49
1.50 @@ -271,12 +297,12 @@
1.51 m_errno = ERROR_AFNOSUPPORT;
1.52 return -1;
1.53 }
1.54 - if (p->GetSize () > GetTxAvailable ())
1.55 + ad = PacketSocketAddress::ConvertFrom (address);
1.56 + if (p->GetSize () > GetMinMtu (ad))
1.57 {
1.58 m_errno = ERROR_MSGSIZE;
1.59 return -1;
1.60 }
1.61 - ad = PacketSocketAddress::ConvertFrom (address);
1.62
1.63 bool error = false;
1.64 Address dest = ad.GetPhysicalAddress ();
2.1 --- a/src/node/packet-socket.h Wed Jun 04 10:47:34 2008 -0700
2.2 +++ b/src/node/packet-socket.h Wed Jun 04 10:59:30 2008 -0700
2.3 @@ -105,6 +105,7 @@
2.4 void ForwardUp (Ptr<NetDevice> device, Ptr<Packet> packet,
2.5 uint16_t protocol, const Address &from);
2.6 int DoBind (const PacketSocketAddress &address);
2.7 + uint32_t GetMinMtu (PacketSocketAddress ad) const;
2.8 virtual void DoDispose (void);
2.9
2.10 enum State {