Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 2 | /* |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2011 University of California, Los Angeles |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 4 | * |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 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; |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 8 | * |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 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: Ilya Moiseenko <iliamo@cs.ucla.edu> |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 19 | */ |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 20 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/network-module.h" |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 23 | #include "ns3/point-to-point-module.h" |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 24 | #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 | |
| 31 | #include "ns3/visualizer-module.h" |
| 32 | #include "ns3/ccnx.h" |
| 33 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 34 | |
| 35 | using namespace ns3; |
| 36 | |
| 37 | NS_LOG_COMPONENT_DEFINE ("SyncTopologyNDNabstraction"); |
| 38 | |
| 39 | int |
| 40 | main (int argc, char *argv[]) |
| 41 | { |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 42 | GlobalValue::Bind ("SimulatorImplementationType", StringValue |
| 43 | ("ns3::VisualSimulatorImpl")); |
| 44 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 45 | // Set up some default values for the simulation. Use the |
| 46 | |
| 47 | Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (210)); |
| 48 | Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("448kb/s")); |
| 49 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 50 | Packet::EnableChecking(); |
| 51 | Packet::EnablePrinting(); |
| 52 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 53 | // Allow the user to override any of the defaults and the above |
| 54 | // DefaultValue::Bind ()s at run-time, via command-line arguments |
| 55 | CommandLine cmd; |
| 56 | cmd.Parse (argc, argv); |
| 57 | |
| 58 | // Here, we will explicitly create seven nodes. |
| 59 | NS_LOG_INFO ("Create nodes."); |
| 60 | NodeContainer c; |
| 61 | c.Create (7); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 62 | Names::Add ("1", c.Get (0)); |
| 63 | Names::Add ("2", c.Get (1)); |
| 64 | Names::Add ("3", c.Get (2)); |
| 65 | Names::Add ("4", c.Get (3)); |
| 66 | Names::Add ("5", c.Get (4)); |
| 67 | Names::Add ("6", c.Get (5)); |
| 68 | Names::Add ("7", c.Get (6)); |
| 69 | |
| 70 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 71 | NodeContainer n13 = NodeContainer (c.Get (0), c.Get (2)); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 72 | NodeContainer n23 = NodeContainer (c.Get (1), c.Get (2)); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 73 | NodeContainer n35 = NodeContainer (c.Get (2), c.Get (4)); |
| 74 | NodeContainer n34 = NodeContainer (c.Get (2), c.Get (3)); |
| 75 | NodeContainer n45 = NodeContainer (c.Get (3), c.Get (4)); |
| 76 | NodeContainer n56 = NodeContainer (c.Get (4), c.Get (5)); |
| 77 | NodeContainer n57 = NodeContainer (c.Get (4), c.Get (6)); |
| 78 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 79 | //Ipv4StaticRoutingHelper staticRouting; |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 80 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 81 | //Ipv4ListRoutingHelper list; |
| 82 | //list.Add (staticRouting, 1); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 83 | |
| 84 | //Add static routing |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 85 | //InternetStackHelper internet; |
| 86 | //internet.SetRoutingHelper (list); // has effect on the next Install () |
| 87 | //internet.Install (c); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 88 | |
| 89 | // We create the channels first without any IP addressing information |
| 90 | NS_LOG_INFO ("Create channels."); |
| 91 | PointToPointHelper p2p; |
| 92 | p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
| 93 | p2p.SetChannelAttribute ("Delay", StringValue ("1ms")); |
| 94 | NetDeviceContainer nd13 = p2p.Install (n13); |
| 95 | NetDeviceContainer nd23 = p2p.Install (n23); |
| 96 | NetDeviceContainer nd56 = p2p.Install (n56); |
| 97 | |
| 98 | p2p.SetDeviceAttribute ("DataRate", StringValue ("10Mbps")); |
| 99 | p2p.SetChannelAttribute ("Delay", StringValue ("50ms")); |
| 100 | NetDeviceContainer nd57 = p2p.Install (n57); |
| 101 | |
| 102 | p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps")); |
| 103 | p2p.SetChannelAttribute ("Delay", StringValue ("1ms")); |
| 104 | NetDeviceContainer nd34 = p2p.Install (n34); |
| 105 | NetDeviceContainer nd45 = p2p.Install (n45); |
| 106 | |
| 107 | p2p.SetDeviceAttribute ("DataRate", StringValue ("1Mbps")); |
| 108 | p2p.SetChannelAttribute ("Delay", StringValue ("50ms")); |
| 109 | NetDeviceContainer nd35 = p2p.Install (n35); |
| 110 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 111 | InternetStackHelper stack; |
| 112 | Ipv4GlobalRoutingHelper ipv4RoutingHelper; |
| 113 | // Ptr<Ipv4RoutingHelper> ipv4RoutingHelper = stack.GetRoutingHelper (); |
| 114 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 115 | stack.Install(c); |
| 116 | // // Create router nodes, initialize routing database and set up the routing |
| 117 | // // tables in the nodes. |
| 118 | Ipv4GlobalRoutingHelper::PopulateRoutingTables (); |
| 119 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 120 | // Later, we add IP addresses. |
| 121 | NS_LOG_INFO ("Assign IP Addresses."); |
| 122 | Ipv4AddressHelper ipv4; |
| 123 | ipv4.SetBase ("192.168.1.0", "255.255.255.0"); |
| 124 | Ipv4InterfaceContainer i13 = ipv4.Assign (nd13); |
| 125 | Ipv4InterfaceContainer i23 = ipv4.Assign (nd23); |
| 126 | Ipv4InterfaceContainer i35 = ipv4.Assign (nd35); |
| 127 | Ipv4InterfaceContainer i34 = ipv4.Assign (nd34); |
| 128 | Ipv4InterfaceContainer i45 = ipv4.Assign (nd45); |
| 129 | Ipv4InterfaceContainer i56 = ipv4.Assign (nd56); |
| 130 | Ipv4InterfaceContainer i57 = ipv4.Assign (nd57); |
| 131 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 132 | |
| 133 | |
| 134 | |
| 135 | CcnxStackHelper ccnx(Ccnx::NDN_FLOODING/*Ccnx::NDN_BESTROUTE*/); |
| 136 | Ptr<CcnxFaceContainer> cf = ccnx.Install (c); |
| 137 | |
| 138 | NS_LOG_INFO ("Installing Applications"); |
| 139 | CcnxConsumerHelper helper ("/3"); |
| 140 | ApplicationContainer app = helper.Install (c.Get(1)); |
| 141 | app.Start (Seconds (1.0)); |
| 142 | app.Stop (Seconds (1000.05)); |
| 143 | |
| 144 | /*CcnxConsumerHelper helper2 ("/4"); |
| 145 | ApplicationContainer app2 = helper2.Install(c.Get(5)); |
| 146 | app2.Start (Seconds (1.0)); |
| 147 | app2.Stop (Seconds (1000.05)); |
| 148 | */ |
| 149 | CcnxProducerHelper helper3 ("/3",120); |
| 150 | ApplicationContainer app3 = helper3.Install(c.Get(6)); |
| 151 | app3.Start(Seconds(0.0)); |
| 152 | app3.Stop(Seconds(1500.0)); |
| 153 | /* |
| 154 | CcnxProducerHelper helper4 ("/4",150); |
| 155 | ApplicationContainer app4 = helper4.Install(c.Get(0)); |
| 156 | app4.Start(Seconds(0.0)); |
| 157 | app4.Stop(Seconds(1500.0)); |
| 158 | */ |
| 159 | |
| 160 | ccnx.AddRoute("1","/3",0,1); |
| 161 | ccnx.AddRoute("3","/3",2,1); |
| 162 | ccnx.AddRoute("3","/3",3,1); |
| 163 | ccnx.AddRoute("4","/3",1,1); |
| 164 | ccnx.AddRoute("5","/3",2,1); |
| 165 | |
| 166 | /*ccnx.AddRoute ("1", "/3", 0, 1); |
| 167 | ccnx.AddRoute ("1", "/3", 1, 1); |
| 168 | |
| 169 | ccnx.AddRoute ("2", "/3", 1, 1); |
| 170 | |
| 171 | ccnx.AddRoute ("3", "/3", 1, 1); |
| 172 | |
| 173 | ccnx.AddRoute ("4", "/3", 2, 1); |
| 174 | |
| 175 | ccnx.AddRoute ("6", "/3", 2, 1); |
| 176 | |
| 177 | ccnx.AddRoute ("7", "/3", 1, 1); |
| 178 | |
| 179 | ccnx.AddRoute ("8", "/3", 1, 1); |
| 180 | */ |
| 181 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 182 | // Create the OnOff application to send UDP datagrams of size |
| 183 | // 210 bytes at a rate of 448 Kb/s from n0 to n4 |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 184 | /*NS_LOG_INFO ("Create Applications."); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 185 | uint16_t port = 9; // Discard port (RFC 863) |
| 186 | |
| 187 | std::string sendsizeattr = "SendSize"; |
| 188 | //flow2 7-->2 |
| 189 | BulkSendHelper bulksend0 ("ns3::UdpSocketFactory", InetSocketAddress (i23.GetAddress (0), port)); |
| 190 | //bulksend0.SetAttribute(sendsizeattr, AttributeValue(ConstantVariable(2560))); |
| 191 | bulksend0.SetAttribute("MaxBytes", UintegerValue(2560)); |
| 192 | ApplicationContainer apps = bulksend0.Install(c.Get(6)); |
| 193 | apps.Start(Seconds (1.0)); |
| 194 | apps.Stop(Seconds (10.0)); |
| 195 | |
| 196 | // Create a packet sink to receive these packets |
| 197 | PacketSinkHelper sink0 ("ns3::UdpSocketFactory", InetSocketAddress(Ipv4Address::GetAny (), port)); |
| 198 | apps = sink0.Install(c.Get(1)); |
| 199 | apps.Start(Seconds(0.0)); |
| 200 | apps.Stop(Seconds(20.0)); |
| 201 | |
| 202 | //flow1 1-->6 |
| 203 | BulkSendHelper bulksend ("ns3::UdpSocketFactory", InetSocketAddress (i56.GetAddress (1), port)); |
| 204 | //bulksend.SetAttribute(sendsizeattr, AttributeValue( ConstantVariable(2560))); |
| 205 | bulksend0.SetAttribute("MaxBytes", UintegerValue(2560)); |
| 206 | apps = bulksend.Install (c.Get (0)); |
| 207 | apps.Start (Seconds (6.0)); |
| 208 | apps.Stop (Seconds (20.0)); |
| 209 | |
| 210 | // Create a packet sink to receive these packets |
| 211 | PacketSinkHelper sink ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), port)); |
| 212 | apps = sink.Install (c.Get (5)); |
| 213 | apps.Start(Seconds(0.0)); |
| 214 | apps.Stop(Seconds(20.0)); |
| 215 | |
| 216 | AsciiTraceHelper ascii; |
| 217 | p2p.EnableAsciiAll (ascii.CreateFileStream ("sync-topology-ndnabstraction.tr")); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 218 | p2p.EnablePcapAll ("sync-topology-ndnabstraction");*/ |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 219 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame^] | 220 | Simulator::Stop (Seconds (2000)); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 221 | |
| 222 | NS_LOG_INFO ("Run Simulation."); |
| 223 | Simulator::Run (); |
| 224 | Simulator::Destroy (); |
| 225 | NS_LOG_INFO ("Done."); |
| 226 | |
| 227 | return 0; |
| 228 | } |