Repository navigation
Expand file tree
/
Copy pathndn-csma.cpp
More file actions
118 lines (93 loc) · 3.7 KB
/
Copy pathndn-csma.cpp
File metadata and controls
118 lines (93 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
* Copyright (c) 2011-2015 Regents of the University of California.
*
* This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and
* contributors.
*
* ndnSIM is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
**/
// ndn-csma.cpp
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/csma-module.h"
#include "ns3/ndnSIM-module.h"
#include "ns3/mobility-module.h"
namespace ns3 {
int
main(int argc, char* argv[])
{
// setting default parameters for PointToPoint links and channels
//Config::SetDefault("ns3::CsmaChannel::DataRate", StringValue("1Mbps"));
//Config::SetDefault("ns3::CsmaChannel::Delay", StringValue("10ms"));
//Config::SetDefault("ns3::QueueBase::MaxSize", StringValue("20p"));
// Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
CommandLine cmd;
cmd.Parse(argc, argv);
// Creating nodes
NodeContainer nodes;
nodes.Create(30);
NodeContainer router;
router.Create(1);
NodeContainer remoteHost;
remoteHost.Create(1);
NodeContainer allNodes = NodeContainer(nodes, router, remoteHost);
// Connecting nodes using two links
CsmaHelper csma;
csma.Install(allNodes);
// Install NDN stack on all nodes
ndn::StackHelper ndnHelper;
//ndnHelper.SetDefaultRoutes(true);
ndnHelper.InstallAll();
// Install Mobility model
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::RandomDiscPositionAllocator",
"X", StringValue ("500.0"),
"Y", StringValue ("0.0"),
"Rho", StringValue ("ns3::UniformRandomVariable[Min=0|Max=30]"));
mobility.Install (nodes);
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (250, 6, 0));
mobility.SetPositionAllocator (positionAlloc);
mobility.Install (router);
positionAlloc->Add (Vector (250, 20, 0));
mobility.SetPositionAllocator (positionAlloc);
mobility.Install (remoteHost);
// Installing applications
string prefix = "/ucla/hello";
ndn::StrategyChoiceHelper::InstallAll (prefix, "/localhost/nfd/strategy/multicast");
// Consumer
ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
// Consumer will request /prefix/0, /prefix/1, ...
consumerHelper.SetPrefix(prefix);
consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
consumerHelper.Install(nodes);
// Producer
ndn::AppHelper producerHelper("ns3::ndn::Producer");
// Producer will reply to all requests starting with /prefix
producerHelper.SetPrefix(prefix);
producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
producerHelper.Install(remoteHost);
ndn::L3RateTracer::InstallAll("rate-trace.txt", Seconds (1.0));
ndn::CsTracer::InstallAll("cs-trace.txt", Seconds (1.0));
ndn::AppDelayTracer::InstallAll("app-delay-tracer.txt");
Simulator::Stop(Seconds(30.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
} // namespace ns3
int
main(int argc, char* argv[])
{
return ns3::main(argc, argv);
}