blob: 450d8d1b4f2d74bc1c4d79453dc130d5c3b5a11d [file] [log] [blame]
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2011 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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
21#include <ctime>
22#include <sstream>
23
24#include "ns3/core-module.h"
25#include "ns3/network-module.h"
26#include "ns3/internet-module.h"
27#include "ns3/point-to-point-module.h"
28#include "ns3/applications-module.h"
29#include "ns3/ipv4-static-routing-helper.h"
30#include "ns3/ipv4-list-routing-helper.h"
31#include "ns3/annotated-topology-reader.h"
32#include <list>
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080033#include "ns3/ccnx.h"
34#include "ns3/ipv4-global-routing-helper.h"
35#include "ns3/NDNabstraction-module.h"
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070036
37using namespace ns3;
38using namespace std;
39
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -080040NS_LOG_COMPONENT_DEFINE ("AnnotatedTopologyExample");
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070041
42int main (int argc, char *argv[])
43{
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080044 // Packet::EnableChecking();
45 // Packet::EnablePrinting();
46 string input ("./src/NDNabstraction/examples/simpletopology.txt");
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070047
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080048 // Time finishTime;
49 // string animationFile;
50 string strategy = "ns3::CcnxFloodingStrategy";
51 CommandLine cmd;
52 // cmd.AddValue ("finish", "Finish time", finishTime);
53 // cmd.AddValue ("netanim", "NetAnim filename", animationFile);
54 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
55 cmd.Parse (argc, argv);
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070056
57
Alexander Afanasyev11453142011-11-25 16:13:33 -080058 // ------------------------------------------------------------
59 // -- Read topology data.
60 // --------------------------------------------
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080061 AnnotatedTopologyReader reader;
62 reader.SetFileName (input);
63
64 NodeContainer nodes = reader.Read ();
65
66 if (reader.LinksSize () == 0)
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070067 {
Alexander Afanasyev11453142011-11-25 16:13:33 -080068 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
69 return -1;
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070070 }
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080071
Alexander Afanasyev11453142011-11-25 16:13:33 -080072 // ------------------------------------------------------------
73 // -- Create nodes and network stacks
74 // --------------------------------------------
75 NS_LOG_INFO ("creating internet stack");
76 InternetStackHelper stack;
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070077
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080078 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
Alexander Afanasyev11453142011-11-25 16:13:33 -080079 stack.SetRoutingHelper (ipv4RoutingHelper);
80 stack.Install(nodes);
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -070081
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080082 NS_LOG_INFO ("Assigning IPv4 addresses");
83 reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0")); // will assign metrics
84
Alexander Afanasyev11453142011-11-25 16:13:33 -080085 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080086
87
Alexander Afanasyev11453142011-11-25 16:13:33 -080088 NS_LOG_INFO("installing ccnx stack");
89 CcnxStackHelper ccnx;
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080090 ccnx.SetForwardingStrategy (strategy);
Alexander Afanasyev11453142011-11-25 16:13:33 -080091 ccnx.EnableLimits (false);
92
93 Ptr<CcnxFaceContainer> cf = ccnx.Install (nodes);
Ilya Moiseenko2bd1bc32011-08-23 16:01:35 -070094
Alexander Afanasyev11453142011-11-25 16:13:33 -080095 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyev4975f732011-12-20 17:52:19 -080096 CcnxAppHelper helper ("ns3::CcnxConsumer");
97 helper.SetPrefix ("/3");
98 ApplicationContainer app = helper.Install ("1");
Alexander Afanasyev11453142011-11-25 16:13:33 -080099 app.Start (Seconds (1.0));
100 app.Stop (Seconds (1000.05));
Alexander Afanasyev4975f732011-12-20 17:52:19 -0800101
102 CcnxAppHelper helper2 ("ns3::CcnxProducer");
103 helper2.SetPrefix ("/3");
104 helper2.SetAttribute ("PayloadSize", StringValue("1024"));
105 ApplicationContainer app2 = helper2.Install("3");
106
107 app2.Start(Seconds(0.0));
108 app2.Stop(Seconds(1500.0));
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700109
Alexander Afanasyev11453142011-11-25 16:13:33 -0800110 // ------------------------------------------------------------
111 // -- Run the simulation
112 // --------------------------------------------
113 NS_LOG_INFO ("Run Simulation.");
114 Simulator::Stop (Seconds (20));
115 Simulator::Run ();
116 Simulator::Destroy ();
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700117
Alexander Afanasyev11453142011-11-25 16:13:33 -0800118 NS_LOG_INFO ("Done.");
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700119
Alexander Afanasyev11453142011-11-25 16:13:33 -0800120 return 0;
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700121}