Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 UCLA |
| 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 | |
| 21 | #include "ns3/network-module.h" |
| 22 | #include "ns3/core-module.h" |
| 23 | #include "ns3/internet-module.h" |
| 24 | #include "ns3/ipv4-global-routing-helper.h" |
| 25 | #include "ns3/point-to-point-grid.h" |
| 26 | #include "ns3/ipv4-global-routing-helper.h" |
Alexander Afanasyev | beceb36 | 2011-11-02 16:54:12 -0700 | [diff] [blame] | 27 | #include "ns3/applications-module.h" |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 28 | #include "ns3/NDNabstraction-module.h" |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 29 | |
| 30 | using namespace ns3; |
| 31 | |
| 32 | NS_LOG_COMPONENT_DEFINE ("SimpleRouting"); |
| 33 | |
| 34 | // Parameters |
| 35 | uint32_t nNodes = 2; |
| 36 | uint32_t stopTime = 60; |
| 37 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 38 | // void TestDisable (Ptr<Node> node) |
| 39 | // { |
| 40 | // NS_LOG_FUNCTION (node->GetId ()); |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 42 | // Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> (); |
| 43 | // NS_ASSERT_MSG (ipv4 != 0, "ipv4 should not be null"); |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 44 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 45 | // // The thing I didn't know is that interface status (isUp/isDown) and device status (isLinkUp) are two totally different things. It is possible to set interface up and down, but there is not an easy way to alter status of device. This similar to reality: it is possible to programmatically disable interface, but to actually disable a link one needs to physically cut the cable |
| 46 | // ipv4->SetDown (2); |
| 47 | // } |
| 48 | |
| 49 | void PrintCcnxFib (Ptr<Node> node, Ptr<OutputStreamWrapper> wrapper) |
| 50 | { |
| 51 | Ptr<CcnxFib> fib = node->GetObject<CcnxFib> (); |
| 52 | *wrapper->GetStream () << *fib; |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | int main (int argc, char *argv[]) |
| 56 | { |
| 57 | CommandLine cmd; |
| 58 | cmd.AddValue ("nNodes", "Number of Router nodes", nNodes); |
| 59 | cmd.AddValue ("stopTime", "Time to stop(seconds)", stopTime); |
| 60 | cmd.Parse (argc, argv); |
| 61 | |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 62 | InternetStackHelper stack; |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 63 | CcnxStackHelper ccnxHelper; |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 64 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 65 | Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingOrderedNexthops"); |
| 66 | // Ipv4GlobalRoutingHelper ipv4RoutingHelper ("ns3::Ipv4GlobalRoutingUnorderedNexthops"); |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 67 | stack.SetRoutingHelper (ipv4RoutingHelper); |
| 68 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 69 | PointToPointHelper p2p; |
| 70 | |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 71 | PointToPointGridHelper grid (nNodes, nNodes, p2p); |
Alexander Afanasyev | 3875a4b | 2011-11-10 11:55:53 -0800 | [diff] [blame] | 72 | grid.BoundingBox(100,100,270,270); |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 73 | grid.InstallStack (stack); |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 74 | |
| 75 | grid.AssignIpv4Addresses ( |
| 76 | Ipv4AddressHelper("10.1.0.0", "255.255.255.0"), |
| 77 | Ipv4AddressHelper("10.2.0.0", "255.255.255.0") |
| 78 | ); |
| 79 | |
Alexander Afanasyev | 3875a4b | 2011-11-10 11:55:53 -0800 | [diff] [blame] | 80 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 81 | ccnxHelper.InstallAll (); |
| 82 | ccnxHelper.InstallFakeGlobalRoutes (); |
| 83 | // ccnxHelper.InstallRouteTo (grid.GetNode (0,0)); |
| 84 | ccnxHelper.InstallRoutesToAll (); |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 85 | |
| 86 | // Trace routing tables |
| 87 | Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("routes.log", std::ios::out); |
Alexander Afanasyev | beceb36 | 2011-11-02 16:54:12 -0700 | [diff] [blame] | 88 | *routingStream->GetStream () << "Node (1,1)\n"; |
| 89 | ipv4RoutingHelper.PrintRoutingTableAt (Seconds (20), grid.GetNode (1,1), routingStream); |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 52e9aa9 | 2011-11-15 20:23:20 -0800 | [diff] [blame] | 91 | Simulator::ScheduleWithContext (grid.GetNode (1,1)->GetId (), |
| 92 | Seconds (20.0), PrintCcnxFib, grid.GetNode (1,1), routingStream); |
| 93 | |
Alexander Afanasyev | 5b43386 | 2011-10-31 15:25:07 -0700 | [diff] [blame] | 94 | Simulator::Stop (Seconds(160.0)); |
| 95 | Simulator::Run (); |
| 96 | Simulator::Destroy (); |
| 97 | |
| 98 | NS_LOG_INFO ("End of experiment"); |
| 99 | |
| 100 | return 0; |
| 101 | } |