merged with nsnam

This commit is contained in:
Pavel Boyko
2009-06-16 17:58:16 +04:00
49 changed files with 424 additions and 212 deletions

View File

@@ -142,8 +142,7 @@ void PacketSink::HandleRead (Ptr<Socket> socket)
{
InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
NS_LOG_INFO ("Received " << packet->GetSize() << " bytes from " <<
address.GetIpv4() << " [" << address << "]---'" <<
packet->PeekData() << "'");
address.GetIpv4() << " [" << address << "]");
}
m_rxTrace (packet, from);
}

View File

@@ -87,10 +87,11 @@ V4Ping::Receive (Ptr<Socket> socket)
if (echo.GetSequenceNumber () == (m_seq - 1) &&
echo.GetIdentifier () == 0)
{
Ptr<const Packet> data = echo.GetData ();
if (data->GetSize () == 16)
uint8_t data[16];
uint32_t dataSize = echo.GetData (data);
if (dataSize == 16)
{
uint32_t *buf = (uint32_t *)data->PeekData ();
uint32_t *buf = (uint32_t *)data;
if (buf[0] == GetNode ()->GetId () &&
buf[1] == GetApplicationId ())
{

View File

@@ -643,6 +643,32 @@ Buffer::PeekData (void) const
return m_data->m_data + m_start;
}
void
Buffer::CopyData(std::ostream *os, uint32_t size) const
{
if (size == GetSize ())
{
// fast path
os->write((const char*)(m_data->m_data + m_start), m_zeroAreaStart-m_start);
char zero = 0;
for (uint32_t i = 0; i < m_zeroAreaEnd - m_zeroAreaStart; ++i)
{
os->write (&zero, 1);
}
os->write ((const char*)(m_data->m_data + m_zeroAreaStart), m_end - m_zeroAreaEnd);
}
else
{
// slow path
Buffer::Iterator i = Begin ();
while (!i.IsEnd () && size > 0)
{
char byte = i.ReadU8 ();
os->write (&byte, 1);
}
}
}
/******************************************************
* The buffer iterator below.
******************************************************/

View File

@@ -22,6 +22,7 @@
#include <stdint.h>
#include <vector>
#include <ostream>
#define BUFFER_HEURISTICS 1
#define BUFFER_USE_INLINE 1
@@ -486,6 +487,8 @@ public:
int32_t GetCurrentStartOffset (void) const;
int32_t GetCurrentEndOffset (void) const;
void CopyData (std::ostream *os, uint32_t size) const;
Buffer (Buffer const &o);
Buffer &operator = (Buffer const &o);
Buffer ();

View File

@@ -356,6 +356,12 @@ Packet::CopyData (uint8_t *buffer, uint32_t size) const
return cur;
}
void
Packet::CopyData(std::ostream *os, uint32_t size) const
{
return m_buffer.CopyData (os, size);
}
uint32_t
Packet::GetUid (void) const
{

View File

@@ -344,6 +344,8 @@ public:
*/
uint32_t CopyData (uint8_t *buffer, uint32_t size) const;
void CopyData(std::ostream *os, uint32_t size) const;
/**
* A packet is allocated a new uid when it is created
* empty or with zero-filled payload.

View File

@@ -164,7 +164,7 @@ PcapWriter::WritePacket (Ptr<const Packet> packet)
Write32 (us & 0xffffffff);
Write32 (packet->GetSize ());
Write32 (packet->GetSize ());
WriteData (packet->PeekData (), packet->GetSize ());
packet->CopyData (m_writer, packet->GetSize ());
}
}
@@ -412,7 +412,7 @@ void PcapWriter::WriteWifiMonitorPacket(Ptr<const Packet> packet, uint16_t chann
}
// finally, write rest of packet
WriteData (packet->PeekData (), packet->GetSize ());
packet->CopyData (m_writer, packet->GetSize ());
}

View File

@@ -16,7 +16,7 @@ def configure(conf):
"library 'libxml-2.0 >= 2.7' not found")
conf.sub_config('stats')
conf.write_config_header('ns3/contrib-config.h', project_root_relative=True)
conf.write_config_header('ns3/contrib-config.h', top=True)
def build(bld):
module = bld.create_ns3_module('contrib', ['simulator', 'common'])

View File

@@ -55,6 +55,18 @@ TestManager::EnableVerbose (void)
{
Get ()->m_verbose = true;
}
void
TestManager::PrintTestNames (std::ostream &os)
{
for (TestsCI i = Get ()->m_tests.begin (); i != Get ()->m_tests.end (); i++)
{
std::string *testName = (*i).second;
os << *testName << std::endl;
}
}
std::ostream &
TestManager::Failure (void)
{
@@ -95,6 +107,47 @@ TestManager::RealRunTests (void)
return isSuccess;
}
bool
TestManager::RunTest (std::string name)
{
return Get ()->RealRunTest (name);
}
bool
TestManager::RealRunTest (std::string name)
{
TestsCI i;
for (i = m_tests.begin (); i != m_tests.end (); i++)
{
std::string *testName = (*i).second;
if (*testName == name)
{
break;
}
}
if (i == m_tests.end ())
{
std::cerr << "Test with name " << name << " not found." << std::endl;
}
if (!(*i).first->RunTests ())
{
if (m_verbose)
{
std::cerr << "FAIL " << name << std::endl;
}
return false;
}
else
{
if (m_verbose)
{
std::cerr << "PASS "<< name << std::endl;
}
return true;
}
}
Test::Test (char const *name)
{
TestManager::Add (this, name);

View File

@@ -89,12 +89,17 @@ public:
*/
static bool RunTests (void);
static bool RunTest (std::string name);
static void PrintTestNames (std::ostream &os);
private:
friend class Test;
static void Add (Test *test, char const *name);
static std::ostream &Failure (void);
static TestManager *Get (void);
bool RealRunTests (void);
bool RealRunTest (std::string name);
TestManager ();
~TestManager ();

View File

@@ -41,7 +41,7 @@ int main ()
conf.env['ENABLE_THREADING'],
"<pthread.h> include not detected")
conf.write_config_header('ns3/core-config.h', project_root_relative=True)
conf.write_config_header('ns3/core-config.h', top=True)
def build(bld):
core = bld.create_ns3_module('core')

View File

@@ -29,7 +29,9 @@ TypeId
BridgeChannel::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::BridgeChannel")
.SetParent<Channel> ();
.SetParent<Channel> ()
.AddConstructor<BridgeChannel> ()
;
return tid;
}

