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 /** @copydoc Ipv4::SetWeakEsModel */
293 NS_DEPRECATED_3_41("Use SetStrongEndSystemModel instead")
294 void SetWeakEsModel(bool model) override;
295 /** @copydoc Ipv4::GetWeakEsModel */
297 bool GetWeakEsModel() const override;
298
299 void SetStrongEndSystemModel(bool model) override;
300 bool GetStrongEndSystemModel() const override;
301
302 /**
303 * @brief Decrease the identification value for a dropped or recursed packet
304 * @param source source IPv4 address
305 * @param destination destination IPv4 address
306 * @param protocol L4 protocol
307 */
308 void DecreaseIdentification(Ipv4Address source, Ipv4Address destination, uint8_t protocol);
309
310 /**
311 * @brief Construct an IPv4 header.
312 * @param source source IPv4 address
313 * @param destination destination IPv4 address
314 * @param protocol L4 protocol
315 * @param payloadSize payload size
316 * @param ttl Time to Live
317 * @param tos Type of Service
318 * @param mayFragment true if the packet can be fragmented
319 * @return newly created IPv4 header
320 */
322 Ipv4Address destination,
323 uint8_t protocol,
324 uint16_t payloadSize,
325 uint8_t ttl,
326 uint8_t tos,
327 bool mayFragment);
328
329 /**
330 * @brief Send packet with route.
331 * @param route route
332 * @param packet packet to send
333 * @param ipHeader IPv4 header to add to the packet
334 */
335 void SendRealOut(Ptr<Ipv4Route> route, Ptr<Packet> packet, const Ipv4Header& ipHeader);
336
337 /**
338 * @brief Forward a packet.
339 * @param rtentry route
340 * @param p packet to forward
341 * @param header IPv4 header to add to the packet
342 */
343 void IpForward(Ptr<Ipv4Route> rtentry, Ptr<const Packet> p, const Ipv4Header& header);
344
345 /**
346 * @brief Forward a multicast packet.
347 * @param mrtentry route
348 * @param p packet to forward
349 * @param header IPv4 header to add to the packet
350 */
352 Ptr<const Packet> p,
353 const Ipv4Header& header);
354
355 /**
356 * @brief Deliver a packet.
357 * @param p packet delivered
358 * @param ip IPv4 header
359 * @param iif input interface packet was received
360 */
361 void LocalDeliver(Ptr<const Packet> p, const Ipv4Header& ip, uint32_t iif);
362
363 /**
364 * @brief Fallback when no route is found.
365 * @param p packet
366 * @param ipHeader IPv4 header
367 * @param sockErrno error number
368 */
369 void RouteInputError(Ptr<const Packet> p,
370 const Ipv4Header& ipHeader,
371 Socket::SocketErrno sockErrno);
372
373 /**
374 * @brief Add an IPv4 interface to the stack.
375 * @param interface interface to add
376 * @return index of newly added interface
377 */
379
380 /**
381 * @brief Setup loopback interface.
382 */
383 void SetupLoopback();
384
385 /**
386 * @brief Get ICMPv4 protocol.
387 * @return Icmpv4L4Protocol pointer
388 */
390
391 /**
392 * @brief Check if an IPv4 address is unicast.
393 * @param ad address
394 * @param interfaceMask the network mask
395 * @return true if the address is unicast
396 */
397 bool IsUnicast(Ipv4Address ad, Ipv4Mask interfaceMask) const;
398
399 /**
400 * @brief Pair of a packet and an Ipv4 header.
401 */
403
404 /**
405 * @brief Fragment a packet
406 * @param packet the packet
407 * @param ipv4Header the IPv4 header
408 * @param outIfaceMtu the MTU of the interface
409 * @param listFragments the list of fragments
410 */
411 void DoFragmentation(Ptr<Packet> packet,
412 const Ipv4Header& ipv4Header,
413 uint32_t outIfaceMtu,
414 std::list<Ipv4PayloadHeaderPair>& listFragments);
415
416 /**
417 * @brief Process a packet fragment
418 * @param packet the packet
419 * @param ipHeader the IP header
420 * @param iif Input Interface
421 * @return true is the fragment completed the packet
422 */
423 bool ProcessFragment(Ptr<Packet>& packet, Ipv4Header& ipHeader, uint32_t iif);
424
425 /**
426 * @brief Make a copy of the packet, add the header and invoke the TX trace callback
427 * @param ipHeader the IP header that will be added to the packet
428 * @param packet the packet
429 * @param ipv4 the Ipv4 protocol
430 * @param interface the IP-level interface index
431 *
432 * Note: If the TracedCallback API ever is extended, we could consider
433 * to check for connected functions before adding the header
434 */
435 void CallTxTrace(const Ipv4Header& ipHeader,
436 Ptr<Packet> packet,
437 Ptr<Ipv4> ipv4,
438 uint32_t interface);
439
440 /**
441 * @brief Container of the IPv4 Interfaces.
442 */
444 /**
445 * @brief Container of NetDevices registered to IPv4 and their interface indexes.
446 */
448 /**
449 * @brief Container of the IPv4 Raw Sockets.
450 */
452
453 /**
454 * @brief Container of the IPv4 L4 keys: protocol number, interface index
455 */
456 typedef std::pair<int, int32_t> L4ListKey_t;
457
458 /**
459 * @brief Container of the IPv4 L4 instances.
460 */
462
463 bool m_ipForward; //!< Forwarding packets (i.e. router mode) state.
464 bool m_strongEndSystemModel; //!< Strong End System Model state
465 L4List_t m_protocols; //!< List of transport protocol.
466 Ipv4InterfaceList m_interfaces; //!< List of IPv4 interfaces.
468 m_reverseInterfacesContainer; //!< Container of NetDevice / Interface index associations.
469 uint8_t m_defaultTtl; //!< Default TTL
470 std::map<std::pair<uint64_t, uint8_t>, uint16_t>
471 m_identification; //!< Identification (for each {src, dst, proto} tuple)
472 Ptr<Node> m_node; //!< Node attached to stack.
473
474 /// Trace of sent packets
476 /// Trace of unicast forwarded packets
478 /// Trace of multicast forwarded packets
480 /// Trace of locally delivered packets
482
483 // The following two traces pass a packet with an IP header
484 /// Trace of transmitted packets
485 /// @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
486 /// and will be changed to \c Ptr<const Ipv4> in a future release.
487 // NS_DEPRECATED() - tag for future removal
489 /// Trace of received packets
490 /// @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
491 /// and will be changed to \c Ptr<const Ipv4> in a future release.
492 // NS_DEPRECATED() - tag for future removal
494 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
495 /// Trace of dropped packets
496 /// @deprecated The non-const \c Ptr<Ipv4> argument is deprecated
497 /// and will be changed to \c Ptr<const Ipv4> in a future release.
498 // NS_DEPRECATED() - tag for future removal
501
502 Ptr<Ipv4RoutingProtocol> m_routingProtocol; //!< Routing protocol associated with the stack
503
504 SocketList m_sockets; //!< List of IPv4 raw sockets.
505
506 /// Key identifying a fragmented packet
507 typedef std::pair<uint64_t, uint32_t> FragmentKey_t;
508
509 /// Container for fragment timeouts.
510 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv4Header, uint32_t>>
512 /// Container Iterator for fragment timeouts..
513 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv4Header, uint32_t>>::iterator
515
516 /**
517 * @brief Process the timeout for packet fragments
518 * @param key representing the packet fragments
519 * @param ipHeader the IP header of the original packet
520 * @param iif Input Interface
521 */
523
524 /**
525 * @brief Set a new timeout "event" for a fragmented packet
526 * @param key the fragment identification
527 * @param ipHeader the IPv4 header of the fragmented packet
528 * @param iif input interface of the packet
529 * @return an iterator to the inserted "event"
530 */
532
533 /**
534 * @brief Handles a fragmented packet timeout
535 */
536 void HandleTimeout();
537
538 FragmentsTimeoutsList_t m_timeoutEventList; //!< Timeout "events" container
539
540 EventId m_timeoutEvent; //!< Event for the next scheduled timeout
541
542 /**
543 * @brief A Set of Fragment belonging to the same packet (src, dst, identification and proto)
544 */
546 {
547 public:
548 /**
549 * @brief Constructor.
550 */
551 Fragments();
552
553 /**
554 * @brief Add a fragment.
555 * @param fragment the fragment
556 * @param fragmentOffset the offset of the fragment
557 * @param moreFragment the bit "More Fragment"
558 */
559 void AddFragment(Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFragment);
560
561 /**
562 * @brief If all fragments have been added.
563 * @returns true if the packet is entire
564 */
565 bool IsEntire() const;
566
567 /**
568 * @brief Get the entire packet.
569 * @return the entire packet
570 */
571 Ptr<Packet> GetPacket() const;
572
573 /**
574 * @brief Get the complete part of the packet.
575 * @return the part we have complete
576 */
577 Ptr<Packet> GetPartialPacket() const;
578
579 /**
580 * @brief Set the Timeout iterator.
581 * @param iter The iterator.
582 */
583 void SetTimeoutIter(FragmentsTimeoutsListI_t iter);
584
585 /**
586 * @brief Get the Timeout iterator.
587 * @returns The iterator.
588 */
589 FragmentsTimeoutsListI_t GetTimeoutIter();
590
591 private:
592 /**
593 * @brief True if other fragments will be sent.
594 */
596
597 /**
598 * @brief The current fragments.
599 */
600 std::list<std::pair<Ptr<Packet>, uint16_t>> m_fragments;
601
602 /**
603 * @brief Timeout iterator to "event" handler
604 */
606 };
607
608 /// Container of fragments, stored as pairs(src+dst addr, src+dst port) / fragment
609 typedef std::map<FragmentKey_t, Ptr<Fragments>> MapFragments_t;
610
611 MapFragments_t m_fragments; //!< Fragmented packets.
612 Time m_fragmentExpirationTimeout; //!< Expiration timeout
613
614 /// IETF RFC 6621, Section 6.2 de-duplication w/o IPSec
615 /// RFC 6621 recommended duplicate packet tuple: {IPV hash, IP protocol, IP source address, IP
616 /// destination address}
617 typedef std::tuple<uint64_t, uint8_t, Ipv4Address, Ipv4Address> DupTuple_t;
618 /// Maps packet duplicate tuple to expiration time
619 typedef std::map<DupTuple_t, Time> DupMap_t;
620
621 /**
622 * Registers duplicate entry, return false if new
623 * @param [in] p Possibly duplicate packet.
624 * @param [in] header Packet \pname{p} header.
625 * @return True if this packet is a duplicate
626 */
627 bool UpdateDuplicate(Ptr<const Packet> p, const Ipv4Header& header);
628 /**
629 * Remove expired duplicates packet entry
630 */
631 void RemoveDuplicates();
632
633 bool m_enableDpd; //!< Enable multicast duplicate packet detection
634 DupMap_t m_dups; //!< map of packet duplicate tuples to expiry event
635 Time m_expire; //!< duplicate entry expiration delay
636 Time m_purge; //!< time between purging expired duplicate entries
637 EventId m_cleanDpd; //!< event to cleanup expired duplicate entries
638
643};
644
645} // Namespace ns3
646
647#endif /* IPV4_L3_PROTOCOL_H */
a polymophic address class
Definition address.h:90
An identifier for simulation events.
Definition event-id.h:45
This is the implementation of the ICMP protocol as described in RFC 792 .
L4 Protocol abstract base class.
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
The IPv4 representation of a network interface.
A Set of Fragment belonging to the same packet (src, dst, identification and proto)
std::list< std::pair< Ptr< Packet >, uint16_t > > m_fragments
The current fragments.
bool m_moreFragment
True if other fragments will be sent.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
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.
bool GetWeakEsModel() const override
Get the Weak Es Model status.
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...
void SetWeakEsModel(bool model) override
Set or unset the Weak Es Model.
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
Ipv4 multicast route cache entry (similar to Linux struct mfc_cache)
Definition ipv4-route.h:104
IPv4 route cache entry (similar to Linux struct rtable)
Definition ipv4-route.h:31
Abstract base class for IPv4 routing protocols.
Network layer to device interface.
Definition net-device.h:87
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:289
A network Node.
Definition node.h:46
network packets
Definition packet.h:228
Smart pointer class similar to boost::intrusive_ptr.
A template-based reference counting class.
A low-level Socket API based loosely on the BSD Socket API.
Definition socket.h:57
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
#define NS_DEPRECATED_3_41(msg)
Tag for things deprecated in version ns-3.41.
Definition deprecated.h:112
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.