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 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 31 | #include "ns3/ccnx.h" |
| 32 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 33 | |
| 34 | using namespace ns3; |
| 35 | |
| 36 | NS_LOG_COMPONENT_DEFINE ("SyncTopologyNDNabstraction"); |
| 37 | |
| 38 | int |
| 39 | main (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 Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 46 | Packet::EnableChecking(); |
| 47 | Packet::EnablePrinting(); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 48 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 49 | // 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 Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 58 | 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 65 | |
| 66 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 67 | NodeContainer n13 = NodeContainer (c.Get (0), c.Get (2)); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 68 | NodeContainer n23 = NodeContainer (c.Get (1), c.Get (2)); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 69 | 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 75 | //Ipv4StaticRoutingHelper staticRouting; |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 76 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 77 | //Ipv4ListRoutingHelper list; |
| 78 | //list.Add (staticRouting, 1); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 79 | |
| 80 | //Add static routing |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 81 | //InternetStackHelper internet; |
| 82 | //internet.SetRoutingHelper (list); // has effect on the next Install () |
| 83 | //internet.Install (c); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 84 | |
| 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 Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 107 | 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 115 | |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 116 | // 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 128 | |
| 129 | |
| 130 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 131 | CcnxStackHelper ccnx; |
| 132 | ccnx.SetForwardingStrategy ("ns3::CcnxFloodingStrategy"); |
| 133 | ccnx.EnableLimits (false); |
| 134 | Ptr<CcnxFaceContainer> cf = ccnx.Install (c); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 135 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 136 | 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 141 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 142 | /*CcnxConsumerHelper helper2 ("/4"); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 143 | ApplicationContainer app2 = helper2.Install(c.Get(5)); |
| 144 | app2.Start (Seconds (1.0)); |
| 145 | app2.Stop (Seconds (1000.05)); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 146 | */ |
| 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 152 | 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 Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 158 | 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 163 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 164 | /*ccnx.AddRoute ("1", "/3", 0, 1); |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 165 | 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 Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 180 | // 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 Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 182 | /*NS_LOG_INFO ("Create Applications."); |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 183 | uint16_t port = 9; // Discard port (RFC 863) |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 184 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 185 | 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 Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 193 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 194 | // 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 Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 199 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 200 | //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 Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 207 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 208 | // 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 Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 213 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 214 | AsciiTraceHelper ascii; |
| 215 | p2p.EnableAsciiAll (ascii.CreateFileStream ("sync-topology-ndnabstraction.tr")); |
| 216 | p2p.EnablePcapAll ("sync-topology-ndnabstraction");*/ |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 217 | |
Ilya Moiseenko | c3188b9 | 2011-11-15 17:57:00 -0800 | [diff] [blame] | 218 | Simulator::Stop (Seconds (2000)); |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 219 | |
| 220 | NS_LOG_INFO ("Run Simulation."); |
| 221 | Simulator::Run (); |
| 222 | Simulator::Destroy (); |
| 223 | NS_LOG_INFO ("Done."); |
| 224 | |
Alexander Afanasyev | 1145314 | 2011-11-25 16:13:33 -0800 | [diff] [blame] | 225 | return 0; |
Ilya Moiseenko | a9b20d1 | 2011-08-01 11:03:59 -0700 | [diff] [blame] | 226 | } |