merge with HEAD

--HG--
rename : src/mobility/random-position.cc => src/mobility/position-allocator.cc
rename : src/mobility/random-position.h => src/mobility/position-allocator.h
This commit is contained in:
Mathieu Lacage committed 2008-02-27 22:19:39 +01:00
commit f31fa14684
172 files changed
+8742 -3211

No files matched your search

+8
View File
@@ -107,6 +107,8 @@ Address::Register (void)
return type;
}
VALUE_HELPER_CPP (Address);
bool operator == (const Address &a, const Address &b)
{
NS_ASSERT (a.m_type == b.m_type ||
@@ -159,6 +161,12 @@ std::ostream& operator<< (std::ostream& os, const Address & address)
return os;
}
std::istream& operator>> (std::istream& is, Address & address)
{
// XXX: need to be able to parse this.
return is;
}
} // namespace ns3
+8 -1
View File
@@ -3,6 +3,8 @@
#include <stdint.h>
#include <ostream>
#include "ns3/attribute.h"
#include "ns3/attribute-helper.h"
namespace ns3 {
@@ -151,6 +153,8 @@ public:
* \returns a new type id.
*/
static uint8_t Register (void);
VALUE_HELPER_HEADER_1 (Address);
private:
friend bool operator == (const Address &a, const Address &b);
friend bool operator < (const Address &a, const Address &b);
@@ -161,12 +165,15 @@ private:
uint8_t m_data[MAX_SIZE];
};
VALUE_HELPER_HEADER_2 (Address);
bool operator == (const Address &a, const Address &b);
bool operator != (const Address &a, const Address &b);
bool operator < (const Address &a, const Address &b);
std::ostream& operator<< (std::ostream& os, const Address & address);
std::istream& operator>> (std::istream& is, Address & address);
} // namespace ns3
#endif /* ADDRESS_H */
+16 -4
View File
@@ -31,14 +31,26 @@ using namespace std;
namespace ns3 {
NS_OBJECT_ENSURE_REGISTERED (Application);
// Application Methods
// \brief Application Constructor
Application::Application(Ptr<Node> n)
: m_node (n)
TypeId
Application::GetTypeId (void)
{
m_node->AddApplication (this);
static TypeId tid = TypeId ("Application")
.SetParent<Object> ()
.AddAttribute ("Node", "The on which this application resides",
Ptr<Node> (0),
MakePtrAccessor (&Application::m_node),
MakePtrChecker<Node> ())
;
return tid;
}
// \brief Application Constructor
Application::Application()
{}
// \brief Application Destructor
Application::~Application()
+2 -1
View File
@@ -52,7 +52,8 @@ class RandomVariable;
class Application : public Object
{
public:
Application(Ptr<Node>);
static TypeId GetTypeId (void);
Application();
virtual ~Application();
/**
+27 -37
View File
@@ -18,6 +18,7 @@
*/
#include "ns3/log.h"
#include "ns3/uinteger.h"
#include "drop-tail-queue.h"
NS_LOG_COMPONENT_DEFINE ("DropTailQueue");
@@ -30,14 +31,19 @@ TypeId DropTailQueue::GetTypeId (void)
{
static TypeId tid = TypeId ("DropTailQueue")
.SetParent<Queue> ()
.AddConstructor<DropTailQueue> ();
.AddConstructor<DropTailQueue> ()
.AddAttribute ("MaxPackets", "The maximum number of packets accepted by this DropTailQueue.",
Uinteger (100),
MakeUintegerAccessor (&DropTailQueue::m_maxPackets),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
DropTailQueue::DropTailQueue () :
Queue (),
m_packets (),
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
m_packets ()
{
NS_LOG_FUNCTION;
}
@@ -47,22 +53,6 @@ DropTailQueue::~DropTailQueue ()
NS_LOG_FUNCTION;
}
void
DropTailQueue::SetMaxPackets (uint32_t npackets)
{
NS_LOG_FUNCTION;
NS_LOG_PARAMS (this << npackets);
m_maxPackets = npackets;
}
uint32_t
DropTailQueue::GetMaxPackets (void)
{
NS_LOG_FUNCTION;
NS_LOG_LOGIC ("returns " << m_maxPackets);
return m_maxPackets;
}
bool
DropTailQueue::DoEnqueue (Ptr<Packet> p)
{
@@ -142,8 +132,8 @@ DropTailQueueTest::RunTests (void)
{
bool result = true;
DropTailQueue queue;
queue.SetMaxPackets (3);
Ptr<DropTailQueue> queue = CreateObject<DropTailQueue> ();
NS_TEST_ASSERT (queue->SetAttribute ("MaxPackets", Uinteger (3)));
Ptr<Packet> p1, p2, p3, p4;
p1 = Create<Packet> ();
@@ -151,34 +141,34 @@ DropTailQueueTest::RunTests (void)
p3 = Create<Packet> ();
p4 = Create<Packet> ();
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0);
queue.Enqueue (p1);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1);
queue.Enqueue (p2);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2);
queue.Enqueue (p3);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3);
queue.Enqueue (p4); // will be dropped
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 3);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 0);
queue->Enqueue (p1);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 1);
queue->Enqueue (p2);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 2);
queue->Enqueue (p3);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 3);
queue->Enqueue (p4); // will be dropped
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 3);
Ptr<Packet> p;
p = queue.Dequeue ();
p = queue->Dequeue ();
NS_TEST_ASSERT (p != 0);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 2);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 2);
NS_TEST_ASSERT_EQUAL (p->GetUid (), p1->GetUid ());
p = queue.Dequeue ();
p = queue->Dequeue ();
NS_TEST_ASSERT (p != 0);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 1);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 1);
NS_TEST_ASSERT_EQUAL (p->GetUid (), p2->GetUid ());
p = queue.Dequeue ();
p = queue->Dequeue ();
NS_TEST_ASSERT (p != 0);
NS_TEST_ASSERT_EQUAL (queue.GetNPackets (), 0);
NS_TEST_ASSERT_EQUAL (queue->GetNPackets (), 0);
NS_TEST_ASSERT_EQUAL (p->GetUid (), p3->GetUid ());
p = queue.Dequeue ();
p = queue->Dequeue ();
NS_TEST_ASSERT (p == 0);
return result;
-12
View File
@@ -28,8 +28,6 @@ namespace ns3 {
class TraceContainer;
const int DTQ_NPACKETS_MAX_DEFAULT = 100;
/**
* \brief A FIFO packet queue that drops tail-end packets on overflow
*/
@@ -44,16 +42,6 @@ public:
DropTailQueue ();
virtual ~DropTailQueue();
/**
* \param npackets The maximum number of packets this queue will hold before
* dropping packets.
*/
void SetMaxPackets (uint32_t npackets);
/**
* \return The maximum number of packets this queue will hold before dropping
* packets.
*/
uint32_t GetMaxPackets (void);
private:
virtual bool DoEnqueue (Ptr<Packet> p);
+18 -1
View File
@@ -301,6 +301,21 @@ std::ostream& operator<< (std::ostream& os, Ipv4Mask const& mask)
mask.Print (os);
return os;
}
std::istream & operator >> (std::istream &is, Ipv4Address &address)
{
std::string str;
is >> str;
address = Ipv4Address (str.c_str ());
return is;
}
std::istream & operator >> (std::istream &is, Ipv4Mask &mask)
{
std::string str;
is >> str;
mask = Ipv4Mask (str.c_str ());
return is;
}
bool operator == (Ipv4Mask const &a, Ipv4Mask const &b)
{
return a.IsEqual (b);
@@ -310,5 +325,7 @@ bool operator != (Ipv4Mask const &a, Ipv4Mask const &b)
return !a.IsEqual (b);
}
VALUE_HELPER_CPP (Ipv4Address);
VALUE_HELPER_CPP (Ipv4Mask);
}; // namespace ns3
} // namespace ns3
+11 -1
View File
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <ostream>
#include "address.h"
#include "ns3/attribute-helper.h"
namespace ns3 {
@@ -141,6 +142,8 @@ public:
static Ipv4Address GetAny (void);
static Ipv4Address GetBroadcast (void);
static Ipv4Address GetLoopback (void);
VALUE_HELPER_HEADER_1 (Ipv4Address);
private:
Address ConvertTo (void) const;
static uint8_t GetType (void);
@@ -177,12 +180,19 @@ public:
static Ipv4Mask GetLoopback (void);
static Ipv4Mask GetZero (void);
VALUE_HELPER_HEADER_1 (Ipv4Mask);
private:
uint32_t m_mask;
};
VALUE_HELPER_HEADER_2 (Ipv4Address);
VALUE_HELPER_HEADER_2 (Ipv4Mask);
std::ostream& operator<< (std::ostream& os, Ipv4Address const& address);
std::ostream& operator<< (std::ostream& os, Ipv4Mask const& mask);
std::istream & operator >> (std::istream &is, Ipv4Address &address);
std::istream & operator >> (std::istream &is, Ipv4Mask &mask);
inline bool operator == (const Ipv4Address &a, const Ipv4Address &b)
{
@@ -206,6 +216,6 @@ public:
bool operator == (Ipv4Mask const &a, Ipv4Mask const &b);
bool operator != (Ipv4Mask const &a, Ipv4Mask const &b);
}; // namespace ns3
} // namespace ns3
#endif /* IPV4_ADDRESS_H */
+9
View File
@@ -25,6 +25,8 @@
namespace ns3 {
VALUE_HELPER_CPP (Mac48Address);
#define ASCII_a (0x41)
#define ASCII_z (0x5a)
#define ASCII_A (0x61)
@@ -149,6 +151,7 @@ Mac48Address::GetBroadcast (void)
static Mac48Address broadcast = Mac48Address ("ff:ff:ff:ff:ff:ff");
return broadcast;
}
bool operator == (const Mac48Address &a, const Mac48Address &b)
{
return memcmp (a.m_address, b.m_address, 6) == 0;
@@ -197,5 +200,11 @@ std::ostream& operator<< (std::ostream& os, const Mac48Address & address)
return os;
}
std::istream& operator>> (std::istream& is, const Mac48Address & address)
{
// XXX !
return is;
}
} // namespace ns3
+10 -3
View File
@@ -17,11 +17,13 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef EUI48_ADDRESS_H
#define EUI48_ADDRESS_H
#ifndef MAC48_ADDRESS_H
#define MAC48_ADDRESS_H
#include <stdint.h>
#include <ostream>
#include "ns3/attribute.h"
#include "ns3/attribute-helper.h"
namespace ns3 {
@@ -93,6 +95,8 @@ public:
* \returns the broadcast address
*/
static Mac48Address GetBroadcast (void);
VALUE_HELPER_HEADER_1 (Mac48Address);
private:
/**
* \returns a new Address instance
@@ -107,11 +111,14 @@ private:
uint8_t m_address[6];
};
VALUE_HELPER_HEADER_2 (Mac48Address);
bool operator == (const Mac48Address &a, const Mac48Address &b);
bool operator != (const Mac48Address &a, const Mac48Address &b);
bool operator < (const Mac48Address &a, const Mac48Address &b);
std::ostream& operator<< (std::ostream& os, const Mac48Address & address);
std::istream& operator>> (std::istream& is, const Mac48Address & address);
} // namespace ns3
#endif /* EUI48_ADDRESS_H */
#endif /* MAC48_ADDRESS_H */
+3 -3
View File
@@ -17,8 +17,8 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef EUI64_ADDRESS_H
#define EUI64_ADDRESS_H
#ifndef MAC64_ADDRESS_H
#define MAC64_ADDRESS_H
#include <stdint.h>
#include <ostream>
@@ -95,4 +95,4 @@ std::ostream& operator<< (std::ostream& os, const Mac64Address & address);
} // namespace ns3
#endif /* EUI64_ADDRESS_H */
#endif /* MAC64_ADDRESS_H */
+40
View File
@@ -0,0 +1,40 @@
#include "net-device-container.h"
namespace ns3 {
NetDeviceContainer::Iterator
NetDeviceContainer::Begin (void) const
{
return m_nodes.begin ();
}
NetDeviceContainer::Iterator
NetDeviceContainer::End (void) const
{
return m_nodes.end ();
}
uint32_t
NetDeviceContainer::GetN (void) const
{
return m_nodes.size ();
}
Ptr<NetDevice>
NetDeviceContainer::Get (uint32_t i) const
{
return m_nodes[i];
}
void
NetDeviceContainer::Add (NetDeviceContainer other)
{
for (Iterator i = other.Begin (); i != other.End (); i++)
{
m_nodes.push_back (*i);
}
}
void
NetDeviceContainer::Add (Ptr<NetDevice> node)
{
m_nodes.push_back (node);
}
} // namespace ns3
+31
View File
@@ -0,0 +1,31 @@
#ifndef NET_DEVICE_CONTAINER_H
#define NET_DEVICE_CONTAINER_H
#include <stdint.h>
#include <vector>
#include "net-device.h"
namespace ns3 {
class NetDeviceContainer
{
public:
typedef std::vector<Ptr<NetDevice> >::const_iterator Iterator;
Iterator Begin (void) const;
Iterator End (void) const;
uint32_t GetN (void) const;
Ptr<NetDevice> Get (uint32_t i) const;
void Create (uint32_t n);
void Add (NetDeviceContainer other);
void Add (Ptr<NetDevice> node);
private:
std::vector<Ptr<NetDevice> > m_nodes;
};
} // namespace ns3
#endif /* NET_DEVICE_CONTAINER_H */
+2 -273
View File
@@ -19,15 +19,9 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include <iostream>
#include "ns3/assert.h"
#include "ns3/object.h"
#include "ns3/log.h"
#include "ns3/trace-resolver.h"
#include "ns3/packet.h"
#include "channel.h"
#include "net-device.h"
#include "node.h"
NS_LOG_COMPONENT_DEFINE ("NetDevice");
@@ -42,272 +36,7 @@ TypeId NetDevice::GetTypeId (void)
return tid;
}
NetDevice::NetDevice(Ptr<Node> node, const Address& addr) :
m_node (node),
m_name(""),
m_ifIndex (0),
m_address (addr),
m_mtu (0xffff),
m_isUp (false),
m_isBroadcast (false),
m_isMulticast (false),
m_isPointToPoint (false)
{
NS_LOG_FUNCTION;
m_node->AddDevice (this);
}
NetDevice::~NetDevice ()
{
NS_LOG_FUNCTION;
}
{}
Address
NetDevice::GetAddress (void) const
{
NS_LOG_FUNCTION;
return m_address;
}
bool
NetDevice::SetMtu (const uint16_t mtu)
{
NS_LOG_FUNCTION;
m_mtu = mtu;
return true;
}
uint16_t
NetDevice::GetMtu (void) const
{
NS_LOG_FUNCTION;
return m_mtu;
}
void
NetDevice::SetName(const std::string name)
{
NS_LOG_FUNCTION;
m_name = name;
}
std::string
NetDevice::GetName(void) const
{
NS_LOG_FUNCTION;
return m_name;
}
void
NetDevice::SetIfIndex(uint32_t index)
{
NS_LOG_FUNCTION;
m_ifIndex = index;
}
uint32_t
NetDevice::GetIfIndex(void) const
{
NS_LOG_FUNCTION;
return m_ifIndex;
}
bool
NetDevice::IsLinkUp (void) const
{
NS_LOG_FUNCTION;
return m_isUp;
}
void
NetDevice::SetLinkChangeCallback (Callback<void> callback)
{
NS_LOG_FUNCTION;
m_linkChangeCallback = callback;
}
bool
NetDevice::IsBroadcast (void) const
{
NS_LOG_FUNCTION;
return m_isBroadcast;
}
Address const &
NetDevice::GetBroadcast (void) const
{
NS_LOG_FUNCTION;
NS_ASSERT (m_isBroadcast);
return m_broadcast;
}
void
NetDevice::EnableBroadcast (Address broadcast)
{
NS_LOG_FUNCTION;
m_isBroadcast = true;
m_broadcast = broadcast;
}
void
NetDevice::DisableBroadcast (void)
{
NS_LOG_FUNCTION;
m_isBroadcast = false;
}
bool
NetDevice::IsMulticast (void) const
{
NS_LOG_FUNCTION;
return m_isMulticast;
}
Address
NetDevice::GetMulticast (void) const
{
NS_LOG_FUNCTION;
NS_ASSERT_MSG (m_isMulticast, "NetDevice::GetMulticast (): "
"Invalid operation when not IsMulticast ()");
return m_multicast;
}
Address
NetDevice::MakeMulticastAddress(Ipv4Address multicastGroup) const
{
NS_LOG_FUNCTION;
NS_ASSERT_MSG (m_isMulticast, "NetDevice::GetMulticast (): "
"Invalid operation when not IsMulticast ()");
return m_multicast;
}
void
NetDevice::EnableMulticast (Address multicast)
{
NS_LOG_FUNCTION;
m_isMulticast = true;
m_multicast = multicast;
}
void
NetDevice::DisableMulticast (void)
{
NS_LOG_FUNCTION;
m_isMulticast = false;
}
bool
NetDevice::IsPointToPoint (void) const
{
NS_LOG_FUNCTION;
return m_isPointToPoint;
}
void
NetDevice::EnablePointToPoint (void)
{
NS_LOG_FUNCTION;
m_isPointToPoint = true;
}
void
NetDevice::DisablePointToPoint (void)
{
NS_LOG_FUNCTION;
m_isPointToPoint = false;
}
// Receive packet from above
bool
NetDevice::Send(Ptr<Packet> p, const Address& dest, uint16_t protocolNumber)
{
NS_LOG_FUNCTION;
if (m_isUp)
{
return SendTo(p, dest, protocolNumber);
}
else
{
return false;
}
}
Ptr<Channel>
NetDevice::GetChannel (void) const
{
NS_LOG_FUNCTION;
return DoGetChannel ();
}
// Receive packets from below
bool
NetDevice::ForwardUp(Ptr<Packet> p, uint16_t param, const Address &from)
{
NS_LOG_FUNCTION;
bool retval = false;
NS_LOG_LOGIC ("UID is " << p->GetUid() << " device is: " << GetName());
if (!m_receiveCallback.IsNull ())
{
retval = m_receiveCallback (this, p, param, from);
}
else
{
NS_LOG_WARN ("NetDevice::Receive call back is NULL");
}
return retval;
}
void
NetDevice::NotifyLinkUp (void)
{
NS_LOG_FUNCTION;
m_isUp = true;
if (!m_linkChangeCallback.IsNull ())
{
m_linkChangeCallback ();
}
}
void
NetDevice::NotifyLinkDown (void)
{
NS_LOG_FUNCTION;
m_isUp = false;
if (!m_linkChangeCallback.IsNull ())
{
m_linkChangeCallback ();
}
}
Ptr<Node>
NetDevice::GetNode (void) const
{
NS_LOG_FUNCTION;
return m_node;
}
bool
NetDevice::NeedsArp (void) const
{
NS_LOG_FUNCTION;
return DoNeedsArp ();
}
void
NetDevice::SetReceiveCallback (ReceiveCallback cb)
{
NS_LOG_FUNCTION;
m_receiveCallback = cb;
}
void
NetDevice::DoDispose()
{
NS_LOG_FUNCTION;
m_node = 0;
}
}; // namespace ns3
} // namespace ns3
+38 -143
View File
@@ -63,52 +63,53 @@ public:
static TypeId GetTypeId (void);
virtual ~NetDevice();
/**
* \param name name of the device (e.g. "eth0")
*/
virtual void SetName(const std::string name) = 0;
/**
* \return name name of the device (e.g. "eth0")
*/
virtual std::string GetName(void) const = 0;
/**
* \param index ifIndex of the device
*/
virtual void SetIfIndex(const uint32_t index) = 0;
/**
* \return index ifIndex of the device
*/
virtual uint32_t GetIfIndex(void) const = 0;
/**
* \return the channel this NetDevice is connected to. The value
* returned can be zero if the NetDevice is not yet connected
* to any channel.
*/
Ptr<Channel> GetChannel (void) const;
virtual Ptr<Channel> GetChannel (void) const = 0;
/**
* \return the current Address of this interface.
*/
Address GetAddress (void) const;
virtual Address GetAddress (void) const = 0;
/**
* \param mtu MTU value, in bytes, to set for the device
* \return whether the MTU value was within legal bounds
*
* Override for default MTU defined on a per-type basis.
*/
bool SetMtu (const uint16_t mtu);
virtual bool SetMtu (const uint16_t mtu) = 0;
/**
* \return the link-level MTU in bytes for this interface.
*
* This value is typically used by the IP layer to perform
* IP fragmentation when needed.
*/
uint16_t GetMtu (void) const;
/**
* \param name name of the device (e.g. "eth0")
*/
void SetName(const std::string name);
/**
* \return name name of the device (e.g. "eth0")
*/
std::string GetName(void) const;
/**
* \param index ifIndex of the device
*/
void SetIfIndex(const uint32_t index);
/**
* \return index ifIndex of the device
*/
uint32_t GetIfIndex(void) const;
virtual uint16_t GetMtu (void) const = 0;
/**
* \return true if link is up; false otherwise
*/
bool IsLinkUp (void) const;
virtual bool IsLinkUp (void) const = 0;
/**
* \param callback the callback to invoke
*
@@ -117,12 +118,12 @@ public:
* by the IP/ARP layer to flush the ARP cache
* whenever the link goes up.
*/
void SetLinkChangeCallback (Callback<void> callback);
virtual void SetLinkChangeCallback (Callback<void> callback) = 0;
/**
* \return true if this interface supports a broadcast address,
* false otherwise.
*/
bool IsBroadcast (void) const;
virtual bool IsBroadcast (void) const = 0;
/**
* \return the broadcast address supported by
* this netdevice.
@@ -130,12 +131,12 @@ public:
* Calling this method is invalid if IsBroadcast returns
* not true.
*/
Address const &GetBroadcast (void) const;
virtual Address GetBroadcast (void) const = 0;
/**
* \return value of m_isMulticast flag
*/
bool IsMulticast (void) const;
virtual bool IsMulticast (void) const = 0;
/**
* \brief Return the MAC multicast base address used when mapping multicast
@@ -160,8 +161,8 @@ public:
* The method NS_ASSERTs if the device is not a multicast device.
* \see NetDevice::MakeMulticastAddress
*/
Address GetMulticast (void) const;
virtual Address GetMulticast (void) const = 0;
/**
* \brief Make and return a MAC multicast address using the provided
* multicast group
@@ -192,12 +193,12 @@ public:
* \see Address
* \see NetDevice::IsMulticast
*/
virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const = 0;
/**
* \return value of m_isPointToPoint flag
*/
bool IsPointToPoint (void) const;
virtual bool IsPointToPoint (void) const = 0;
/**
* \param packet packet sent from above down to Network Device
* \param dest mac address of the destination (already resolved)
@@ -210,7 +211,7 @@ public:
*
* \return whether the Send operation succeeded
*/
bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) = 0;
/**
* \returns the node base class which contains this network
* interface.
@@ -219,7 +220,7 @@ public:
* base class to print the nodeid for example, it can invoke
* this method.
*/
Ptr<Node> GetNode (void) const;
virtual Ptr<Node> GetNode (void) const = 0;
/**
* \returns true if ARP is needed, false otherwise.
@@ -227,7 +228,7 @@ public:
* Called by higher-layers to check if this NetDevice requires
* ARP to be used.
*/
bool NeedsArp (void) const;
virtual bool NeedsArp (void) const = 0;
/**
* \param device a pointer to the net device which is calling this callback
@@ -246,116 +247,10 @@ public:
* be forwarded to the higher layers.
*
*/
void SetReceiveCallback (ReceiveCallback cb);
virtual void SetReceiveCallback (ReceiveCallback cb) = 0;
protected:
/**
* \param node base class node pointer of device's node
* \param addr MAC address of this device.
*/
NetDevice(Ptr<Node> node, const Address& addr);
/**
* Enable broadcast support. This method should be
* called by subclasses from their constructor
*/
void EnableBroadcast (Address broadcast);
/**
* Set m_isBroadcast flag to false
*/
void DisableBroadcast (void);
/**
* Enable multicast support. This method should be
* called by subclasses from their constructor
*/
void EnableMulticast (Address multicast);
/**
* Set m_isMulticast flag to false
*/
void DisableMulticast (void);
/**
* Set m_isPointToPoint flag to true
*/
void EnablePointToPoint (void);
/**
* Set m_isPointToPoint flag to false
*/
void DisablePointToPoint (void);
/**
* When a subclass notices that the link status has changed to up,
* it notifies its parent class by calling this method. This method
* is responsible for notifying any LinkUp callbacks.
*/
void NotifyLinkUp (void);
/**
* When a subclass notices that the link status has changed to
* down, it notifies its parent class by calling this method.
*/
void NotifyLinkDown (void);
/**
* \param p packet sent from below up to Network Device
* \param param Extra parameter extracted from header and needed by
* some protocols
* \param address the address of the sender of this packet.
* \returns true if the packet was forwarded successfully,
* false otherwise.
*
* When a subclass gets a packet from the channel, it
* forwards it to the higher layers by calling this method
* which is responsible for passing it up to the Rx callback.
*/
bool ForwardUp (Ptr<Packet> p, uint16_t param, const Address &address);
/**
* The dispose method for this NetDevice class.
* Subclasses are expected to override this method _and_
* to chain up to it by calling NetDevice::DoDispose
* at the end of their own DoDispose method.
*/
virtual void DoDispose (void);
private:
/**
* \param p packet to send
* \param dest address of destination to which packet must be sent
* \param protocolNumber Number of the protocol (used with some protocols)
* \returns true if the packet could be sent successfully, false
* otherwise.
*
* This is the private virtual target function of the public Send()
* method. When the link is Up, this method is invoked to ask
* subclasses to forward packets. Subclasses MUST override this method.
*/
virtual bool SendTo (Ptr<Packet> p, const Address &dest, uint16_t protocolNumber) = 0;
/**
* \returns true if this NetDevice needs the higher-layers
* to perform ARP over it, false otherwise.
*
* Subclasses must implement this method.
*/
virtual bool DoNeedsArp (void) const = 0;
/**
* \returns the channel associated to this NetDevice.
*
* Subclasses must implement this method.
*/
virtual Ptr<Channel> DoGetChannel (void) const = 0;
Ptr<Node> m_node;
std::string m_name;
uint16_t m_ifIndex;
Address m_address;
Address m_broadcast;
Address m_multicast;
uint16_t m_mtu;
bool m_isUp;
bool m_isBroadcast;
bool m_isMulticast;
bool m_isPointToPoint;
Callback<void> m_linkChangeCallback;
ReceiveCallback m_receiveCallback;
};
}; // namespace ns3
#endif
} // namespace ns3
#endif /* NET_DEVICE_H */
+48
View File
@@ -0,0 +1,48 @@
#include "node-container.h"
namespace ns3 {
NodeContainer::Iterator
NodeContainer::Begin (void) const
{
return m_nodes.begin ();
}
NodeContainer::Iterator
NodeContainer::End (void) const
{
return m_nodes.end ();
}
uint32_t
NodeContainer::GetN (void) const
{
return m_nodes.size ();
}
Ptr<Node>
NodeContainer::Get (uint32_t i) const
{
return m_nodes[i];
}
void
NodeContainer::Create (uint32_t n)
{
for (uint32_t i = 0; i < n; i++)
{
m_nodes.push_back (CreateObject<Node> ());
}
}
void
NodeContainer::Add (NodeContainer other)
{
for (Iterator i = other.Begin (); i != other.End (); i++)
{
m_nodes.push_back (*i);
}
}
void
NodeContainer::Add (Ptr<Node> node)
{
m_nodes.push_back (node);
}
} // namespace ns3
+31
View File
@@ -0,0 +1,31 @@
#ifndef NODE_CONTAINER_H
#define NODE_CONTAINER_H
#include <stdint.h>
#include <vector>
#include "node.h"
namespace ns3 {
class NodeContainer
{
public:
typedef std::vector<Ptr<Node> >::const_iterator Iterator;
Iterator Begin (void) const;
Iterator End (void) const;
uint32_t GetN (void) const;
Ptr<Node> Get (uint32_t i) const;
void Create (uint32_t n);
void Add (NodeContainer other);
void Add (Ptr<Node> node);
private:
std::vector<Ptr<Node> > m_nodes;
};
} // namespace ns3
#endif /* NODE_CONTAINER_H */
+51 -10
View File
@@ -22,7 +22,7 @@
#include "ns3/composite-trace-resolver.h"
#include "ns3/simulator.h"
#include "ns3/simulation-singleton.h"
#include "ns3/object-vector.h"
#include "node-list.h"
#include "node.h"
@@ -60,9 +60,10 @@ NodeListIndex::GetTypeName (void) const
/**
* The private node list used by the static-based API
*/
class NodeListPriv
class NodeListPriv : public Object
{
public:
static TypeId GetTypeId (void);
NodeListPriv ();
~NodeListPriv ();
@@ -73,10 +74,50 @@ public:
Ptr<Node> GetNode (uint32_t n);
uint32_t GetNNodes (void);
static Ptr<NodeListPriv> Get (void);
private:
static Ptr<NodeListPriv> *DoGet (void);
static void Delete (void);
std::vector<Ptr<Node> > m_nodes;
};
TypeId
NodeListPriv::GetTypeId (void)
{
static TypeId tid = TypeId ("NodeListPriv")
.SetParent<Object> ()
.AddAttribute ("NodeList", "The list of all nodes created during the simulation.",
ObjectVector (),
MakeObjectVectorAccessor (&NodeListPriv::m_nodes),
MakeObjectVectorChecker ())
;
return tid;
}
Ptr<NodeListPriv>
NodeListPriv::Get (void)
{
return *DoGet ();
}
Ptr<NodeListPriv> *
NodeListPriv::DoGet (void)
{
static Ptr<NodeListPriv> ptr = 0;
if (ptr == 0)
{
ptr = CreateObject<NodeListPriv> ();
Simulator::ScheduleDestroy (&NodeListPriv::Delete);
}
return &ptr;
}
void
NodeListPriv::Delete (void)
{
(*DoGet ()) = 0;
}
NodeListPriv::NodeListPriv ()
{}
NodeListPriv::~NodeListPriv ()
@@ -143,42 +184,42 @@ namespace ns3 {
uint32_t
NodeList::Add (Ptr<Node> node)
{
return SimulationSingleton<NodeListPriv>::Get ()->Add (node);
return NodeListPriv::Get ()->Add (node);
}
NodeList::Iterator
NodeList::Begin (void)
{
return SimulationSingleton<NodeListPriv>::Get ()->Begin ();
return NodeListPriv::Get ()->Begin ();
}
NodeList::Iterator
NodeList::End (void)
{
return SimulationSingleton<NodeListPriv>::Get ()->End ();
return NodeListPriv::Get ()->End ();
}
Ptr<Node>
NodeList::GetNode (uint32_t n)
{
return SimulationSingleton<NodeListPriv>::Get ()->GetNode (n);
return NodeListPriv::Get ()->GetNode (n);
}
void
NodeList::Connect (std::string name, const CallbackBase &cb)
{
SimulationSingleton<NodeListPriv>::Get ()->GetTraceResolver ()->Connect (name, cb, TraceContext ());
NodeListPriv::Get ()->GetTraceResolver ()->Connect (name, cb, TraceContext ());
}
void
NodeList::Disconnect (std::string name, const CallbackBase &cb)
{
SimulationSingleton<NodeListPriv>::Get ()->GetTraceResolver ()->Disconnect (name, cb);
NodeListPriv::Get ()->GetTraceResolver ()->Disconnect (name, cb);
}
void
NodeList::TraceAll (std::ostream &os)
{
SimulationSingleton<NodeListPriv>::Get ()->GetTraceResolver ()->TraceAll (os, TraceContext ());
NodeListPriv::Get ()->GetTraceResolver ()->TraceAll (os, TraceContext ());
}
Ptr<TraceResolver>
NodeList::GetTraceResolver (void)
{
return SimulationSingleton<NodeListPriv>::Get ()->GetTraceResolver ();
return NodeListPriv::Get ()->GetTraceResolver ();
}
}//namespace ns3
+17 -69
View File
@@ -26,6 +26,8 @@
#include "ns3/packet.h"
#include "ns3/simulator.h"
#include "ns3/composite-trace-resolver.h"
#include "ns3/object-vector.h"
#include "ns3/uinteger.h"
namespace ns3{
@@ -35,68 +37,24 @@ TypeId
Node::GetTypeId (void)
{
static TypeId tid = TypeId ("Node")
.SetParent<Object> ();
.SetParent<Object> ()
.AddAttribute ("DeviceList", "The list of devices associated to this Node.",
ObjectVector (),
MakeObjectVectorAccessor (&Node::m_devices),
MakeObjectVectorChecker ())
.AddAttribute ("ApplicationList", "The list of applications associated to this Node.",
ObjectVector (),
MakeObjectVectorAccessor (&Node::m_applications),
MakeObjectVectorChecker ())
.AddAttribute ("Id", "The id (unique integer) of this Node.",
TypeId::ATTR_GET, // allow only getting it.
Uinteger (0),
MakeUintegerAccessor (&Node::m_id),
MakeUintegerChecker<uint32_t> ())
;
return tid;
}
NodeNetDeviceIndex::NodeNetDeviceIndex ()
: m_index (0)
{}
NodeNetDeviceIndex::NodeNetDeviceIndex (uint32_t index)
: m_index (index)
{}
uint32_t
NodeNetDeviceIndex::Get (void) const
{
return m_index;
}
void
NodeNetDeviceIndex::Print (std::ostream &os) const
{
os << "device=" << m_index;
}
uint16_t
NodeNetDeviceIndex::GetUid (void)
{
static uint16_t uid = AllocateUid<NodeNetDeviceIndex> ("NodeNetDeviceIndex");
return uid;
}
std::string
NodeNetDeviceIndex::GetTypeName (void) const
{
return "ns3::NodeNetDeviceIndex";
}
NodeApplicationIndex::NodeApplicationIndex ()
: m_index (0)
{}
NodeApplicationIndex::NodeApplicationIndex (uint32_t index)
: m_index (index)
{}
uint32_t
NodeApplicationIndex::Get (void) const
{
return m_index;
}
void
NodeApplicationIndex::Print (std::ostream &os) const
{
os << "device=" << m_index;
}
uint16_t
NodeApplicationIndex::GetUid (void)
{
static uint16_t uid = AllocateUid<NodeApplicationIndex> ("NodeApplicationIndex");
return uid;
}
std::string
NodeApplicationIndex::GetTypeName (void) const
{
return "ns3::NodeApplicationIndex";
}
Node::Node()
: m_id(0),
m_sid(0)
@@ -122,16 +80,6 @@ Node::Construct (void)
Node::~Node ()
{}
Ptr<TraceResolver>
Node::GetTraceResolver (void) const
{
Ptr<CompositeTraceResolver> resolver = Create<CompositeTraceResolver> ();
resolver->AddArray ("devices", m_devices.begin (), m_devices.end (), NodeNetDeviceIndex ());
resolver->AddArray ("applications", m_applications.begin (), m_applications.end (), NodeApplicationIndex ());
resolver->SetParentResolver (Object::GetTraceResolver ());
return resolver;
}
uint32_t
Node::GetId (void) const
{
-41
View File
@@ -25,56 +25,16 @@
#include "ns3/object.h"
#include "ns3/callback.h"
#include "ns3/trace-context-element.h"
#include "ns3/ptr.h"
namespace ns3 {
class TraceContext;
class TraceResolver;
class NetDevice;
class Application;
class Packet;
class Address;
class CompositeTraceResolver;
/**
* \brief hold in a TraceContext the index of a NetDevice within a Node
*/
class NodeNetDeviceIndex : public TraceContextElement
{
public:
NodeNetDeviceIndex ();
NodeNetDeviceIndex (uint32_t index);
/**
* \returns the index of the NetDevice within its container Node.
*/
uint32_t Get (void) const;
void Print (std::ostream &os) const;
std::string GetTypeName (void) const;
static uint16_t GetUid (void);
private:
uint32_t m_index;
};
/**
* \brief hold in a TraceContext the index of an Application within a Node
*/
class NodeApplicationIndex : public TraceContextElement
{
public:
NodeApplicationIndex ();
NodeApplicationIndex (uint32_t index);
/**
* \returns the index of the Application within its container Node.
*/
uint32_t Get (void) const;
void Print (std::ostream &os) const;
std::string GetTypeName (void) const;
static uint16_t GetUid (void);
private:
uint32_t m_index;
};
/**
* \brief A network Node.
@@ -199,7 +159,6 @@ public:
void UnregisterProtocolHandler (ProtocolHandler handler);
protected:
virtual Ptr<TraceResolver> GetTraceResolver (void) const;
/**
* The dispose method. Subclasses must override this method
* and must chain up to it by calling Node::DoDispose at the
+4
View File
@@ -28,6 +28,8 @@ def build(bld):
'tcp.cc',
'ipv4.cc',
'application.cc',
'node-container.cc',
'net-device-container.cc',
]
headers = bld.create_obj('ns3header')
@@ -56,4 +58,6 @@ def build(bld):
'tcp.h',
'ipv4.h',
'application.h',
'node-container.h',
'net-device-container.h',
]