Project

General

Profile

Bug #2535 » ndn-routing-crash.cc

Code that will crash using ndnsim global routing helper - Christian Kreuzberger, 02/18/2015 11:15 AM

 
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/**
3
 * Copyright (c) 2011-2015  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
// ndn-simple.cpp
21

    
22
#include "ns3/core-module.h"
23
#include "ns3/network-module.h"
24
#include "ns3/point-to-point-module.h"
25
#include "ns3/ndnSIM-module.h"
26

    
27
namespace ns3 {
28

    
29

    
30
int
31
main(int argc, char* argv[])
32
{
33
  // setting default parameters for PointToPoint links and channels
34
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
35
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
36
  Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
37

    
38
  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
39
  CommandLine cmd;
40
  cmd.Parse(argc, argv);
41

    
42
  // Creating nodes
43
  NodeContainer nodes;
44
  nodes.Create(13);
45

    
46
  // Connecting nodes using two links
47
  PointToPointHelper p2p;
48
  p2p.Install(nodes.Get(0), nodes.Get(1));
49
  p2p.Install(nodes.Get(1), nodes.Get(2));
50
  p2p.Install(nodes.Get(1), nodes.Get(3));
51
  p2p.Install(nodes.Get(1), nodes.Get(4));
52
  p2p.Install(nodes.Get(1), nodes.Get(5));
53
  p2p.Install(nodes.Get(1), nodes.Get(6));
54
  p2p.Install(nodes.Get(1), nodes.Get(7));
55
  p2p.Install(nodes.Get(1), nodes.Get(8));
56
  p2p.Install(nodes.Get(1), nodes.Get(9));
57
  p2p.Install(nodes.Get(0), nodes.Get(12));
58
  p2p.Install(nodes.Get(0), nodes.Get(11));
59

    
60
  // Install NDN stack on all nodes
61
  ndn::StackHelper ndnHelper;
62
  ndnHelper.SetDefaultRoutes(true);
63
  ndnHelper.InstallAll();
64

    
65
  // Choosing forwarding strategy
66
  ndn::StrategyChoiceHelper::InstallAll("/prefix", "/localhost/nfd/strategy/best-route");
67

    
68
  // Installing global routing interface on all nodes
69
  ndn::GlobalRoutingHelper ndnGlobalRoutingHelper;
70
  ndnGlobalRoutingHelper.InstallAll();
71

    
72
  // Installing applications
73

    
74
  // Consumer
75
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
76
  // Consumer will request /prefix/0, /prefix/1, ...
77
  consumerHelper.SetPrefix("/prefix");
78
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
79
  consumerHelper.Install(nodes.Get(0));                        // first node
80

    
81
  // Producer
82
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
83
  // Producer will reply to all requests starting with /prefix
84
  producerHelper.SetPrefix("/prefix");
85
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
86
  producerHelper.Install(nodes.Get(2)); // last node
87

    
88
  // Add /prefix origins to ndn::GlobalRouter
89
  ndnGlobalRoutingHelper.AddOrigins("/prefix", nodes.Get(2));
90

    
91
  // Calculate and install FIBs
92
  ndn::GlobalRoutingHelper::CalculateAllPossibleRoutes();
93
  //ndn::GlobalRoutingHelper::CalculateRoutes();
94

    
95
  Simulator::Stop(Seconds(20.0));
96

    
97
  Simulator::Run();
98
  Simulator::Destroy();
99

    
100
  return 0;
101
}
102

    
103
} // namespace ns3
104

    
105
int
106
main(int argc, char* argv[])
107
{
108
  return ns3::main(argc, argv);
109
}
(3-3/3)