2 #include <netinet/in.h>
3 #include <sys/socket.h>
8 #include "ns3/ipv4-packet-info-tag.h"
9 #include "ns3/inet-socket-address.h"
11 #include "ns3/packet.h"
12 #include "ns3/uinteger.h"
13 #include "ns3/boolean.h"
27 .SetGroupName (
"Internet")
28 .AddAttribute (
"Protocol",
"Protocol number to match.",
31 MakeUintegerChecker<uint16_t> ())
32 .AddAttribute (
"IcmpFilter",
33 "Any icmp header whose type field matches a bit in this filter is dropped. Type must be less than 32.",
36 MakeUintegerChecker<uint32_t> ())
45 .AddAttribute (
"IpHeaderInclude",
46 "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
156 ipv4->DeleteRawSocket (
this);
208 return SendTo (p, flags, to);
229 uint8_t tos = ad.
GetTos ();
254 if (ipv4->GetRoutingProtocol ())
273 int32_t index = ipv4->GetInterfaceForAddress (src);
275 oif = ipv4->GetNetDevice (index);
276 NS_LOG_LOGIC (
"Set index " << oif <<
"from source " << src);
280 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
284 uint32_t pktSize = p->
GetSize ();
292 ipv4->SendWithHeader (p, header, route);
311 for (std::list<Data>::const_iterator i =
m_recv.begin (); i !=
m_recv.end (); ++i)
313 rx += (i->packet)->GetSize ();
322 return RecvFrom (maxSize, flags, tmp);
340 if (!(flags & MSG_PEEK))
369 if (boundNetDevice != incomingInterface->
GetDevice())
409 uint8_t type = icmpHeader.
GetType ();
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Ipv4Address m_src
Source address.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
SocketErrno
Enumeration of the possible errors returned by a socket.
AttributeValue implementation for Boolean.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Ptr< Packet > packet
Packet data.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void AddPacketTag(const Tag &tag) const
Add a packet tag.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
static TypeId GetTypeId(void)
Get the type ID of this class.
Ipv4Address fromIp
Source address.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
SocketType
Enumeration of the possible socket types.
void SetTos(uint8_t tos)
Set the tag's TOS.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
virtual void DoDispose(void)
Destructor implementation.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
a polymophic address class
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack...
virtual int Close(void)
Close a socket.
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound netdevice, if any.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
A low-level Socket API based loosely on the BSD Socket API.
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
bool m_shutdownSend
Flag to shutdown send capability.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
Hold an unsigned integer type.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
indicates whether the socket has a priority set.
Ipv4Address m_dst
Destination address.
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Ipv4Address GetSource(void) const
uint8_t GetTos(void) const
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Access to the IPv4 forwarding table, interfaces, and configuration.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
virtual int Bind6()
Allocate a local IPv6 endpoint for this socket.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
virtual int Bind()
Allocate a local IPv4 endpoint for this socket.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
std::list< struct Data > m_recv
Packet waiting to be processed.
virtual int ShutdownRecv(void)
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
virtual enum Socket::SocketType GetSocketType(void) const
Get socket type (NS3_SOCK_RAW)
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
virtual void DoDispose(void)
Destructor implementation.
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
Ipv4 addresses are stored in host order in this class.
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
Ptr< NetDevice > GetDevice(void) const
virtual int Listen(void)
Listen for incoming connections.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
uint16_t m_protocol
Protocol.
IPv4 raw data and additional information.
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
uint32_t m_icmpFilter
ICMPv4 filter specification.
void SetPriority(uint8_t priority)
Set the tag's priority.
uint8_t GetPriority(void) const
Query the priority value of this socket.
indicates whether the socket has IP_TOS set.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
a unique identifier for an interface.
bool m_shutdownRecv
Flag to shutdown receive capability.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
uint16_t fromProtocol
Protocol used.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
void SetProtocol(uint16_t protocol)
Set protocol field.
static bool IsMatchingType(const Address &address)
virtual enum Socket::SocketErrno GetErrno() const
Get last error number.
bool m_iphdrincl
Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
void AddHeader(const Header &header)
Add header to this packet.
virtual int ShutdownSend(void)
enum Socket::SocketErrno m_err
Last error number.
virtual int GetSockName(Address &address) const
Get socket address.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.