|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
21 #include "ns3/packet.h"
23 #include "ns3/callback.h"
24 #include "ns3/ipv4-address.h"
25 #include "ns3/ipv4-route.h"
27 #include "ns3/socket.h"
28 #include "ns3/net-device.h"
29 #include "ns3/uinteger.h"
30 #include "ns3/string.h"
31 #include "ns3/boolean.h"
32 #include "ns3/trace-source-accessor.h"
33 #include "ns3/object-vector.h"
34 #include "ns3/ipv4-header.h"
35 #include "ns3/boolean.h"
36 #include "ns3/ipv4-routing-table-entry.h"
37 #include "ns3/traffic-control-layer.h"
60 .SetGroupName (
"Internet")
62 .AddAttribute (
"DefaultTtl",
63 "The TTL value set by default on "
64 "all outgoing packets generated on this node.",
67 MakeUintegerChecker<uint8_t> ())
68 .AddAttribute (
"FragmentExpirationTimeout",
69 "When this timeout expires, the fragments "
70 "will be cleared from the buffer.",
74 .AddAttribute (
"EnableDuplicatePacketDetection",
75 "Enable multicast duplicate packet detection based on RFC 6621",
79 .AddAttribute (
"DuplicateExpire",
"Expiration delay for duplicate cache entries",
83 .AddAttribute (
"PurgeExpiredPeriod",
84 "Time between purges of expired duplicate packet entries, "
85 "0 means never purge",
89 .AddTraceSource (
"Tx",
90 "Send ipv4 packet to outgoing interface.",
92 "ns3::Ipv4L3Protocol::TxRxTracedCallback")
93 .AddTraceSource (
"Rx",
94 "Receive ipv4 packet from incoming interface.",
96 "ns3::Ipv4L3Protocol::TxRxTracedCallback")
97 .AddTraceSource (
"Drop",
100 "ns3::Ipv4L3Protocol::DropTracedCallback")
101 .AddAttribute (
"InterfaceList",
102 "The set of Ipv4 interfaces associated to this Ipv4 stack.",
105 MakeObjectVectorChecker<Ipv4Interface> ())
107 .AddTraceSource (
"SendOutgoing",
108 "A newly-generated packet by this node is "
109 "about to be queued for transmission",
111 "ns3::Ipv4L3Protocol::SentTracedCallback")
112 .AddTraceSource (
"UnicastForward",
113 "A unicast IPv4 packet was received by this node "
114 "and is being forwarded to another node",
116 "ns3::Ipv4L3Protocol::SentTracedCallback")
117 .AddTraceSource (
"MulticastForward",
118 "A multicast IPv4 packet was received by this node "
119 "and is being forwarded to another node",
121 "ns3::Ipv4L3Protocol::SentTracedCallback")
122 .AddTraceSource (
"LocalDeliver",
123 "An IPv4 packet was received by/for this node, "
124 "and it is being forward up the stack",
126 "ns3::Ipv4L3Protocol::SentTracedCallback")
193 NS_LOG_WARN (
"Trying to remove an non-existent protocol " <<
int(protocol->
GetProtocolNumber ()) <<
" on interface " <<
int(interfaceIndex));
215 L4List_t::const_iterator i;
216 if (interfaceIndex >= 0)
219 key = std::make_pair (protocolNumber, interfaceIndex);
227 key = std::make_pair (protocolNumber, -1);
365 device = CreateObject<LoopbackNetDevice> ();
368 interface->SetDevice (device);
369 interface->SetNode (
m_node);
371 interface->AddAddress (ifaceAddr);
412 interface->SetDevice (device);
413 interface->SetTrafficControl (tc);
451 int32_t
interface = 0;
452 for (Ipv4InterfaceList::const_iterator i =
m_interfaces.begin ();
456 for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
458 if ((*i)->GetAddress (j).GetLocal () ==
address)
474 int32_t
interface = 0;
475 for (Ipv4InterfaceList::const_iterator i =
m_interfaces.begin ();
479 for (uint32_t j = 0; j < (*i)->GetNAddresses (); j++)
481 if ((*i)->GetAddress (j).GetLocal ().CombineMask (mask) ==
address.CombineMask (mask))
500 return (*iter).second;
529 if (MulticastCheckGroup (iif,
address ))
548 if (j == uint32_t (iif))
continue;
560 NS_LOG_LOGIC (
"For me (interface broadcast address on another interface)");
573 NS_LOG_FUNCTION (
this << device << p << protocol << from << to << packetType);
575 NS_LOG_LOGIC (
"Packet from " << from <<
" received on node " <<
579 int32_t
interface = GetInterfaceForDevice(device);
580 NS_ASSERT_MSG (interface != -1,
"Received a packet from an interface that is not known to IPv4");
586 if (ipv4Interface->
IsUp ())
592 NS_LOG_LOGIC (
"Dropping received packet -- interface is down");
614 NS_LOG_LOGIC (
"Dropping received packet -- checksum not ok");
637 std::list<ArpCache::Entry *> entryList = arpCache->
LookupInverse (from);
638 std::list<ArpCache::Entry *>::iterator iter;
639 for (iter = entryList.begin (); iter != entryList.end (); iter ++)
641 if ((*iter)->IsAlive ())
643 (*iter)->UpdateSeen ();
653 socket->
ForwardUp (packet, ipHeader, ipv4Interface);
658 NS_LOG_LOGIC (
"Dropping received packet -- duplicate.");
671 NS_LOG_WARN (
"No route found for forwarding packet. Drop.");
703 for (uint32_t ifaceIndex = 0; ifaceIndex <
GetNInterfaces (); ifaceIndex++)
756 NS_LOG_FUNCTION (
this << packet << source << destination << uint32_t (protocol) << route);
758 bool mayFragment =
true;
794 if (!route->GetGateway ().IsInitialized ())
800 NS_FATAL_ERROR (
"Ipv4L3Protocol::Send case 1a: packet passed with a route but the Gateway address is uninitialized. This case not yet implemented.");
804 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 1b: passed in with route and valid gateway");
818 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 2: limited broadcast - no route");
819 uint32_t ifaceIndex = 0;
820 for (Ipv4InterfaceList::iterator ifaceIter =
m_interfaces.begin ();
821 ifaceIter !=
m_interfaces.end (); ifaceIter++, ifaceIndex++)
825 bool sendIt = source.
IsAny ();
827 for (uint32_t index = 0; !sendIt && index < outInterface->
GetNAddresses (); index++)
839 route->SetDestination (destination);
841 route->SetSource (source);
842 route->SetOutputDevice (outInterface->
GetDevice ());
844 Send (pktCopyWithTags, source, destination, protocol, route);
851 for (Ipv4InterfaceList::iterator ifaceIter =
m_interfaces.begin ();
863 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 3: subnet directed bcast to " << ifAddr.
GetLocal () <<
" - no route");
866 route->SetDestination (destination);
868 route->SetSource (source);
869 route->SetOutputDevice (outInterface->
GetDevice ());
871 Send (pktCopyWithTags, source, destination, protocol, route);
878 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 4: not broadcast and passed in with no route " << destination);
884 newRoute =
m_routingProtocol->RouteOutput (pktCopyWithTags, ipHeader, oif, errno_);
888 NS_LOG_ERROR (
"Ipv4L3Protocol::Send: m_routingProtocol == 0");
893 Send (pktCopyWithTags, source, destination, protocol, newRoute);
908 uint64_t src = source.
Get ();
909 uint64_t dst = destination.
Get ();
910 uint64_t srcDst = dst | (src << 32);
911 std::pair<uint64_t, uint8_t> key = std::make_pair (srcDst, protocol);
920 uint16_t payloadSize,
925 NS_LOG_FUNCTION (
this << source << destination << (uint16_t)protocol << payloadSize << (uint16_t)ttl << (uint16_t)tos << mayFragment);
934 uint64_t src = source.
Get ();
935 uint64_t dst = destination.
Get ();
936 uint64_t srcDst = dst | (src << 32);
937 std::pair<uint64_t, uint8_t> key = std::make_pair (srcDst, protocol);
939 if (mayFragment ==
true)
975 int32_t
interface = GetInterfaceForDevice (outDev);
978 NS_LOG_LOGIC (
"Send via NetDevice ifIndex " << outDev->
GetIfIndex () <<
" ipv4InterfaceIndex " << interface);
981 std::string targetLabel;
982 if (route->GetGateway ().IsAny ())
985 targetLabel =
"destination";
989 target = route->GetGateway ();
990 targetLabel =
"gateway";
993 if (outInterface->
IsUp ())
995 NS_LOG_LOGIC (
"Send to " << targetLabel <<
" " << target);
998 std::list<Ipv4PayloadHeaderPair> listFragments;
1000 for ( std::list<Ipv4PayloadHeaderPair>::iterator it = listFragments.begin (); it != listFragments.end (); it++ )
1004 outInterface->
Send (it->first, it->second, target);
1010 outInterface->
Send (packet, ipHeader, target);
1022 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
1023 std::map<uint32_t, uint32_t>::iterator mapIter;
1025 for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
1027 uint32_t
interface = mapIter->
first;
1033 if (ipHeader.
GetTtl () == 0)
1039 NS_LOG_LOGIC (
"Forward multicast via interface " << interface);
1041 rtentry->SetSource (ipHeader.
GetSource ());
1063 if (ipHeader.
GetTtl () == 0)
1070 icmp->SendTimeExceededTtl (ipHeader, packet,
false);
1100 NS_LOG_LOGIC (
"Received a fragment, processing " << *p );
1101 bool isPacketComplete;
1103 if ( isPacketComplete ==
false)
1107 NS_LOG_LOGIC (
"Got last fragment, Packet is complete " << *p );
1136 bool subnetDirected =
false;
1143 subnetDirected =
true;
1146 if (subnetDirected ==
false)
1148 GetIcmp ()->SendDestUnreachPort (ipHeader, copy);
1239 if (test.GetLocal ().CombineMask (test.GetMask ()) == dest.
CombineMask (test.GetMask ()))
1241 if (test.IsSecondary () ==
false)
1243 return test.GetLocal ();
1267 if (iaddr.
GetScope () > scope)
continue;
1298 NS_LOG_WARN (
"Could not find source address for " << dst <<
" and scope "
1299 << scope <<
", returning 0");
1332 return interface->
IsUp ();
1345 if (interface->GetDevice ()->GetMtu () >= 68)
1347 interface->
SetUp ();
1356 NS_LOG_LOGIC (
"Interface " <<
int(i) <<
" is set to be down for IPv4. Reason: not respecting minimum IPv4 MTU (68 octects)");
1378 NS_LOG_LOGIC (
"Forwarding state: " << interface->IsForwarding ());
1379 return interface->IsForwarding ();
1404 (*i)->SetForwarding (forward);
1433 NS_LOG_LOGIC (
"Route input failure-- dropping packet to " << ipHeader <<
" with errno " << sockErrno);
1452 "IPv4 fragmentation implementation only works without option headers." );
1454 uint16_t offset = 0;
1455 bool moreFragment =
true;
1458 uint32_t currentFragmentablePartSize = 0;
1463 uint32_t fragmentSize = (outIfaceMtu - ipv4Header.
GetSerializedSize () ) & ~uint32_t (0x7);
1465 NS_LOG_LOGIC (
"Fragmenting - Target Size: " << fragmentSize );
1471 if (p->
GetSize () > offset + fragmentSize )
1473 moreFragment =
true;
1474 currentFragmentablePartSize = fragmentSize;
1479 moreFragment =
false;
1480 currentFragmentablePartSize = p->
GetSize () - offset;
1481 if (!isLastFragment)
1491 NS_LOG_LOGIC (
"Fragment creation - " << offset <<
", " << currentFragmentablePartSize );
1505 NS_LOG_LOGIC (
"New fragment Header " << fragmentHeader);
1507 std::ostringstream oss;
1508 oss << fragmentHeader;
1509 fragment->
Print (oss);
1513 listFragments.emplace_back (fragment, fragmentHeader);
1515 offset += currentFragmentablePartSize;
1518 while (moreFragment);
1534 key.first = addressCombination;
1535 key.second = idProto;
1539 MapFragments_t::iterator it =
m_fragments.find (key);
1542 fragments = Create<Fragments> ();
1543 m_fragments.insert (std::make_pair (key, fragments));
1550 fragments = it->second;
1570 : m_moreFragment (0)
1585 std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it;
1589 if (it->second > fragmentOffset)
1597 m_moreFragment = moreFragment;
1608 bool ret = !m_moreFragment &&
m_fragments.size () > 0;
1612 uint16_t lastEndOffset = 0;
1617 NS_LOG_LOGIC (
"Checking overlaps " << lastEndOffset <<
" - " << it->second );
1619 if (lastEndOffset < it->
second)
1625 uint16_t fragmentEnd = it->first->GetSize () + it->second;
1626 lastEndOffset =
std::max ( lastEndOffset, fragmentEnd );
1638 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
1641 uint16_t lastEndOffset = p->
GetSize ();
1646 if ( lastEndOffset > it->second )
1652 uint32_t newStart = lastEndOffset - it->second;
1653 if ( it->first->GetSize () > newStart )
1655 uint32_t newSize = it->first->GetSize () - newStart;
1656 Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
1665 lastEndOffset = p->
GetSize ();
1676 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
1679 uint16_t lastEndOffset = 0;
1688 if ( lastEndOffset > it->second )
1690 uint32_t newStart = lastEndOffset - it->second;
1691 uint32_t newSize = it->first->GetSize () - newStart;
1692 Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
1695 else if ( lastEndOffset == it->second )
1700 lastEndOffset = p->
GetSize ();
1709 m_timeoutIter = iter;
1716 return m_timeoutIter;
1725 MapFragments_t::iterator it =
m_fragments.find (key);
1726 Ptr<Packet> packet = it->second->GetPartialPacket ();
1732 icmp->SendTimeExceededTtl (ipHeader, packet,
true);
1754 uint64_t
hash =
id << 32;
1768 std::ostringstream oss (std::ios_base::binary);
1770 std::string bytes = oss.str ();
1772 NS_ASSERT_MSG (bytes.size () >= 20,
"Degenerate header serialization");
1776 bytes[6] = bytes[7] = 0;
1778 bytes[10] = bytes[11] = 0;
1797 std::hex << std::get<0> (key) <<
", " <<
1798 std::dec << +std::get<1> (key) <<
", " <<
1799 std::get<2> (key) <<
", " <<
1800 std::get<3> (key) <<
")");
1803 DupMap_t::iterator iter;
1804 bool inserted, isDup;
1805 std::tie (iter, inserted) =
m_dups.emplace (key,
Seconds (0));
1818 DupMap_t::size_type
n = 0;
1820 auto iter =
m_dups.cbegin ();
1821 while (iter !=
m_dups.cend ())
1823 if (iter->second < expire)
1826 std::hex << std::get<0> (iter->first) <<
", " <<
1827 std::dec << +std::get<1> (iter->first) <<
", " <<
1828 std::get<2> (iter->first) <<
", " <<
1829 std::get<3> (iter->first) <<
")");
1830 iter =
m_dups.erase (iter);
void HandleTimeout(void)
Handles a fragmented packet timeout.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Time m_fragmentExpirationTimeout
Expiration timeout.
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
Ipv4InterfaceList m_interfaces
List of IPv4 interfaces.
std::list< std::tuple< Time, FragmentKey_t, Ipv4Header, uint32_t > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts..
#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,...
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
AttributeValue implementation for Boolean.
@ DROP_NO_ROUTE
No route to host.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
@ DROP_DUPLICATE
Duplicate packet received.
uint16_t GetMetric(void) const
virtual enum RxStatus Receive(Ptr< Packet > p, Ipv4Header const &header, Ptr< Ipv4Interface > incomingInterface)=0
Called from lower-level layers to send the packet up in the stack.
bool m_ipForward
Forwarding packets (i.e.
bool IsUp(void) const
These are IP interface states and may be distinct from NetDevice states, such as found in real implem...
Ptr< Socket > CreateRawSocket(void)
Creates a raw socket.
virtual bool GetIpForward(void) const
Get the IP forwarding state.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
uint32_t GetId(void) const
void AddHeader(const Header &header)
Add header to this packet.
SocketErrno
Enumeration of the possible errors returned by a socket.
virtual void SetIpForward(bool forward)
Set or unset the IP forwarding state.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
Ipv4Header BuildHeader(Ipv4Address source, Ipv4Address destination, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, uint8_t tos, bool mayFragment)
Construct an IPv4 header.
static Time Now(void)
Return the current simulation virtual time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Called by NetDevices, incoming packet.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex)
Remove the address at addressIndex on named interface.
A record that that holds information about an ArpCache entry.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
virtual void SetWeakEsModel(bool model)
Set or unset the Weak Es Model.
void SetForwarding(uint32_t i, bool val)
Ipv4Mask GetMask(void) const
Get the network mask.
uint8_t GetTos(void) const
Get the tag's TOS.
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.
void IpMulticastForward(Ptr< Ipv4MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a multicast packet.
virtual void NotifyNewAggregate()
This function will notify other components connected to the node that a new stack member is now conne...
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
Ptr< NetDevice > GetDevice(void) const
@ DROP_TTL_EXPIRED
Packet TTL has expired.
The IPv4 representation of a network interface.
Ptr< Packet > GetPacket() const
Get the entire packet.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
Ptr< ArpCache > GetArpCache() const
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
std::tuple< uint64_t, uint8_t, Ipv4Address, Ipv4Address > DupTuple_t
IETF RFC 6621, Section 6.2 de-duplication w/o IPSec RFC 6621 recommended duplicate packet tuple: {IPV...
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope(void) const
Get address scope.
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
uint32_t GetNAddresses(uint32_t interface) const
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void DoFragmentation(Ptr< Packet > packet, const Ipv4Header &ipv4Header, uint32_t outIfaceMtu, std::list< Ipv4PayloadHeaderPair > &listFragments)
Fragment a packet.
Ptr< Ipv4Interface > GetInterface(uint32_t i) const
Get an interface.
void SetMetric(uint32_t i, uint16_t metric)
uint32_t Get(void) const
Get the host-order 32-bit IP address.
Ipv4 addresses are stored in host order in this class.
std::list< ArpCache::Entry * > LookupInverse(Address destination)
Do lookup in the ARP cache against a MAC address.
Ptr< Node > m_node
Node attached to stack.
uint32_t GetNAddresses(void) const
Container for a set of ns3::Object pointers.
Ptr< Packet > GetPartialPacket() const
Get the complete part of the packet.
static Ipv4Mask GetLoopback(void)
std::pair< uint64_t, uint32_t > FragmentKey_t
Key identifying a fragmented packet.
Time m_expire
duplicate entry expiration delay
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
virtual uint16_t GetMtu(void) const =0
void HandleFragmentsTimeout(FragmentKey_t key, Ipv4Header &ipHeader, uint32_t iif)
Process the timeout for packet fragments.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
@ DROP_FRAGMENT_TIMEOUT
Fragment timeout exceeded.
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_txTrace
Trace of transmitted packets.
U * PeekPointer(const Ptr< U > &p)
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Lower layer calls this method after calling L3Demux::Lookup The ARP subclass needs to know from which...
void RouteInputError(Ptr< const Packet > p, const Ipv4Header &ipHeader, Socket::SocketErrno sockErrno)
Fallback when no route is found.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, DropReason, Ptr< Ipv4 >, uint32_t > m_dropTrace
Trace of dropped packets.
EventId m_timeoutEvent
Event for the next scheduled timeout.
bool IsEntire() const
If all fragments have been added.
Ipv4InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
bool IsUp(uint32_t i) const
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route)
int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address)
Access to the IPv4 forwarding table, interfaces, and configuration.
This is the implementation of the ICMP protocol as described in RFC 792.
bool IsMulticast(void) const
void SetMetric(uint16_t metric)
void SetPriority(uint8_t priority)
Set the tag's priority.
virtual ~Ipv4L3Protocol()
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope)
Return the first primary source address with scope less than or equal to the requested scope,...
bool m_weakEsModel
Weak ES model state.
void CallTxTrace(const Ipv4Header &ipHeader, Ptr< Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Make a copy of the packet, add the header and invoke the TX trace callback.
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
void SetDown(void)
Disable this interface.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
void SetForwarding(bool val)
Ptr< Ipv4RoutingProtocol > m_routingProtocol
Routing protocol associated with the stack.
uint32_t Hash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer, using the default hash function.
void LocalDeliver(Ptr< const Packet > p, Ipv4Header const &ip, uint32_t iif)
Deliver a packet.
a polymophic address class
a class to store IPv4 address information on an interface
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const
Get the routing protocol to be used by this Ipv4 stack.
static uint16_t GetStaticProtocolNumber(void)
Get the protocol number.
void DecreaseIdentification(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Decrease the identification value for a dropped or recursed packet.
void Send(Ptr< Packet > p, const Ipv4Header &hdr, Ipv4Address dest)
bool IsLocalMulticast(void) const
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
SocketList m_sockets
List of IPv4 raw sockets.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
InterfaceAddressScope_e
Address scope.
static bool ChecksumEnabled(void)
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
std::pair< int, int32_t > L4ListKey_t
Container of the IPv4 L4 keys: protocol number, interface index.
Simulation virtual time values and global simulation resolution.
void DeleteRawSocket(Ptr< Socket > socket)
Deletes a particular raw socket.
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_rxTrace
Trace of received packets.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
virtual Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest)
Choose the source address to use with destination address.
bool IsBroadcast(void) const
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
@ DROP_BAD_CHECKSUM
Bad checksum.
void SetUp(void)
Enable this interface.
DupMap_t m_dups
map of packet duplicate tuples to expiry event
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_multicastForwardTrace
Trace of multicast forwarded packets.
static const uint16_t PROT_NUMBER
Protocol number (0x0800)
bool m_enableDpd
Enable multicast duplicate packet detection.
static Ipv4Address GetLoopback(void)
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
uint8_t GetTtl(void) const
Get the tag's TTL.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
void IpForward(Ptr< Ipv4Route > rtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a packet.
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const
Determine whether address and interface corresponding to received packet can be accepted for local de...
Time m_purge
time between purging expired duplicate entries
bool IsUnicast(Ipv4Address ad) const
Check if an IPv4 address is unicast according to the node.
uint32_t AddInterface(Ptr< NetDevice > device)
uint32_t GetNInterfaces(void) const
@ DROP_ROUTE_ERROR
Route error.
indicates whether the socket has a priority set.
uint32_t AddIpv4Interface(Ptr< Ipv4Interface > interface)
Add an IPv4 interface to the stack.
std::map< std::pair< uint64_t, uint8_t >, uint16_t > m_identification
Identification (for each {src, dst, proto} tuple)
void SetNode(Ptr< Node > node)
Set node associated with this stack.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
static Ipv4Address GetAny(void)
void SetDefaultTtl(uint8_t ttl)
indicates whether the socket has IP_TOS set.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
EventId m_cleanDpd
event to cleanup expired duplicate entries
@ DROP_INTERFACE_DOWN
Interface is down so can not send packet.
bool ProcessFragment(Ptr< Packet > &packet, Ipv4Header &ipHeader, uint32_t iif)
Process a packet fragment.
void SendRealOut(Ptr< Ipv4Route > route, Ptr< Packet > packet, Ipv4Header const &ipHeader)
Send packet with route.
Introspection did not find any typical Config paths.
bool AddAddress(Ipv4InterfaceAddress address)
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
void RemoveDuplicates(void)
Remove expired duplicates packet entry.
bool IsForwarding(uint32_t i) const
uint16_t GetMtu(uint32_t i) const
Time Seconds(double value)
Construct a Time in the indicated unit.
uint16_t GetMetric(uint32_t i) const
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 UpdateDuplicate(Ptr< const Packet > p, const Ipv4Header &header)
Registers duplicate entry, return false if new.
virtual void Remove(Ptr< IpL4Protocol > protocol)
Ipv4InterfaceAddress GetAddress(uint32_t index) const
bool IsSecondary(void) const
Check if the address is a secondary address.
Implement the IPv4 layer.
uint8_t m_defaultTtl
Default TTL.
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
AttributeValue implementation for Time.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
a class to represent an Ipv4 address mask
Ipv4Address GetLocal(void) const
Get the local address.
Ptr< Icmpv4L4Protocol > GetIcmp(void) const
Get ICMPv4 protocol.
Ptr< NetDevice > GetNetDevice(uint32_t i)
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
virtual int GetProtocolNumber(void) const =0
Returns the protocol number of this protocol.
int32_t GetInterfaceForAddress(Ipv4Address addr) const
Return the interface number of the interface that has been assigned the specified IP address.
virtual bool GetWeakEsModel(void) const
Get the Weak Es Model status.
void Print(std::ostream &os) const
Print the packet contents.
void SetNode(Ptr< Node > node)
Set node associated with interface.
PacketType
Packet types are used as they are in Linux.
Hold an unsigned integer type.
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, Ipv4Header ipHeader, uint32_t iif)
Set a new timeout "event" for a fragmented packet.
uint32_t GetNDevices(void) const
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
void SetupLoopback(void)
Setup loopback interface.
L4List_t m_protocols
List of transport protocol.
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
MapFragments_t m_fragments
Fragmented packets.
Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
void UpdateSeen(void)
Update the entry when seeing a packet.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t GetIfIndex(void) const =0
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
virtual void DoDispose(void)
Destructor implementation.
virtual void DoDispose(void)
Destructor implementation.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
virtual void Insert(Ptr< IpL4Protocol > protocol)
uint64_t GetUid(void) const
Returns the packet's Uid.
bool IsSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.