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 bool subnetDirectedBroadcast =
false;
258 for (uint32_t j = 0; j < ipv4->GetNAddresses (iif); j++)
261 if (dst.IsSubnetDirectedBroadcast (ifAddr.
GetMask ()))
263 subnetDirectedBroadcast =
true;
268 if (dst.IsBroadcast () || subnetDirectedBroadcast)
271 if (ipv4->GetNInterfaces () == 1)
273 boundNetDevice = ipv4->GetNetDevice (0);
275 if (boundNetDevice == 0)
288 route->SetSource (src);
289 route->SetDestination (dst);
290 route->SetOutputDevice (boundNetDevice);
291 ipv4->Send (p, route->GetSource (), dst,
m_protocol, route);
300 route->SetSource (src);
301 route->SetDestination (dst);
302 route->SetOutputDevice (boundNetDevice);
303 ipv4->SendWithHeader (p, header, route);
311 if (ipv4->GetRoutingProtocol ())
330 int32_t index = ipv4->GetInterfaceForAddress (src);
332 oif = ipv4->GetNetDevice (index);
333 NS_LOG_LOGIC (
"Set index " << oif <<
"from source " << src);
337 route = ipv4->GetRoutingProtocol ()->RouteOutput (p, header, oif, errno_);
344 ipv4->Send (p, route->GetSource (), dst,
m_protocol, route);
349 ipv4->SendWithHeader (p, header, route);
368 for (std::list<Data>::const_iterator i =
m_recv.begin (); i !=
m_recv.end (); ++i)
379 return RecvFrom (maxSize, flags, tmp);
394 if (
data.packet->GetSize () > maxSize)
397 if (!(flags & MSG_PEEK))
399 data.packet->RemoveAtStart (maxSize);
426 if (boundNetDevice != incomingInterface->
GetDevice())
468 uint8_t type = icmpHeader.
GetType ();
a polymophic address class
AttributeValue implementation for Boolean.
uint8_t GetTos(void) const
Ipv4Address GetIpv4(void) const
static bool IsMatchingType(const Address &address)
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny(void)
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
Ipv4Mask GetMask(void) const
Get the network mask.
Ptr< NetDevice > GetDevice(void) const
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
void SetAddress(Ipv4Address addr)
Set the tag's address.
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
virtual int ShutdownSend(void)
Ipv4Address m_src
Source address.
virtual int ShutdownRecv(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.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual void DoDispose(void)
Destructor implementation.
Ipv4Address m_dst
Destination address.
static TypeId GetTypeId(void)
Get the type ID of this class.
std::list< struct Data > m_recv
Packet waiting to be processed.
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 enum Socket::SocketType GetSocketType(void) const
Get socket type (NS3_SOCK_RAW)
void SetProtocol(uint16_t protocol)
Set protocol field.
virtual int Close(void)
Close a socket.
virtual int GetSockName(Address &address) const
Get socket address.
bool m_iphdrincl
Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
uint16_t m_protocol
Protocol.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
virtual int Listen(void)
Listen for incoming connections.
enum Socket::SocketErrno m_err
Last error number.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
uint32_t m_icmpFilter
ICMPv4 filter specification.
bool m_shutdownRecv
Flag to shutdown receive capability.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
virtual int Bind6()
Allocate a local IPv6 endpoint for this socket.
virtual enum Socket::SocketErrno GetErrno() const
Get last error number.
bool m_shutdownSend
Flag to shutdown send capability.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
virtual uint32_t GetIfIndex(void) const =0
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void AddHeader(const Header &header)
Add header to this packet.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
A low-level Socket API based loosely on the BSD Socket API.
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound NetDevice, if any.
uint8_t GetPriority(void) const
Query the priority value of this socket.
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
virtual void DoDispose(void)
Destructor implementation.
SocketType
Enumeration of the possible socket types.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack.
void NotifyDataRecv(void)
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).
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
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.
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
indicates whether the socket has IP_TOS set.
void SetTos(uint8_t tos)
Set the tag's TOS.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
indicates whether the socket has a priority set.
void SetPriority(uint8_t priority)
Set the tag's priority.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added.
IPv4 raw data and additional information.
uint32_t pktSize
packet size used for the simulation (in bytes)