|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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 unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
bool ReplacePacketTag(Tag &tag)
Replace the value of a packet tag.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
static bool IsMatchingType(const Address &address)
void SetIpTos(uint8_t ipTos)
Manually set IP Type of Service field.
AttributeValue implementation for Boolean.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
IPv4 raw data and additional information.
bool IsIpRecvTtl(void) const
Ask if the socket is currently passing information about IP_TTL up the stack.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
void AddHeader(const Header &header)
Add header to this packet.
SocketErrno
Enumeration of the possible errors returned by a socket.
virtual enum Socket::SocketErrno GetErrno() const
Get last error number.
virtual int Close(void)
Close a socket.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
std::list< struct Data > m_recv
Packet waiting to be processed.
Ipv4Mask GetMask(void) const
Get the network mask.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Ptr< NetDevice > GetDevice(void) const
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
void SetProtocol(uint16_t protocol)
Set protocol field.
enum Socket::SocketErrno m_err
Last error number.
Ipv4 addresses are stored in host order in this class.
void SetTtl(uint8_t ttl)
Set the tag's TTL.
void SetTtl(uint8_t ttl)
Set the tag's Time to Live Implemented, but not used in the stack yet.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual uint8_t GetIpTtl(void) const
Query the value of IP Time to Live field of this socket.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
virtual int Bind()
Allocate a local IPv4 endpoint for this socket.
uint16_t m_protocol
Protocol.
virtual int Bind6()
Allocate a local IPv6 endpoint for this socket.
bool m_iphdrincl
Include IP Header information (a.k.a setsockopt (IP_HDRINCL))
Access to the IPv4 forwarding table, interfaces, and configuration.
void SetPriority(uint8_t priority)
Set the tag's priority.
virtual int Listen(void)
Listen for incoming connections.
virtual int ShutdownSend(void)
A low-level Socket API based loosely on the BSD Socket API.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
a polymophic address class
a class to store IPv4 address information on an interface
Ipv4Address GetIpv4(void) const
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Ipv4Address m_src
Source address.
SocketType
Enumeration of the possible socket types.
uint32_t m_icmpFilter
ICMPv4 filter specification.
bool m_shutdownRecv
Flag to shutdown receive capability.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
Ptr< NetDevice > GetBoundNetDevice()
Returns socket's bound NetDevice, if any.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
virtual void DoDispose(void)
Destructor implementation.
virtual int GetSockName(Address &address) const
Get socket address.
This class implements Linux struct pktinfo in order to deliver ancillary information to the socket in...
static TypeId GetTypeId(void)
Get the type ID of this class.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
indicates whether the socket has a priority set.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
static Ipv4Address GetAny(void)
indicates whether the socket has IP_TOS set.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
void SetTos(uint8_t tos)
Set the tag's TOS.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer.
bool m_shutdownSend
Flag to shutdown send capability.
uint32_t pktSize
packet size used for the simulation (in bytes)
uint8_t GetPriority(void) const
Query the priority value of this socket.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
uint8_t GetTos(void) const
virtual void DoDispose(void)
Destructor implementation.
Hold an unsigned integer type.
virtual int ShutdownRecv(void)
Ptr< NetDevice > m_boundnetdevice
the device this socket is bound to (might be null).
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void SetAddress(Ipv4Address addr)
Set the tag's address.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
void SetRecvIf(uint32_t ifindex)
Set the tag's receiving interface.
void NotifySend(uint32_t spaceAvailable)
Notify through the callback (if set) that some data have been sent.
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
bool IsManualIpTtl(void) const
Checks if the socket has a specific IPv4 TTL set.
uint8_t GetIpTos(void) const
Query the value of IP Type of Service of this socket.
virtual enum Socket::SocketType GetSocketType(void) const
Get socket type (NS3_SOCK_RAW)
virtual uint32_t GetIfIndex(void) const =0
Ipv4Address m_dst
Destination address.
bool IsIpRecvTos(void) const
Ask if the socket is currently passing information about IP Type of Service up the stack.
bool IsRecvPktInfo() const
Get status indicating whether enable/disable packet information to socket.