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");
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);
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();
84 fibManager->onFibRequest(*command);
90 NS_LOG_LOGIC(
"[" << node->GetId() <<
"]$ route add " << prefix <<
" via " << face->getLocalUri()
91 <<
" metric " << metric);
94 Ptr<L3Protocol> L3protocol = node->GetObject<
L3Protocol>();
96 shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->
getForwarder();
99 parameters.setName(prefix);
100 parameters.setFaceId(face->getId());
101 parameters.setCost(metric);
103 AddNextHop(parameters, node);
110 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
112 shared_ptr<Face> face = ndn->getFaceById(faceId);
113 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" 114 << node->GetId() <<
"]");
116 AddRoute(node, prefix, face, metric);
123 Ptr<Node> node = Names::Find<Node>(nodeName);
124 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
127 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
129 shared_ptr<Face> face = ndn->getFaceById(faceId);
130 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" << nodeName
133 AddRoute(node, prefix, face, metric);
139 for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
140 Ptr<PointToPointNetDevice> netDevice =
141 DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
145 Ptr<Channel> channel = netDevice->GetChannel();
149 if (channel->GetDevice(0)->GetNode() == otherNode
150 || channel->GetDevice(1)->GetNode() == otherNode) {
152 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
154 shared_ptr<Face> face = ndn->getFaceByNetDevice(netDevice);
155 NS_ASSERT_MSG(face != 0,
"There is no face associated with the p2p link");
157 AddRoute(node, prefix, face, metric);
163 NS_FATAL_ERROR(
"Cannot add route: Node# " << node->GetId() <<
" and Node# " << otherNode->GetId()
164 <<
" are not connected");
169 const std::string& otherNodeName, int32_t metric)
171 Ptr<Node> node = Names::Find<Node>(nodeName);
172 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
174 Ptr<Node> otherNode = Names::Find<Node>(otherNodeName);
175 NS_ASSERT_MSG(otherNode != 0,
"Node [" << otherNodeName <<
"] does not exist");
177 AddRoute(node, prefix, otherNode, metric);
184 Ptr<L3Protocol> L3protocol = node->GetObject<
L3Protocol>();
186 shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->
getForwarder();
189 parameters.setName(prefix);
190 parameters.setFaceId(face->getId());
192 RemoveNextHop(parameters, node);
199 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
201 shared_ptr<Face> face = ndn->getFaceById(faceId);
202 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" 203 << node->GetId() <<
"]");
211 Ptr<Node> node = Names::Find<Node>(nodeName);
213 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
215 shared_ptr<Face> face = ndn->getFaceById(faceId);
216 NS_ASSERT_MSG(face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" 217 << node->GetId() <<
"]");
225 for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
226 Ptr<PointToPointNetDevice> netDevice =
227 DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
231 Ptr<Channel> channel = netDevice->GetChannel();
235 if (channel->GetDevice(0)->GetNode() == otherNode
236 || channel->GetDevice(1)->GetNode() == otherNode) {
238 NS_ASSERT_MSG(ndn != 0,
"Ndn stack should be installed on the node");
240 shared_ptr<Face> face = ndn->getFaceByNetDevice(netDevice);
241 NS_ASSERT_MSG(face != 0,
"There is no face associated with the p2p link");
249 NS_FATAL_ERROR(
"Cannot remove route: Node# " << node->GetId() <<
" and Node# " << otherNode->GetId()
250 <<
" are not connected");
255 const std::string& otherNodeName)
257 Ptr<Node> node = Names::Find<Node>(nodeName);
258 Ptr<Node> otherNode = Names::Find<Node>(otherNodeName);
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< nfd::Forwarder > getForwarder()
Get smart pointer to nfd::Forwarder installed on the node.
static void AddRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face, int32_t metric)
Add forwarding entry to FIB.
shared_ptr< nfd::FibManager > getFibManager()
Get smart pointer to nfd::FibManager, used by node's NFD.
Copyright (c) 2011-2015 Regents of the University of California.
Implementation network-layer of NDN stack.
static KeyChain & getKeyChain()
static void RemoveRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face)
remove forwarding entry in FIB