blob: f959dc7fc2a4c24ff5a362b13153c089c72870e1 [file] [log] [blame]
Alexander Afanasyevf4e24522013-06-24 14:11:57 -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 * -------------------- tcp 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-tcp
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.SetDefaultRoutes (false);
76 ndnHelper.InstallAll ();
77
78 InternetStackHelper ipStack;
79 ipStack.SetIpv6StackInstall (false);
80 ipStack.InstallAll ();
81
82 Ipv4AddressHelper ipAddressHelper;
83 ipAddressHelper.SetBase (Ipv4Address ("10.1.1.0"), Ipv4Mask ("255.255.255.0"));
84 ipAddressHelper.Assign (link1);
85
86 ipAddressHelper.SetBase (Ipv4Address ("10.1.2.0"), Ipv4Mask ("255.255.255.0"));
87 ipAddressHelper.Assign (link2);
88
89 Ipv4StaticRoutingHelper ipStaticRouting;
90 ipStaticRouting.GetStaticRouting (nodes.Get (0)->GetObject<Ipv4> ())->
91 AddNetworkRouteTo (Ipv4Address ("10.1.2.0"), Ipv4Mask ("255.255.255.0"),
92 Ipv4Address ("10.1.1.2"),
93 1, 1);
94
95 ipStaticRouting.GetStaticRouting (nodes.Get (2)->GetObject<Ipv4> ())->
96 AddNetworkRouteTo (Ipv4Address ("10.1.1.0"), Ipv4Mask ("255.255.255.0"),
97 Ipv4Address ("10.1.2.1"),
98 1, 1);
99
Alexander Afanasyevaa84fae2013-07-27 12:01:37 -0700100 ndn::IpFacesHelper::InstallAll ();
101 ndn::IpFacesHelper::CreateTcpFace (Seconds (1.0), nodes.Get (0), Ipv4Address ("10.1.2.2"), "/tcp-route");
Alexander Afanasyevf4e24522013-06-24 14:11:57 -0700102
103 // Installing applications
104
105 // Consumer
106 ndn::AppHelper consumerHelper ("ns3::ndn::ConsumerCbr");
107 // Consumer will request /tcp-route/0, /tcp-route/1, ...
108 consumerHelper.SetPrefix ("/tcp-route");
109 consumerHelper.SetAttribute ("Frequency", StringValue ("10")); // 10 interests a second
110 consumerHelper.Install (nodes.Get (0)).
111 Start (Seconds (3)); // first node
112
113 // Producer
114 ndn::AppHelper producerHelper ("ns3::ndn::Producer");
115 // Producer will reply to all requests starting with /prefix
116 producerHelper.SetPrefix ("/tcp-route");
117 producerHelper.SetAttribute ("PayloadSize", StringValue("1024"));
118 producerHelper.Install (nodes.Get (2)); // last node
119
120 Simulator::Stop (Seconds (20.0));
121
122 Simulator::Run ();
123 Simulator::Destroy ();
124
125 return 0;
126}