blob: 75a4b995605514db81032ff005c99850bd3032b9 [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");
Ilya Moiseenko58d26672011-12-08 13:48:06 -080068
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080069 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);
Ilya Moiseenko58d26672011-12-08 13:48:06 -080084
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080085 NodeContainer nodes = reader.Read ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -080086
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080087 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -080088 {
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080089 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
90 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -080091 }
92
Alexander Afanasyeva174aa52011-12-13 01:30:32 -080093 // InternetStackHelper stack;
94 // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
95 // stack.SetRoutingHelper (ipv4RoutingHelper);
96 // stack.Install (nodes);
97
98 // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
99
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800100 NS_LOG_INFO("Nodes = " << nodes.GetN());
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800101 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800102
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800103 // Install CCNx stack
104 NS_LOG_INFO ("Installing CCNx stack");
105 CcnxStackHelper ccnxHelper;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800106 ccnxHelper.SetForwardingStrategy (strategy);
107 ccnxHelper.EnableLimits (false, Seconds(0.1));
108 ccnxHelper.SetDefaultRoutes (true);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800109 ccnxHelper.InstallAll ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800110
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800111 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800112 CcnxConsumerHelper consumerHelper ("/5");
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800113 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800114
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800115 CcnxProducerHelper producerHelper ("/5",1024);
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800116 ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800117
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800118 // // Populate FIB based on IPv4 global routing controller
119 // ccnxHelper.InstallFakeGlobalRoutes ();
120 // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng"));
121
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800122 // Simulator::Schedule (Seconds (1.0), PrintFIBs);
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800123 // PrintFIBs ();
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800124
125 Simulator::Schedule (Seconds (10.0), PrintTime);
126
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800127 Simulator::Stop (finishTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800128
129 AnimationInterface *anim = 0;
130 if (animationFile != "")
131 {
132 anim = new AnimationInterface (animationFile);
133 anim->SetMobilityPollInterval (Seconds (1));
134 }
135
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800136 NS_LOG_INFO ("Run Simulation.");
137 Simulator::Run ();
138 Simulator::Destroy ();
139 NS_LOG_INFO ("Done.");
140 return 0;
141}