merge with ns-3-dev

This commit is contained in:
Pavel Boyko
2009-11-16 13:35:38 +03:00
156 changed files with 4279 additions and 2438 deletions

View File

@@ -40,6 +40,14 @@ Application::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::Application")
.SetParent<Object> ()
.AddAttribute ("StartTime", "Time at which the application will start",
TimeValue (Seconds (0.0)),
MakeTimeAccessor (&Application::m_startTime),
MakeTimeChecker ())
.AddAttribute ("StopTime", "Time at which the application will stop",
TimeValue (TimeStep (0)),
MakeTimeAccessor (&Application::m_stopTime),
MakeTimeChecker ())
;
return tid;
}
@@ -52,38 +60,38 @@ Application::Application()
Application::~Application()
{}
void
Application::SetStartTime (Time start)
{
m_startTime = start;
}
void
Application::SetStopTime (Time stop)
{
m_stopTime = stop;
}
void
Application::DoDispose (void)
{
m_node = 0;
Simulator::Cancel(m_startEvent);
Simulator::Cancel(m_stopEvent);
m_startEvent.Cancel ();
m_stopEvent.Cancel ();
Object::DoDispose ();
}
void Application::Start(const Time& startTime)
{
ScheduleStart (startTime);
}
void Application::Start(const RandomVariable& startVar)
void
Application::DoStart (void)
{
RandomVariable v = startVar;
ScheduleStart (Seconds (v.GetValue ()));
m_startEvent = Simulator::Schedule (m_startTime, &Application::StartApplication, this);
if (m_stopTime != TimeStep (0))
{
m_stopEvent = Simulator::Schedule (m_stopTime, &Application::StopApplication, this);
}
Object::DoStart ();
}
void Application::Stop(const Time& stopTime)
{
ScheduleStop (stopTime);
}
void Application::Stop(const RandomVariable& stopVar)
{
RandomVariable v = stopVar;
ScheduleStop (Seconds (v.GetValue ()));
}
Ptr<Node> Application::GetNode() const
{
return m_node;
@@ -105,20 +113,6 @@ void Application::StopApplication()
{ // Provide null functionality in case subclass is not interested
}
// Private helpers
void Application::ScheduleStart (const Time &startTime)
{
m_startEvent = Simulator::Schedule (startTime,
&Application::StartApplication, this);
}
void Application::ScheduleStop (const Time &stopTime)
{
m_stopEvent = Simulator::Schedule (stopTime,
&Application::StopApplication, this);
}
} //namespace ns3

View File

@@ -64,7 +64,7 @@ public:
static TypeId GetTypeId (void);
Application ();
virtual ~Application ();
/**
* \brief Specify application start time
* \param startTime Start time for this application,
@@ -76,15 +76,7 @@ public:
* private "StartApplication" method defined below, which is called at the
* time specified, to cause the application to begin.
*/
void Start (const Time& startTime);
/**
* \brief Specify application start time.
* \param startVariable the random variable to use to pick
* the real start time as a relative time, in units of
* seconds, relative to the current simulation time.
*/
void Start (const RandomVariable& startVariable);
void SetStartTime (Time start);
/**
* \brief Specify application stop time
@@ -97,16 +89,8 @@ public:
* the private StopApplication method, to be notified when that
* time has come.
*/
void Stop (const Time& stopTime);
/**
* \brief Specify application stop time
* \param stopVariable the random variable to use to pick
* the real stop time, in units of seconds,
* relative to the current simulation time.
*/
void Stop (const RandomVariable& stopVariable);
void SetStopTime (Time stop);
/**
* \returns the Node to which this Application object is attached.
*/
@@ -137,13 +121,13 @@ private:
virtual void StopApplication (void);
protected:
virtual void DoDispose (void);
private:
void ScheduleStart (const Time &time);
void ScheduleStop (const Time &time);
virtual void DoStart (void);
EventId m_startEvent;
EventId m_stopEvent;
Ptr<Node> m_node;
Time m_startTime;
Time m_stopTime;
EventId m_startEvent;
EventId m_stopEvent;
};
} //namespace ns3

View File

