blob: 5ca03e1a5b3cc5414bfa0ae2364c880aced75725 [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
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080046 Packet::EnableChecking();
47 Packet::EnablePrinting();
48
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);
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -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));
65
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
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -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 ();
115
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
131 CcnxStackHelper ccnx(Ccnx::NDN_FLOODING/*Ccnx::NDN_BESTROUTE*/);
132 Ptr<CcnxFaceContainer> cf = ccnx.Install (c);
133
134 NS_LOG_INFO ("Installing Applications");
135 CcnxConsumerHelper helper ("/3");
136 ApplicationContainer app = helper.Install (c.Get(1));
137 app.Start (Seconds (1.0));
138 app.Stop (Seconds (1000.05));
139
140 /*CcnxConsumerHelper helper2 ("/4");
141 ApplicationContainer app2 = helper2.Install(c.Get(5));
142 app2.Start (Seconds (1.0));
143 app2.Stop (Seconds (1000.05));
144 */
145 CcnxProducerHelper helper3 ("/3",120);
146 ApplicationContainer app3 = helper3.Install(c.Get(6));
147 app3.Start(Seconds(0.0));
148 app3.Stop(Seconds(1500.0));
149 /*
150 CcnxProducerHelper helper4 ("/4",150);
151 ApplicationContainer app4 = helper4.Install(c.Get(0));
152 app4.Start(Seconds(0.0));
153 app4.Stop(Seconds(1500.0));
154 */
155
156 ccnx.AddRoute("1","/3",0,1);
157 ccnx.AddRoute("3","/3",2,1);
158 ccnx.AddRoute("3","/3",3,1);
159 ccnx.AddRoute("4","/3",1,1);
160 ccnx.AddRoute("5","/3",2,1);
161
162 /*ccnx.AddRoute ("1", "/3", 0, 1);
163 ccnx.AddRoute ("1", "/3", 1, 1);
164
165 ccnx.AddRoute ("2", "/3", 1, 1);
166
167 ccnx.AddRoute ("3", "/3", 1, 1);
168
169 ccnx.AddRoute ("4", "/3", 2, 1);
170
171 ccnx.AddRoute ("6", "/3", 2, 1);
172
173 ccnx.AddRoute ("7", "/3", 1, 1);
174
175 ccnx.AddRoute ("8", "/3", 1, 1);
176 */
177
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700178 // Create the OnOff application to send UDP datagrams of size
179 // 210 bytes at a rate of 448 Kb/s from n0 to n4
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800180 /*NS_LOG_INFO ("Create Applications.");
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700181 uint16_t port = 9; // Discard port (RFC 863)
182
183 std::string sendsizeattr = "SendSize";
184 //flow2 7-->2
185 BulkSendHelper bulksend0 ("ns3::UdpSocketFactory", InetSocketAddress (i23.GetAddress (0), port));
186 //bulksend0.SetAttribute(sendsizeattr, AttributeValue(ConstantVariable(2560)));
187 bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
188 ApplicationContainer apps = bulksend0.Install(c.Get(6));
189 apps.Start(Seconds (1.0));
190 apps.Stop(Seconds (10.0));
191
192 // Create a packet sink to receive these packets
193 PacketSinkHelper sink0 ("ns3::UdpSocketFactory", InetSocketAddress(Ipv4Address::GetAny (), port));
194 apps = sink0.Install(c.Get(1));
195 apps.Start(Seconds(0.0));
196 apps.Stop(Seconds(20.0));
197
198 //flow1 1-->6
199 BulkSendHelper bulksend ("ns3::UdpSocketFactory", InetSocketAddress (i56.GetAddress (1), port));
200 //bulksend.SetAttribute(sendsizeattr, AttributeValue( ConstantVariable(2560)));
201 bulksend0.SetAttribute("MaxBytes", UintegerValue(2560));
202 apps = bulksend.Install (c.Get (0));
203 apps.Start (Seconds (6.0));
204 apps.Stop (Seconds (20.0));
205
206 // Create a packet sink to receive these packets
207 PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port));
208 apps = sink.Install (c.Get (5));
209 apps.Start(Seconds(0.0));
210 apps.Stop(Seconds(20.0));
211
212 AsciiTraceHelper ascii;
213 p2p.EnableAsciiAll (ascii.CreateFileStream ("sync-topology-ndnabstraction.tr"));
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800214 p2p.EnablePcapAll ("sync-topology-ndnabstraction");*/
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700215
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800216 Simulator::Stop (Seconds (2000));
Ilya Moiseenkoa9b20d12011-08-01 11:03:59 -0700217
218 NS_LOG_INFO ("Run Simulation.");
219 Simulator::Run ();
220 Simulator::Destroy ();
221 NS_LOG_INFO ("Done.");
222
223 return 0;
224}