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>
21 #include <sys/types.h>
34 TypeId(
"ns3::Ipv4RawSocketImpl")
36 .SetGroupName(
"Internet")
37 .AddAttribute(
"Protocol",
38 "Protocol number to match.",
41 MakeUintegerChecker<uint16_t>())
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.",
47 MakeUintegerChecker<uint32_t>())
56 .AddAttribute(
"IpHeaderInclude",
57 "Include IP Header information (a.k.a setsockopt (IP_HDRINCL)).",
172 ipv4->DeleteRawSocket(
this);
232 return SendTo(p, flags, to);
253 uint8_t tos = ad.
GetTos();
282 int32_t index =
ipv4->GetInterfaceForAddress(
m_src);
284 boundNetDevice =
ipv4->GetNetDevice(index);
287 bool subnetDirectedBroadcast =
false;
290 uint32_t iif =
ipv4->GetInterfaceForDevice(boundNetDevice);
291 for (uint32_t j = 0; j <
ipv4->GetNAddresses(iif); j++)
294 if (dst.IsSubnetDirectedBroadcast(ifAddr.
GetMask()))
296 subnetDirectedBroadcast =
true;
301 if (dst.IsBroadcast() || subnetDirectedBroadcast)
303 if (
ipv4->GetNInterfaces() == 1)
305 boundNetDevice =
ipv4->GetNetDevice(0);
320 route->SetSource(src);
321 route->SetDestination(dst);
322 route->SetOutputDevice(boundNetDevice);
323 route->SetGateway(
"0.0.0.0");
333 route->SetSource(src);
334 route->SetDestination(dst);
335 route->SetOutputDevice(boundNetDevice);
336 route->SetGateway(
"0.0.0.0");
337 ipv4->SendWithHeader(p, header, route);
344 if (
ipv4->GetRoutingProtocol())
364 int32_t index =
ipv4->GetInterfaceForAddress(src);
366 oif =
ipv4->GetNetDevice(index);
367 NS_LOG_LOGIC(
"Set index " << oif <<
"from source " << src);
371 route =
ipv4->GetRoutingProtocol()->RouteOutput(p, header, oif, errno_);
383 ipv4->SendWithHeader(p, header, route);
415 return RecvFrom(maxSize, flags, tmp);
430 if (
data.packet->GetSize() > maxSize)
433 if (!(flags & MSG_PEEK))
435 data.packet->RemoveAtStart(maxSize);
464 if (boundNetDevice != incomingInterface->
GetDevice())
529 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.
Ptr< NetDevice > GetDevice() 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.
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.
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.
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.
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.
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 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.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(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)