26 #include "ns3/packet.h" 27 #include "ns3/uinteger.h" 28 #include "ns3/trace-source-accessor.h" 43 .SetGroupName(
"Network")
45 .AddTraceSource (
"Drop",
"Drop packet due to receive buffer overflow",
47 "ns3::Packet::TracedCallback")
48 .AddAttribute (
"RcvBufSize",
49 "PacketSocket maximum receive buffer size (bytes)",
52 MakeUintegerChecker<uint32_t> ())
279 return device->GetMtu ();
283 uint32_t minMtu = 0xffff;
287 minMtu =
std::min (minMtu, (uint32_t)device->GetMtu ());
387 uint16_t protocol,
const Address &from,
390 NS_LOG_FUNCTION (
this << device << packet << protocol << from << to << packetType);
396 address.SetPhysicalAddress (from);
397 address.SetSingleDevice (device->GetIfIndex ());
398 address.SetProtocol (protocol);
425 NS_LOG_WARN (
"No receive buffer space available. Drop.");
569 .SetGroupName(
"Network")
613 if (
n.substr(0,5) ==
"ns3::" )
633 .SetGroupName(
"Network")
655 i.
Write ( (uint8_t*)
n , (uint32_t) l);
663 i.
Read ( (uint8_t* ) buf, (uint32_t) l);
static TypeId GetTypeId(void)
Get the type ID.
void Write(const uint8_t *buffer, uint32_t size)
uint64_t GetUid(void) const
Returns the packet's Uid.
virtual void Print(std::ostream &os) const
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
std::string m_deviceName
Device name.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
NetDevice::PacketType m_packetType
Packet type.
Address m_destAddr
Default destination address.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error...
an address for a packet socket
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
static bool IsMatchingType(const Address &address)
virtual enum SocketType GetSocketType(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void DoDispose(void)
Destructor implementation.
A PacketSocket is a link between an application and a net device.
virtual void Print(std::ostream &os) const
void SetAllDevices(void)
Set the address to match all the outgoing NetDevice.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetPacketType(NetDevice::PacketType t)
Set the packet type.
virtual int Bind(void)
Bind the socket to the NetDevice and register the protocol handler.
uint32_t m_rxAvailable
Rx queue size [Bytes].
SocketErrno
Enumeration of the possible errors returned by a socket.
void UnregisterProtocolHandler(ProtocolHandler handler)
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
TAG_BUFFER_INLINE uint8_t ReadU8(void)
NetDevice::PacketType GetPacketType(void) const
Get the packet type.
uint32_t GetMinMtu(PacketSocketAddress ad) const
Get the minimum MTU supported by the NetDevices bound to a specific address.
a polymophic address class
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
uint32_t GetSerializedSize(void) const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
Ptr< Node > m_node
the associated node
virtual int GetSockName(Address &address) const
Get socket address.
bool IsSingleDevice(void) const
Checks if the address is bound to a specified NetDevice.
A low-level Socket API based loosely on the BSD Socket API.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
void SetDestAddress(Address a)
Set the destination address of the corresponding packet.
virtual int ShutdownRecv(void)
virtual void Deserialize(TagBuffer i)
Hold an unsigned integer type.
enum State m_state
Socket state.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
uint16_t GetProtocol(void) const
Get the protocol.
indicates whether the socket has a priority set.
static TypeId GetTypeId(void)
Get the type ID.
virtual void Serialize(TagBuffer i) const
PacketSocketTag()
Create an empty PacketSocketTag.
bool m_isSingleDevice
Is bound to a single netDevice.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
virtual int Listen(void)
Listen for incoming connections.
void Deserialize(TagBuffer buffer)
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
uint32_t m_device
index of the bound NetDevice
void Serialize(TagBuffer buffer) const
Serialize this address in host byte order to a byte buffer.
tag a set of bytes in a packet
uint32_t GetSingleDevice(void) const
Get the device this address is bound to.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetPhysicalAddress(const Address address)
Set the destination address.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
uint32_t m_rcvBufSize
Rx buffer size [Bytes].
virtual void Serialize(TagBuffer i) const
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
bool m_shutdownSend
Send no longer allowed.
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
This class implements a tag that carries the ns3 device name from where a packet is coming...
enum SocketErrno m_errno
Socket error code.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
Address GetDestAddress(void) const
Get the destination address of the corresponding packet.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
virtual void Deserialize(TagBuffer i)
virtual int Close(void)
Close a socket.
uint16_t m_protocol
Socket protocol.
Address m_destAddr
Destination address.
std::string GetDeviceName(void) const
Get the device name from where the corresponding packet is coming.
bool m_shutdownRecv
Receive no longer allowed.
void SetNode(Ptr< Node > node)
Set the associated node.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
int DoBind(const PacketSocketAddress &address)
Bind the socket to the NetDevice and register the protocol handler specified in the address...
void AddPacketTag(const Tag &tag) const
Add a packet tag.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Rx queue.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
virtual uint32_t GetSerializedSize(void) const
DeviceNameTag()
Create an empty DeviceNameTag.
void SetProtocol(uint16_t protocol)
Set the protocol.
static PacketSocketAddress ConvertFrom(const Address &address)
Address GetPhysicalAddress(void) const
Get the destination address.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
void Read(uint8_t *buffer, uint32_t size)
virtual uint32_t GetSerializedSize(void) const
virtual int Bind6(void)
Bind the socket to the NetDevice and register the protocol handler.
PacketType
Packet types are used as they are in Linux.
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
This class implements a tag that carries the dest address of a packet and the packet type...
TracedCallback< Ptr< const Packet > > m_dropTrace
Traced callback: dropped packets.
void SetPriority(uint8_t priority)
Set the tag's priority.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
virtual int ShutdownSend(void)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
SocketType
Enumeration of the possible socket types.
a unique identifier for an interface.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void ForwardUp(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Called by the L3 protocol when it received a packet to pass on to TCP.
uint8_t GetPriority(void) const
Query the priority value of this socket.
uint32_t GetNDevices(void) const
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
void SetDeviceName(std::string n)
Set the device name.