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 static const uint16_t PROT_NUMBER; //!< Protocol number (0x0800)
81
83 ~Ipv4L3Protocol() override;
84
85 // Delete copy constructor and assignment operator to avoid misuse
88
89 /**
90 * \enum DropReason
91 * \brief Reason why a packet has been dropped.
92 */
94 {
95 DROP_TTL_EXPIRED = 1, /**< Packet TTL has expired */
96 DROP_NO_ROUTE, /**< No route to host */
97 DROP_BAD_CHECKSUM, /**< Bad checksum */
98 DROP_INTERFACE_DOWN, /**< Interface is down so can not send packet */
99 DROP_ROUTE_ERROR, /**< Route error */
100 DROP_FRAGMENT_TIMEOUT, /**< Fragment timeout exceeded */
101 DROP_DUPLICATE /**< Duplicate packet received */
102 };
103
104 /**
105 * \brief Set node associated with this stack.
106 * \param node node to set
107 */
108 void SetNode(Ptr<Node> node);
109
110 // functions defined in base class Ipv4
111
112 void SetRoutingProtocol(Ptr<Ipv4RoutingProtocol> routingProtocol) override;
114
115 Ptr<Socket> CreateRawSocket() override;
116 void DeleteRawSocket(Ptr<Socket> socket) override;
117
118 void Insert(Ptr<IpL4Protocol> protocol) override;
119 void Insert(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
120
121 void Remove(Ptr<IpL4Protocol> protocol) override;
122 void Remove(Ptr<IpL4Protocol> protocol, uint32_t interfaceIndex) override;
123
124 Ptr<IpL4Protocol> GetProtocol(int protocolNumber) const override;
125 Ptr<IpL4Protocol> GetProtocol(int protocolNumber, int32_t interfaceIndex) const override;
126
127 Ipv4Address SourceAddressSelection(uint32_t interface, Ipv4Address dest) override;
128
129 /**
130 * \param ttl default ttl to use
131 *
132 * When we need to send an ipv4 packet, we use this default
133 * ttl value.
134 */
135 void SetDefaultTtl(uint8_t ttl);
136
137 /**
138 * Lower layer calls this method after calling L3Demux::Lookup
139 * The ARP subclass needs to know from which NetDevice this
140 * packet is coming to:
141 * - implement a per-NetDevice ARP cache
142 * - send back arp replies on the right device
143 * \param device network device
144 * \param p the packet
145 * \param protocol protocol value
146 * \param from address of the correspondent
147 * \param to address of the destination
148 * \param packetType type of the packet
149 */
150 void Receive(Ptr<NetDevice> device,
152 uint16_t protocol,
153 const Address& from,
154 const Address& to,
155 NetDevice::PacketType packetType);
156
157 /**
158 * \param packet packet to send
159 * \param source source address of packet
160 * \param destination address of packet
161 * \param protocol number of packet
162 * \param route route entry
163 *
164 * Higher-level layers call this method to send a packet
165 * down the stack to the MAC and PHY layers.
166 */
167 void Send(Ptr<Packet> packet,
168 Ipv4Address source,
169 Ipv4Address destination,
170 uint8_t protocol,
171 Ptr<Ipv4Route> route) override;
172 /**
173 * \param packet packet to send
174 * \param ipHeader IP Header
175 * \param route route entry
176 *
177 * Higher-level layers call this method to send a packet with IPv4 Header
178 * (Intend to be used with IpHeaderInclude attribute.)
179 */
180 void SendWithHeader(Ptr<Packet> packet, Ipv4Header ipHeader, Ptr<Ipv4Route> route) override;
181
182 uint32_t AddInterface(Ptr<NetDevice> device) override;
183 /**
184 * \brief Get an interface.
185 * \param i interface index
186 * \return IPv4 interface pointer
187 */
189 uint32_t GetNInterfaces() const override;
190
191 int32_t GetInterfaceForAddress(Ipv4Address addr) const override;
192 int32_t GetInterfaceForPrefix(Ipv4Address addr, Ipv4Mask mask) const override;
194 bool IsDestinationAddress(Ipv4Address address, uint32_t iif) const override;
195
196 bool AddAddress(uint32_t i, Ipv4InterfaceAddress address) override;
197 Ipv4InterfaceAddress GetAddress(uint32_t interfaceIndex, uint32_t addressIndex) const override;
198 uint32_t GetNAddresses(uint32_t interface) const override;
199 bool RemoveAddress(uint32_t interfaceIndex, uint32_t addressIndex) override;
200 bool RemoveAddress(uint32_t interface, Ipv4Address address) override;
202 Ipv4Address dst,
204
205 void SetMetric(uint32_t i, uint16_t metric) override;
206 uint16_t GetMetric(uint32_t i) const override;
207 uint16_t GetMtu(uint32_t i) const override;
208 bool IsUp(uint32_t i) const override;
209 void SetUp(uint32_t i) override;
210 void SetDown(uint32_t i) override;
211 bool IsForwarding(uint32_t i) const override;
212 void SetForwarding(uint32_t i, bool val) override;
213
215
216 /**
217 * \brief Check if an IPv4 address is unicast according to the node.
218 *
219 * This function checks all the node's interfaces and the respective subnet masks.
220 * An address is considered unicast if it's not broadcast, subnet-broadcast or multicast.
221 *
222 * \param ad address
223 *
224 * \return true if the address is unicast
225 */
226 bool IsUnicast(Ipv4Address ad) const;
227
228 /**
229 * TracedCallback signature for packet send, forward, or local deliver events.
230 *
231 * \param [in] header the Ipv4Header
232 * \param [in] packet the packet
233 * \param [in] interface IP-level interface number
234 */
235 typedef void (*SentTracedCallback)(const Ipv4Header& header,
236 Ptr<const Packet> packet,
237 uint32_t interface);
238
239 /**
240 * TracedCallback signature for packet transmission or reception events.
241 *
242 * \param [in] packet the packet.
243 * \param [in] ipv4 the Ipv4 protocol
244 * \param [in] interface IP-level interface number
245 * \deprecated The non-const \c Ptr<Ipv4> argument is deprecated
246 * and will be changed to \c Ptr<const Ipv4> in a future release.
247 */
248 // NS_DEPRECATED() - tag for future removal
249 typedef void (*TxRxTracedCallback)(Ptr<const Packet> packet,
250 Ptr<Ipv4> ipv4,
251 uint32_t interface);
252
253 /**
254 * TracedCallback signature for packet drop events.
255 *
256 * \param [in] header the Ipv4Header.
257 * \param [in] packet the packet.
258 * \param [in] reason the reason the packet was dropped.
259 * \param [in] ipv4 the Ipv4 protocol
260 * \param [in] interface IP-level interface number
261 * \deprecated The non-const \c Ptr<Ipv4> argument is deprecated
262 * and will be changed to \c Ptr<const Ipv4> in a future release.
263 */
264 // NS_DEPRECATED() - tag for future removal
265 typedef void (*DropTracedCallback)(const Ipv4Header& header,
266 Ptr<const Packet> packet,
267 DropReason reason,
268 Ptr<Ipv4> ipv4,
269 uint32_t interface);
270
271 protected:
272 void DoDispose() override;
273 /**
274 * This function will notify other components connected to the node that a new stack member is
275 * now connected This will be used to notify Layer 3 protocol of layer 4 protocol stack to
276 * connect them together.
277 */
278 void NotifyNewAggregate() override;
279
280 private:
281 /**
282 * \brief Ipv4L3ProtocolTestCase test case.
283 * \relates Ipv4L3ProtocolTestCase
284 */
285 friend class ::Ipv4L3ProtocolTestCase;
286
287 // class Ipv4 attributes
288 void SetIpForward(bool forward) override;
289 bool GetIpForward() const override;
290
291 /** \copydoc Ipv4::SetWeakEsModel */
292 NS_DEPRECATED_3_41("Use SetStrongEndSystemModel instead")
293 void SetWeakEsModel(bool model) override;
294 /** \copydoc Ipv4::GetWeakEsModel */
296 bool GetWeakEsModel() const override;
297
298 void SetStrongEndSystemModel(bool model) override;
299 bool GetStrongEndSystemModel() const override;
300
301 /**
302 * \brief Decrease the identification value for a dropped or recursed packet
303 * \param source source IPv4 address
304 * \param destination destination IPv4 address
305 * \param protocol L4 protocol
306 */
307 void DecreaseIdentification(Ipv4Address source, Ipv4Address destination, uint8_t protocol);
308
309 /**
310 * \brief Construct an IPv4 header.
311 * \param source source IPv4 address
312 * \param destination destination IPv4 address
313 * \param protocol L4 protocol
314 * \param payloadSize payload size
315 * \param ttl Time to Live
316 * \param tos Type of Service
317 * \param mayFragment true if the packet can be fragmented
318 * \return newly created IPv4 header
319 */
321 Ipv4Address destination,
322 uint8_t protocol,
323 uint16_t payloadSize,
324 uint8_t ttl,
325 uint8_t tos,
326 bool mayFragment);
327
328 /**
329 * \brief Send packet with route.
330 * \param route route
331 * \param packet packet to send
332 * \param ipHeader IPv4 header to add to the packet
333 */
334 void SendRealOut(Ptr<Ipv4Route> route, Ptr<Packet> packet, const Ipv4Header& ipHeader);
335
336 /**
337 * \brief Forward a packet.
338 * \param rtentry route
339 * \param p packet to forward
340 * \param header IPv4 header to add to the packet
341 */
342 void IpForward(Ptr<Ipv4Route> rtentry, Ptr<const Packet> p, const Ipv4Header& header);
343
344 /**
345 * \brief Forward a multicast packet.
346 * \param mrtentry route
347 * \param p packet to forward
348 * \param header IPv4 header to add to the packet
349 */
351 Ptr<const Packet> p,
352 const Ipv4Header& header);
353
354 /**
355 * \brief Deliver a packet.
356 * \param p packet delivered
357 * \param ip IPv4 header
358 * \param iif input interface packet was received
359 */
360 void LocalDeliver(Ptr<const Packet> p, const Ipv4Header& ip, uint32_t iif);
361
362 /**
363 * \brief Fallback when no route is found.
364 * \param p packet
365 * \param ipHeader IPv4 header
366 * \param sockErrno error number
367 */
368 void RouteInputError(Ptr<const Packet> p,
369 const Ipv4Header& ipHeader,
370 Socket::SocketErrno sockErrno);
371
372 /**
373 * \brief Add an IPv4 interface to the stack.
374 * \param interface interface to add
375 * \return index of newly added interface
376 */
378
379 /**
380 * \brief Setup loopback interface.
381 */
382 void SetupLoopback();
383
384 /**
385 * \brief Get ICMPv4 protocol.
386 * \return Icmpv4L4Protocol pointer
387 */
389
390 /**
391 * \brief Check if an IPv4 address is unicast.
392 * \param ad address
393 * \param interfaceMask the network mask
394 * \return true if the address is unicast
395 */
396 bool IsUnicast(Ipv4Address ad, Ipv4Mask interfaceMask) const;
397
398 /**
399 * \brief Pair of a packet and an Ipv4 header.
400 */
402
403 /**
404 * \brief Fragment a packet
405 * \param packet the packet
406 * \param ipv4Header the IPv4 header
407 * \param outIfaceMtu the MTU of the interface
408 * \param listFragments the list of fragments
409 */
410 void DoFragmentation(Ptr<Packet> packet,
411 const Ipv4Header& ipv4Header,
412 uint32_t outIfaceMtu,
413 std::list<Ipv4PayloadHeaderPair>& listFragments);
414
415 /**
416 * \brief Process a packet fragment
417 * \param packet the packet
418 * \param ipHeader the IP header
419 * \param iif Input Interface
420 * \return true is the fragment completed the packet
421 */
422 bool ProcessFragment(Ptr<Packet>& packet, Ipv4Header& ipHeader, uint32_t iif);
423
424 /**
425 * \brief Make a copy of the packet, add the header and invoke the TX trace callback
426 * \param ipHeader the IP header that will be added to the packet
427 * \param packet the packet
428 * \param ipv4 the Ipv4 protocol
429 * \param interface the IP-level interface index
430 *
431 * Note: If the TracedCallback API ever is extended, we could consider
432 * to check for connected functions before adding the header
433 */
434 void CallTxTrace(const Ipv4Header& ipHeader,
435 Ptr<Packet> packet,
436 Ptr<Ipv4> ipv4,
437 uint32_t interface);
438
439 /**
440 * \brief Container of the IPv4 Interfaces.
441 */
443 /**
444 * \brief Container of NetDevices registered to IPv4 and their interface indexes.
445 */
447 /**
448 * \brief Container of the IPv4 Raw Sockets.
449 */
451
452 /**
453 * \brief Container of the IPv4 L4 keys: protocol number, interface index
454 */
455 typedef std::pair<int, int32_t> L4ListKey_t;
456
457 /**
458 * \brief Container of the IPv4 L4 instances.
459 */
461
462 bool m_ipForward; //!< Forwarding packets (i.e. router mode) state.
463 bool m_strongEndSystemModel; //!< Strong End System Model state
464 L4List_t m_protocols; //!< List of transport protocol.
465 Ipv4InterfaceList m_interfaces; //!< List of IPv4 interfaces.
467 m_reverseInterfacesContainer; //!< Container of NetDevice / Interface index associations.
468 uint8_t m_defaultTtl; //!< Default TTL
469 std::map<std::pair<uint64_t, uint8_t>, uint16_t>
470 m_identification; //!< Identification (for each {src, dst, proto} tuple)
471 Ptr<Node> m_node; //!< Node attached to stack.
472
473 /// Trace of sent packets
475 /// Trace of unicast forwarded packets
477 /// Trace of multicast forwarded packets
479 /// Trace of locally delivered packets
481
482 // The following two traces pass a packet with an IP header
483 /// Trace of transmitted packets
484 /// \deprecated The non-const \c Ptr<Ipv4> argument is deprecated
485 /// and will be changed to \c Ptr<const Ipv4> in a future release.
486 // NS_DEPRECATED() - tag for future removal
488 /// Trace of received 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
493 // <ip-header, payload, reason, ifindex> (ifindex not valid if reason is DROP_NO_ROUTE)
494 /// Trace of dropped 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
500
501 Ptr<Ipv4RoutingProtocol> m_routingProtocol; //!< Routing protocol associated with the stack
502
503 SocketList m_sockets; //!< List of IPv4 raw sockets.
504
505 /// Key identifying a fragmented packet
506 typedef std::pair<uint64_t, uint32_t> FragmentKey_t;
507
508 /// Container for fragment timeouts.
509 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv4Header, uint32_t>>
511 /// Container Iterator for fragment timeouts..
512 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv4Header, uint32_t>>::iterator
514
515 /**
516 * \brief Process the timeout for packet fragments
517 * \param key representing the packet fragments
518 * \param ipHeader the IP header of the original packet
519 * \param iif Input Interface
520 */
522
523 /**
524 * \brief Set a new timeout "event" for a fragmented packet
525 * \param key the fragment identification
526 * \param ipHeader the IPv4 header of the fragmented packet
527 * \param iif input interface of the packet
528 * \return an iterator to the inserted "event"
529 */
531
532 /**
533 * \brief Handles a fragmented packet timeout
534 */
535 void HandleTimeout();
536
537 FragmentsTimeoutsList_t m_timeoutEventList; //!< Timeout "events" container
538
539 EventId m_timeoutEvent; //!< Event for the next scheduled timeout
540
541 /**
542 * \brief A Set of Fragment belonging to the same packet (src, dst, identification and proto)
543 */
545 {
546 public:
547 /**
548 * \brief Constructor.
549 */
550 Fragments();
551
552 /**
553 * \brief Add a fragment.
554 * \param fragment the fragment
555 * \param fragmentOffset the offset of the fragment
556 * \param moreFragment the bit "More Fragment"
557 */
558 void AddFragment(Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFragment);
559
560 /**
561 * \brief If all fragments have been added.
562 * \returns true if the packet is entire
563 */
564 bool IsEntire() const;
565
566 /**
567 * \brief Get the entire packet.
568 * \return the entire packet
569 */
570 Ptr<Packet> GetPacket() const;
571
572 /**
573 * \brief Get the complete part of the packet.
574 * \return the part we have complete
575 */
576 Ptr<Packet> GetPartialPacket() const;
577
578 /**
579 * \brief Set the Timeout iterator.
580 * \param iter The iterator.
581 */
582 void SetTimeoutIter(FragmentsTimeoutsListI_t iter);
583
584 /**
585 * \brief Get the Timeout iterator.
586 * \returns The iterator.
587 */
588 FragmentsTimeoutsListI_t GetTimeoutIter();
589
590 private:
591 /**
592 * \brief True if other fragments will be sent.
593 */
595
596 /**
597 * \brief The current fragments.
598 */
599 std::list<std::pair<Ptr<Packet>, uint16_t>> m_fragments;
600
601 /**
602 * \brief Timeout iterator to "event" handler
603 */
605 };
606
607 /// Container of fragments, stored as pairs(src+dst addr, src+dst port) / fragment
608 typedef std::map<FragmentKey_t, Ptr<Fragments>> MapFragments_t;
609
610 MapFragments_t m_fragments; //!< Fragmented packets.
611 Time m_fragmentExpirationTimeout; //!< Expiration timeout
612
613 /// IETF RFC 6621, Section 6.2 de-duplication w/o IPSec
614 /// RFC 6621 recommended duplicate packet tuple: {IPV hash, IP protocol, IP source address, IP
615 /// destination address}
616 typedef std::tuple<uint64_t, uint8_t, Ipv4Address, Ipv4Address> DupTuple_t;
617 /// Maps packet duplicate tuple to expiration time
618 typedef std::map<DupTuple_t, Time> DupMap_t;
619
620 /**
621 * Registers duplicate entry, return false if new
622 * \param [in] p Possibly duplicate packet.
623 * \param [in] header Packet \pname{p} header.
624 * \return True if this packet is a duplicate
625 */
626 bool UpdateDuplicate(Ptr<const Packet> p, const Ipv4Header& header);
627 /**
628 * Remove expired duplicates packet entry
629 */
630 void RemoveDuplicates();
631
632 bool m_enableDpd; //!< Enable multicast duplicate packet detection
633 DupMap_t m_dups; //!< map of packet duplicate tuples to expiry event
634 Time m_expire; //!< duplicate entry expiration delay
635 Time m_purge; //!< time between purging expired duplicate entries
636 EventId m_cleanDpd; //!< event to cleanup expired duplicate entries
637
642};
643
644} // Namespace ns3
645
646#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.
static const uint16_t PROT_NUMBER
Protocol number (0x0800)
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
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:48
#define NS_DEPRECATED_3_41(msg)
Tag for things deprecated in version ns-3.41.
Definition deprecated.h:105
Every class exported by the ns3 library is enclosed in the ns3 namespace.
STL namespace.