16#include "ns3/packet.h"
17#include "ns3/trace-source-accessor.h"
18#include "ns3/uinteger.h"
34 .SetGroupName(
"Network")
36 .AddTraceSource(
"Drop",
37 "Drop packet due to receive buffer overflow",
39 "ns3::Packet::TracedCallback")
40 .AddAttribute(
"RcvBufSize",
41 "PacketSocket maximum receive buffer size (bytes)",
105 address.SetProtocol(0);
106 address.SetAllDevices();
145 if (address.IsSingleDevice())
154 address.GetProtocol(),
159 m_device = address.GetSingleDevice();
271 return device->GetMtu();
279 minMtu = std::min(minMtu, (
uint32_t)device->GetMtu());
333 p->ReplacePacketTag(priorityTag);
386 NS_LOG_FUNCTION(
this << device << packet << protocol << from << to << packetType);
392 address.SetPhysicalAddress(from);
393 address.SetSingleDevice(device->GetIfIndex());
394 address.SetProtocol(protocol);
404 copy->AddPacketTag(pst);
405 copy->AddPacketTag(dnt);
408 copy->RemovePacketTag(priorityTag);
411 NS_LOG_LOGIC(
"UID is " << packet->GetUid() <<
" PacketSocket " <<
this);
421 NS_LOG_WARN(
"No receive buffer space available. Drop.");
457 if (p->GetSize() <= maxSize)
512 return !allowBroadcast;
561 .SetGroupName(
"Network")
609 if (n.substr(0, 5) ==
"ns3::")
629 .SetGroupName(
"Network")
a polymophic address class
uint32_t GetSerializedSize() const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
void Serialize(TagBuffer buffer) const
Serialize this address in host byte order to a byte buffer.
void Deserialize(TagBuffer buffer)
This class implements a tag that carries the ns3 device name from where a packet is coming.
DeviceNameTag()
Create an empty DeviceNameTag.
void Serialize(TagBuffer i) const override
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
std::string m_deviceName
Device name.
void SetDeviceName(std::string n)
Set the device name.
void Print(std::ostream &os) const override
uint32_t GetSerializedSize() const override
std::string GetDeviceName() const
Get the device name from where the corresponding packet is coming.
void Deserialize(TagBuffer i) override
PacketType
Packet types are used as they are in Linux.
void UnregisterProtocolHandler(ProtocolHandler handler)
uint32_t GetNDevices() const
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
an address for a packet socket
uint32_t GetSingleDevice() const
Get the device this address is bound to.
bool IsSingleDevice() const
Checks if the address is bound to a specified NetDevice.
Address GetPhysicalAddress() const
Get the destination address.
void SetProtocol(uint16_t protocol)
Set the protocol.
static bool IsMatchingType(const Address &address)
void SetPhysicalAddress(const Address address)
Set the destination address.
static PacketSocketAddress ConvertFrom(const Address &address)
void SetSingleDevice(uint32_t device)
Set the address to match only a specified NetDevice.
void SetAllDevices()
Set the address to match all the outgoing NetDevice.
uint16_t GetProtocol() const
Get the protocol.
A PacketSocket is a link between an application and a net device.
Ptr< Node > m_node
the associated node
int Bind6() override
Bind the socket to the NetDevice and register the protocol handler.
int Send(Ptr< Packet > p, uint32_t flags) override
Send data (or dummy data) to the remote host.
int Close() override
Close a socket.
Address m_destAddr
Default destination address.
int Connect(const Address &address) override
Initiate a connection to a remote host.
uint32_t m_rxAvailable
Rx queue size [Bytes].
int GetSockName(Address &address) const override
Get socket address.
Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress) override
Read a single packet from the socket and retrieve the sender address.
int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress) override
Send data to a specified peer.
std::queue< std::pair< Ptr< Packet >, Address > > m_deliveryQueue
Rx queue.
int GetPeerName(Address &address) const override
Get the peer address of a connected socket.
Ptr< Node > GetNode() const override
Return the node this socket is associated with.
int DoBind(const PacketSocketAddress &address)
Bind the socket to the NetDevice and register the protocol handler specified in the address.
int ShutdownSend() override
static TypeId GetTypeId()
Get the type ID.
bool SetAllowBroadcast(bool allowBroadcast) override
Configure whether broadcast datagram transmissions are allowed.
uint32_t m_rcvBufSize
Rx buffer size [Bytes].
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.
bool m_isSingleDevice
Is bound to a single netDevice.
uint32_t GetMinMtu(PacketSocketAddress ad) const
Get the minimum MTU supported by the NetDevices bound to a specific address.
int Bind() override
Bind the socket to the NetDevice and register the protocol handler.
bool GetAllowBroadcast() const override
Query whether broadcast datagram transmissions are allowed.
int Listen() override
Listen for incoming connections.
uint16_t m_protocol
Socket protocol.
SocketErrno m_errno
Socket error code.
void SetNode(Ptr< Node > node)
Set the associated node.
uint32_t GetTxAvailable() const override
Returns the number of bytes which can be sent in a single call to Send.
SocketType GetSocketType() const override
State m_state
Socket state.
bool m_shutdownSend
Send no longer allowed.
uint32_t m_device
index of the bound NetDevice
int ShutdownRecv() override
SocketErrno GetErrno() const override
Get last error number.
TracedCallback< Ptr< const Packet > > m_dropTrace
Traced callback: dropped packets.
uint32_t GetRxAvailable() const override
Return number of bytes which can be returned from one or multiple calls to Recv.
bool m_shutdownRecv
Receive no longer allowed.
void DoDispose() override
Destructor implementation.
This class implements a tag that carries the dest address of a packet and the packet type.
Address GetDestAddress() const
Get the destination address of the corresponding packet.
Address m_destAddr
Destination address.
uint32_t GetSerializedSize() const override
NetDevice::PacketType GetPacketType() const
Get the packet type.
void Print(std::ostream &os) const override
NetDevice::PacketType m_packetType
Packet type.
static TypeId GetTypeId()
Get the type ID.
PacketSocketTag()
Create an empty PacketSocketTag.
void Serialize(TagBuffer i) const override
void SetPacketType(NetDevice::PacketType t)
Set the packet type.
void Deserialize(TagBuffer i) override
void SetDestAddress(Address a)
Set the destination address of the corresponding packet.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Smart pointer class similar to boost::intrusive_ptr.
A low-level Socket API based loosely on the BSD Socket API.
Ptr< Packet > Recv()
Read a single packet from the socket.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
SocketType
Enumeration of the possible socket types.
void NotifyDataRecv()
Notify through the callback (if set) that some data have been received.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
SocketErrno
Enumeration of the possible errors returned by a socket.
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
void NotifyConnectionSucceeded()
Notify through the callback (if set) that the connection has been established.
uint8_t GetPriority() const
Query the priority value of this socket.
void NotifyConnectionFailed()
Notify through the callback (if set) that the connection has not been established due to an error.
indicates whether the socket has a priority set.
void SetPriority(uint8_t priority)
Set the tag's priority.
void Read(uint8_t *buffer, uint32_t size)
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
TAG_BUFFER_INLINE uint8_t ReadU8()
void Write(const uint8_t *buffer, uint32_t size)
tag a set of bytes in a packet
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
uint32_t pktSize
packet size used for the simulation (in bytes)