A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv4-l3-protocol.h
Go to the documentation of this file.
1//
2// Copyright (c) 2006 Georgia Tech Research Corporation
3//
4// SPDX-License-Identifier: GPL-2.0-only
5//
6// Author: George F. Riley<riley@ece.gatech.edu>
7//
8
9#ifndef IPV4_L3_PROTOCOL_H
10#define IPV4_L3_PROTOCOL_H
11
12#include "ipv4-header.h"
14#include "ipv4.h"
15
16#include "ns3/deprecated.h"
17#include "ns3/ipv4-address.h"
18#include "ns3/net-device.h"
19#include "ns3/nstime.h"
20#include "ns3/ptr.h"
21#include "ns3/simulator.h"
22#include "ns3/traced-callback.h"
23
24#include <list>
25#include <map>
26#include <stdint.h>
27#include <vector>
28
30
31namespace ns3
32{
33
34class Packet;
35class NetDevice;
36class Ipv4Interface;
37class Ipv4Address;
38class Ipv4Header;
39class Ipv4RoutingTableEntry;
40class Ipv4Route;
41class Node;
42class Socket;
43class Ipv4RawSocketImpl;
44class IpL4Protocol;
45class Icmpv4L4Protocol;
46
47/**
48 * @ingroup ipv4
49 *
50 * @brief Implement the IPv4 layer.
51 *
52 * This is the actual implementation of IP. It contains APIs to send and
53 * receive packets at the IP layer, as well as APIs for IP routing.
54 *
55 * This class contains two distinct groups of trace sources. The
56 * trace sources 'Rx' and 'Tx' are called, respectively, immediately
57 * after receiving from the NetDevice and immediately before sending
58 * to a NetDevice for transmitting a packet. These are low level
59 * trace sources that include the Ipv4Header already serialized into
60 * the packet. In contrast, the Drop, SendOutgoing, UnicastForward,
61 * and LocalDeliver trace sources are slightly higher-level and pass
62 * around the Ipv4Header as an explicit parameter and not as part of
63 * the packet.
64 *
65 * IP fragmentation and reassembly is handled at this level.
66 * At the moment the fragmentation does not handle IP option headers,
67 * and in particular the ones that shall not be fragmented.
68 * Moreover, the actual implementation does not mimic exactly the Linux
69 * kernel. Hence it is not possible, for instance, to test a fragmentation
70 * attack.
71 */
72class Ipv4L3Protocol : public Ipv4
73{
74 public:
75 /**
76 * @brief Get the type ID.
77 * @return the object TypeId
78 */
79 static TypeId GetTypeId();
80
81 static constexpr uint16_t PROT_NUMBER = 0x0800; //!< Protocol number
82
84 ~Ipv4L3Protocol() override;
85
86 // Delete copy constructor and assignment operator to avoid misuse
89
90 /**
91 * @enum DropReason
92 * @brief Reason why a packet has been dropped.
93 */
95 {
96 DROP_TTL_EXPIRED = 1, /**< Packet TTL has expired */
97 DROP_NO_ROUTE, /**< No route to host */
98 DROP_BAD_CHECKSUM, /**< Bad checksum */
99 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
100 DROP_ROUTE_ERROR, /**< Route error */
101 DROP_FRAGMENT_TIMEOUT, /**< Fragment timeout exceeded */
102 DROP_DUPLICATE /**< Duplicate packet received */
103 };
104
105 /**
106 * @brief Set node associated with this stack.
107 * @param node node to set
108 */
109 void SetNode(Ptr<Node> node);
110
111 // functions defined in base class Ipv4
112
113 void SetRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol) override;
115
116 Ptr<Socket> CreateRawSocket() override;
117 void DeleteRawSocket(Ptr<Socket> socket) override;
118
119 void Insert(Ptr<IpL4Protocol> protocol) override;
120 void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
121
122 void Remove(Ptr<IpL4Protocol> protocol) override;
123 void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
124
125 Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const override;
126 Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const override;
127
128 Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override;
129
130 /**
131 * @param ttl default ttl to use
132 *
133 * When we need to send an ipv4 packet, we use this default
134 * ttl value.
135 */
136 void SetDefaultTtl(uint8_t ttl);
137
138 /**
139 * Lower layer calls this method after calling L3Demux::Lookup
140 * The ARP subclass needs to know from which NetDevice this
141 * packet is coming to:
142 * - implement a per-NetDevice ARP cache
143 * - send back arp replies on the right device
144 * @param device network device
145 * @param p the packet
146 * @param protocol protocol value
147 * @param from address of the correspondent
148 * @param to address of the destination
149 * @param packetType type of the packet
150 */
151 void Receive(Ptr<NetDevice> device,
153 uint16_t protocol,
154 const Address& from,
155 const Address& to,
156 NetDevice::PacketType packetType);
157
158 /**
159 * @param packet packet to send
160 * @param source source address of packet
161 * @param destination address of packet
162 * @param protocol number of packet
163 * @param route route entry
164 *
165 * Higher-level layers call this method to send a packet
166 * down the stack to the MAC and PHY layers.
167 */
168 void Send(Ptr<Packet> packet,
169 Ipv4Address source,
170 Ipv4Address destination,
171 uint8_t protocol,
172 Ptr<Ipv4Route> route) override;
173 /**
174 * @param packet packet to send
175 * @param ipHeader IP Header
176 * @param route route entry
177 *
178 * Higher-level layers call this method to send a packet with IPv4 Header
179 * (Intend to be used with IpHeaderInclude attribute.)
180 */
181 void SendWithHeader(Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route) override;
182
183 uint32_t AddInterface(Ptr<NetDevice> device) override;
184 /**
185 * @brief Get an interface.
186 * @param i interface index
187 * @return IPv4 interface pointer
188 */
190 uint32_t GetNInterfaces() const override;
191
192 int32_t GetInterfaceForAddress(Ipv4Address addr) const override;
193 int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override;
195 bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override;
196
197 bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override;
198 Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override;
199 uint32_t GetNAddresses(uint32_t interface) const override;
200 bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override;
201 bool RemoveAddress(uint32_t interface, Ipv4Address address) override;
203 Ipv4Address dst,
205
206 void SetMetric(uint32_t i, uint16_t metric) override;
207 uint16_t GetMetric(uint32_t i) const override;
208 uint16_t GetMtu(uint32_t i) const override;
209 bool IsUp(uint32_t i) const override;
210 void SetUp(uint32_t i) override;
211 void SetDown(uint32_t i) override;
212 bool IsForwarding(uint32_t i) const override;
213 void SetForwarding(uint32_t i, bool val) override;
214
216
217 /**
218 * @brief Check if an IPv4 address is unicast according to the node.
219 *
220 * This function checks all the node's interfaces and the respective subnet masks.
221 * An address is considered unicast if it's not broadcast, subnet-broadcast or multicast.
222 *
223 * @param ad address
224 *
225 * @return true if the address is unicast
226 */
227 bool IsUnicast(Ipv4Address ad) const;
228
229 /**
230 * TracedCallback signature for packet send, forward, or local deliver events.
231 *
232 * @param [in] header the Ipv4Header
233 * @param [in] packet the packet
234 * @param [in] interface IP-level interface number
235 */
236 typedef void (*SentTracedCallback)(const Ipv4Header& header,
237 Ptr<const Packet> packet,
238 uint32_t interface);
239
240 /**
241 * TracedCallback signature for packet transmission or reception events.
242 *
243 * @param [in] packet the packet.
244 * @param [in] ipv4 the Ipv4 protocol
245 * @param [in] interface IP-level interface number
246 * @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
247 * and will be changed to \c Ptr<const Ipv4> in a future release.
248 */
249 // NS_DEPRECATED() - tag for future removal
250 typedef void (*TxRxTracedCallback)(Ptr<const Packet> packet,
251 Ptr<Ipv4> ipv4,
252 uint32_t interface);
253
254 /**
255 * TracedCallback signature for packet drop events.
256 *
257 * @param [in] header the Ipv4Header.
258 * @param [in] packet the packet.
259 * @param [in] reason the reason the packet was dropped.
260 * @param [in] ipv4 the Ipv4 protocol
261 * @param [in] interface IP-level interface number
262 * @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
263 * and will be changed to \c Ptr<const Ipv4> in a future release.
264 */
265 // NS_DEPRECATED() - tag for future removal
266 typedef void (*DropTracedCallback)(const Ipv4Header& header,
267 Ptr<const Packet> packet,
268 DropReason reason,
269 Ptr<Ipv4> ipv4,
270 uint32_t interface);
271
272 protected:
273 void DoDispose() override;
274 /**
275 * This function will notify other components connected to the node that a new stack member is
276 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
277 * connect them together.
278 */
279 void NotifyNewAggregate() override;
280
281 private:
282 /**
283 * @brief Ipv4L3ProtocolTestCase test case.
284 * @relates Ipv4L3ProtocolTestCase
285 */
286 friend class ::Ipv4L3ProtocolTestCase;
287
288 // class Ipv4 attributes
289 void SetIpForward(bool forward) override;
290 bool GetIpForward() const override;
291
292 void SetStrongEndSystemModel(bool model) override;
293 bool GetStrongEndSystemModel() const override;
294
295 /**
296 * @brief Decrease the identification value for a dropped or recursed packet
297 * @param source source IPv4 address
298 * @param destination destination IPv4 address
299 * @param protocol L4 protocol
300 */
301 void DecreaseIdentification(Ipv4Address source, Ipv4Address destination, uint8_t protocol);
302
303 /**
304 * @brief Construct an IPv4 header.
305 * @param source source IPv4 address
306 * @param destination destination IPv4 address
307 * @param protocol L4 protocol
308 * @param payloadSize payload size
309 * @param ttl Time to Live
310 * @param tos Type of Service
311 * @param mayFragment true if the packet can be fragmented
312 * @return newly created IPv4 header
313 */
315 Ipv4Address destination,
316 uint8_t protocol,
317 uint16_t payloadSize,
318 uint8_t ttl,
319 uint8_t tos,
320 bool mayFragment);
321
322 /**
323 * @brief Send packet with route.
324 * @param route route
325 * @param packet packet to send
326 * @param ipHeader IPv4 header to add to the packet
327 */
328 void SendRealOut(Ptr<Ipv4Route> route, Ptr<Packet> packet, const Ipv4Header& ipHeader);
329
330 /**
331 * @brief Forward a packet.
332 * @param rtentry route
333 * @param p packet to forward
334 * @param header IPv4 header to add to the packet
335 */
336 void IpForward(Ptr<Ipv4Route> rtentry, Ptr<const Packet> p, const Ipv4Header& header);
337
338 /**
339 * @brief Forward a multicast packet.
340 * @param mrtentry route
341 * @param p packet to forward
342 * @param header IPv4 header to add to the packet
343 */
346 const Ipv4Header& header);
347
348 /**
349 * @brief Deliver a packet.
350 * @param p packet delivered
351 * @param ip IPv4 header
352 * @param iif input interface packet was received
353 */
354 void LocalDeliver(Ptr<const Packet> p, const Ipv4Header& ip, uint32_t iif);
355
356 /**
357 * @brief Fallback when no route is found.
358 * @param p packet
359 * @param ipHeader IPv4 header
360 * @param sockErrno error number
361 */
363 const Ipv4Header& ipHeader,
364 Socket::SocketErrno sockErrno);
365
366 /**
367 * @brief Add an IPv4 interface to the stack.
368 * @param interface interface to add
369 * @return index of newly added interface
370 */
372
373 /**
374 * @brief Setup loopback interface.
375 */
376 void SetupLoopback();
377
378 /**
379 * @brief Get ICMPv4 protocol.
380 * @return Icmpv4L4Protocol pointer
381 */
383
384 /**
385 * @brief Check if an IPv4 address is unicast.
386 * @param ad address
387 * @param interfaceMask the network mask
388 * @return true if the address is unicast
389 */
390 bool IsUnicast(Ipv4Address ad, Ipv4Mask interfaceMask) const;
391
392 /**
393 * @brief Pair of a packet and an Ipv4 header.
394 */
395 typedef std::pair<Ptr<Packet>, Ipv4Header> Ipv4PayloadHeaderPair;
396
397 /**
398 * @brief Fragment a packet
399 * @param packet the packet
400 * @param ipv4Header the IPv4 header
401 * @param outIfaceMtu the MTU of the interface
402 * @param listFragments the list of fragments
403 */
404 void DoFragmentation(Ptr<Packet> packet,
405 const Ipv4Header& ipv4Header,
406 uint32_t outIfaceMtu,
407 std::list<Ipv4PayloadHeaderPair>& listFragments);
408
409 /**
410 * @brief Process a packet fragment
411 * @param packet the packet
412 * @param ipHeader the IP header
413 * @param iif Input Interface
414 * @return true is the fragment completed the packet
415 */
416 bool ProcessFragment(Ptr<Packet>& packet, Ipv4Header& ipHeader, uint32_t iif);
417
418 /**
419 * @brief Make a copy of the packet, add the header and invoke the TX trace callback
420 * @param ipHeader the IP header that will be added to the packet
421 * @param packet the packet
422 * @param ipv4 the Ipv4 protocol
423 * @param interface the IP-level interface index
424 *
425 * Note: If the TracedCallback API ever is extended, we could consider
426 * to check for connected functions before adding the header
427 */
428 void CallTxTrace(const Ipv4Header& ipHeader,
429 Ptr<Packet> packet,
430 Ptr<Ipv4> ipv4,
431 uint32_t interface);
432
433 /**
434 * @brief Container of the IPv4 Interfaces.
435 */
436 typedef std::vector<Ptr<Ipv4Interface>> Ipv4InterfaceList;
437 /**
438 * @brief Container of NetDevices registered to IPv4 and their interface indexes.
439 */
440 typedef std::map<Ptr<const NetDevice>, uint32_t> Ipv4InterfaceReverseContainer;
441 /**
442 * @brief Container of the IPv4 Raw Sockets.
443 */
444 typedef std::list<Ptr<Ipv4RawSocketImpl>> SocketList;
445
446 /**
447 * @brief Container of the IPv4 L4 keys: protocol number, interface index
448 */
449 typedef std::pair<int, int32_t> L4ListKey_t;
450
451 /**
452 * @brief Container of the IPv4 L4 instances.
453 */
454 typedef std::map<L4ListKey_t, Ptr<IpL4Protocol>> L4List_t;
455
456 bool m_ipForward; //!< Forwarding packets (i.e. router mode) state.
457 bool m_strongEndSystemModel; //!< Strong End System Model state
458 L4List_t m_protocols; //!< List of transport protocol.
459 Ipv4InterfaceList m_interfaces; //!< List of IPv4 interfaces.
461 m_reverseInterfacesContainer; //!< Container of NetDevice / Interface index associations.
462 uint8_t m_defaultTtl; //!< Default TTL
463 std::map<std::pair<uint64_t, uint8_t>, uint16_t>
464 m_identification; //!< Identification (for each {src, dst, proto} tuple)
465 Ptr<Node> m_node; //!< Node attached to stack.
466
467 /// Trace of sent packets
469 /// Trace of unicast forwarded packets
471 /// Trace of multicast forwarded packets
473 /// Trace of locally delivered packets
475
476 // The following two traces pass a packet with an IP header
477 /// Trace of transmitted packets
478 /// @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
479 /// and will be changed to \c Ptr<const Ipv4> in a future release.
480 // NS_DEPRECATED() - tag for future removal
482 /// Trace of received packets
483 /// @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
484 /// and will be changed to \c Ptr<const Ipv4> in a future release.
485 // NS_DEPRECATED() - tag for future removal
487 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
488 /// Trace of dropped packets
489 /// @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
490 /// and will be changed to \c Ptr<const Ipv4> in a future release.
491 // NS_DEPRECATED() - tag for future removal
494
495 Ptr<Ipv4RoutingProtocol> m_routingProtocol; //!< Routing protocol associated with the stack
496
497 SocketList m_sockets; //!< List of IPv4 raw sockets.
498
499 /// Key identifying a fragmented packet
500 typedef std::pair<uint64_t, uint32_t> FragmentKey_t;
501
502 /// Container for fragment timeouts.
503 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv4Header, uint32_t>>
505 /// Container Iterator for fragment timeouts..
506 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv4Header, uint32_t>>::iterator
508
509 /**
510 * @brief Process the timeout for packet fragments
511 * @param key representing the packet fragments
512 * @param ipHeader the IP header of the original packet
513 * @param iif Input Interface
514 */
516
517 /**
518 * @brief Set a new timeout "event" for a fragmented packet
519 * @param key the fragment identification
520 * @param ipHeader the IPv4 header of the fragmented packet
521 * @param iif input interface of the packet
522 * @return an iterator to the inserted "event"
523 */
525
526 /**
527 * @brief Handles a fragmented packet timeout
528 */
529 void HandleTimeout();
530
531 FragmentsTimeoutsList_t m_timeoutEventList; //!< Timeout "events" container
532
533 EventId m_timeoutEvent; //!< Event for the next scheduled timeout
534
535 /**
536 * @brief A Set of Fragment belonging to the same packet (src, dst, identification and proto)
537 */
538 class Fragments : public SimpleRefCount<Fragments>
539 {
540 public:
541 /**
542 * @brief Constructor.
543 */
544 Fragments();
545
546 /**
547 * @brief Add a fragment.
548 * @param fragment the fragment
549 * @param fragmentOffset the offset of the fragment
550 * @param moreFragment the bit "More Fragment"
551 */
552 void AddFragment(Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFragment);
553
554 /**
555 * @brief If all fragments have been added.
556 * @returns true if the packet is entire
557 */
558 bool IsEntire() const;
559
560 /**
561 * @brief Get the entire packet.
562 * @return the entire packet
563 */
564 Ptr<Packet> GetPacket() const;
565
566 /**
567 * @brief Get the complete part of the packet.
568 * @return the part we have complete
569 */
571
572 /**
573 * @brief Set the Timeout iterator.
574 * @param iter The iterator.
575 */
577
578 /**
579 * @brief Get the Timeout iterator.
580 * @returns The iterator.
581 */
583
584 private:
585 /**
586 * @brief True if other fragments will be sent.
587 */
589
590 /**
591 * @brief The current fragments.
592 */
593 std::list<std::pair<Ptr<Packet>, uint16_t>> m_fragments;
594
595 /**
596 * @brief Timeout iterator to "event" handler
597 */
599 };
600
601 /// Container of fragments, stored as pairs(src+dst addr, src+dst port) / fragment
602 typedef std::map<FragmentKey_t, Ptr<Fragments>> MapFragments_t;
603
604 MapFragments_t m_fragments; //!< Fragmented packets.
605 Time m_fragmentExpirationTimeout; //!< Expiration timeout
606
607 /// IETF RFC 6621, Section 6.2 de-duplication w/o IPSec
608 /// RFC 6621 recommended duplicate packet tuple: {IPV hash, IP protocol, IP source address, IP
609 /// destination address}
610 typedef std::tuple<uint64_t, uint8_t, Ipv4Address, Ipv4Address> DupTuple_t;
611 /// Maps packet duplicate tuple to expiration time
612 typedef std::map<DupTuple_t, Time> DupMap_t;
613
614 /**
615 * Registers duplicate entry, return false if new
616 * @param [in] p Possibly duplicate packet.
617 * @param [in] header Packet \pname{p} header.
618 * @return True if this packet is a duplicate
619 */
620 bool UpdateDuplicate(Ptr<const Packet> p, const Ipv4Header& header);
621 /**
622 * Remove expired duplicates packet entry
623 */
624 void RemoveDuplicates();
625
626 bool m_enableDpd; //!< Enable multicast duplicate packet detection
627 DupMap_t m_dups; //!< map of packet duplicate tuples to expiry event
628 Time m_expire; //!< duplicate entry expiration delay
629 Time m_purge; //!< time between purging expired duplicate entries
630 EventId m_cleanDpd; //!< event to cleanup expired duplicate entries
631
636};
637
638} // Namespace ns3
639
640#endif /* IPV4_L3_PROTOCOL_H */
a polymophic address class
Definition address.h:90
An identifier for simulation events.
Definition event-id.h:45
Ipv4 addresses are stored in host order in this class.
Packet header for IPv4.
Definition ipv4-header.h:23
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition ipv4.h:69
a class to store IPv4 address information on an interface
A Set of Fragment belonging to the same packet (src, dst, identification and proto)
bool IsEntire() const
If all fragments have been added.
Ptr< Packet > GetPartialPacket() const
Get the complete part of the packet.
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_fragments
The current fragments.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
bool m_moreFragment
True if other fragments will be sent.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
Ptr< Packet > GetPacket() const
Get the entire packet.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
Implement the IPv4 layer.
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...
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.
DropReason
Reason why a packet has been dropped.
@ DROP_BAD_CHECKSUM
Bad checksum.
@ DROP_NO_ROUTE
No route to host.
@ DROP_INTERFACE_DOWN
Interface is down so can not send packet.
@ DROP_DUPLICATE
Duplicate packet received.
@ DROP_TTL_EXPIRED
Packet TTL has expired.
@ DROP_ROUTE_ERROR
Route error.
@ DROP_FRAGMENT_TIMEOUT
Fragment timeout exceeded.
void DecreaseIdentification(Ipv4Address source, Ipv4Address destination, uint8_t protocol)
Decrease the identification value for a dropped or recursed packet.
std::map< FragmentKey_t, Ptr< Fragments > > MapFragments_t
Container of fragments, stored as pairs(src+dst addr, src+dst port) / fragment.
Ipv4InterfaceList m_interfaces
List of IPv4 interfaces.
void DeleteRawSocket(Ptr< Socket > socket) override
Deletes a particular raw socket.
MapFragments_t m_fragments
Fragmented packets.
void LocalDeliver(Ptr< const Packet > p, const Ipv4Header &ip, uint32_t iif)
Deliver a packet.
bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override
Determine whether address and interface corresponding to received packet can be accepted for local de...
std::pair< uint64_t, uint32_t > FragmentKey_t
Key identifying a fragmented packet.
std::list< std::tuple< Time, FragmentKey_t, Ipv4Header, uint32_t > > FragmentsTimeoutsList_t
Container for fragment timeouts.
Time m_expire
duplicate entry expiration delay
bool m_strongEndSystemModel
Strong End System Model state.
Ipv4RoutingProtocol::ErrorCallback m_ecb
Error callback.
std::pair< Ptr< Packet >, Ipv4Header > Ipv4PayloadHeaderPair
Pair of a packet and an Ipv4 header.
bool m_ipForward
Forwarding packets (i.e.
void(* DropTracedCallback)(const Ipv4Header &header, Ptr< const Packet > packet, DropReason reason, Ptr< Ipv4 > ipv4, uint32_t interface)
TracedCallback signature for packet drop events.
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 SetUp(uint32_t i) override
uint32_t GetNInterfaces() const override
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 RouteInputError(Ptr< const Packet > p, const Ipv4Header &ipHeader, Socket::SocketErrno sockErrno)
Fallback when no route is found.
std::list< Ptr< Ipv4RawSocketImpl > > SocketList
Container of the IPv4 Raw Sockets.
void SetMetric(uint32_t i, uint16_t metric) override
void DoDispose() override
Destructor implementation.
void Remove(Ptr< IpL4Protocol > protocol) override
void SetIpForward(bool forward) override
Set or unset the IP forwarding state.
bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_unicastForwardTrace
Trace of unicast forwarded packets.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_localDeliverTrace
Trace of locally delivered packets.
bool IsUnicast(Ipv4Address ad) const
Check if an IPv4 address is unicast according to the node.
void HandleFragmentsTimeout(FragmentKey_t key, Ipv4Header &ipHeader, uint32_t iif)
Process the timeout for packet fragments.
uint16_t GetMtu(uint32_t i) const override
Ptr< Icmpv4L4Protocol > GetIcmp() const
Get ICMPv4 protocol.
Ptr< IpL4Protocol > GetProtocol(int protocolNumber) const override
static constexpr uint16_t PROT_NUMBER
Protocol number.
void RemoveDuplicates()
Remove expired duplicates packet entry.
void DoFragmentation(Ptr< Packet > packet, const Ipv4Header &ipv4Header, uint32_t outIfaceMtu, std::list< Ipv4PayloadHeaderPair > &listFragments)
Fragment a packet.
SocketList m_sockets
List of IPv4 raw sockets.
bool m_enableDpd
Enable multicast duplicate packet detection.
std::map< std::pair< uint64_t, uint8_t >, uint16_t > m_identification
Identification (for each {src, dst, proto} tuple)
bool IsUp(uint32_t i) const override
Time m_fragmentExpirationTimeout
Expiration timeout.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_sendOutgoingTrace
Trace of sent packets.
EventId m_timeoutEvent
Event for the next scheduled timeout.
int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override
Return the interface number of first interface found that has an Ipv4 address within the prefix speci...
Time m_purge
time between purging expired duplicate entries
std::map< Ptr< const NetDevice >, uint32_t > Ipv4InterfaceReverseContainer
Container of NetDevices registered to IPv4 and their interface indexes.
void SetNode(Ptr< Node > node)
Set node associated with this stack.
void IpMulticastForward(Ptr< Ipv4MulticastRoute > mrtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a multicast packet.
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_rxTrace
Trace of received packets.
uint16_t GetMetric(uint32_t i) const override
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
TracedCallback< Ptr< const Packet >, Ptr< Ipv4 >, uint32_t > m_txTrace
Trace of transmitted packets.
Ptr< Socket > CreateRawSocket() override
Creates a raw socket.
bool ProcessFragment(Ptr< Packet > &packet, Ipv4Header &ipHeader, uint32_t iif)
Process a packet fragment.
static TypeId GetTypeId()
Get the type ID.
Ipv4RoutingProtocol::UnicastForwardCallback m_ucb
Unicast forward callback.
void HandleTimeout()
Handles a fragmented packet timeout.
Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override
Choose the source address to use with destination address.
void NotifyNewAggregate() override
This function will notify other components connected to the node that a new stack member is now conne...
Ipv4InterfaceReverseContainer m_reverseInterfacesContainer
Container of NetDevice / Interface index associations.
uint32_t AddInterface(Ptr< NetDevice > device) override
Ipv4L3Protocol & operator=(const Ipv4L3Protocol &)=delete
EventId m_cleanDpd
event to cleanup expired duplicate entries
void SendWithHeader(Ptr< Packet > packet, Ipv4Header ipHeader, Ptr< Ipv4Route > route) override
bool IsForwarding(uint32_t i) const override
void Send(Ptr< Packet > packet, Ipv4Address source, Ipv4Address destination, uint8_t protocol, Ptr< Ipv4Route > route) override
Ptr< NetDevice > GetNetDevice(uint32_t i) override
L4List_t m_protocols
List of transport protocol.
uint32_t GetNAddresses(uint32_t interface) const override
void SetDown(uint32_t i) override
void SetRoutingProtocol(Ptr< Ipv4RoutingProtocol > routingProtocol) override
Register a new routing protocol to be used by this Ipv4 stack.
void(* TxRxTracedCallback)(Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
TracedCallback signature for packet transmission or reception events.
Ptr< Ipv4RoutingProtocol > GetRoutingProtocol() const override
Get the routing protocol to be used by this Ipv4 stack.
Ptr< Ipv4RoutingProtocol > m_routingProtocol
Routing protocol associated with the stack.
Ipv4RoutingProtocol::MulticastForwardCallback m_mcb
Multicast forward callback.
TracedCallback< const Ipv4Header &, Ptr< const Packet >, uint32_t > m_multicastForwardTrace
Trace of multicast forwarded packets.
bool GetStrongEndSystemModel() const override
Get the Strong End System Model status.
uint8_t m_defaultTtl
Default TTL.
std::map< L4ListKey_t, Ptr< IpL4Protocol > > L4List_t
Container of the IPv4 L4 instances.
DupMap_t m_dups
map of packet duplicate tuples to expiry event
void SendRealOut(Ptr< Ipv4Route > route, Ptr< Packet > packet, const Ipv4Header &ipHeader)
Send packet with route.
Ptr< Node > m_node
Node attached to stack.
bool UpdateDuplicate(Ptr< const Packet > p, const Ipv4Header &header)
Registers duplicate entry, return false if new.
Ipv4Address SelectSourceAddress(Ptr< const NetDevice > device, Ipv4Address dst, Ipv4InterfaceAddress::InterfaceAddressScope_e scope) override
Return the first primary source address with scope less than or equal to the requested scope,...
bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override
Remove the address at addressIndex on named interface.
std::vector< Ptr< Ipv4Interface > > Ipv4InterfaceList
Container of the IPv4 Interfaces.
Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override
Because addresses can be removed, the addressIndex is not guaranteed to be static across calls to thi...
int32_t GetInterfaceForAddress(Ipv4Address addr) const override
Return the interface number of the interface that has been assigned the specified IP address.
Ipv4L3Protocol(const Ipv4L3Protocol &)=delete
Ptr< Ipv4Interface > GetInterface(uint32_t i) const
Get an interface.
void IpForward(Ptr< Ipv4Route > rtentry, Ptr< const Packet > p, const Ipv4Header &header)
Forward a packet.
void SetForwarding(uint32_t i, bool val) override
std::list< std::tuple< Time, FragmentKey_t, Ipv4Header, uint32_t > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts..
void SetupLoopback()
Setup loopback interface.
void SetStrongEndSystemModel(bool model) override
Set or unset the Strong End System Model.
void(* SentTracedCallback)(const Ipv4Header &header, Ptr< const Packet > packet, uint32_t interface)
TracedCallback signature for packet send, forward, or local deliver events.
void SetDefaultTtl(uint8_t ttl)
int32_t GetInterfaceForDevice(Ptr< const NetDevice > device) const override
std::map< DupTuple_t, Time > DupMap_t
Maps packet duplicate tuple to expiration time.
Ipv4RoutingProtocol::LocalDeliverCallback m_lcb
Local delivery callback.
void Insert(Ptr< IpL4Protocol > protocol) override
TracedCallback< const Ipv4Header &, Ptr< const Packet >, DropReason, Ptr< Ipv4 >, uint32_t > m_dropTrace
Trace of dropped packets.
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, Ipv4Header ipHeader, uint32_t iif)
Set a new timeout "event" for a fragmented packet.
bool GetIpForward() const override
Get the IP forwarding state.
std::pair< int, int32_t > L4ListKey_t
Container of the IPv4 L4 keys: protocol number, interface index.
uint32_t AddIpv4Interface(Ptr< Ipv4Interface > interface)
Add an IPv4 interface to the stack.
a class to represent an Ipv4 address mask
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:289
Smart pointer class similar to boost::intrusive_ptr.
A template-based reference counting class.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition socket.h:73
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:49
Every class exported by the ns3 library is enclosed in the ns3 namespace.