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;
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");
814 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 2: limited broadcast - no route");
815 uint32_t ifaceIndex = 0;
816 for (Ipv4InterfaceList::iterator ifaceIter =
m_interfaces.begin ();
817 ifaceIter !=
m_interfaces.end (); ifaceIter++, ifaceIndex++)
821 bool sendIt = source.
IsAny ();
823 for (uint32_t index = 0; !sendIt && index < outInterface->
GetNAddresses (); index++)
840 Send (pktCopyWithTags, source, destination, protocol, route);
847 for (Ipv4InterfaceList::iterator ifaceIter =
m_interfaces.begin ();
859 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 3: subnet directed bcast to " << ifAddr.
GetLocal () <<
" - no route");
864 route->SetSource (source);
865 route->SetOutputDevice (outInterface->
GetDevice ());
867 Send (pktCopyWithTags, source, destination, protocol, route);
874 NS_LOG_LOGIC (
"Ipv4L3Protocol::Send case 4: not broadcast and passed in with no route " << destination);
880 newRoute =
m_routingProtocol->RouteOutput (pktCopyWithTags, ipHeader, oif, errno_);
884 NS_LOG_ERROR (
"Ipv4L3Protocol::Send: m_routingProtocol == 0");
889 Send (pktCopyWithTags, source, destination, protocol, newRoute);
904 uint64_t src = source.
Get ();
905 uint64_t dst = destination.
Get ();
906 uint64_t srcDst = dst | (src << 32);
907 std::pair<uint64_t, uint8_t> key = std::make_pair (srcDst, protocol);
916 uint16_t payloadSize,
921 NS_LOG_FUNCTION (
this << source << destination << (uint16_t)protocol << payloadSize << (uint16_t)ttl << (uint16_t)tos << mayFragment);
930 uint64_t src = source.
Get ();
931 uint64_t dst = destination.
Get ();
932 uint64_t srcDst = dst | (src << 32);
933 std::pair<uint64_t, uint8_t> key = std::make_pair (srcDst, protocol);
935 if (mayFragment ==
true)
971 int32_t
interface = GetInterfaceForDevice (outDev);
974 NS_LOG_LOGIC (
"Send via NetDevice ifIndex " << outDev->GetIfIndex () <<
" ipv4InterfaceIndex " << interface);
977 std::string targetLabel;
981 targetLabel =
"destination";
986 targetLabel =
"gateway";
989 if (outInterface->
IsUp ())
991 NS_LOG_LOGIC (
"Send to " << targetLabel <<
" " << target);
994 std::list<Ipv4PayloadHeaderPair> listFragments;
996 for ( std::list<Ipv4PayloadHeaderPair>::iterator it = listFragments.begin (); it != listFragments.end (); it++ )
1000 outInterface->
Send (it->first, it->second, target);
1006 outInterface->
Send (packet, ipHeader, target);
1018 std::map<uint32_t, uint32_t> ttlMap = mrtentry->GetOutputTtlMap ();
1019 std::map<uint32_t, uint32_t>::iterator mapIter;
1021 for (mapIter = ttlMap.begin (); mapIter != ttlMap.end (); mapIter++)
1023 uint32_t
interface = mapIter->
first;
1029 if (ipHeader.
GetTtl () == 0)
1035 NS_LOG_LOGIC (
"Forward multicast via interface " << interface);
1058 ipHeader.SetTtl (ipHeader.GetTtl () - 1);
1059 if (ipHeader.GetTtl () == 0)
1062 if (ipHeader.GetDestination ().IsBroadcast () ==
false &&
1063 ipHeader.GetDestination ().IsMulticast () ==
false)
1066 icmp->SendTimeExceededTtl (ipHeader, packet,
false);
1096 NS_LOG_LOGIC (
"Received a fragment, processing " << *p );
1097 bool isPacketComplete;
1099 if ( isPacketComplete ==
false)
1103 NS_LOG_LOGIC (
"Got last fragment, Packet is complete " << *p );
1132 bool subnetDirected =
false;
1139 subnetDirected =
true;
1142 if (subnetDirected ==
false)
1144 GetIcmp ()->SendDestUnreachPort (ipHeader, copy);
1235 if (test.GetLocal ().CombineMask (test.GetMask ()) == dest.
CombineMask (test.GetMask ()))
1237 if (test.IsSecondary () ==
false)
1239 return test.GetLocal ();
1263 if (iaddr.
GetScope () > scope)
continue;
1294 NS_LOG_WARN (
"Could not find source address for " << dst <<
" and scope " 1295 << scope <<
", returning 0");
1320 return interface->
GetDevice ()->GetMtu ();
1328 return interface->
IsUp ();
1341 if (interface->GetDevice ()->GetMtu () >= 68)
1343 interface->
SetUp ();
1352 NS_LOG_LOGIC (
"Interface " <<
int(i) <<
" is set to be down for IPv4. Reason: not respecting minimum IPv4 MTU (68 octects)");
1374 NS_LOG_LOGIC (
"Forwarding state: " << interface->IsForwarding ());
1375 return interface->IsForwarding ();
1400 (*i)->SetForwarding (forward);
1429 NS_LOG_LOGIC (
"Route input failure-- dropping packet to " << ipHeader <<
" with errno " << sockErrno);
1448 "IPv4 fragmentation implementation only works without option headers." );
1450 uint16_t offset = 0;
1451 bool moreFragment =
true;
1454 uint32_t currentFragmentablePartSize = 0;
1459 uint32_t fragmentSize = (outIfaceMtu - ipv4Header.
GetSerializedSize () ) & ~uint32_t (0x7);
1461 NS_LOG_LOGIC (
"Fragmenting - Target Size: " << fragmentSize );
1467 if (p->
GetSize () > offset + fragmentSize )
1469 moreFragment =
true;
1470 currentFragmentablePartSize = fragmentSize;
1475 moreFragment =
false;
1476 currentFragmentablePartSize = p->
GetSize () - offset;
1477 if (!isLastFragment)
1487 NS_LOG_LOGIC (
"Fragment creation - " << offset <<
", " << currentFragmentablePartSize );
1501 NS_LOG_LOGIC (
"New fragment Header " << fragmentHeader);
1503 std::ostringstream oss;
1504 oss << fragmentHeader;
1505 fragment->
Print (oss);
1509 listFragments.emplace_back (fragment, fragmentHeader);
1511 offset += currentFragmentablePartSize;
1514 while (moreFragment);
1530 key.first = addressCombination;
1531 key.second = idProto;
1535 MapFragments_t::iterator it =
m_fragments.find (key);
1538 fragments = Create<Fragments> ();
1539 m_fragments.insert (std::make_pair (key, fragments));
1546 fragments = it->second;
1566 : m_moreFragment (0)
1581 std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it;
1585 if (it->second > fragmentOffset)
1593 m_moreFragment = moreFragment;
1604 bool ret = !m_moreFragment &&
m_fragments.size () > 0;
1608 uint16_t lastEndOffset = 0;
1613 NS_LOG_LOGIC (
"Checking overlaps " << lastEndOffset <<
" - " << it->second );
1615 if (lastEndOffset < it->
second)
1621 uint16_t fragmentEnd = it->first->GetSize () + it->second;
1622 lastEndOffset =
std::max ( lastEndOffset, fragmentEnd );
1634 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
1637 uint16_t lastEndOffset = p->
GetSize ();
1642 if ( lastEndOffset > it->second )
1648 uint32_t newStart = lastEndOffset - it->second;
1649 if ( it->first->GetSize () > newStart )
1651 uint32_t newSize = it->first->GetSize () - newStart;
1652 Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
1661 lastEndOffset = p->
GetSize ();
1672 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
1675 uint16_t lastEndOffset = 0;
1684 if ( lastEndOffset > it->second )
1686 uint32_t newStart = lastEndOffset - it->second;
1687 uint32_t newSize = it->first->GetSize () - newStart;
1688 Ptr<Packet> tempFragment = it->first->CreateFragment (newStart, newSize);
1691 else if ( lastEndOffset == it->second )
1696 lastEndOffset = p->
GetSize ();
1705 m_timeoutIter = iter;
1712 return m_timeoutIter;
1721 MapFragments_t::iterator it =
m_fragments.find (key);
1722 Ptr<Packet> packet = it->second->GetPartialPacket ();
1728 icmp->SendTimeExceededTtl (ipHeader, packet,
true);
1750 uint64_t
hash =
id << 32;
1764 std::ostringstream oss (std::ios_base::binary);
1766 std::string bytes = oss.str ();
1768 NS_ASSERT_MSG (bytes.size () >= 20,
"Degenerate header serialization");
1772 bytes[6] = bytes[7] = 0;
1774 bytes[10] = bytes[11] = 0;
1793 std::hex << std::get<0> (key) <<
", " <<
1794 std::dec << +std::get<1> (key) <<
", " <<
1795 std::get<2> (key) <<
", " <<
1796 std::get<3> (key) <<
")");
1799 DupMap_t::iterator iter;
1800 bool inserted, isDup;
1801 std::tie (iter, inserted) =
m_dups.emplace (key,
Seconds (0));
1814 DupMap_t::size_type
n = 0;
1816 auto iter =
m_dups.cbegin ();
1817 while (iter !=
m_dups.cend ())
1819 if (iter->second < expire)
1822 std::hex << std::get<0> (iter->first) <<
", " <<
1823 std::dec << +std::get<1> (iter->first) <<
", " <<
1824 std::get<2> (iter->first) <<
", " <<
1825 std::get<3> (iter->first) <<
")");
1826 iter =
m_dups.erase (iter);
virtual Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest)
Choose the source address to use with destination address.
void SetDown(void)
Disable this interface.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
uint8_t GetTos(void) const
Get the tag's TOS.
bool m_weakEsModel
Weak ES model state.
void SetForwarding(bool val)
InterfaceAddressScope_e
Address scope.
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
uint64_t GetUid(void) const
Returns the packet's Uid.
void SetDefaultTtl(uint8_t ttl)
Simulation virtual time values and global simulation resolution.
virtual void SetIpForward(bool forward)
Set or unset the IP forwarding state.
void Receive(Ptr< NetDevice > device, Ptr< const Packet > p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Receive a packet.
void Send(Ptr< Packet > p, const Ipv4Header &hdr, Ipv4Address dest)
static Ipv4Address GetAny(void)
void Print(std::ostream &os) const
Print the packet contents.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t GetNAddresses(uint32_t interface) const
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const
Determine whether address and interface corresponding to received packet can be accepted for local de...
virtual void NotifyNewAggregate()
This function will notify other components connected to the node that a new stack member is now conne...
AttributeValue implementation for Boolean.
Time m_fragmentExpirationTimeout
Expiration timeout.
uint32_t GetId(void) const
bool IsBroadcast(void) const
bool IsInitialized(void) const
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Introspection did not find any typical Config paths.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
a class to represent an Ipv4 address mask
Ptr< NetDevice > GetDevice(uint32_t index) const
Retrieve the index-th NetDevice associated to this node.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static bool ChecksumEnabled(void)
ArpCache::Entry * Lookup(Ipv4Address destination)
Do lookup in the ARP cache against an IP address.
The IPv4 representation of a network interface.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
U * PeekPointer(const Ptr< U > &p)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
void HandleFragmentsTimeout(FragmentKey_t key, Ipv4Header &ipHeader, uint32_t iif)
Process the timeout for packet fragments.
void SetNode(Ptr< Node > node)
Set the node associated with this socket.
DupMap_t m_dups
map of packet duplicate tuples to expiry event
Fragment timeout exceeded.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
void RemoveDuplicates(void)
Remove duplicate packet entry.
virtual void DoDispose(void)
Destructor implementation.
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 AddAddress(Ipv4InterfaceAddress address)
uint32_t AddInterface(Ptr< NetDevice > device)
TracedCallback< const Ipv4Header &, Ptr< const Packet >, DropReason, Ptr< Ipv4 >, uint32_t > m_dropTrace
Trace of dropped packets.
bool IsEntire() const
If all fragments have been added.
static uint8_t IpTos2Priority(uint8_t ipTos)
Return the priority corresponding to a given TOS value.
int32_t GetInterfaceForAddress(Ipv4Address addr) const
Return the interface number of the interface that has been assigned the specified IP address...
virtual int GetProtocolNumber(void) const =0
Returns the protocol number of this protocol.
This class implements a tag that carries the socket-specific TTL of a packet to the IP layer...
SocketErrno
Enumeration of the possible errors returned by a socket.
virtual bool GetIpForward(void) const
Get the IP forwarding state.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_multicastForwardTrace
Trace of multicast forwarded packets.
Ipv4InterfaceAddress GetAddress(uint32_t index) const
Ptr< Ipv4RoutingProtocol > m_routingProtocol
Routing protocol associated with the stack.
uint32_t GetNInterfaces(void) const
L4List_t m_protocols
List of transport protocol.
void SetNode(Ptr< Node > node)
Set node associated with interface.
a polymophic address class
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Ptr< Packet > GetPartialPacket() const
Get the complete part of the packet.
bool m_enableDpd
Enable multicast duplicate packet detection.
void SetSource(Ipv4Address src)
Ipv4InterfaceList m_interfaces
List of IPv4 interfaces.
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_rxTrace
Trace of received packets.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
bool IsMulticast(void) const
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...
Ptr< Icmpv4L4Protocol > GetIcmp(void) const
Get ICMPv4 protocol.
bool IsSubnetDirectedBroadcast(Ipv4Mask const &mask) const
Generate subnet-directed broadcast address corresponding to mask.
void SetupLoopback(void)
Setup loopback interface.
Ipv4Address CombineMask(Ipv4Mask const &mask) const
Combine this address with a network mask.
AttributeValue implementation for Time.
bool IsUnicast(Ipv4Address ad) const
Check if an IPv4 address is unicast according to the node.
void SetGateway(Ipv4Address gw)
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_txTrace
Trace of transmitted packets.
Hold an unsigned integer type.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
Ptr< Ipv4Interface > GetInterface(uint32_t i) const
Get an interface.
void SetMetric(uint32_t i, uint16_t metric)
virtual void DoDispose(void)
Destructor implementation.
EventId m_cleanDpd
event to cleanup expired duplicate entries
indicates whether the socket has a priority set.
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.
bool IsLocalMulticast(void) const
EventId m_timeoutEvent
Event for the next scheduled timeout.
virtual bool GetWeakEsModel(void) const
Get the Weak Es Model status.
Ptr< Socket > CreateRawSocket(void)
Creates a raw socket.
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.
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route)
std::pair< uint64_t, uint32_t > FragmentKey_t
Key identifying a fragmented packet.
static TypeId GetTypeId(void)
Get the type ID.
Ipv4Address GetBroadcast(void) const
Get the broadcast address.
MapFragments_t m_fragments
Fragmented packets.
Ipv4Mask GetMask(void) const
Get the network mask.
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route)
void IpForward(Ptr< Ipv4Route > rtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a packet.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol(void) const
Get the routing protocol to be used by this Ipv4 stack.
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex)
Remove the address at addressIndex on named interface.
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
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...
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
bool UpdateDuplicate(Ptr< const Packet > p, const Ipv4Header &header)
Registers duplicate entry, return false if new.
Access to the IPv4 forwarding table, interfaces, and configuration.
bool m_ipForward
Forwarding packets (i.e.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void SetForwarding(uint32_t i, bool val)
void DoFragmentation(Ptr< Packet > packet, const Ipv4Header &ipv4Header, uint32_t outIfaceMtu, std::list< Ipv4PayloadHeaderPair > &listFragments)
Fragment a packet.
Time m_expire
duplicate entry expiration delay
Implement the IPv4 layer.
Ptr< NetDevice > GetOutputDevice(void) const
static const uint16_t PROT_NUMBER
ARP protocol number (0x0806)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t Hash32(const char *buffer, const std::size_t size)
Compute 32-bit hash of a byte buffer, using the default hash function.
Ptr< NetDevice > GetDevice(void) const
Ptr< ArpCache > GetArpCache() const
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
void RemoveAtEnd(uint32_t size)
Remove size bytes from the end of the current packet.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv4 L4 keys: protocol number, interface index.
Time m_purge
time between purging expired duplicate entries
bool IsForwarding(uint32_t i) const
void DecreaseIdentification(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Decrease the identification value for a dropped or recursed packet.
Ptr< Node > m_node
Node attached to stack.
void RouteInputError(Ptr< const Packet > p, const Ipv4Header &ipHeader, Socket::SocketErrno sockErrno)
Fallback when no route is found.
Ipv4Header BuildHeader(Ipv4Address source, Ipv4Address destination, uint8_t protocol, uint16_t payloadSize, uint8_t ttl, uint8_t tos, bool mayFragment)
Construct an IPv4 header.
void SendRealOut(Ptr< Ipv4Route > route, Ptr< Packet > packet, Ipv4Header const &ipHeader)
Send packet with route.
A record that that holds information about an ArpCache entry.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Ipv4InterfaceAddress::InterfaceAddressScope_e GetScope(void) const
Get address scope.
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, Ipv4Header ipHeader, uint32_t iif)
Set a new timeout "event" for a fragmented packet.
static Time Now(void)
Return the current simulation virtual time.
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev.
static Ipv4Address GetLoopback(void)
static Ipv4Mask GetLoopback(void)
bool IsUp(void) const
These are IP interface states and may be distinct from NetDevice states, such as found in real implem...
Ipv4Address GetGateway(void) const
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
Ptr< NetDevice > GetNetDevice(uint32_t i)
void HandleTimeout(void)
Handles a fragmented packet timeout.
void UpdateSeen(void)
Update the entry when seeing a packet.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
bool ProcessFragment(Ptr< Packet > &packet, Ipv4Header &ipHeader, uint32_t iif)
Process a packet fragment.
uint32_t AddIpv4Interface(Ptr< Ipv4Interface > interface)
Add an IPv4 interface to the stack.
uint16_t GetMetric(uint32_t i) const
uint16_t GetMetric(void) const
virtual void Remove(Ptr< IpL4Protocol > protocol)
Ipv4 addresses are stored in host order in this class.
virtual void SetWeakEsModel(bool model)
Set or unset the Weak Es Model.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
uint32_t AddDevice(Ptr< NetDevice > device)
Associate a NetDevice to this node.
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const
a class to store IPv4 address information on an interface
Ptr< Packet > GetPacket() const
Get the entire packet.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
SocketList m_sockets
List of IPv4 raw sockets.
void DeleteRawSocket(Ptr< Socket > socket)
Deletes a particular raw socket.
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address)
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
static uint16_t GetStaticProtocolNumber(void)
Get the protocol number.
virtual void Insert(Ptr< IpL4Protocol > protocol)
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
void LocalDeliver(Ptr< const Packet > p, Ipv4Header const &ip, uint32_t iif)
Deliver a packet.
void IpMulticastForward(Ptr< Ipv4MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a multicast packet.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
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 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...
bool ForwardUp(Ptr< const Packet > p, Ipv4Header ipHeader, Ptr< Ipv4Interface > incomingInterface)
Forward up to receive method.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsSecondary(void) const
Check if the address is a secondary address.
Ipv4Address GetLocal(void) const
Get the local address.
uint8_t m_defaultTtl
Default TTL.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Interface is down so can not send packet.
void SetMetric(uint16_t metric)
std::list< ArpCache::Entry * > LookupInverse(Address destination)
Do lookup in the ARP cache against a MAC address.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
std::list< std::tuple< Time, FragmentKey_t, Ipv4Header, uint32_t > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts..
uint32_t Get(void) const
Get the host-order 32-bit IP address.
uint32_t GetNAddresses(void) const
uint16_t GetMtu(uint32_t i) const
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
PacketType
Packet types are used as they are in Linux.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
Container for a set of ns3::Object pointers.
This is the implementation of the ICMP protocol as described in RFC 792.
void SetPriority(uint8_t priority)
Set the tag's priority.
Ipv4InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
indicates whether the socket has IP_TOS set.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
a unique identifier for an interface.
std::map< std::pair< uint64_t, uint8_t >, uint16_t > m_identification
Identification (for each {src, dst, proto} tuple)
Duplicate packet received.
bool IsUp(uint32_t i) const
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual ~Ipv4L3Protocol()
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...
virtual Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const
void AddHeader(const Header &header)
Add header to this packet.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
uint8_t GetTtl(void) const
Get the tag's TTL.
static const uint16_t PROT_NUMBER
Protocol number (0x0800)
void SetDestination(Ipv4Address dest)
uint32_t GetNDevices(void) const
void SetUp(void)
Enable this interface.
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...
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol)
Register a new routing protocol to be used by this Ipv4 stack.