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"
48 NS_LOG_COMPONENT_DEFINE(
"ndn.FibHelper");
53 Block encodedParameters(parameters.wireEncode());
55 Name commandName(
"/localhost/nfd/fib");
56 commandName.append(
"add-nexthop");
57 commandName.append(encodedParameters);
59 shared_ptr<Interest> command(make_shared<Interest>(commandName));
60 command->setCanBePrefix(
false);
63 Ptr<L3Protocol> l3protocol = node->GetObject<
L3Protocol>();
70 Block encodedParameters(parameters.wireEncode());
72 Name commandName(
"/localhost/nfd/fib");
73 commandName.append(
"remove-nexthop");
74 commandName.append(encodedParameters);
76 shared_ptr<Interest> command(make_shared<Interest>(commandName));
77 command->setCanBePrefix(
false);
80 Ptr<L3Protocol> l3protocol = node->GetObject<
L3Protocol>();
81 l3protocol->injectInterest(*command);
87 NS_LOG_LOGIC(
"[" << node->GetId() <<
"]$ route add " << prefix <<
" via " << face->getLocalUri()
88 <<
" metric " << metric);
91 parameters.setName(prefix);
92 parameters.setFaceId(face->getId());
93 parameters.setCost(metric);
95 AddNextHop(parameters, node);
102 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
104 shared_ptr<Face> face =
ndn->getFaceById(faceId);
105 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node ["
106 << node->GetId() <<
"]");
108 AddRoute(node, prefix, face, metric);
115 Ptr<Node> node = Names::Find<Node>(nodeName);
116 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
119 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
121 shared_ptr<Face> face =
ndn->getFaceById(faceId);
122 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" << nodeName
125 AddRoute(node, prefix, face, metric);
131 for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
132 Ptr<PointToPointNetDevice> netDevice =
133 DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
137 Ptr<Channel> channel = netDevice->GetChannel();
141 if (channel->GetDevice(0)->GetNode() == otherNode
142 || channel->GetDevice(1)->GetNode() == otherNode) {
144 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
146 shared_ptr<Face> face =
ndn->getFaceByNetDevice(netDevice);
147 NS_ASSERT_MSG(face != 0,
"There is no face associated with the p2p link");
149 AddRoute(node, prefix, face, metric);
155 NS_FATAL_ERROR(
"Cannot add route: Node# " << node->GetId() <<
" and Node# " << otherNode->GetId()
156 <<
" are not connected");
161 const std::string& otherNodeName, int32_t metric)
163 Ptr<Node> node = Names::Find<Node>(nodeName);
164 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
166 Ptr<Node> otherNode = Names::Find<Node>(otherNodeName);
167 NS_ASSERT_MSG(otherNode != 0,
"Node [" << otherNodeName <<
"] does not exist");
169 AddRoute(node, prefix, otherNode, metric);
175 NS_LOG_LOGIC(
"[" << node->GetId() <<
"]$ route del " << prefix <<
" via " << face->getLocalUri());
178 Ptr<L3Protocol> L3protocol = node->GetObject<
L3Protocol>();
180 shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->
getForwarder();
183 parameters.setName(prefix);
184 parameters.setFaceId(face->getId());
186 RemoveNextHop(parameters, node);
193 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
195 shared_ptr<Face> face =
ndn->getFaceById(faceId);
196 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node ["
197 << node->GetId() <<
"]");
205 Ptr<Node> node = Names::Find<Node>(nodeName);
207 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
209 shared_ptr<Face> face =
ndn->getFaceById(faceId);
210 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node ["
211 << node->GetId() <<
"]");
219 for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
220 Ptr<PointToPointNetDevice> netDevice =
221 DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
225 Ptr<Channel> channel = netDevice->GetChannel();
229 if (channel->GetDevice(0)->GetNode() == otherNode
230 || channel->GetDevice(1)->GetNode() == otherNode) {
232 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
234 shared_ptr<Face> face =
ndn->getFaceByNetDevice(netDevice);
235 NS_ASSERT_MSG(face != 0,
"There is no face associated with the p2p link");
243 NS_FATAL_ERROR(
"Cannot remove route: Node# " << node->GetId() <<
" and Node# " << otherNode->GetId()
244 <<
" are not connected");
249 const std::string& otherNodeName)
251 Ptr<Node> node = Names::Find<Node>(nodeName);
252 Ptr<Node> otherNode = Names::Find<Node>(otherNodeName);