blob: a96daf7977e99aa5d42240343c9b9f7766edda8b [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"
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080033#include "../utils/spring-mobility-helper.h"
Ilya Moiseenko58d26672011-12-08 13:48:06 -080034
35using namespace ns3;
36using namespace std;
37
38NS_LOG_COMPONENT_DEFINE ("CcnxAbileneTopology");
39
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080040void PrintTime ()
41{
42 NS_LOG_INFO (Simulator::Now ());
43
44 Simulator::Schedule (Seconds (10.0), PrintTime);
45}
46
47void PrintFIBs ()
48{
49 NS_LOG_INFO ("Outputing FIBs into [fibs.log]");
50 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("fibs.log", std::ios::out);
51 for (NodeList::Iterator node = NodeList::Begin ();
52 node != NodeList::End ();
53 node++)
54 {
55 // *routingStream->GetStream () << "Node " << (*node)->GetId () << "\n";
56
57 Ptr<CcnxFib> fib = (*node)->GetObject<CcnxFib> ();
58 NS_ASSERT_MSG (fib != 0, "Fire alarm");
59 *routingStream->GetStream () << *fib << "\n\n";
60 }
61}
62
Ilya Moiseenko58d26672011-12-08 13:48:06 -080063int
64main (int argc, char *argv[])
65{
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080066 // Packet::EnableChecking();
67 // Packet::EnablePrinting();
68 string input ("./src/NDNabstraction/examples/abilene-topology.txt");
Ilya Moiseenko58d26672011-12-08 13:48:06 -080069
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080070 Time finishTime = Seconds (20.0);
71 string animationFile;
72 string strategy = "ns3::CcnxFloodingStrategy";
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080073 CommandLine cmd;
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080074 cmd.AddValue ("finish", "Finish time", finishTime);
75 cmd.AddValue ("netanim", "NetAnim filename", animationFile);
76 cmd.AddValue ("strategy", "CCNx forwarding strategy", strategy);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080077 cmd.Parse (argc, argv);
Ilya Moiseenko58d26672011-12-08 13:48:06 -080078
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080079 // ------------------------------------------------------------
80 // -- Read topology data.
81 // --------------------------------------------
Ilya Moiseenko58d26672011-12-08 13:48:06 -080082
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -080083 AnnotatedTopologyReader reader ("/abilene");
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080084 reader.SetMobilityModel ("ns3::SpringMobilityModel");
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080085 reader.SetFileName (input);
Ilya Moiseenko58d26672011-12-08 13:48:06 -080086
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080087 NodeContainer nodes = reader.Read ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -080088
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -080089 if (reader.LinksSize () == 0)
Ilya Moiseenko58d26672011-12-08 13:48:06 -080090 {
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -080091 NS_LOG_ERROR ("Problems reading the topology file. Failing.");
92 return -1;
Ilya Moiseenko58d26672011-12-08 13:48:06 -080093 }
94
Alexander Afanasyev7dbdcaf2011-12-13 21:40:37 -080095 SpringMobilityHelper::InstallSprings (reader.LinksBegin (), reader.LinksEnd ());
96
Alexander Afanasyeva174aa52011-12-13 01:30:32 -080097 // InternetStackHelper stack;
98 // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops");
99 // stack.SetRoutingHelper (ipv4RoutingHelper);
100 // stack.Install (nodes);
101
102 // reader.AssignIpv4Addresses (Ipv4Address ("10.0.0.0"));
103
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800104 NS_LOG_INFO("Nodes = " << nodes.GetN());
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800105 NS_LOG_INFO("Links = " << reader.LinksSize ());
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800106
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800107 // Install CCNx stack
108 NS_LOG_INFO ("Installing CCNx stack");
109 CcnxStackHelper ccnxHelper;
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800110 ccnxHelper.SetForwardingStrategy (strategy);
111 ccnxHelper.EnableLimits (false, Seconds(0.1));
112 ccnxHelper.SetDefaultRoutes (true);
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800113 ccnxHelper.InstallAll ();
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800114
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800115 NS_LOG_INFO ("Installing Applications");
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800116 CcnxConsumerHelper consumerHelper ("/5");
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800117 ApplicationContainer consumers = consumerHelper.Install (Names::Find<Node> ("/abilene", "ATLAng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800118
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800119 CcnxProducerHelper producerHelper ("/5",1024);
Alexander Afanasyev66e6fd72011-12-12 21:34:51 -0800120 ApplicationContainer producers = producerHelper.Install (Names::Find<Node> ("/abilene", "IPLSng"));
Ilya Moiseenko58d26672011-12-08 13:48:06 -0800121
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800122 // // Populate FIB based on IPv4 global routing controller
123 // ccnxHelper.InstallFakeGlobalRoutes ();
124 // ccnxHelper.InstallRouteTo (Names::Find<Node> ("/abilene", "IPLSng"));
125
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800126 // Simulator::Schedule (Seconds (1.0), PrintFIBs);
Alexander Afanasyeva174aa52011-12-13 01:30:32 -0800127 // PrintFIBs ();
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800128
129 Simulator::Schedule (Seconds (10.0), PrintTime);
130
Alexander Afanasyev8633d5d2011-12-12 18:02:31 -0800131 Simulator::Stop (finishTime);
Alexander Afanasyev4a5c2c12011-12-12 18:50:57 -0800132
133 AnimationInterface *anim = 0;
134 if (animationFile != "")
135 {
136 anim = new AnimationInterface (animationFile);
137 anim->SetMobilityPollInterval (Seconds (1));
138 }
139
Alexander Afanasyev3406f3e2011-12-08 14:11:31 -0800140 NS_LOG_INFO ("Run Simulation.");
141 Simulator::Run ();
142 Simulator::Destroy ();
143 NS_LOG_INFO ("Done.");
144 return 0;
145}