blob: 7a08f7950c133d953737727c3b4dd1aa0a62e4c3 [file] [log] [blame]
Alexander Afanasyevfff84982013-05-30 09:19:46 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 */
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080020
Alexander Afanasyevfff84982013-05-30 09:19:46 -070021// ndn-csma.cc
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080022
Alexander Afanasyevfff84982013-05-30 09:19:46 -070023#include "ns3/core-module.h"
24#include "ns3/network-module.h"
25#include "ns3/csma-module.h"
26#include "ns3/ndnSIM-module.h"
27
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -080028namespace ns3 {
Alexander Afanasyevfff84982013-05-30 09:19:46 -070029
30/**
31 * This scenario simulates a very simple network topology:
32 *
33 * CSMA bus (1Mbps, 10ms)
34 * +--------------------------+--------------------------+
35 * | | |
36 *
37 * +----------+ +--------+ +----------+
38 * | consumer | | router | | producer |
39 * +----------+ +--------+ +----------+
40 *
41 *
42 * Consumer requests data from producer with frequency 10 interests per second
43 * (interests contain constantly increasing sequence number).
44 *
45 * For every received interest, producer replies with a data packet, containing
46 * 1024 bytes of virtual payload.
47 *
48 * To run scenario and see what is happening, use the following command:
49 *
50 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-csma
51 */
52
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080053int
54main(int argc, char* argv[])
Alexander Afanasyevfff84982013-05-30 09:19:46 -070055{
56 // setting default parameters for PointToPoint links and channels
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080057 Config::SetDefault("ns3::CsmaChannel::DataRate", StringValue("1Mbps"));
58 Config::SetDefault("ns3::CsmaChannel::Delay", StringValue("10ms"));
59 Config::SetDefault("ns3::DropTailQueue::MaxPackets", StringValue("20"));
Alexander Afanasyevfff84982013-05-30 09:19:46 -070060
61 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
62 CommandLine cmd;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080063 cmd.Parse(argc, argv);
Alexander Afanasyevfff84982013-05-30 09:19:46 -070064
65 // Creating nodes
66 NodeContainer nodes;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080067 nodes.Create(3);
Alexander Afanasyevfff84982013-05-30 09:19:46 -070068
69 // Connecting nodes using two links
70 CsmaHelper csma;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080071 csma.Install(nodes);
Alexander Afanasyevfff84982013-05-30 09:19:46 -070072
73 // Install NDN stack on all nodes
74 ndn::StackHelper ndnHelper;
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080075 ndnHelper.SetDefaultRoutes(true);
76 ndnHelper.InstallAll();
Alexander Afanasyevfff84982013-05-30 09:19:46 -070077
78 // Installing applications
79
80 // Consumer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080081 ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
Alexander Afanasyevfff84982013-05-30 09:19:46 -070082 // Consumer will request /prefix/0, /prefix/1, ...
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080083 consumerHelper.SetPrefix("/prefix");
84 consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
85 consumerHelper.Install(nodes.Get(0)); // first node
Alexander Afanasyevfff84982013-05-30 09:19:46 -070086
87 // Producer
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080088 ndn::AppHelper producerHelper("ns3::ndn::Producer");
Alexander Afanasyevfff84982013-05-30 09:19:46 -070089 // Producer will reply to all requests starting with /prefix
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080090 producerHelper.SetPrefix("/prefix");
91 producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
92 producerHelper.Install(nodes.Get(2)); // last node
Alexander Afanasyevfff84982013-05-30 09:19:46 -070093
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080094 Simulator::Stop(Seconds(20.0));
Alexander Afanasyevfff84982013-05-30 09:19:46 -070095
Alexander Afanasyevbe55cf62014-12-20 17:51:09 -080096 Simulator::Run();
97 Simulator::Destroy();
Alexander Afanasyevfff84982013-05-30 09:19:46 -070098
99 return 0;
100}
Spyridon Mastorakisdb8280f2014-11-21 20:00:17 -0800101
102} // namespace ns3
103
104int
105main(int argc, char* argv[])
106{
107 return ns3::main(argc, argv);
108}