27 #include "ns3/packet.h"
28 #include "ns3/trace-source-accessor.h"
29 #include "ns3/uinteger.h"
45 .SetGroupName(
"Network")
47 .AddTraceSource(
"Drop",
48 "Drop packet due to receive buffer overflow",
50 "ns3::Packet::TracedCallback")
51 .AddAttribute(
"RcvBufSize",
52 "PacketSocket maximum receive buffer size (bytes)",
55 MakeUintegerChecker<uint32_t>());
282 return device->GetMtu();
286 uint32_t minMtu = 0xffff;
290 minMtu =
std::min(minMtu, (uint32_t)device->GetMtu());
397 NS_LOG_FUNCTION(
this << device << packet << protocol << from << to << packetType);
403 address.SetPhysicalAddress(from);
404 address.SetSingleDevice(device->GetIfIndex());
432 NS_LOG_WARN(
"No receive buffer space available. Drop.");
523 return !allowBroadcast;
572 .SetGroupName(
"Network")
620 if (n.substr(0, 5) ==
"ns3::")
640 .SetGroupName(
"Network")
665 i.
Write((uint8_t*)n, (uint32_t)l);
674 i.
Read((uint8_t*)buf, (uint32_t)l);
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)
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
uint32_t GetSize() const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< Packet > Copy() const
performs a COW copy of the packet.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
uint64_t GetUid() const
Returns the packet's Uid.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
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.
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.
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)