blob: c220873bf07dd8c074ff803541b26ad2ffea2a61 [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");
96 CcnxConsumerHelper helper ("/3");
97 ApplicationContainer app = helper.Install (nodes.Get(1));
98 app.Start (Seconds (1.0));
99 app.Stop (Seconds (1000.05));
Ilya Moiseenkoc3188b92011-11-15 17:57:00 -0800100
Alexander Afanasyev11453142011-11-25 16:13:33 -0800101 CcnxProducerHelper helper3 ("/3",120);
102 ApplicationContainer app3 = helper3.Install(nodes.Get(6));
103 app3.Start(Seconds(0.0));
104 app3.Stop(Seconds(1500.0));
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700105
Alexander Afanasyev11453142011-11-25 16:13:33 -0800106 // ------------------------------------------------------------
107 // -- Run the simulation
108 // --------------------------------------------
109 NS_LOG_INFO ("Run Simulation.");
110 Simulator::Stop (Seconds (20));
111 Simulator::Run ();
112 Simulator::Destroy ();
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700113
Alexander Afanasyev11453142011-11-25 16:13:33 -0800114 NS_LOG_INFO ("Done.");
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700115
Alexander Afanasyev11453142011-11-25 16:13:33 -0800116 return 0;
Ilya Moiseenkof9a4fb42011-08-17 10:56:29 -0700117}