This commit is contained in:
Gustavo J. A. M. Carneiro
2008-05-29 09:34:47 +01:00
11 changed files with 66 additions and 130 deletions

View File

@@ -102,7 +102,7 @@ Experiment::ReceivePacket (Ptr<Socket> socket)
Ptr<Socket>
Experiment::SetupPacketReceive (Ptr<Node> node)
{
TypeId tid = TypeId::LookupByName ("ns3::PacketSocket");
TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
Ptr<Socket> sink = Socket::CreateSocket (node, tid);
sink->Bind ();
sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
@@ -136,7 +136,7 @@ Experiment::Run (const WifiHelper &wifi)
socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
socket.SetProtocol (1);
OnOffHelper onoff ("ns3::PacketSocket", Address (socket));
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (250)));
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000)));

View File

@@ -203,11 +203,13 @@ Buffer::Create (uint32_t size)
Buffer::Buffer ()
{
NS_LOG_FUNCTION (this);
Initialize (0);
}
Buffer::Buffer (uint32_t dataSize)
{
NS_LOG_FUNCTION (this << dataSize);
Initialize (dataSize);
}
@@ -225,17 +227,21 @@ Buffer::CheckInternalState (void) const
m_start <= m_data->m_size &&
m_zeroAreaStart <= m_data->m_size;
NS_ASSERT (offsetsOk);
NS_ASSERT (dirtyOk);
NS_ASSERT (internalSizeOk);
return m_data->m_count > 0 && offsetsOk && dirtyOk &&
internalSizeOk;
bool ok = m_data->m_count > 0 && offsetsOk && dirtyOk && internalSizeOk;
if (!ok)
{
LOG_INTERNAL_STATE ("check " << this <<
", " << (offsetsOk?"true":"false") <<
", " << (dirtyOk?"true":"false") <<
", " << (internalSizeOk?"true":"false") << " ");
}
return ok;
}
void
Buffer::Initialize (uint32_t zeroSize)
{
NS_LOG_FUNCTION (this << zeroSize);
m_data = Buffer::Create (0);
#ifdef BUFFER_HEURISTICS
m_start = std::min (m_data->m_size, g_recommendedStart);
@@ -261,6 +267,7 @@ Buffer::Buffer (Buffer const&o)
m_start (o.m_start),
m_end (o.m_end)
{
NS_LOG_FUNCTION (this << &o);
m_data->m_count++;
NS_ASSERT (CheckInternalState ());
}
@@ -268,6 +275,7 @@ Buffer::Buffer (Buffer const&o)
Buffer &
Buffer::operator = (Buffer const&o)
{
NS_LOG_FUNCTION (this << &o);
NS_ASSERT (CheckInternalState ());
if (m_data != o.m_data)
{
@@ -294,6 +302,8 @@ Buffer::operator = (Buffer const&o)
Buffer::~Buffer ()
{
NS_LOG_FUNCTION (this);
NS_ASSERT (CheckInternalState ());
HEURISTICS (g_recommendedStart = std::max (g_recommendedStart, m_maxZeroAreaStart));
m_data->m_count--;
if (m_data->m_count == 0)
@@ -336,6 +346,7 @@ Buffer::GetInternalEnd (void) const
bool
Buffer::AddAtStart (uint32_t start)
{
NS_LOG_FUNCTION (this << start);
bool dirty;
NS_ASSERT (CheckInternalState ());
bool isDirty = m_data->m_count > 1 && m_start > m_data->m_dirtyStart;
@@ -385,6 +396,7 @@ Buffer::AddAtStart (uint32_t start)
bool
Buffer::AddAtEnd (uint32_t end)
{
NS_LOG_FUNCTION (this << end);
bool dirty;
NS_ASSERT (CheckInternalState ());
bool isDirty = m_data->m_count > 1 && m_end < m_data->m_dirtyEnd;
@@ -438,6 +450,7 @@ Buffer::AddAtEnd (uint32_t end)
void
Buffer::AddAtEnd (const Buffer &o)
{
NS_LOG_FUNCTION (this << &o);
if (m_data->m_count == 1 &&
m_end == m_zeroAreaEnd &&
m_end == m_data->m_dirtyEnd &&
@@ -460,6 +473,7 @@ Buffer::AddAtEnd (const Buffer &o)
Buffer::Iterator src = o.End ();
src.Prev (endData);
dst.Write (src, o.End ());
NS_ASSERT (CheckInternalState ());
return;
}
@@ -471,11 +485,13 @@ Buffer::AddAtEnd (const Buffer &o)
destStart.Prev (src.GetSize ());
destStart.Write (src.Begin (), src.End ());
*this = dst;
NS_ASSERT (CheckInternalState ());
}
void
Buffer::RemoveAtStart (uint32_t start)
{
NS_LOG_FUNCTION (this << start);
NS_ASSERT (CheckInternalState ());
uint32_t newStart = m_start + start;
if (newStart <= m_zeroAreaStart)
@@ -520,6 +536,7 @@ Buffer::RemoveAtStart (uint32_t start)
void
Buffer::RemoveAtEnd (uint32_t end)
{
NS_LOG_FUNCTION (this << end);
NS_ASSERT (CheckInternalState ());
uint32_t newEnd = m_end - std::min (end, m_end - m_start);
if (newEnd > m_zeroAreaEnd)
@@ -555,6 +572,7 @@ Buffer::RemoveAtEnd (uint32_t end)
Buffer
Buffer::CreateFragment (uint32_t start, uint32_t length) const
{
NS_LOG_FUNCTION (this << start << length);
NS_ASSERT (CheckInternalState ());
Buffer tmp = *this;
tmp.RemoveAtStart (start);
@@ -566,6 +584,7 @@ Buffer::CreateFragment (uint32_t start, uint32_t length) const
Buffer
Buffer::CreateFullCopy (void) const
{
NS_LOG_FUNCTION (this);
NS_ASSERT (CheckInternalState ());
if (m_zeroAreaEnd - m_zeroAreaStart != 0)
{
@@ -580,6 +599,7 @@ Buffer::CreateFullCopy (void) const
Buffer::Iterator i = tmp.End ();
i.Prev (dataEnd);
i.Write (m_data->m_data+m_zeroAreaStart,dataEnd);
NS_ASSERT (tmp.CheckInternalState ());
return tmp;
}
NS_ASSERT (CheckInternalState ());

View File

@@ -19,6 +19,9 @@
*/
#include "packet.h"
#include "ns3/assert.h"
#include "ns3/log.h"
NS_LOG_COMPONENT_DEFINE ("Packet");
namespace ns3 {
@@ -156,6 +159,7 @@ Packet::Packet (const Buffer &buffer, const TagList &tagList, const PacketMetad
Ptr<Packet>
Packet::CreateFragment (uint32_t start, uint32_t length) const
{
NS_LOG_FUNCTION (this << start << length);
Buffer buffer = m_buffer.CreateFragment (start, length);
NS_ASSERT (m_buffer.GetSize () >= start + length);
uint32_t end = m_buffer.GetSize () - (start + length);
@@ -174,6 +178,7 @@ Packet::GetSize (void) const
void
Packet::AddHeader (const Header &header)
{
NS_LOG_FUNCTION (this << &header);
uint32_t size = header.GetSerializedSize ();
uint32_t orgStart = m_buffer.GetCurrentStartOffset ();
bool resized = m_buffer.AddAtStart (size);
@@ -188,6 +193,7 @@ Packet::AddHeader (const Header &header)
uint32_t
Packet::RemoveHeader (Header &header)
{
NS_LOG_FUNCTION (this << &header);
uint32_t deserialized = header.Deserialize (m_buffer.Begin ());
m_buffer.RemoveAtStart (deserialized);
m_metadata.RemoveHeader (header, deserialized);
@@ -196,6 +202,7 @@ Packet::RemoveHeader (Header &header)
void
Packet::AddTrailer (const Trailer &trailer)
{
NS_LOG_FUNCTION (this << &trailer);
uint32_t size = trailer.GetSerializedSize ();
uint32_t orgEnd = m_buffer.GetCurrentEndOffset ();
bool resized = m_buffer.AddAtEnd (size);
@@ -211,6 +218,7 @@ Packet::AddTrailer (const Trailer &trailer)
uint32_t
Packet::RemoveTrailer (Trailer &trailer)
{
NS_LOG_FUNCTION (this << &trailer);
uint32_t deserialized = trailer.Deserialize (m_buffer.End ());
m_buffer.RemoveAtEnd (deserialized);
m_metadata.RemoveTrailer (trailer, deserialized);
@@ -220,6 +228,7 @@ Packet::RemoveTrailer (Trailer &trailer)
void
Packet::AddAtEnd (Ptr<const Packet> packet)
{
NS_LOG_FUNCTION (this << packet);
uint32_t aStart = m_buffer.GetCurrentStartOffset ();
uint32_t bEnd = packet->m_buffer.GetCurrentEndOffset ();
m_buffer.AddAtEnd (packet->m_buffer);
@@ -235,6 +244,7 @@ Packet::AddAtEnd (Ptr<const Packet> packet)
void
Packet::AddPaddingAtEnd (uint32_t size)
{
NS_LOG_FUNCTION (this << size);
uint32_t orgEnd = m_buffer.GetCurrentEndOffset ();
bool resized = m_buffer.AddAtEnd (size);
if (resized)
@@ -247,12 +257,14 @@ Packet::AddPaddingAtEnd (uint32_t size)
void
Packet::RemoveAtEnd (uint32_t size)
{
NS_LOG_FUNCTION (this << size);
m_buffer.RemoveAtEnd (size);
m_metadata.RemoveAtEnd (size);
}
void
Packet::RemoveAtStart (uint32_t size)
{
NS_LOG_FUNCTION (this << size);
m_buffer.RemoveAtStart (size);
m_metadata.RemoveAtStart (size);
}
@@ -260,6 +272,7 @@ Packet::RemoveAtStart (uint32_t size)
void
Packet::RemoveAllTags (void)
{
NS_LOG_FUNCTION (this);
m_tagList.RemoveAll ();
}
@@ -408,12 +421,14 @@ Packet::BeginItem (void) const
void
Packet::EnableMetadata (void)
{
NS_LOG_FUNCTION_NOARGS ();
PacketMetadata::Enable ();
}
Buffer
Packet::Serialize (void) const
{
NS_LOG_FUNCTION (this);
Buffer buffer;
uint32_t reserve;
@@ -441,6 +456,7 @@ Packet::Serialize (void) const
void
Packet::Deserialize (Buffer buffer)
{
NS_LOG_FUNCTION (this);
Buffer buf = buffer;
// read size
uint32_t packetSize = buf.Begin ().ReadU32 ();
@@ -466,6 +482,7 @@ Packet::Deserialize (Buffer buffer)
void
Packet::AddTag (const Tag &tag) const
{
NS_LOG_FUNCTION (this << &tag);
TagList *list = const_cast<TagList *> (&m_tagList);
TagBuffer buffer = list->Add (tag.GetInstanceTypeId (), tag.GetSerializedSize (),
m_buffer.GetCurrentStartOffset (),

View File

@@ -327,12 +327,10 @@ public:
bool IsNoneEnabled (void) const;
void Enable (enum LogLevel level);
void Disable (enum LogLevel level);
bool Decorate (void) const;
char const *Name (void) const;
private:
int32_t m_levels;
char const *m_name;
bool m_decorate;
};
class ParameterLogger : public std::ostream

View File

@@ -77,11 +77,11 @@ ConstantRateWifiManager::GetTypeId (void)
static TypeId tid = TypeId ("ns3::ConstantRateWifiManager")
.SetParent<WifiRemoteStationManager> ()
.AddConstructor<ConstantRateWifiManager> ()
.AddAttribute ("DataMode", "XXX",
.AddAttribute ("DataMode", "The transmission mode to use for every data packet transmission",
StringValue ("wifia-6mbs"),
MakeWifiModeAccessor (&ConstantRateWifiManager::m_dataMode),
MakeWifiModeChecker ())
.AddAttribute ("ControlMode", "XXX",
.AddAttribute ("ControlMode", "The transmission mode to use for every control packet transmission.",
StringValue ("wifia-6mbs"),
MakeWifiModeAccessor (&ConstantRateWifiManager::m_ctlMode),
MakeWifiModeChecker ())

View File

@@ -139,10 +139,6 @@ void
DcaTxop::DoDispose (void)
{
NS_LOG_FUNCTION (this);
delete m_transmissionListener;
delete m_dcf;
delete m_rng;
delete m_txMiddle;
m_transmissionListener = 0;
m_dcf = 0;
m_rng = 0;
@@ -150,6 +146,10 @@ DcaTxop::DoDispose (void)
m_queue = 0;
m_low = 0;
m_stationManager = 0;
delete m_transmissionListener;
delete m_dcf;
delete m_rng;
delete m_txMiddle;
}
void

View File

@@ -114,21 +114,20 @@ Address::GetSerializedSize (void) const
}
void
Address::Serialize (uint8_t* buf, uint32_t len) const
Address::Serialize (TagBuffer buffer) const
{
NS_ASSERT (len >= static_cast<uint32_t> (m_len + 2));
buf[0] = m_type;
buf[1] = m_len;
for (uint8_t i = 0; i < m_len; i++)
{
buf[i+2] = m_data[i];
}
buffer.WriteU8 (m_type);
buffer.WriteU8 (m_len);
buffer.Write (m_data, m_len);
}
Address
Address::Deserialize (const uint8_t* buf)
void
Address::Deserialize (TagBuffer buffer)
{
return Address (buf[0], buf + 2, buf[1]);
m_type = buffer.ReadU8 ();
m_len = buffer.ReadU8 ();
NS_ASSERT (m_len <= MAX_SIZE);
buffer.Read (m_data, m_len);
}
ATTRIBUTE_HELPER_CPP (Address);

View File

@@ -5,6 +5,7 @@
#include <ostream>
#include "ns3/attribute.h"
#include "ns3/attribute-helper.h"
#include "ns3/tag-buffer.h"
namespace ns3 {
@@ -166,14 +167,14 @@ public:
* \param buf output buffer that gets written with this Address
* \param len length of output buffer
*/
void Serialize (uint8_t* buf, uint32_t len) const;
void Serialize (TagBuffer buffer) const;
/**
* \param buf buffer to read address from
* \returns an Address
*
* The input address buffer is expected to be in host byte order format.
*/
static Address Deserialize (const uint8_t* buf);
void Deserialize (TagBuffer buffer);
private:
friend bool operator == (const Address &a, const Address &b);

View File

@@ -1,42 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "socket-defaults.h"
#include "ns3/uinteger.h"
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (SocketDefaults);
TypeId SocketDefaults::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::SocketDefaults")
.SetParent<Object> ()
.AddAttribute ("DefaultSndBufLimit",
"Default maximum receive buffer size (bytes)",
UintegerValue (0xffffffffl),
MakeUintegerAccessor (&SocketDefaults::m_defaultSndBufLimit),
MakeUintegerChecker<uint32_t> ())
.AddAttribute ("DefaultRcvBufLimit",
"Default maximum receive buffer size (bytes)",
UintegerValue (0xffffffffl),
MakeUintegerAccessor (&SocketDefaults::m_defaultRcvBufLimit),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
} // namespace ns3

View File

@@ -1,42 +0,0 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SOCKET_DEFAULTS_H
#define SOCKET_DEFAULTS_H
#include "ns3/object.h"
namespace ns3 {
/**
* \brief Object to hold socket option defaults
*
* This class can be aggregated to a Node and can be used to store
* socket defaults for a Node.
*
*/
class SocketDefaults : public Object
{
public:
static TypeId GetTypeId (void);
private:
uint32_t m_defaultSndBufLimit;
uint32_t m_defaultRcvBufLimit;
};
} // namespace ns3
#endif /* SOCKET_DEFAULTS_H */

View File

@@ -304,27 +304,12 @@ SocketRxAddressTag::GetSerializedSize (void) const
void
SocketRxAddressTag::Serialize (TagBuffer i) const
{
uint8_t len = m_address.GetSerializedSize ();
uint8_t* buffer = new uint8_t[len];
memset (buffer, 0, len);
m_address.Serialize (buffer, len);
i.Write (buffer, len);
delete [] buffer;
m_address.Serialize (i);
}
void
SocketRxAddressTag::Deserialize (TagBuffer i)
{
uint8_t type = i.ReadU8 ();
uint8_t len = i.ReadU8 ();
// Len is the length of the address starting from buffer[2]
NS_ASSERT (len >= 2);
uint8_t* buffer = new uint8_t[len];
memset (buffer, 0, len);
buffer[0] = type;
buffer[1] = len;
i.Read (buffer+2, len); // ReadU8 consumes a byte
m_address = Address::Deserialize (buffer);
delete [] buffer;
m_address.Deserialize (i);
}
SocketIpTtlTag::SocketIpTtlTag ()