@@ -36,6 +36,9 @@ class NetDevice;
*
* A channel is a logical path over which information flows. The path can
* be as simple as a short piece of wire, or as complicated as space-time.
*
* Subclasses must use Simulator::ScheduleWithContext to correctly update
* event contexts when scheduling an event from one node to another one.
*/
class Channel : public Object
{

View File

@@ -23,7 +23,7 @@
#include <vector>
#include <ostream>
#include "ns3/ref-count-base.h"
#include "ns3/simple-ref-count.h"
#include "ipv4-address.h"
namespace ns3 {
@@ -38,7 +38,8 @@ class NetDevice;
* This is a reference counted object. In the future, we will add other
* entries from struct dst_entry, struct rtable, and struct dst_ops as needed.
*/
class Ipv4Route : public RefCountBase {
class Ipv4Route : public SimpleRefCount<Ipv4Route>
{
public:
Ipv4Route ();
@@ -103,7 +104,8 @@ std::ostream& operator<< (std::ostream& os, Ipv4Route const& route);
*
* \brief Ipv4 multicast route cache entry (similar to Linux struct mfc_cache)
*/
class Ipv4MulticastRoute : public RefCountBase {
class Ipv4MulticastRoute : public SimpleRefCount<Ipv4MulticastRoute>
{
public:
Ipv4MulticastRoute ();

View File

@@ -25,7 +25,7 @@
#include <vector>
#include <ostream>
#include "ns3/ref-count-base.h"
#include "ns3/simple-ref-count.h"
#include "ipv6-address.h"
@@ -39,7 +39,7 @@ class NetDevice;
* \class Ipv6Route
* \brief IPv6 route cache entry.
*/
class Ipv6Route : public RefCountBase
class Ipv6Route : public SimpleRefCount<Ipv6Route>
{
public:
/**
@@ -129,7 +129,7 @@ std::ostream& operator<< (std::ostream& os, Ipv6Route const& route);
* \class Ipv6MulticastRoute
* \brief IPv6 multicast route entry.
*/
class Ipv6MulticastRoute : public RefCountBase
class Ipv6MulticastRoute : public SimpleRefCount<Ipv6MulticastRoute>
{
public:
/**

View File

@@ -119,6 +119,7 @@ NodeListPriv::Add (Ptr<Node> node)
{
uint32_t index = m_nodes.size ();
m_nodes.push_back (node);
Simulator::ScheduleWithContext (index, TimeStep (0), &Node::Start, node);
return index;
}

View File

@@ -167,6 +167,24 @@ Node::DoDispose()
m_applications.clear ();
Object::DoDispose ();
}
void
Node::DoStart (void)
{
for (std::vector<Ptr<NetDevice> >::iterator i = m_devices.begin ();
i != m_devices.end (); i++)
{
Ptr<NetDevice> device = *i;
device->Start ();
}
for (std::vector<Ptr<Application> >::iterator i = m_applications.begin ();
i != m_applications.end (); i++)
{
Ptr<Application> application = *i;
application->Start ();
}
Object::DoStart ();
}
void
Node::NotifyDeviceAdded (Ptr<NetDevice> device)
@@ -247,6 +265,9 @@ bool
Node::ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
const Address &from, const Address &to, NetDevice::PacketType packetType, bool promiscuous)
{
NS_ASSERT_MSG (Simulator::GetContext () == GetId (), "Received packet with erroneous context ; " <<
"make sure the channels in use are correctly updating events context " <<
"when transfering events from one node to another.");
NS_LOG_DEBUG("Node " << GetId () << " ReceiveFromDevice: dev "
<< device->GetIfIndex () << " (type=" << device->GetInstanceTypeId ().GetName ()
<< ") Packet UID " << packet->GetUid ());

View File

@@ -186,6 +186,7 @@ protected:
* end of their own DoDispose method.
*/
virtual void DoDispose (void);
virtual void DoStart (void);
private:
/**

View File

@@ -497,7 +497,6 @@ PbbAddressTlvBlock::operator!= (const PbbAddressTlvBlock &other) const
PbbPacket::PbbPacket (void)
{
m_refCount = 1;
m_version = VERSION;
m_hasseqnum = false;
}
@@ -746,21 +745,6 @@ PbbPacket::MessageClear (void)
m_messageList.clear ();
}
void
PbbPacket::Ref (void) const
{
m_refCount++;
}
void
PbbPacket::Unref (void) const
{
m_refCount--;
if (m_refCount == 0)
{
delete this;
}
}
TypeId
PbbPacket::GetTypeId (void)
@@ -947,7 +931,6 @@ PbbPacket::operator!= (const PbbPacket &other) const
PbbMessage::PbbMessage ()
{
m_refCount = 1;
/* Default to IPv4 */
m_addrSize = IPV4;
m_hasOriginatorAddress = false;
@@ -1274,22 +1257,6 @@ PbbMessage::AddressBlockClear (void)
return m_addressBlockList.clear();
}
void
PbbMessage::Ref (void) const
{
m_refCount++;
}
void
PbbMessage::Unref (void) const
{
m_refCount--;
if (m_refCount == 0)
{
delete this;
}
}
uint32_t
PbbMessage::GetSerializedSize (void) const
{
@@ -1699,13 +1666,10 @@ PbbMessageIpv6::AddressBlockDeserialize (Buffer::Iterator &start) const
/* End PbbMessageIpv6 Class */
PbbAddressBlock::PbbAddressBlock ()
{
m_refCount = 1;
}
{}
PbbAddressBlock::~PbbAddressBlock ()
{
}
{}
/* Manipulating the address block */
@@ -2002,23 +1966,6 @@ PbbAddressBlock::TlvClear (void)
{
m_addressTlvList.Clear();
}
void
PbbAddressBlock::Ref (void) const
{
m_refCount++;
}
void
PbbAddressBlock::Unref (void) const
{
m_refCount--;
if (m_refCount == 0)
{
delete this;
}
}
uint32_t
PbbAddressBlock::GetSerializedSize (void) const
{
@@ -2448,7 +2395,6 @@ PbbAddressBlockIpv6::PrintAddress (std::ostream &os, ConstAddressIterator iter)
PbbTlv::PbbTlv (void)
{
m_refCount = 1;
m_hasTypeExt = false;
m_hasIndexStart = false;
m_hasIndexStop = false;
@@ -2573,22 +2519,6 @@ PbbTlv::HasValue (void) const
return m_hasValue;
}
void
PbbTlv::Ref (void) const
{
m_refCount++;
}
void
PbbTlv::Unref (void) const
{
m_refCount--;
if (m_refCount == 0)
{
delete this;
}
}
uint32_t
PbbTlv::GetSerializedSize (void) const
{

View File

@@ -31,6 +31,7 @@
#include "ns3/address.h"
#include "ns3/header.h"
#include "ns3/buffer.h"
#include "ns3/simple-ref-count.h"
namespace ns3 {
@@ -360,7 +361,7 @@ private:
*
* See: http://tools.ietf.org/html/rfc5444 for details.
*/
class PbbPacket : public Header
class PbbPacket : public SimpleRefCount<PbbPacket,Header>
{
public:
typedef std::list< Ptr<PbbTlv> >::iterator TlvIterator;
@@ -595,10 +596,6 @@ public:
*/
void MessageClear (void);
/* Smart pointer methods */
void Ref (void) const;
void Unref (void) const;
/* Methods implemented by all headers */
static TypeId GetTypeId (void);
virtual TypeId GetInstanceTypeId (void) const;
@@ -644,8 +641,6 @@ private:
bool m_hasseqnum;
uint16_t m_seqnum;
mutable uint32_t m_refCount;
};
/**
@@ -655,7 +650,7 @@ private:
* virtual base class, when creating a message, you should instantiate either
* PbbMessageIpv4 or PbbMessageIpv6.
*/
class PbbMessage
class PbbMessage : public SimpleRefCount<PbbMessage>
{
public:
typedef std::list< Ptr<PbbTlv> >::iterator TlvIterator;
@@ -959,10 +954,6 @@ public:
*/
void AddressBlockClear (void);
/* Smart pointer methods */
void Ref (void) const;
void Unref (void) const;
/**
* \brief Deserializes a message, returning the correct object depending on
* whether it is an IPv4 message or an IPv6 message.
@@ -1048,8 +1039,6 @@ private:
bool m_hasSequenceNumber;
uint16_t m_sequenceNumber;
mutable uint32_t m_refCount;
};
/**
@@ -1098,7 +1087,7 @@ protected:
* This is a pure virtual base class, when creating address blocks, you should
* instantiate either PbbAddressBlockIpv4 or PbbAddressBlockIpv6.
*/
class PbbAddressBlock
class PbbAddressBlock : public SimpleRefCount<PbbAddressBlock>
{
public:
typedef std::list< Address >::iterator AddressIterator;
@@ -1412,10 +1401,6 @@ public:
*/
void TlvClear (void);
/* Smart pointer methods */
void Ref (void) const;
void Unref (void) const;
/**
* \return The size (in bytes) needed to serialize this address block.
*/
@@ -1475,8 +1460,6 @@ private:
std::list<Address> m_addressList;
std::list<uint8_t> m_prefixList;
PbbAddressTlvBlock m_addressTlvList;
mutable uint32_t m_refCount;
};
/**
@@ -1520,11 +1503,11 @@ protected:
/**
* \brief A packet or message TLV
*/
class PbbTlv
class PbbTlv : public SimpleRefCount<PbbTlv>
{
public:
PbbTlv (void);
~PbbTlv (void);
virtual ~PbbTlv (void);
/**
* \brief Sets the type of this TLV.
@@ -1599,10 +1582,6 @@ public:
*/
bool HasValue (void) const;
/* Smart pointer methods */
void Ref (void) const;
void Unref (void) const;
/**
* \return The size (in bytes) needed to serialize this TLV.
*/
@@ -1672,8 +1651,6 @@ private:
bool m_isMultivalue;
bool m_hasValue;
Buffer m_value;
mutable uint32_t m_refCount;
};
/**

View File

@@ -21,6 +21,7 @@
#include "simple-net-device.h"
#include "ns3/simulator.h"
#include "ns3/packet.h"
#include "ns3/node.h"
namespace ns3 {
@@ -49,7 +50,8 @@ SimpleChannel::Send (Ptr<Packet> p, uint16_t protocol,
{
continue;
}
Simulator::ScheduleNow (&SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from);
Simulator::ScheduleWithContext (tmp->GetNode ()->GetId (), Seconds (0),
&SimpleNetDevice::Receive, tmp, p->Copy (), protocol, to, from);
}
}