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