blob: b3baa7c18d5efdc5f8197919dd884d0e0fc642cd [file] [log] [blame]
Ilya Moiseenko58d26672011-12-08 13:48:06 -08001/* -*- 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
22#include "ns3/core-module.h"
23#include "ns3/network-module.h"
24#include "ns3/point-to-point-module.h"
25#include "ns3/NDNabstraction-module.h"
26#include "ns3/point-to-point-grid.h"
27#include "ns3/ipv4-global-routing-helper.h"
28
29#include <iostream>
30#include <sstream>
Ilya Moiseenko58d26672011-12-08 13:48:06 -080031#include "ns3/rocketfuel-topology-reader.h"
32
Ilya Moiseenko58d26672011-12-08 13:48:06 -080033using namespace ns3;
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080034using namespace std;
Ilya Moiseenko58d26672011-12-08 13:48:06 -080035
36NS_LOG_COMPONENT_DEFINE ("CcnxSprintTopology");
37
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080038void PrintTime ()
39{
40 NS_LOG_INFO (Simulator::Now ());
41
42 Simulator::Schedule (Seconds (1.0), PrintTime);
43}
44
Ilya Moiseenko58d26672011-12-08 13:48:06 -080045int
46main (int argc, char *argv[])
47{
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080048 // Packet::EnableChecking();
49 // Packet::EnablePrinting();
50 string weights ("./src/NDNabstraction/examples/sprint.weights");
51 string latencies ("./src/NDNabstraction/examples/sprint.latencies");
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080052 string positions;
Ilya Moiseenko58d26672011-12-08 13:48:06 -080053
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080054 Time finishTime = Seconds (2.0);
55 string animationFile;
56 string strategy = "ns3::CcnxFloodingStrategy";
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080057 string save;
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080058 CommandLine cmd;
59 cmd.AddValue ("finish", "Finish time", finishTime);
60 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
61 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
62 cmd.AddValue ("weights", "Weights file", weights);
63 cmd.AddValue ("latencies", "Latencies file", latencies);
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080064 cmd.AddValue ("positions", "Positions files", positions);
65 cmd.AddValue ("save", "Save positions to a file", save);
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080066 cmd.Parse (argc, argv);
Alexander Afanasyevae3b7c32011-12-13 13:20:06 -080067
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080068 // ------------------------------------------------------------
69 // -- Read topology data.
70 // --------------------------------------------
Ilya Moiseenko58d26672011-12-08 13:48:06 -080071
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080072 RocketfuelWeightsReader reader ("/sprint");
73 reader.SetBoundingBox (0, 0, 400, 250);
74
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080075 if (!positions.empty())
76 {
77 reader.SetFileName (positions);
78 reader.SetFileType (RocketfuelWeightsReader::POSITIONS);
79 reader.Read ();
80 }
81
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080082 reader.SetFileName (weights);
83 reader.SetFileType (RocketfuelWeightsReader::WEIGHTS);
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080084 reader.Read ();
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080085
86 reader.SetFileName (latencies);
87 reader.SetFileType (RocketfuelWeightsReader::LATENCIES);
88 reader.Read ();
89
90 reader.Commit ();
91 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -080092 {
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080093 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
94 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -080095 }
96
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -080097 NS_LOG_INFO("Nodes = " << reader.GetNodes ().GetN());
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080098 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -080099
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800100 InternetStackHelper stack;
101 Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
102 stack.SetRoutingHelper (ipv4RoutingHelper);
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -0800103 stack.Install (reader.GetNodes ());
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800104
105 reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
106
107 // Install CCNx stack
108 NS_LOG_INFO ("Installing CCNx stack");
109 CcnxStackHelper ccnxHelper;
110 ccnxHelper.SetForwardingStrategy (strategy);
111 ccnxHelper.EnableLimits (false, Seconds(0.1));
112 ccnxHelper.SetDefaultRoutes (true);
113 ccnxHelper.InstallAll ();
114
115 // // Populate FIB based on IPv4 global routing controller
116 // ccnxHelper.InstallFakeGlobalRoutes ();
117 // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/sprint", "San+Jose,+CA4062"));
118
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800119 Simulator::Stop (finishTime);
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -0800120 Simulator::Schedule (Seconds (1.0), PrintTime);
121
122 // reader.SavePositions (save+".debug");
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800123
124 NS_LOG_INFO ("Run Simulation.");
125 Simulator::Run ();
126 Simulator::Destroy ();
127 NS_LOG_INFO ("Done.");
Alexander Afanasyev5beb35a2011-12-21 16:45:13 -0800128
129 if (!save.empty ())
130 {
131 NS_LOG_INFO ("Saving positions.");
132 reader.SavePositions (save);
133 }
134
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -0800135 return 0;
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800136}