26 #include "ns3/packet.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/trace-source-accessor.h"
44 .AddConstructor<PacketSocket> ()
45 .AddTraceSource (
"Drop",
"Drop packet due to receive buffer overflow",
47 .AddAttribute (
"RcvBufSize",
48 "PacketSocket maximum receive buffer size (bytes)",
51 MakeUintegerChecker<uint32_t> ())
278 return device->GetMtu ();
282 uint32_t minMtu = 0xffff;
286 minMtu = std::min (minMtu, (uint32_t)device->GetMtu ());
378 uint16_t protocol,
const Address &from,
381 NS_LOG_FUNCTION (
this << device << packet << protocol << from << to << packetType);
416 NS_LOG_WARN (
"No receive buffer space available. Drop.");
548 .AddConstructor<PacketSocketTag> ()
591 if ( n.substr(0,5) ==
"ns3::" )
612 .AddConstructor<DeviceNameTag> ();
636 i.
Write ( (uint8_t*) n , (uint32_t) l);
644 i.
Read ( (uint8_t* ) buf, (uint32_t) l);
static TypeId GetTypeId(void)
uint16_t GetProtocol(void) const
void Write(const uint8_t *buffer, uint32_t size)
virtual enum SocketErrno GetErrno(void) const
Get last error number.
#define NS_LOG_FUNCTION(parameters)
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Address GetDestAddress(void) const
Get the destination address of the corresponding packet.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
NetDevice::PacketType m_packetType
void AddPacketTag(const Tag &tag) const
Add a packet tag.
void SetAddress(Address addr)
Set the tag's address.
uint64_t GetUid(void) const
A packet is allocated a new uid when it is created empty or with zero-filled payload.
void NotifyConnectionFailed(void)
Notify through the callback (if set) that the connection has not been established due to an error...
std::queue< Ptr< Packet > > m_deliveryQueue
Default destination address.
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.
#define NS_ASSERT(condition)
static bool IsMatchingType(const Address &address)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
uint32_t GetSize(void) const
virtual uint32_t GetSerializedSize(void) const
void SetPacketType(NetDevice::PacketType t)
Set the packet type.
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
virtual void Print(std::ostream &os) const
virtual int GetSockName(Address &address) const
Get socket address.
SocketErrno
Enumeration of the possible errors returned by a socket.
uint32_t GetSingleDevice(void) const
void UnregisterProtocolHandler(ProtocolHandler handler)
void SetSingleDevice(uint32_t device)
TAG_BUFFER_INLINE uint8_t ReadU8(void)
a polymophic address class
virtual TypeId GetInstanceTypeId(void) const
virtual void Serialize(TagBuffer i) const
A low-level Socket API based loosely on the BSD Socket API.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
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.
virtual uint32_t GetSerializedSize(void) const
static TypeId GetTypeId(void)
PacketSocketTag()
Create an empty PacketSocketTag.
Ptr< NetDevice > GetDevice(uint32_t index) const
This class implements a tag that carries an address of a packet across the socket interface...
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 Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
virtual int Listen(void)
Listen for incoming connections.
#define NS_LOG_LOGIC(msg)
void Deserialize(TagBuffer buffer)
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
uint32_t GetSerializedSize(void) const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
uint32_t GetNDevices(void) const
Ptr< Packet > Copy(void) const
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
tag a set of bytes in a packet
void SetPhysicalAddress(const Address address)
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
Address GetPhysicalAddress(void) const
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...
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
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.
Size of serialization buffer data.
NS_LOG_COMPONENT_DEFINE("PacketSocket")
void SetNode(Ptr< Node > node)
static TypeId GetTypeId(void)
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
void Serialize(TagBuffer buffer) const
Serialize this address in host byte order to a byte buffer.
int DoBind(const PacketSocketAddress &address)
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
virtual void Serialize(TagBuffer i) const
Address GetAddress(void) const
Get the tag's address.
NetDevice::PacketType GetPacketType(void) const
Get the packet type.
virtual void Print(std::ostream &os) const
bool IsSingleDevice(void) const
DeviceNameTag()
Create an empty DeviceNameTag.
void SetProtocol(uint16_t protocol)
static PacketSocketAddress ConvertFrom(const Address &address)
virtual TypeId GetInstanceTypeId(void) const
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
void Read(uint8_t *buffer, uint32_t size)
uint32_t GetMinMtu(PacketSocketAddress ad) const
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
std::string GetDeviceName(void) const
Get the device name from where the corresponding packet is coming.
PacketType
Packet types are used as they are in Linux.
This class implements a tag that carries the dest address of a packet and the packet type...
TracedCallback< Ptr< const Packet > > m_dropTrace
virtual int ShutdownSend(void)
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)
virtual enum SocketType GetSocketType(void) const
void ForwardUp(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
void SetDeviceName(std::string n)
Set the device name.