View File

@@ -805,7 +805,7 @@ MacLow::DoNavResetNow (Time duration)
(*i)->NavReset (duration);
}
m_lastNavStart = Simulator::Now ();
m_lastNavDuration = duration;
m_lastNavStart = duration;
}
bool
MacLow::DoNavStartNow (Time duration)

View File

@@ -38,6 +38,7 @@ WifiNetDevice::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::WifiNetDevice")
.SetParent<NetDevice> ()
.AddConstructor<WifiNetDevice> ()
.AddAttribute ("Channel", "The channel attached to this device",
PointerValue (),
MakePointerAccessor (&WifiNetDevice::DoGetChannel),

View File

@@ -31,6 +31,7 @@ public:
virtual ~NqosWifiMacHelper ();
/**
* Create a mac helper in a default working state.
* i.e., this is an adhoc mac by default.
*/
static NqosWifiMacHelper Default (void);
/**

View File

@@ -108,7 +108,9 @@ Icmpv4Echo::SetSequenceNumber (uint16_t seq)
void
Icmpv4Echo::SetData (Ptr<const Packet> data)
{
m_data = data->Copy ();
uint32_t size = (data->GetSize ()>16)?16:data->GetSize();
data->CopyData (m_data, size);
m_dataSize = size;
}
uint16_t
Icmpv4Echo::GetIdentifier (void) const
@@ -120,10 +122,11 @@ Icmpv4Echo::GetSequenceNumber (void) const
{
return m_sequence;
}
Ptr<const Packet>
Icmpv4Echo::GetData (void) const
uint32_t
Icmpv4Echo::GetData (uint8_t data[16]) const
{
return m_data->Copy ();
memcpy (data, m_data, m_dataSize);
return m_dataSize;
}
@@ -139,8 +142,14 @@ Icmpv4Echo::GetTypeId (void)
Icmpv4Echo::Icmpv4Echo ()
: m_identifier (0),
m_sequence (0),
m_data (0)
{}
m_dataSize (0)
{
// make sure that thing is initialized to get initialized bytes
for (uint8_t j = 0; j < 16; j++)
{
m_data[j] = 0;
}
}
Icmpv4Echo::~Icmpv4Echo ()
{}
TypeId
@@ -151,14 +160,14 @@ Icmpv4Echo::GetInstanceTypeId (void) const
uint32_t
Icmpv4Echo::GetSerializedSize (void) const
{
return 4 + m_data->GetSize ();
return 4 + m_dataSize;
}
void
Icmpv4Echo::Serialize (Buffer::Iterator start) const
{
start.WriteHtonU16 (m_identifier);
start.WriteHtonU16 (m_sequence);
start.Write (m_data->PeekData (), m_data->GetSize ());
start.Write (m_data, m_dataSize);
}
uint32_t
Icmpv4Echo::Deserialize (Buffer::Iterator start)
@@ -166,11 +175,8 @@ Icmpv4Echo::Deserialize (Buffer::Iterator start)
m_identifier = start.ReadNtohU16 ();
m_sequence = start.ReadNtohU16 ();
NS_ASSERT (start.GetSize () >= 4);
uint32_t size = start.GetSize () - 4;
uint8_t *buffer = new uint8_t[size] ();
start.Read (buffer, size);
m_data = Create<Packet> (buffer, size);
delete[] buffer;
m_dataSize = start.GetSize () - 4;
start.Read (m_data, m_dataSize);
return start.GetSize ();
}
void

View File

@@ -50,7 +50,7 @@ public:
void SetData (Ptr<const Packet> data);
uint16_t GetIdentifier (void) const;
uint16_t GetSequenceNumber (void) const;
Ptr<const Packet> GetData (void) const;
uint32_t GetData (uint8_t payload[16]) const;
static TypeId GetTypeId (void);
@@ -64,7 +64,8 @@ public:
private:
uint16_t m_identifier;
uint16_t m_sequence;
Ptr<Packet> m_data;
uint8_t m_data[16];
uint32_t m_dataSize;
};
class Icmpv4DestinationUnreachable : public Header

View File

@@ -35,6 +35,7 @@ Ipv4ListRoutingImpl::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Ipv4ListRoutingImpl")
.SetParent<Ipv4ListRouting> ()
.AddConstructor<Ipv4ListRoutingImpl> ()
;
return tid;
}

View File

@@ -36,6 +36,7 @@ Ipv4StaticRoutingImpl::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Ipv4StaticRoutingImpl")
.SetParent<Ipv4StaticRouting> ()
.AddConstructor<Ipv4StaticRoutingImpl> ()
;
return tid;
}

View File

@@ -448,7 +448,7 @@ NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
{
SocketAddressTag tag;
bool found;
found = packet->FindFirstMatchingTag (tag);
found = packet->PeekPacketTag (tag);
NS_ASSERT (found);
fromAddress = tag.GetAddress ();
}
@@ -600,7 +600,7 @@ bool NscTcpSocketImpl::ReadPendingData (void)
SocketAddressTag tag;
tag.SetAddress (m_peerAddress);
p->AddTag (tag);
p->AddPacketTag (tag);
m_deliveryQueue.push (p);
m_rxAvailable += p->GetSize ();

View File

@@ -189,7 +189,7 @@ TcpSocketImplTest::Test1_HandleRecv (Ptr<Socket> sock)
{
rxBytes1 += sz;
rxPayload = new uint8_t[sz];
memcpy (rxPayload, p->PeekData(), sz);
p->CopyData (rxPayload, sz);
}
else
{

View File

@@ -82,7 +82,6 @@ def build(bld):
'ipv4-l3-protocol.cc',
'ipv4-static-routing-impl.cc',
'ipv4-list-routing-impl.cc',
'ipv4-global-routing.cc',
'ipv4-end-point.cc',
'udp-l4-protocol.cc',
'tcp-l4-protocol.cc',
@@ -110,7 +109,6 @@ def build(bld):
'udp-header.h',
'tcp-header.h',
'sequence-number.h',
'ipv4-global-routing.h',
'ipv4-list-routing-impl.h',
'ipv4-static-routing-impl.h',
'icmpv4.h',

View File

@@ -24,7 +24,7 @@
namespace ns3 {
/**
* \ingroup ipv4-routing
* \ingroup ipv4Routing
*
* This class is a specialization of Ipv4RoutingProtocol that allows
* other instances of Ipv4RoutingProtocol to be inserted in a

View File

@@ -31,7 +31,7 @@ namespace ns3 {
class NetDevice;
/**
* \ingroup ipv4-routing
* \ingroup ipv4Routing
*
*\brief Ipv4 route cache entry (similar to Linux struct rtable)
*
@@ -99,7 +99,7 @@ private:
std::ostream& operator<< (std::ostream& os, Ipv4Route const& route);
/**
* \ingroup ipv4-routing
* \ingroup ipv4Routing
*
* \brief Ipv4 multicast route cache entry (similar to Linux struct mfc_cache)
*/

View File

@@ -32,7 +32,7 @@ class NetDevice;
/**
* \ingroup node
* \defgroup ipv4-routing Ipv4 Routing
* \defgroup ipv4Routing Ipv4 Routing
*
* Abstract base class for Ipv4 routing protocols. Defines two
* virtual functions for packet routing and forwarding. The first,

View File

@@ -29,7 +29,7 @@
namespace ns3 {
/**
* \ingroup ipv4-routing
* \ingroup ipv4Routing
*
* A record of an IPv4 routing table entry for Ipv4GlobalRouting and
* Ipv4StaticRouting. This is not a reference counted object.
@@ -155,7 +155,7 @@ private:
std::ostream& operator<< (std::ostream& os, Ipv4RoutingTableEntry const& route);
/**
* \ingroup ipv4-routing
* \ingroup ipv4Routing
*
* \brief A record of an IPv4 multicast route for Ipv4GlobalRouting and Ipv4StaticRouting
*/

View File

@@ -44,7 +44,7 @@ class Ipv4RoutingTableEntry;
class Ipv4MulticastRoutingTableEntry;
/**
* \ingroup ipv4-routing
* \ingroup ipv4Routing
*
* \brief Static routing protocol for IP version 4 stacks.
*

View File

@@ -148,7 +148,7 @@ Socket::Recv (uint8_t* buf, uint32_t size, uint32_t flags)
{
return 0;
}
memcpy (buf, p->PeekData (), p->GetSize());
p->CopyData (buf, p->GetSize ());
return p->GetSize ();
}
@@ -169,7 +169,7 @@ Socket::RecvFrom (uint8_t* buf, uint32_t size, uint32_t flags,
{
return 0;
}
memcpy (buf, p->PeekData (), p->GetSize());
p->CopyData (buf, p->GetSize ());
return p->GetSize ();
}

View File

@@ -30,12 +30,12 @@
#include "ns3/log.h"
#include "ns3/node-list.h"
#include "ns3/ipv4.h"
#include "ns3/ipv4-global-routing.h"
#include "ns3/ipv4-routing-protocol.h"
#include "ns3/ipv4-list-routing.h"
#include "global-router-interface.h"
#include "global-route-manager-impl.h"
#include "candidate-queue.h"
#include "ipv4-global-routing.h"
NS_LOG_COMPONENT_DEFINE ("GlobalRouteManager");

View File

@@ -7,6 +7,7 @@ def build(bld):
'global-route-manager.cc',
'global-route-manager-impl.cc',
'candidate-queue.cc',
'ipv4-global-routing.cc',
]
headers = bld.new_task_gen('ns3header')
headers.module = 'global-routing'

View File

@@ -31,7 +31,7 @@ def configure(conf):
conf.check(header_name='sys/inttypes.h', define_name='HAVE_SYS_INT_TYPES_H')
conf.write_config_header('ns3/simulator-config.h', project_root_relative=True)
conf.write_config_header('ns3/simulator-config.h', top=True)
if not conf.check(lib='rt', uselib='RT', define_name='HAVE_RT'):
conf.report_optional_feature("RealTime", "Real Time Simulator",