A Discrete-Event Network Simulator
API
nix-vector-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 The Georgia Institute of Technology
4  * Copyright (c) 2021 NITK Surathkal
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * This file is adapted from the old ipv4-nix-vector-helper.cc.
20  *
21  * Authors: Josh Pelkey <jpelkey@gatech.edu>
22  *
23  * Modified by: Ameya Deshpande <ameyanrd@outlook.com>
24  */
25 
26 #include "nix-vector-helper.h"
27 #include "ns3/nix-vector-routing.h"
28 #include "ns3/assert.h"
29 
30 namespace ns3 {
31 
32 template <typename T>
34 {
35  std::string name = (IsIpv4::value ? "Ipv4" : "Ipv6");
36  m_agentFactory.SetTypeId ("ns3::" + name + "NixVectorRouting");
37 }
38 
39 template <typename T>
41  : m_agentFactory (o.m_agentFactory)
42 {
43  // Check if the T is Ipv4RoutingHelper or Ipv6RoutingHelper.
44  NS_ASSERT_MSG ((IsIpv4::value || std::is_same <Ipv6RoutingHelper, T>::value),
45  "Template parameter is not Ipv4RoutingHelper or Ipv6Routing Helper");
46 }
47 
48 template <typename T>
51 {
52  return new NixVectorHelper<T> (*this);
53 }
54 
55 template <typename T>
58 {
60  agent->SetNode (node);
61  node->AggregateObject (agent);
62  return agent;
63 }
64 
65 template <typename T>
66 void
68 {
69  Simulator::Schedule (printTime, &NixVectorHelper<T>::PrintRoute, source, dest, stream, unit);
70 }
71 
72 template <typename T>
73 void
75 {
76  Ptr<NixVectorRouting<IpRoutingProtocol>> rp = T::template GetRouting <NixVectorRouting<IpRoutingProtocol>> (source->GetObject<Ip> ()->GetRoutingProtocol ());
77  NS_ASSERT (rp);
78  rp->PrintRoutingPath (source, dest, stream, unit);
79 }
80 
83 
84 } // 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.
typename std::conditional< IsIpv4::value, Ipv4Address, Ipv6Address >::type IpAddress
Alias for Ipv4Address and Ipv6Address classes.
NixVectorHelper< T > * Copy(void) const
typename std::conditional< IsIpv4::value, Ipv4, Ipv6 >::type 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.
virtual Ptr< IpRoutingProtocol > Create(Ptr< Node > node) const
NixVectorHelper()
Construct an NixVectorHelper to make life easier while adding Nix-vector routing to nodes.
Nix-vector routing protocol.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
void AggregateObject(Ptr< Object > other)
Aggregate two Objects together.
Definition: object.cc:252
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:109
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
Every class exported by the ns3 library is enclosed in the ns3 namespace.