22 #include "ns3/assert.h"
24 #include "ns3/object.h"
25 #include "ns3/names.h"
26 #include "ns3/packet-socket-factory.h"
27 #include "ns3/config.h"
28 #include "ns3/simulator.h"
29 #include "ns3/string.h"
30 #include "ns3/net-device.h"
31 #include "ns3/channel.h"
32 #include "ns3/callback.h"
34 #include "ns3/core-config.h"
35 #include "ns3/point-to-point-net-device.h"
36 #include "ns3/point-to-point-helper.h"
37 #include "ns3/callback.h"
38 #include "ns3/node-list.h"
39 #include "ns3/data-rate.h"
42 #include "ns3/ndnSIM/model/ndn-l3-protocol.hpp"
43 #include "ns3/ndnSIM/helper/ndn-stack-helper.hpp"
49 NS_LOG_COMPONENT_DEFINE(
"ndn.FibHelper");
52 FibHelper::AddNextHop(
const ControlParameters& parameters, Ptr<Node> node)
54 NS_LOG_DEBUG(
"Add Next Hop command was initialized");
55 Block encodedParameters(parameters.wireEncode());
57 Name commandName(
"/localhost/nfd/fib");
58 commandName.append(
"add-nexthop");
59 commandName.append(encodedParameters);
61 shared_ptr<Interest> command(make_shared<Interest>(commandName));
64 Ptr<L3Protocol> l3protocol = node->GetObject<
L3Protocol>();
65 shared_ptr<nfd::FibManager> fibManager = l3protocol->
getFibManager();
66 fibManager->onFibRequest(*command);
70 FibHelper::RemoveNextHop(
const ControlParameters& parameters, Ptr<Node> node)
72 NS_LOG_DEBUG(
"Remove Next Hop command was initialized");
73 Block encodedParameters(parameters.wireEncode());
75 Name commandName(
"/localhost/nfd/fib");
76 commandName.append(
"remove-nexthop");
77 commandName.append(encodedParameters);
79 shared_ptr<Interest> command(make_shared<Interest>(commandName));
82 Ptr<L3Protocol> L3protocol = node->GetObject<
L3Protocol>();
83 shared_ptr<nfd::FibManager> fibManager = L3protocol->getFibManager();
85 fibManager->onFibRequest(*command);
91 NS_LOG_LOGIC(
"[" << node->GetId() <<
"]$ route add " << prefix <<
" via " << face->getLocalUri()
92 <<
" metric " << metric);
95 Ptr<L3Protocol> L3protocol = node->GetObject<
L3Protocol>();
97 shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->
getForwarder();
99 ControlParameters parameters;
100 parameters.setName(prefix);
101 parameters.setFaceId(face->getId());
102 parameters.setCost(metric);
104 AddNextHop(parameters, node);
110 Ptr<L3Protocol> ndn = node->GetObject<
L3Protocol>();
111 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
113 shared_ptr<Face> face = ndn->getFaceById(faceId);
114 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node ["
115 << node->GetId() <<
"]");
117 AddRoute(node, prefix, face, metric);
124 Ptr<Node> node = Names::Find<Node>(nodeName);
125 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
127 Ptr<L3Protocol> ndn = node->GetObject<
L3Protocol>();
128 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
130 shared_ptr<Face> face = ndn->getFaceById(faceId);
131 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" << nodeName
134 AddRoute(node, prefix, face, metric);
140 for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
141 Ptr<PointToPointNetDevice> netDevice =
142 DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
146 Ptr<Channel> channel = netDevice->GetChannel();
150 if (channel->GetDevice(0)->GetNode() == otherNode
151 || channel->GetDevice(1)->GetNode() == otherNode) {
152 Ptr<L3Protocol> ndn = node->GetObject<
L3Protocol>();
153 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
155 shared_ptr<Face> face = ndn->getFaceByNetDevice(netDevice);
156 NS_ASSERT_MSG(face != 0,
"There is no face associated with the p2p link");
158 AddRoute(node, prefix, face, metric);
164 NS_FATAL_ERROR(
"Cannot add route: Node# " << node->GetId() <<
" and Node# " << otherNode->GetId()
165 <<
" are not connected");
170 const std::string& otherNodeName, int32_t metric)
172 Ptr<Node> node = Names::Find<Node>(nodeName);
173 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
175 Ptr<Node> otherNode = Names::Find<Node>(otherNodeName);
176 NS_ASSERT_MSG(otherNode != 0,
"Node [" << otherNodeName <<
"] does not exist");
178 AddRoute(node, prefix, otherNode, metric);
shared_ptr< nfd::Forwarder > getForwarder()
Get smart pointer to nfd::Forwarder installed on the node.
shared_ptr< nfd::FibManager > getFibManager()
Get smart pointer to nfd::FibManager, used by node's NFD.
ndn L3Protocol
Copyright (c) 2011-2015 Regents of the University of California.
Implementation network-layer of NDN stack.
static KeyChain & getKeyChain()
static void AddRoute(const std::string &nodeName, const Name &prefix, uint32_t faceId, int32_t metric)
Add forwarding entry to FIB.