A Discrete-Event Network Simulator
API
nix-vector-helper.cc
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.cc.
19  *
20  * Authors: Josh Pelkey <jpelkey@gatech.edu>
21  *
22  * Modified by: Ameya Deshpande <ameyanrd@outlook.com>
23  */
24 
25 #include "nix-vector-helper.h"
26 
27 #include "ns3/assert.h"
28 #include "ns3/nix-vector-routing.h"
29 
30 namespace ns3
31 {
32 
33 template <typename T>
35 {
36  std::string name;
37  if constexpr (IsIpv4)
38  {
39  name = "Ipv4";
40  }
41  else
42  {
43  name = "Ipv6";
44  }
45 
46  m_agentFactory.SetTypeId("ns3::" + name + "NixVectorRouting");
47 }
48 
49 template <typename T>
51  : m_agentFactory(o.m_agentFactory)
52 {
53  // Check if the T is Ipv4RoutingHelper or Ipv6RoutingHelper.
54  static_assert((std::is_same_v<Ipv4RoutingHelper, T> || std::is_same_v<Ipv6RoutingHelper, T>),
55  "Template parameter is not Ipv4RoutingHelper or Ipv6Routing Helper");
56 }
57 
58 template <typename T>
61 {
62  return new NixVectorHelper<T>(*this);
63 }
64 
65 template <typename T>
68 {
70  m_agentFactory.Create<NixVectorRouting<IpRoutingProtocol>>();
71  agent->SetNode(node);
72  node->AggregateObject(agent);
73  return agent;
74 }
75 
76 template <typename T>
77 void
79  Ptr<Node> source,
80  IpAddress dest,
82  Time::Unit unit)
83 {
84  Simulator::Schedule(printTime, &NixVectorHelper<T>::PrintRoute, source, dest, stream, unit);
85 }
86 
87 template <typename T>
88 void
90  IpAddress dest,
92  Time::Unit unit)
93 {
95  T::template GetRouting<NixVectorRouting<IpRoutingProtocol>>(
96  source->GetObject<Ip>()->GetRoutingProtocol());
97  NS_ASSERT(rp);
98  rp->PrintRoutingPath(source, dest, stream, unit);
99 }
100 
103 
104 } // namespace ns3
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.
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.
Nix-vector routing protocol.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:259
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
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
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Every class exported by the ns3 library is enclosed in the ns3 namespace.