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
30namespace ns3 {
31
32template <typename T>
34{
35 std::string name;
36 if constexpr (IsIpv4)
37 {
38 name = "Ipv4";
39 }
40 else
41 {
42 name = "Ipv6";
43 }
44
45 m_agentFactory.SetTypeId ("ns3::" + name + "NixVectorRouting");
46}
47
48template <typename T>
50 : m_agentFactory (o.m_agentFactory)
51{
52 // Check if the T is Ipv4RoutingHelper or Ipv6RoutingHelper.
53 static_assert ((std::is_same_v<Ipv4RoutingHelper, T> || std::is_same_v<Ipv6RoutingHelper, T>),
54 "Template parameter is not Ipv4RoutingHelper or Ipv6Routing Helper");
55}
56
57template <typename T>
60{
61 return new NixVectorHelper<T> (*this);
62}
63
64template <typename T>
67{
69 agent->SetNode (node);
70 node->AggregateObject (agent);
71 return agent;
72}
73
74template <typename T>
75void
77{
78 Simulator::Schedule (printTime, &NixVectorHelper<T>::PrintRoute, source, dest, stream, unit);
79}
80
81template <typename T>
82void
84{
85 Ptr<NixVectorRouting<IpRoutingProtocol>> rp = T::template GetRouting <NixVectorRouting<IpRoutingProtocol>> (source->GetObject<Ip> ()->GetRoutingProtocol ());
86 NS_ASSERT (rp);
87 rp->PrintRoutingPath (source, dest, stream, unit);
88}
89
92
93} // 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_t< IsIpv4, Ipv4, Ipv6 > Ip
Alias for Ipv4 and Ipv6 classes.
NixVectorHelper< T > * Copy(void) const
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.
typename std::conditional_t< IsIpv4, Ipv4Address, Ipv6Address > IpAddress
Alias for Ipv4Address and Ipv6Address classes.
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:78
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:555
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
Unit
The unit to use to interpret a number representing time.
Definition: nstime.h:110
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.