Skip to content

Commit 3878430

Browse files
author
Klaus Schneider
committed
helper: Add LFID route calculation
Loop-Free In-port Dependent (LFID) route calculation provides a set of loop-free paths. Basically porting the existing code from https://github.com/schneiderklaus/ndnSIM-routing Refs: #4985 Change-Id: I1ab25e729851cf2233c3b99be715ba0159cca0c7
1 parent 6c53c75 commit 3878430

14 files changed

+1617
-2
lines changed

docs/source/examples.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,3 +508,32 @@ optimized mode nothing will be printed out)::
508508
-----------------------------------
509509

510510
:ref:`Example of packet drop tracer (L2Tracer)`
511+
512+
513+
LFID (Loop-Free Inport-Dependent) Routing for ndnSIM
514+
----------------------------------------------------
515+
516+
LFID (Loop-Free Inport-Dependent) Routing extends the ndnSIM route calculation to provide loop-free and on average shorter loop-free paths than existing work.
517+
For details see the `tech report.`_
518+
519+
LFID provides a better trade-off than the existing route calculation algorithms:
520+
521+
1. ``CalculateRoutes():`` Only provides a single shortest path nexthop.
522+
2. ``CalculateAllPossibleRoutes():`` Provides all possible nexthops, but many of them lead to loops.
523+
524+
LFID, on the other hand, maximizes the nexthop choice while also completely avoiding loops.
525+
526+
527+
We provide two example topologies (abilene and grid) to compare against the existing route calculation methods:
528+
529+
.. literalinclude:: ../../examples/lfid.cpp
530+
:language: c++
531+
:linenos:
532+
:lines: 71-148
533+
534+
535+
Simply run::
536+
537+
./waf --run "lfid [--grid] [--routing={lfid|sp|allroutes}]"
538+
539+
The output will show the nexthops at each node for the given name prefix, and any loops during forwarding.

