7#include "ns3/boolean.h"
8#include "ns3/inet-socket-address.h"
11#include "ns3/packet.h"
12#include "ns3/uinteger.h"
17#include <netinet/in.h>
18#include <sys/socket.h>
34 TypeId(
"ns3::Ipv4RawSocketImpl")
36 .SetGroupName(
"Internet")
37 .AddAttribute(
"Protocol",
38 "Protocol number to match.",
42 .AddAttribute(
"IcmpFilter",
43 "Any icmp header whose type field matches a bit in this filter is "
44 "dropped. Type must be less than 32.",
56 .AddAttribute(
"IpHeaderInclude",
57 "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
172 ipv4->DeleteRawSocket(
this);
230 return SendTo(p, flags, to);
259 p->ReplacePacketTag(ipTosTag);
266 p->ReplacePacketTag(priorityTag);
273 p->AddPacketTag(tag);
282 boundNetDevice = ipv4->GetNetDevice(index);
285 bool subnetDirectedBroadcast =
false;
288 uint32_t iif = ipv4->GetInterfaceForDevice(boundNetDevice);
289 for (
uint32_t j = 0; j < ipv4->GetNAddresses(iif); j++)
292 if (dst.IsSubnetDirectedBroadcast(ifAddr.
GetMask()))
294 subnetDirectedBroadcast =
true;
299 if (dst.IsBroadcast() || subnetDirectedBroadcast)
301 if (ipv4->GetNInterfaces() == 1)
303 boundNetDevice = ipv4->GetNetDevice(0);
318 route->SetSource(src);
319 route->SetDestination(dst);
320 route->SetOutputDevice(boundNetDevice);
321 route->SetGateway(
"0.0.0.0");
322 ipv4->Send(p, route->GetSource(), dst,
m_protocol, route);
326 p->RemoveHeader(header);
331 route->SetSource(src);
332 route->SetDestination(dst);
333 route->SetOutputDevice(boundNetDevice);
334 route->SetGateway(
"0.0.0.0");
335 ipv4->SendWithHeader(p, header, route);
342 if (ipv4->GetRoutingProtocol())
352 p->RemoveHeader(header);
362 int32_t index = ipv4->GetInterfaceForAddress(src);
364 oif = ipv4->GetNetDevice(index);
365 NS_LOG_LOGIC(
"Set index " << oif <<
"from source " << src);
369 route = ipv4->GetRoutingProtocol()->RouteOutput(p, header, oif, errno_);
376 ipv4->Send(p, route->GetSource(), dst,
m_protocol, route);
381 ipv4->SendWithHeader(p, header, route);
413 return RecvFrom(maxSize, flags, tmp);
428 if (
data.packet->GetSize() > maxSize)
431 if (!(flags & MSG_PEEK))
433 data.packet->RemoveAtStart(maxSize);
462 if (boundNetDevice != incomingInterface->GetDevice())
478 copy->RemovePacketTag(tag);
481 tag.
SetRecvIf(incomingInterface->GetDevice()->GetIfIndex());
482 copy->AddPacketTag(tag);
490 copy->AddPacketTag(ipTosTag);
497 copy->AddPacketTag(ipTtlTag);
503 copy->PeekHeader(icmpHeader);
504 uint8_t type = icmpHeader.
GetType();
511 copy->AddHeader(ipHeader);
527 return allowBroadcast;
a polymophic address class
static bool IsMatchingType(const Address &address)
Ipv4Address GetIpv4() const
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()
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
Ipv4Mask GetMask() const
Get the network mask.
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.
Ptr< Node > GetNode() const override
Return the node this socket is associated with.
Socket::SocketType GetSocketType() const override
Get socket type (NS3_SOCK_RAW)
int GetPeerName(Address &address) const override
Get the peer address of a connected socket.
Ipv4Address m_src
Source address.
std::list< Data > m_recv
Packet waiting to be processed.
int Bind() override
Allocate a local IPv4 endpoint for this socket.
int Send(Ptr< Packet > p, uint32_t flags) override
Send data (or dummy data) to the remote host.
Ipv4Address m_dst
Destination address.
void DoDispose() override
Destructor implementation.
int Close() override
Close a socket.
int Listen() override
Listen for incoming connections.
bool GetAllowBroadcast() const override
Query whether broadcast datagram transmissions are allowed.
uint32_t GetRxAvailable() const override
Return number of bytes which can be returned from one or multiple calls to Recv.
int ShutdownSend() override
Socket::SocketErrno m_err
Last error number.
void SetProtocol(uint16_t protocol)
Set protocol field.
Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress) override
Read a single packet from the socket and retrieve the sender address.
bool m_iphdrincl
Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
uint16_t m_protocol
Protocol.
Socket::SocketErrno GetErrno() const override
Get last error number.
int Connect(const Address &address) override
Initiate a connection to a remote host.
int Bind6() override
Allocate a local IPv6 endpoint for this socket.
bool SetAllowBroadcast(bool allowBroadcast) override
Configure whether broadcast datagram transmissions are allowed.
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.
static TypeId GetTypeId()
Get the type ID of this class.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
uint32_t GetTxAvailable() const override
Returns the number of bytes which can be sent in a single call to Send.
bool m_shutdownSend
Flag to shutdown send capability.
int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress) override
Send data to a specified peer.
int ShutdownRecv() override
int GetSockName(Address &address) const override
Get socket address.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
A low-level Socket API based loosely on the BSD Socket API.
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound NetDevice, if any.
bool IsIpRecvTtl() const
Ask if the socket is currently passing information about IP_TTL up the stack.
Ptr< Packet > Recv()
Read a single packet from the socket.
bool IsManualIpTtl() const
Checks if the socket has a specific IPv4 TTL set.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
virtual uint8_t GetIpTtl() const
Query the value of IP Time to Live field of this socket.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.
uint8_t GetIpTos() const
Query the value of IP Type of Service of this socket.
SocketType
Enumeration of the possible socket types.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
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.
bool IsIpRecvTos() const
Ask if the socket is currently passing information about IP Type of Service up the stack.
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 DoDispose() override
Destructor implementation.
void NotifyConnectionFailed()
Notify through the callback (if set) that the connection has not been established due to an error.
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,...
#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.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
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)