Alexander Afanasyev | c7411ee | 2013-06-10 10:54:54 -0700 | [diff] [blame^] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013 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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | // ndn-triangle-calculate-routes.cc |
| 21 | #include "ns3/core-module.h" |
| 22 | #include "ns3/network-module.h" |
| 23 | #include "ns3/ndnSIM-module.h" |
| 24 | |
| 25 | using namespace ns3; |
| 26 | using namespace std; |
| 27 | |
| 28 | int |
| 29 | main (int argc, char *argv[]) |
| 30 | { |
| 31 | // setting default parameters for PointToPoint links and channels |
| 32 | Config::SetDefault ("ns3::PointToPointNetDevice::DataRate", StringValue ("1Mbps")); |
| 33 | Config::SetDefault ("ns3::PointToPointChannel::Delay", StringValue ("10ms")); |
| 34 | Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("20")); |
| 35 | |
| 36 | // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize |
| 37 | CommandLine cmd; |
| 38 | cmd.Parse (argc, argv); |
| 39 | |
| 40 | ofstream file1 ("/tmp/topo1.txt"); |
| 41 | file1 << "router\n\n" |
| 42 | << "#node city y x mpi-partition\n" |
| 43 | << "A1 NA 1 1 1\n" |
| 44 | << "B1 NA 80 -40 1\n" |
| 45 | << "C1 NA 80 40 1\n" |
| 46 | << "A2 NA 1 1 1\n" |
| 47 | << "B2 NA 80 -40 1\n" |
| 48 | << "C2 NA 80 40 1\n\n" |
| 49 | << "link\n\n" |
| 50 | << "# from to capacity metric delay queue\n" |
| 51 | << "A1 B1 10Mbps 100 1ms 100\n" |
| 52 | << "A1 C1 10Mbps 50 1ms 100\n" |
| 53 | << "B1 C1 10Mbps 1 1ms 100\n" |
| 54 | << "A2 B2 10Mbps 50 1ms 100\n" |
| 55 | << "A2 C2 10Mbps 100 1ms 100\n" |
| 56 | << "B2 C2 10Mbps 1 1ms 100\n"; |
| 57 | file1.close (); |
| 58 | |
| 59 | AnnotatedTopologyReader topologyReader (""); |
| 60 | topologyReader.SetFileName ("/tmp/topo1.txt"); |
| 61 | topologyReader.Read (); |
| 62 | |
| 63 | // Install NDN stack on all nodes |
| 64 | ndn::StackHelper ndnHelper; |
| 65 | ndnHelper.InstallAll (); |
| 66 | |
| 67 | topologyReader.ApplyOspfMetric (); |
| 68 | |
| 69 | ndn::GlobalRoutingHelper ndnGlobalRoutingHelper; |
| 70 | ndnGlobalRoutingHelper.InstallAll (); |
| 71 | |
| 72 | ndnGlobalRoutingHelper.AddOrigins ("/test/prefix", Names::Find<Node> ("C1")); |
| 73 | ndnGlobalRoutingHelper.AddOrigins ("/test/prefix", Names::Find<Node> ("C2")); |
| 74 | ndn::GlobalRoutingHelper::CalculateRoutes (); |
| 75 | |
| 76 | cout << "FIB content on node A1" << endl; |
| 77 | Ptr<ndn::Fib> fib = Names::Find<Node> ("A1")->GetObject<ndn::Fib> (); |
| 78 | for (Ptr<ndn::fib::Entry> entry = fib->Begin (); entry != fib->End (); entry = fib->Next (entry)) |
| 79 | { |
| 80 | cout << *entry << " (this is towards: "; |
| 81 | cout << Names::FindName (DynamicCast<const ndn::NetDeviceFace> (entry->FindBestCandidate (0).GetFace ())->GetNetDevice ()->GetChannel ()->GetDevice (1)->GetNode ()); |
| 82 | cout << ")" << endl; |
| 83 | } |
| 84 | |
| 85 | cout << "FIB content on node A2" << endl; |
| 86 | fib = Names::Find<Node> ("A2")->GetObject<ndn::Fib> (); |
| 87 | for (Ptr<ndn::fib::Entry> entry = fib->Begin (); entry != fib->End (); entry = fib->Next (entry)) |
| 88 | { |
| 89 | cout << *entry << " (this is towards: "; |
| 90 | cout << Names::FindName (DynamicCast<const ndn::NetDeviceFace> (entry->FindBestCandidate (0).GetFace ())->GetNetDevice ()->GetChannel ()->GetDevice (1)->GetNode ()); |
| 91 | cout << ")" << endl; |
| 92 | } |
| 93 | |
| 94 | Simulator::Stop (Seconds (20.0)); |
| 95 | Simulator::Run (); |
| 96 | Simulator::Destroy (); |
| 97 | |
| 98 | return 0; |
| 99 | } |