blob: 2fa093d72e49a5d9a45c3fbaa528ed0f32dad29e [file] [log] [blame]
Alexander Afanasyevd573af22013-07-27 12:57:08 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2012 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 */
20// ndn-simple-tcp.cc
21#include "ns3/core-module.h"
22#include "ns3/network-module.h"
23#include "ns3/point-to-point-module.h"
24#include "ns3/internet-module.h"
25#include "ns3/ndnSIM-module.h"
26
27using namespace ns3;
28
29/**
30 * This scenario simulates a very simple network topology:
31 *
32 *
33 * +----------+ 1Mbps +--------+ 1Mbps +----------+
34 * | consumer | <------------> | router | <------------> | producer |
35 * +----------+ 10ms +--------+ 10ms +----------+
36 * \ /
37 * -------------------- udp face --------------------
38 *
39 * Consumer requests data from producer with frequency 10 interests per second
40 * (interests contain constantly increasing sequence number).
41 *
42 * For every received interest, producer replies with a data packet, containing
43 * 1024 bytes of virtual payload.
44 *
45 * To run scenario and see what is happening, use the following command:
46 *
47 * NS_LOG=ndn.Consumer:ndn.Producer ./waf --run=ndn-simple-udp
48 */
49
50int
51main (int argc, char *argv[])
52{
53 Packet::EnablePrinting ();
54
55 // setting default parameters for PointToPoint links and channels
56 Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps"));
57 Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms"));
58 Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20"));
59
60 // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
61 CommandLine cmd;
62 cmd.Parse (argc, argv);
63
64 // Creating nodes
65 NodeContainer nodes;
66 nodes.Create (3);
67
68 // Connecting nodes using two links
69 PointToPointHelper p2p;
70 NetDeviceContainer link1 = p2p.Install (nodes.Get (0), nodes.Get (1));
71 NetDeviceContainer link2 = p2p.Install (nodes.Get (1), nodes.Get (2));
72
73 // Install NDN stack on all nodes
74 ndn::StackHelper ndnHelper;
75 ndnHelper.SetForwardingStrategy ("ns3::ndn::fw::BestRoute");
76 ndnHelper.SetDefaultRoutes (false);
77 ndnHelper.InstallAll ();
78
79 InternetStackHelper ipStack;
80 ipStack.SetIpv6StackInstall (false);
81 ipStack.InstallAll ();
82
83 Ipv4AddressHelper ipAddressHelper;
84 ipAddressHelper.SetBase (Ipv4Address ("10.1.1.0"), Ipv4Mask ("255.255.255.0"));
85 ipAddressHelper.Assign (link1);
86
87 ipAddressHelper.SetBase (Ipv4Address ("10.1.2.0"), Ipv4Mask ("255.255.255.0"));
88 ipAddressHelper.Assign (link2);
89
90 Ipv4StaticRoutingHelper ipStaticRouting;
91 ipStaticRouting.GetStaticRouting (nodes.Get (0)->GetObject<Ipv4> ())->
92 AddNetworkRouteTo (Ipv4Address ("10.1.2.0"), Ipv4Mask ("255.255.255.0"),
93 Ipv4Address ("10.1.1.2"),
94 1, 1);
95
96 ipStaticRouting.GetStaticRouting (nodes.Get (2)->GetObject<Ipv4> ())->
97 AddNetworkRouteTo (Ipv4Address ("10.1.1.0"), Ipv4Mask ("255.255.255.0"),
98 Ipv4Address ("10.1.2.1"),
99 1, 1);
100
101 ndn::IpFacesHelper::InstallAll ();
102 ndn::IpFacesHelper::CreateUdpFace (Seconds (1.0), nodes.Get (0), Ipv4Address ("10.1.2.2"), "/udp-route1");
103 ndn::IpFacesHelper::CreateUdpFace (Seconds (1.0), nodes.Get (0), Ipv4Address ("10.1.1.2"), "/udp-route2");
104
105 // Installing applications
106
107 // Consumer
108 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
109 // consumerHelper.SetAttribute ("Randomize", StringValue ("uniform"));
110 // Consumer will request /udp-route1/0, /udp-route1/1, ...
111 consumerHelper.SetPrefix ("/udp-route1");
112 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
113 consumerHelper.Install (nodes.Get (0)).
114 Start (Seconds (3)); // first node
115
116 // Consumer will request /udp-route1/0, /udp-route1/1, ...
117 consumerHelper.SetPrefix ("/udp-route2");
118 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
119 consumerHelper.Install (nodes.Get (0)).
120 Start (Seconds (3)); // first node
121
122 // Producer
123 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
124 // Producer will reply to all requests starting with /prefix
125 producerHelper.SetPrefix ("/udp-route1");
126 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
127 producerHelper.Install (nodes.Get (2)); // last node
128
129 producerHelper.SetPrefix ("/udp-route2");
130 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
131 producerHelper.Install (nodes.Get (1)); // last node
132
133 Simulator::Stop (Seconds (20.0));
134
135 Simulator::Run ();
136 Simulator::Destroy ();
137
138 return 0;
139}