A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
nix-vector-helper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 The Georgia Institute of Technology
3 * Copyright (c) 2021 NITK Surathkal
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * This file is adapted from the old ipv4-nix-vector-helper.h.
19 *
20 * Authors: Josh Pelkey <jpelkey@gatech.edu>
21 *
22 * Modified by: Ameya Deshpande <ameyanrd@outlook.com>
23 */
24
25#ifndef NIX_VECTOR_HELPER_H
26#define NIX_VECTOR_HELPER_H
27
28#include "ns3/ipv4-routing-helper.h"
29#include "ns3/ipv6-routing-helper.h"
30#include "ns3/object-factory.h"
31
32namespace ns3
33{
34
35/**
36 * \ingroup nix-vector-routing
37 *
38 * \brief Helper class that adds Nix-vector routing to nodes.
39 *
40 * This class is expected to be used in conjunction with
41 * ns3::InternetStackHelper::SetRoutingHelper
42 *
43 * \internal
44 * Since this class is meant to be specialized only by Ipv4RoutingHelper or
45 * Ipv6RoutingHelper the implementation of this class doesn't need to be
46 * exposed here; it is in nix-vector-helper.cc.
47
48 */
49template <typename T>
50class NixVectorHelper : public std::enable_if_t<std::is_same_v<Ipv4RoutingHelper, T> ||
51 std::is_same_v<Ipv6RoutingHelper, T>,
52 T>
53{
54 /// Alias for determining whether the parent is Ipv4RoutingHelper or Ipv6RoutingHelper
55 static constexpr bool IsIpv4 = std::is_same_v<Ipv4RoutingHelper, T>;
56 /// Alias for Ipv4 and Ipv6 classes
57 using Ip = typename std::conditional_t<IsIpv4, Ipv4, Ipv6>;
58 /// Alias for Ipv4Address and Ipv6Address classes
59 using IpAddress = typename std::conditional_t<IsIpv4, Ipv4Address, Ipv6Address>;
60 /// Alias for Ipv4RoutingProtocol and Ipv6RoutingProtocol classes
62 typename std::conditional_t<IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol>;
63
64 public:
65 /**
66 * Construct an NixVectorHelper to make life easier while adding Nix-vector
67 * routing to nodes.
68 */
70
71 /**
72 * \brief Construct an NixVectorHelper from another previously
73 * initialized instance (Copy Constructor).
74 *
75 * \param o object to copy
76 */
78
79 // Delete assignment operator to avoid misuse
81
82 /**
83 * \returns pointer to clone of this NixVectorHelper
84 *
85 * This method is mainly for internal use by the other helpers;
86 * clients are expected to free the dynamic memory allocated by this method
87 */
88 NixVectorHelper<T>* Copy() const override;
89
90 /**
91 * \param node the node on which the routing protocol will run
92 * \returns a newly-created routing protocol
93 *
94 * This method will be called by ns3::InternetStackHelper::Install
95 */
96 Ptr<IpRoutingProtocol> Create(Ptr<Node> node) const override;
97
98 /**
99 * \brief prints the routing path for a source and destination at a particular time.
100 * If the routing path does not exist, it prints that the path does not exist between
101 * the nodes in the ostream.
102 * \param printTime the time at which the routing path is supposed to be printed.
103 * \param source the source node pointer to start traversing
104 * \param dest the IP destination address
105 * \param stream the output stream object to use
106 * \param unit the time unit to be used in the report
107 *
108 * This method calls the PrintRoutingPath() method of the
109 * NixVectorRouting for the source and destination to provide
110 * the routing path at the specified time.
111 */
112 void PrintRoutingPathAt(Time printTime,
113 Ptr<Node> source,
114 IpAddress dest,
116 Time::Unit unit = Time::S);
117
118 private:
119 ObjectFactory m_agentFactory; //!< Object factory
120
121 /**
122 * \brief prints the routing path for the source and destination. If the routing path
123 * does not exist, it prints that the path does not exist between the nodes in the ostream.
124 * \param source the source node pointer to start traversing
125 * \param dest the IP destination address
126 * \param stream the output stream object to use
127 * \param unit the time unit to be used in the report
128 *
129 * This method calls the PrintRoutingPath() method of the
130 * NixVectorRouting for the source and destination to provide
131 * the routing path.
132 */
133 static void PrintRoute(Ptr<Node> source,
134 IpAddress dest,
136 Time::Unit unit = Time::S);
137};
138
139/**
140 * \ingroup nix-vector-routing
141 * Create the typedef Ipv4NixVectorHelper with T as Ipv4RoutingHelper
142 *
143 * Note: This typedef enables also backwards compatibility with original Ipv4RoutingHelper.
144 */
146
147/**
148 * \ingroup nix-vector-routing
149 * Create the typedef Ipv6NixVectorHelper with T as Ipv6RoutingHelper
150 */
152} // namespace ns3
153
154#endif /* NIX_VECTOR_HELPER_H */
Helper class that adds Nix-vector routing to nodes.
static void PrintRoute(Ptr< Node > source, IpAddress dest, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing path for the source and destination.
NixVectorHelper< T > * Copy() const override
typename std::conditional_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
ObjectFactory m_agentFactory
Object factory.
NixVectorHelper & operator=(const NixVectorHelper &)=delete
static constexpr bool IsIpv4
Alias for determining whether the parent is Ipv4RoutingHelper or Ipv6RoutingHelper.
void PrintRoutingPathAt(Time printTime, Ptr< Node > source, IpAddress dest, Ptr< OutputStreamWrapper > stream, Time::Unit unit=Time::S)
prints the routing path for a source and destination at a particular time.
NixVectorHelper()
Construct an NixVectorHelper to make life easier while adding Nix-vector routing to nodes.
Ptr< IpRoutingProtocol > Create(Ptr< Node > node) const override
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
typename std::conditional_t< IsIpv4, Ipv4RoutingProtocol, Ipv6RoutingProtocol > IpRoutingProtocol
Alias for Ipv4RoutingProtocol and Ipv6RoutingProtocol classes.
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:111
@ S
second
Definition: nstime.h:116
NixVectorHelper< Ipv6RoutingHelper > Ipv6NixVectorHelper
Create the typedef Ipv6NixVectorHelper with T as Ipv6RoutingHelper.
NixVectorHelper< Ipv4RoutingHelper > Ipv4NixVectorHelper
Create the typedef Ipv4NixVectorHelper with T as Ipv4RoutingHelper.
Every class exported by the ns3 library is enclosed in the ns3 namespace.