A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * This file is adapted from the old ipv4-nix-vector-helper.cc.
8 *
9 * Authors: Josh Pelkey <jpelkey@gatech.edu>
10 *
11 * Modified by: Ameya Deshpande <ameyanrd@outlook.com>
12 */
13
14#include "nix-vector-helper.h"
15
16#include "ns3/assert.h"
17#include "ns3/nix-vector-routing.h"
18
19namespace ns3
20{
21
22template <typename T>
24{
25 std::string name;
26 if constexpr (IsIpv4)
27 {
28 name = "Ipv4";
29 }
30 else
31 {
32 name = "Ipv6";
33 }
34
35 m_agentFactory.SetTypeId("ns3::" + name + "NixVectorRouting");
36}
37
38template <typename T>
40 : m_agentFactory(o.m_agentFactory)
41{
42 // Check if the T is Ipv4RoutingHelper or Ipv6RoutingHelper.
43 static_assert((std::is_same_v<Ipv4RoutingHelper, T> || std::is_same_v<Ipv6RoutingHelper, T>),
44 "Template parameter is not Ipv4RoutingHelper or Ipv6Routing Helper");
45}
46
47template <typename T>
50{
51 return new NixVectorHelper<T>(*this);
52}
53
54template <typename T>
57{
59 m_agentFactory.Create<NixVectorRouting<IpRoutingProtocol>>();
60 agent->SetNode(node);
61 node->AggregateObject(agent);
62 return agent;
63}
64
65template <typename T>
66void
68 Ptr<Node> source,
69 IpAddress dest,
71 Time::Unit unit)
72{
73 Simulator::Schedule(printTime, &NixVectorHelper<T>::PrintRoute, source, dest, stream, unit);
74}
75
76template <typename T>
77void
79 IpAddress dest,
81 Time::Unit unit)
82{
84 T::template GetRouting<NixVectorRouting<IpRoutingProtocol>>(
85 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.
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.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Unit
The unit to use to interpret a number representing time.
Definition nstime.h:100
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Every class exported by the ns3 library is enclosed in the ns3 namespace.