blob: 3fc04a19533eb4bfa9a57104a8b9cd4906295bd5 [file] [log] [blame]
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -07002/*
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -08003 * Copyright (c) 2011 University of California, Los Angeles
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -07004 *
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -08005 * 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;
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -07008 *
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -08009 * 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070019 */
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080020
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070021#include "ns3/core-module.h"
22#include "ns3/network-module.h"
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070023#include "ns3/point-to-point-module.h"
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080024#include "ns3/NDNabstraction-module.h"
25#include <ns3/point-to-point-grid.h>
26#include "ns3/ipv4-global-routing-helper.h"
27
28#include <iostream>
29#include <sstream>
30
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080031#include "ns3/ccnx.h"
32
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070033
34using namespace ns3;
35
36NS_LOG_COMPONENT_DEFINE ("SyncTopologyNDNabstraction");
37
38int
39main (int argc, char *argv[])
40{
41 // Set up some default values for the simulation. Use the
42
43 Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210));
44 Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s"));
45
Alexander Afanasyev11453142011-11-25 16:13:33 -080046 Packet::EnableChecking();
47 Packet::EnablePrinting();
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080048
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070049 // Allow the user to override any of the defaults and the above
50 // DefaultValue::Bind ()s at run-time, via command-line arguments
51 CommandLine cmd;
52 cmd.Parse (argc, argv);
53
54 // Here, we will explicitly create seven nodes.
55 NS_LOG_INFO ("Create nodes.");
56 NodeContainer c;
57 c.Create (7);
Alexander Afanasyev11453142011-11-25 16:13:33 -080058 Names::Add ("1", c.Get (0));
59 Names::Add ("2", c.Get (1));
60 Names::Add ("3", c.Get (2));
61 Names::Add ("4", c.Get (3));
62 Names::Add ("5", c.Get (4));
63 Names::Add ("6", c.Get (5));
64 Names::Add ("7", c.Get (6));
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080065
66
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070067 NodeContainer n13 = NodeContainer (c.Get (0), c.Get (2));
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080068 NodeContainer n23 = NodeContainer (c.Get (1), c.Get (2));
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070069 NodeContainer n35 = NodeContainer (c.Get (2), c.Get (4));
70 NodeContainer n34 = NodeContainer (c.Get (2), c.Get (3));
71 NodeContainer n45 = NodeContainer (c.Get (3), c.Get (4));
72 NodeContainer n56 = NodeContainer (c.Get (4), c.Get (5));
73 NodeContainer n57 = NodeContainer (c.Get (4), c.Get (6));
74
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080075 //Ipv4StaticRoutingHelper staticRouting;
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070076
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080077 //Ipv4ListRoutingHelper list;
78 //list.Add (staticRouting, 1);
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070079
80 //Add static routing
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080081 //InternetStackHelper internet;
82 //internet.SetRoutingHelper (list); // has effect on the next Install ()
83 //internet.Install (c);
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -070084
85 // We create the channels first without any IP addressing information
86 NS_LOG_INFO ("Create channels.");
87 PointToPointHelper p2p;
88 p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
89 p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
90 NetDeviceContainer nd13 = p2p.Install (n13);
91 NetDeviceContainer nd23 = p2p.Install (n23);
92 NetDeviceContainer nd56 = p2p.Install (n56);
93
94 p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps"));
95 p2p.SetChannelAttribute ("Delay", StringValue ("50ms"));
96 NetDeviceContainer nd57 = p2p.Install (n57);
97
98 p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));
99 p2p.SetChannelAttribute ("Delay", StringValue ("1ms"));
100 NetDeviceContainer nd34 = p2p.Install (n34);
101 NetDeviceContainer nd45 = p2p.Install (n45);
102
103 p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps"));
104 p2p.SetChannelAttribute ("Delay", StringValue ("50ms"));
105 NetDeviceContainer nd35 = p2p.Install (n35);
106
Alexander Afanasyev11453142011-11-25 16:13:33 -0800107 InternetStackHelper stack;
108 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
109 // Ptr<Ipv4RoutingHelper> ipv4RoutingHelper = stack.GetRoutingHelper ();
110 stack.SetRoutingHelper (ipv4RoutingHelper);
111 stack.Install(c);
112 // // Create router nodes, initialize routing database and set up the routing
113 // // tables in the nodes.
114 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800115
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700116 // Later, we add IP addresses.
117 NS_LOG_INFO ("Assign IP Addresses.");
118 Ipv4AddressHelper ipv4;
119 ipv4.SetBase ("192.168.1.0", "255.255.255.0");
120 Ipv4InterfaceContainer i13 = ipv4.Assign (nd13);
121 Ipv4InterfaceContainer i23 = ipv4.Assign (nd23);
122 Ipv4InterfaceContainer i35 = ipv4.Assign (nd35);
123 Ipv4InterfaceContainer i34 = ipv4.Assign (nd34);
124 Ipv4InterfaceContainer i45 = ipv4.Assign (nd45);
125 Ipv4InterfaceContainer i56 = ipv4.Assign (nd56);
126 Ipv4InterfaceContainer i57 = ipv4.Assign (nd57);
127
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800128
129
130
Alexander Afanasyev11453142011-11-25 16:13:33 -0800131 CcnxStackHelper ccnx;
132 ccnx.SetForwardingStrategy ("ns3::CcnxFloodingStrategy");
133 ccnx.EnableLimits (false);
134 Ptr<CcnxFaceContainer> cf = ccnx.Install (c);
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800135
Alexander Afanasyev11453142011-11-25 16:13:33 -0800136 NS_LOG_INFO ("Installing Applications");
137 CcnxConsumerHelper helper ("/3");
138 ApplicationContainer app = helper.Install (c.Get(1));
139 app.Start (Seconds (1.0));
140 app.Stop (Seconds (1000.05));
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800141
Alexander Afanasyev11453142011-11-25 16:13:33 -0800142 /*CcnxConsumerHelper helper2 ("/4");
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800143 ApplicationContainer app2 = helper2.Install(c.Get(5));
144 app2.Start (Seconds (1.0));
145 app2.Stop (Seconds (1000.05));
Alexander Afanasyev11453142011-11-25 16:13:33 -0800146 */
147 CcnxProducerHelper helper3 ("/3",120);
148 ApplicationContainer app3 = helper3.Install(c.Get(6));
149 app3.Start(Seconds(0.0));
150 app3.Stop(Seconds(1500.0));
151 /*
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800152 CcnxProducerHelper helper4 ("/4",150);
153 ApplicationContainer app4 = helper4.Install(c.Get(0));
154 app4.Start(Seconds(0.0));
155 app4.Stop(Seconds(1500.0));
156 */
157
Alexander Afanasyev11453142011-11-25 16:13:33 -0800158 ccnx.AddRoute("1","/3",0,1);
159 ccnx.AddRoute("3","/3",2,1);
160 ccnx.AddRoute("3","/3",3,1);
161 ccnx.AddRoute("4","/3",1,1);
162 ccnx.AddRoute("5","/3",2,1);
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800163
Alexander Afanasyev11453142011-11-25 16:13:33 -0800164 /*ccnx.AddRoute ("1", "/3", 0, 1);
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800165 ccnx.AddRoute ("1", "/3", 1, 1);
166
167 ccnx.AddRoute ("2", "/3", 1, 1);
168
169 ccnx.AddRoute ("3", "/3", 1, 1);
170
171 ccnx.AddRoute ("4", "/3", 2, 1);
172
173 ccnx.AddRoute ("6", "/3", 2, 1);
174
175 ccnx.AddRoute ("7", "/3", 1, 1);
176
177 ccnx.AddRoute ("8", "/3", 1, 1);
178 */
179
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700180 // Create the OnOff application to send UDP datagrams of size
181 // 210 bytes at a rate of 448 Kb/s from n0 to n4
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800182 /*NS_LOG_INFO ("Create Applications.");
Alexander Afanasyev11453142011-11-25 16:13:33 -0800183 uint16_t port = 9; // Discard port (RFC 863)
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700184
Alexander Afanasyev11453142011-11-25 16:13:33 -0800185 std::string sendsizeattr = "SendSize";
186 //flow2 7-->2
187 BulkSendHelper bulksend0 ("ns3::UdpSocketFactory", InetSocketAddress (i23.GetAddress (0), port));
188 //bulksend0.SetAttribute(sendsizeattr, AttributeValue(ConstantVariable(2560)));
189 bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
190 ApplicationContainer apps = bulksend0.Install(c.Get(6));
191 apps.Start(Seconds (1.0));
192 apps.Stop(Seconds (10.0));
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700193
Alexander Afanasyev11453142011-11-25 16:13:33 -0800194 // Create a packet sink to receive these packets
195 PacketSinkHelper sink0 ("ns3::UdpSocketFactory", InetSocketAddress(Ipv4Address::GetAny (), port));
196 apps = sink0.Install(c.Get(1));
197 apps.Start(Seconds(0.0));
198 apps.Stop(Seconds(20.0));
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700199
Alexander Afanasyev11453142011-11-25 16:13:33 -0800200 //flow1 1-->6
201 BulkSendHelper bulksend ("ns3::UdpSocketFactory", InetSocketAddress (i56.GetAddress (1), port));
202 //bulksend.SetAttribute(sendsizeattr, AttributeValue( ConstantVariable(2560)));
203 bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
204 apps = bulksend.Install (c.Get (0));
205 apps.Start (Seconds (6.0));
206 apps.Stop (Seconds (20.0));
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700207
Alexander Afanasyev11453142011-11-25 16:13:33 -0800208 // Create a packet sink to receive these packets
209 PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
210 apps = sink.Install (c.Get (5));
211 apps.Start(Seconds(0.0));
212 apps.Stop(Seconds(20.0));
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700213
Alexander Afanasyev11453142011-11-25 16:13:33 -0800214 AsciiTraceHelper ascii;
215 p2p.EnableAsciiAll (ascii.CreateFileStream ("sync-topology-ndnabstraction.tr"));
216 p2p.EnablePcapAll ("sync-topology-ndnabstraction");*/
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700217
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800218 Simulator::Stop (Seconds (2000));
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700219
220 NS_LOG_INFO ("Run Simulation.");
221 Simulator::Run ();
222 Simulator::Destroy ();
223 NS_LOG_INFO ("Done.");
224
Alexander Afanasyev11453142011-11-25 16:13:33 -0800225 return 0;
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700226}