blob: 3e7f24ee97c2cb829bd4b5d99d35314c6406097e [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"
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080028#include "ns3/animation-interface.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080029
30#include <iostream>
31#include <sstream>
Ilya Moiseenko58d26672011-12-08 13:48:06 -080032#include "ns3/annotated-topology-reader.h"
33
34using namespace ns3;
35using namespace std;
36
37NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology");
38
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080039void PrintTime ()
40{
41 NS_LOG_INFO (Simulator::Now ());
42
43 Simulator::Schedule (Seconds (10.0), PrintTime);
44}
45
46void PrintFIBs ()
47{
48 NS_LOG_INFO ("Outputing FIBs into [fibs.log]");
49 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out);
50 for (NodeList::Iterator node = NodeList::Begin ();
51 node != NodeList::End ();
52 node++)
53 {
54 // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n";
55
56 Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> ();
57 NS_ASSERT_MSG (fib != 0, "Fire alarm");
58 *routingStream->GetStream () << *fib << "\n\n";
59 }
60}
61
Ilya Moiseenko58d26672011-12-08 13:48:06 -080062int
63main (int argc, char *argv[])
64{
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080065 // Packet::EnableChecking();
66 // Packet::EnablePrinting();
67 string input ("./src/NDNabstraction/examples/abilene-topology.txt");
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080068
69 Time finishTime = Seconds (20.0);
70 string animationFile;
71 string strategy = "ns3::CcnxFloodingStrategy";
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080072 CommandLine cmd;
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080073 cmd.AddValue ("finish", "Finish time", finishTime);
74 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
75 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080076 cmd.Parse (argc, argv);
Ilya Moiseenko58d26672011-12-08 13:48:06 -080077
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080078 // ------------------------------------------------------------
79 // -- Read topology data.
80 // --------------------------------------------
Ilya Moiseenko58d26672011-12-08 13:48:06 -080081
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080082 AnnotatedTopologyReader reader ("/abilene");
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080083 reader.SetFileName (input);
84 reader.SetBoundingBox (100.0, 100.0, 400.0, 400.0);
85
86 NodeContainer nodes = reader.Read ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -080087
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080088 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -080089 {
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080090 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
91 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -080092 }
93
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080094 NS_LOG_INFO("Nodes = " << nodes.GetN());
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080095 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -080096
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080097 // Install CCNx stack
98 NS_LOG_INFO ("Installing CCNx stack");
99 CcnxStackHelper ccnxHelper;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800100 ccnxHelper.SetForwardingStrategy (strategy);
101 ccnxHelper.EnableLimits (false, Seconds(0.1));
102 ccnxHelper.SetDefaultRoutes (true);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800103 ccnxHelper.InstallAll ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800104
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800105 NS_LOG_INFO ("Installing Applications");
106 CcnxConsumerHelper consumerHelper ("tralala");
107 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "1"));
108
109 CcnxProducerHelper producerHelper ("tralala",1024);
110 ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "6"));
111
112 // Simulator::Schedule (Seconds (1.0), PrintFIBs);
113 PrintFIBs ();
114
115 Simulator::Schedule (Seconds (10.0), PrintTime);
116
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800117 Simulator::Stop (finishTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800118
119 AnimationInterface *anim = 0;
120 if (animationFile != "")
121 {
122 anim = new AnimationInterface (animationFile);
123 anim->SetMobilityPollInterval (Seconds (1));
124 }
125
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800126 NS_LOG_INFO ("Run Simulation.");
127 Simulator::Run ();
128 Simulator::Destroy ();
129 NS_LOG_INFO ("Done.");
130 return 0;
131}