examples/lfid.cpp

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2+
/**
3+
* Copyright (c) 2011-2019 Regents of the University of California.
4+
*
5+
* This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
6+
* contributors.
7+
*
8+
* ndnSIM is free software: you can redistribute it and/or modify it under the terms
9+
* of the GNU General Public License as published by the Free Software Foundation,
10+
* either version 3 of the License, or (at your option) any later version.
11+
*
12+
* ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14+
* PURPOSE. See the GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License along with
17+
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18+
**/
19+
20+
#include "ns3/command-line.h"
21+
#include "ns3/double.h"
22+
#include "ns3/names.h"
23+
#include "ns3/point-to-point-channel.h"
24+
#include "ns3/uinteger.h"
25+
26+
#include "ns3/ndnSIM/helper/ndn-app-helper.hpp"
27+
#include "ns3/ndnSIM/helper/ndn-global-routing-helper.hpp"
28+
#include "ns3/ndnSIM/helper/ndn-stack-helper.hpp"
29+
#include "ns3/ndnSIM/helper/ndn-strategy-choice-helper.hpp"
30+
#include "ns3/ndnSIM/model/ndn-l3-protocol.hpp"
31+
#include "ns3/ndnSIM/model/ndn-net-device-transport.hpp"
32+
//#include "ns3/ndnSIM/NFD/daemon/fw/random-strategy.hpp"
33+
#include "ns3/ndnSIM/NFD/daemon/fw/best-route-strategy2.hpp"
34+
#include "ns3/ndnSIM/utils/topology/annotated-topology-reader.hpp"
35+
36+
namespace ns3 {
37+
38+
void
39+
displayRoutes(const NodeContainer& allNodes, const std::string& prefix)
40+
{
41+
for (const auto& n : allNodes) {
42+
const auto& fib = n->GetObject<ndn::L3Protocol>()->getForwarder()->getFib();
43+
const auto& e = fib.findLongestPrefixMatch(prefix);
44+
45+
std::cout << "Node " << n->GetId() << ", prefix: " << prefix << "\n";
46+
47+
for (const auto& nh : e.getNextHops()) {
48+
// Get remote nodeId from face:
49+
const auto transport = dynamic_cast<ndn::NetDeviceTransport*>(nh.getFace().getTransport());
50+
if (transport == nullptr)
51+
continue;
52+
53+
const auto nd1 = transport->GetNetDevice()->GetObject<PointToPointNetDevice>();
54+
if (nd1 == nullptr)
55+
continue;
56+
57+
const auto ppChannel = DynamicCast<PointToPointChannel>(nd1->GetChannel());
58+
if (ppChannel == nullptr)
59+
continue;
60+
61+
auto nd2 = ppChannel->GetDevice(0);
62+
if (nd2->GetNode() == n)
63+
nd2 = ppChannel->GetDevice(1);
64+
65+
std::cout << " NextHop: " << nd2->GetNode()->GetId() << ", cost: " << nh.getCost() << "\n";
66+
}
67+
std::cout << "\n";
68+
}
69+
}
70+
71+
int
72+
main(int argc, char* argv[])
73+
{
74+
bool grid = false; // Use grid topology?
75+
std::string routing = "lfid";
76+
CommandLine cmd;
77+
cmd.AddValue("grid", "use grid topology (instead of abilene)", grid);
78+
cmd.AddValue("routing", "which route computation to use (lfid, sp, allroutes)", routing);
79+
cmd.Parse(argc, argv);
80+
81+
std::string topoName = "abilene";
82+
if (grid) {
83+
topoName = "grid";
84+
}
85+
86+
std::cout << "Using " << topoName << " topology\n\n";
87+
88+
AnnotatedTopologyReader topologyReader{};
89+
topologyReader.SetFileName("src/ndnSIM/examples/topologies/topo-" + topoName + ".txt");
90+
topologyReader.Read();
91+
92+
ndn::StackHelper stackHelper{};
93+
stackHelper.InstallAll();
94+
95+
// IMPORTANT: Has to be run after StackHelper!
96+
topologyReader.ApplyOspfMetric();
97+
98+
const std::string prefix{"/prefix"};
99+
100+
Ptr<Node> consumerN = Names::Find<Node>("router0");
101+
Ptr<Node> producerN = Names::Find<Node>("producer");
102+
NS_ABORT_MSG_UNLESS(consumerN && producerN, "consumer or producer name does not exist in topo file!");
103+
104+
ndn::GlobalRoutingHelper routingHelper;
105+
routingHelper.InstallAll(); // Fills GlobalRouter with incidencies.
106+
routingHelper.AddOrigin(prefix, producerN);
107+
108+
if (routing == "lfid") {
109+
routingHelper.CalculateLfidRoutes();
110+
}
111+
else if (routing == "sp") {
112+
routingHelper.CalculateRoutes();
113+
}
114+
else if (routing == "allroutes") {
115+
routingHelper.CalculateAllPossibleRoutes();
116+
}
117+
else {
118+
NS_FATAL_ERROR("Unknown route calculation! Use --routing {lfid|sp|allroutes}");
119+
}
120+
121+
// IMPORTANT: Some strategy needs to be installed for displayRoutes() to work.
122+
ndn::StrategyChoiceHelper strategyHelper;
123+
strategyHelper.InstallAll<nfd::fw::BestRouteStrategy2>("/");
124+
125+
// TODO: Needs RandomStrategy for test to work!
126+
// Uncomment after NFD version has been updated.
127+
// strategyHelper.InstallAll<nfd::fw::RandomStrategy>("/");
128+
129+
displayRoutes(topologyReader.GetNodes(), prefix);
130+
131+
// Installing applications
132+
ndn::AppHelper consumerHelperX{"ns3::ndn::ConsumerCbr"};
133+
consumerHelperX.SetPrefix(prefix);
134+
consumerHelperX.SetAttribute("Frequency", DoubleValue(100.0));
135+
consumerHelperX.Install(consumerN);
136+
137+
ndn::AppHelper producerHelper0{"ns3::ndn::Producer"};
138+
producerHelper0.SetPrefix(prefix);
139+
producerHelper0.Install(producerN);
140+
141+
Simulator::Stop(Seconds(30));
142+
Simulator::Run();
143+
Simulator::Destroy();
144+
145+
return 0;
146+
}
147+
148+
} // namespace ns3
149+
150+
int
151+
main(int argc, char* argv[])
152+
{
153+
return ns3::main(argc, argv);
154+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# any empty lines and lines starting with '#' symbol are ignored
2+
#
3+
# The file should contain exactly two sections: router and link, each starting with the corresponding keyword
4+
#
5+
# router section defines topology nodes and their relative positions (e.g., to use in visualizer)
6+
router
7+
8+
# each line in this section represents one router and should have the following data
9+
# node comment yPos xPos
10+
11+
router0 NA 0 1
12+
router1 NA 1 1
13+
router2 NA 1 2
14+
router3 NA 1 3
15+
router4 NA 1 4
16+
router5 NA 1 4
17+
router6 NA 1 4
18+
router7 NA 1 4
19+
router8 NA 2 1
20+
router9 NA 2 1
21+
producer NA 2 1
22+
23+
# Note that `node` can be any string. It is possible to access to the node by name using Names::Find, see examples.
24+
25+
# link section defines point-to-point links between nodes and characteristics of these links
26+
link
27+
28+
# Each line should be in the following format (only first two are required, the rest can be omitted)
29+
# srcNode dstNode bandwidth metric delay queue
30+
# bandwidth: link bandwidth
31+
# metric: routing metric // Set real routing metrics inside simulation file!
32+
# delay: link delay
33+
# queue: MaxPackets for transmission queue on the link (both directions)
34+
35+
36+
# label LinkType LinkLabel LinkNote cost
37+
38+
router0 router1 100Mbps 71 5ms
39+
router0 router2 100Mbps 20 5ms
40+
41+
router1 producer 100Mbps 16 5ms
42+
43+
router2 router9 100Mbps 54 5ms
44+
45+
router3 router4 100Mbps 71 5ms
46+
router3 router6 100Mbps 102 5ms
47+
48+
router4 router5 100Mbps 31 5ms
49+
router4 router6 100Mbps 93 5ms
50+
51+
router5 router8 10Mbps 137 5ms
52+
53+
router6 router7 100Mbps 55 5ms
54+
55+
router7 router8 10Mbps 65 5ms
56+
router7 producer 10Mbps 45 5ms
57+
58+
router8 router9 10Mbps 70 5ms
59+
60+
router9 producer 10Mbps 43 5ms

examples/topologies/topo-grid.txt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# any empty lines and lines starting with '#' symbol are ignored
2+
#
3+
# The file should contain exactly two sections: router and link, each starting with the corresponding keyword
4+
#
5+
# router section defines topology nodes and their relative positions (e.g., to use in visualizer)
6+
router
7+
8+
# each line in this section represents one router and should have the following data
9+
# node comment yPos xPos
10+
11+
router0 NA 0 1
12+
router1 NA 1 1
13+
router2 NA 1 2
14+
router3 NA 1 3
15+
router4 NA 1 4
16+
router5 NA 1 4
17+
router6 NA 1 4
18+
router7 NA 1 4
19+
producer NA 2 1
20+
21+
22+
# Note that `node` can be any string. It is possible to access to the node by name using Names::Find, see examples.
23+
24+
# link section defines point-to-point links between nodes and characteristics of these links
25+
link
26+
27+
# Each line should be in the following format (only first two are required, the rest can be omitted)
28+
# srcNode dstNode bandwidth metric delay queue
29+
# bandwidth: link bandwidth
30+
# metric: routing metric // Set real routing metrics inside simulation file!
31+
# delay: link delay
32+
# queue: MaxPackets for transmission queue on the link (both directions)
33+
34+
router0 router1 100Mbps 1 5ms
35+
router0 router3 100Mbps 2 5ms
36+
37+
router1 router2 100Mbps 3 5ms
38+
router1 router4 100Mbps 4 5ms
39+
40+
router2 router5 100Mbps 5 5ms
41+
42+
router3 router4 100Mbps 16 5ms
43+
router3 router6 100Mbps 1 5ms
44+
45+
router4 router5 100Mbps 8 5ms
46+
router4 router7 100Mbps 4 5ms
47+
48+
router6 router7 100Mbps 5 5ms
49+
50+
router5 producer 10Mbps 10 5ms
51+
router7 producer 10Mbps 2 5ms

helper/boost-graph-ndn-global-routing-helper.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22
/**
3-
* Copyright (c) 2011-2015 Regents of the University of California.
3+
* Copyright (c) 2011-2019 Regents of the University of California.
44
*
55
* This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
66
* contributors.
@@ -30,7 +30,9 @@
3030

3131
#include "ns3/ndnSIM/model/ndn-global-router.hpp"
3232

33+
#include "ns3/node.h"
3334
#include "ns3/node-list.h"
35+
#include "ns3/channel.h"
3436
#include "ns3/channel-list.h"
3537

3638
#include <list>

0 commit comments

Comments
 (0)