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 NS_LOG_DEBUG(
"Add Next Hop command was initialized");
54 Block encodedParameters(parameters.wireEncode());
56 Name commandName(
"/localhost/nfd/fib");
57 commandName.append(
"add-nexthop");
58 commandName.append(encodedParameters);
60 shared_ptr<Interest> command(make_shared<Interest>(commandName));
63 Ptr<L3Protocol> l3protocol = node->GetObject<
L3Protocol>();
70 NS_LOG_DEBUG(
"Remove Next Hop command was initialized");
71 Block encodedParameters(parameters.wireEncode());
73 Name commandName(
"/localhost/nfd/fib");
74 commandName.append(
"remove-nexthop");
75 commandName.append(encodedParameters);
77 shared_ptr<Interest> command(make_shared<Interest>(commandName));
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 Ptr<L3Protocol> L3protocol = node->GetObject<
L3Protocol>();
93 shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->
getForwarder();
96 parameters.setName(prefix);
97 parameters.setFaceId(
face->getId());
98 parameters.setCost(metric);
100 AddNextHop(parameters, node);
107 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
109 shared_ptr<Face>
face =
ndn->getFaceById(faceId);
110 NS_ASSERT_MSG(
face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" 111 << node->GetId() <<
"]");
120 Ptr<Node> node = Names::Find<Node>(nodeName);
121 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
124 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
126 shared_ptr<Face>
face =
ndn->getFaceById(faceId);
127 NS_ASSERT_MSG(
face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" << nodeName
136 for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
137 Ptr<PointToPointNetDevice> netDevice =
138 DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
142 Ptr<Channel> channel = netDevice->GetChannel();
146 if (channel->GetDevice(0)->GetNode() == otherNode
147 || channel->GetDevice(1)->GetNode() == otherNode) {
149 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
151 shared_ptr<Face>
face =
ndn->getFaceByNetDevice(netDevice);
152 NS_ASSERT_MSG(
face != 0,
"There is no face associated with the p2p link");
160 NS_FATAL_ERROR(
"Cannot add route: Node# " << node->GetId() <<
" and Node# " << otherNode->GetId()
161 <<
" are not connected");
166 const std::string& otherNodeName, int32_t metric)
168 Ptr<Node> node = Names::Find<Node>(nodeName);
169 NS_ASSERT_MSG(node != 0,
"Node [" << nodeName <<
"] does not exist");
171 Ptr<Node> otherNode = Names::Find<Node>(otherNodeName);
172 NS_ASSERT_MSG(otherNode != 0,
"Node [" << otherNodeName <<
"] does not exist");
174 AddRoute(node, prefix, otherNode, metric);
181 Ptr<L3Protocol> L3protocol = node->GetObject<
L3Protocol>();
183 shared_ptr<nfd::Forwarder> m_forwarder = L3protocol->
getForwarder();
186 parameters.setName(prefix);
187 parameters.setFaceId(
face->getId());
189 RemoveNextHop(parameters, node);
196 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
198 shared_ptr<Face>
face =
ndn->getFaceById(faceId);
199 NS_ASSERT_MSG(
face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" 200 << node->GetId() <<
"]");
208 Ptr<Node> node = Names::Find<Node>(nodeName);
210 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
212 shared_ptr<Face>
face =
ndn->getFaceById(faceId);
213 NS_ASSERT_MSG(
face != 0,
"Face with ID [" << faceId <<
"] does not exist on node [" 214 << node->GetId() <<
"]");
222 for (uint32_t deviceId = 0; deviceId < node->GetNDevices(); deviceId++) {
223 Ptr<PointToPointNetDevice> netDevice =
224 DynamicCast<PointToPointNetDevice>(node->GetDevice(deviceId));
228 Ptr<Channel> channel = netDevice->GetChannel();
232 if (channel->GetDevice(0)->GetNode() == otherNode
233 || channel->GetDevice(1)->GetNode() == otherNode) {
235 NS_ASSERT_MSG(
ndn != 0,
"Ndn stack should be installed on the node");
237 shared_ptr<Face>
face =
ndn->getFaceByNetDevice(netDevice);
238 NS_ASSERT_MSG(
face != 0,
"There is no face associated with the p2p link");
246 NS_FATAL_ERROR(
"Cannot remove route: Node# " << node->GetId() <<
" and Node# " << otherNode->GetId()
247 <<
" are not connected");
252 const std::string& otherNodeName)
254 Ptr<Node> node = Names::Find<Node>(nodeName);
255 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.
Copyright (c) 2011-2015 Regents of the University of California.
ndn L3Protocol
Copyright (c) 2011-2015 Regents of the University of California.
Implementation network-layer of NDN stack.
void injectInterest(const Interest &interest)
Inject interest through internal Face.
static KeyChain & getKeyChain()
static void RemoveRoute(Ptr< Node > node, const Name &prefix, shared_ptr< Face > face)
remove forwarding entry in FIB