blob: 6416c1f6a296256c8c5b451cdeb84145a5f39b35 [file] [log] [blame]
Alexander Afanasyev5b433862011-10-31 15:25:07 -07001/* -*- 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"
27
28using namespace ns3;
29
30NS_LOG_COMPONENT_DEFINE ("SimpleRouting");
31
32// Parameters
33uint32_t nNodes = 2;
34uint32_t stopTime = 60;
35
36void TestDisable (Ptr<Node> node)
37{
38 NS_LOG_FUNCTION (node->GetId ());
39
40 Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
41 NS_ASSERT_MSG (ipv4 != 0, "ipv4 should not be null");
42
43 // 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
44 ipv4->SetDown (2);
45}
46
47int main (int argc, char *argv[])
48{
49 CommandLine cmd;
50 cmd.AddValue ("nNodes", "Number of Router nodes", nNodes);
51 cmd.AddValue ("stopTime", "Time to stop(seconds)", stopTime);
52 cmd.Parse (argc, argv);
53
54 PointToPointHelper p2p;
55 InternetStackHelper stack;
56
57 Ipv4GlobalRoutingHelper ipv4RoutingHelper;
58 // Ptr<Ipv4RoutingHelper> ipv4RoutingHelper = stack.GetRoutingHelper ();
59 stack.SetRoutingHelper (ipv4RoutingHelper);
60
61 PointToPointGridHelper grid (nNodes, nNodes, p2p);
62 grid.InstallStack (stack);
63
64 // // Create router nodes, initialize routing database and set up the routing
65 // // tables in the nodes.
66 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
67
68 grid.AssignIpv4Addresses (
69 Ipv4AddressHelper("10.1.0.0", "255.255.255.0"),
70 Ipv4AddressHelper("10.2.0.0", "255.255.255.0")
71 );
72
73 // apps.Stop (Seconds(150.0));
74
75 Simulator::ScheduleWithContext (grid.GetNode (0,0)->GetId (),
76 Seconds (80.0), TestDisable, grid.GetNode (0,0));
77
78 // Trace routing tables
79 Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("routes.log", std::ios::out);
80 ipv4RoutingHelper.PrintRoutingTableAllEvery (Seconds (10), routingStream);
81
82 Simulator::Stop (Seconds(160.0));
83 Simulator::Run ();
84 Simulator::Destroy ();
85
86 NS_LOG_INFO ("End of experiment");
87
88 return 0;
89}