25 #include "ns3/packet.h"
26 #include "ns3/simulator.h"
27 #include "ns3/object-vector.h"
28 #include "ns3/uinteger.h"
30 #include "ns3/assert.h"
31 #include "ns3/global-value.h"
32 #include "ns3/boolean.h"
33 #include "ns3/simulator.h"
45 "A global switch to enable all checksums for all protocols",
47 MakeBooleanChecker ());
54 .AddConstructor<Node> ()
55 .AddAttribute (
"DeviceList",
"The list of devices associated to this Node.",
58 MakeObjectVectorChecker<NetDevice> ())
59 .AddAttribute (
"ApplicationList",
"The list of applications associated to this Node.",
62 MakeObjectVectorChecker<Application> ())
63 .AddAttribute (
"Id",
"The id (unique integer) of this Node.",
67 MakeUintegerChecker<uint32_t> ())
68 .AddAttribute (
"SystemId",
"The systemId of this node: a unique integer used for parallel simulations.",
72 MakeUintegerChecker<uint32_t> ())
125 device->SetNode (
this);
126 device->SetIfIndex (index);
138 " is out of range (only have " <<
m_devices.size () <<
" devices).");
164 " is out of range (only have " <<
m_applications.size () <<
" applications).");
206 device->Initialize ();
220 uint16_t protocolType,
224 NS_LOG_FUNCTION (
this << &handler << protocolType << device << promiscuous);
256 for (ProtocolHandlerList::iterator i =
m_handlers.begin ();
259 if (i->handler.IsEqual (handler))
280 NS_LOG_FUNCTION (
this << device << packet << protocol << &from << &to << packetType);
296 NS_LOG_FUNCTION (
this << device << packet << protocol << &from << &to << packetType << promiscuous);
298 "make sure the channels in use are correctly updating events context " <<
299 "when transfering events from one node to another.");
301 << device->GetIfIndex () <<
" (type=" << device->GetInstanceTypeId ().GetName ()
302 <<
") Packet UID " << packet->
GetUid ());
305 for (ProtocolHandlerList::iterator i =
m_handlers.begin ();
308 if (i->device == 0 ||
309 (i->device != 0 && i->device == device))
311 if (i->protocol == 0 ||
312 i->protocol == protocol)
314 if (promiscuous == i->promiscuous)
316 i->handler (device, packet, protocol, from, to, packetType);
343 if ((*i).IsEqual (listener))
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
uint32_t AddApplication(Ptr< Application > application)
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t GetNApplications(void) const
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
DeviceAdditionListenerList m_deviceAdditionListeners
Device addition listeners in the node.
static bool ChecksumEnabled(void)
uint64_t GetUid(void) const
Returns the packet's Uid.
void NotifyDeviceAdded(Ptr< NetDevice > device)
Notifies all the DeviceAdditionListener about the new device added.
static uint32_t GetContext(void)
ProtocolHandler handler
the protocol handler
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
std::vector< Ptr< NetDevice > > m_devices
Devices associated to this node.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
hold a so-called 'global value'.
uint32_t GetSystemId(void) const
void UnregisterProtocolHandler(ProtocolHandler handler)
a polymophic address class
The attribute can be read.
bool NonPromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from)
Receive a packet from a device in non-promiscuous mode.
uint32_t m_sid
System id for this node.
static GlobalValue g_checksumEnabled
A global switch to enable all checksums for all protocols.
Ptr< Application > GetApplication(uint32_t index) const
virtual void DoDispose(void)
The dispose method.
Ptr< NetDevice > device
the NetDevice
Hold an unsigned integer type.
static uint32_t Add(Ptr< Node > node)
Ptr< NetDevice > GetDevice(uint32_t index) const
uint16_t protocol
the protocol number
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
static void ScheduleWithContext(uint32_t context, Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event with the given context.
uint32_t GetNDevices(void) const
ProtocolHandlerList m_handlers
Protocol handlers in the node.
void RegisterDeviceAdditionListener(DeviceAdditionListener listener)
The attribute can be written.
void SetNode(Ptr< Node > node)
std::vector< Ptr< Application > > m_applications
Applications associated to this node.
uint32_t m_id
Node id for this node.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
static TypeId GetTypeId(void)
Get the type ID.
bool ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet >, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc)
Receive a packet from a device.
uint32_t AddDevice(Ptr< NetDevice > device)
uint32_t GetId(void) const
void UnregisterDeviceAdditionListener(DeviceAdditionListener listener)
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void Initialize(void)
This method calls the virtual DoInitialize method on all the objects aggregated to this object...
a base class which provides memory management and object aggregation
PacketType
Packet types are used as they are in Linux.
contain a set of ns3::Object pointers.
a unique identifier for an interface.
void Construct(void)
Finish node's construction by setting the correct node ID.
TypeId SetParent(TypeId tid)
void Dispose(void)
Run the DoDispose methods of this object and all the objects aggregated to it.
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
void GetValue(AttributeValue &value) const
bool promiscuous
true if it is a promiscuous handler
bool PromiscReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet from a device in promiscuous mode.