Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 1 | /* -*- 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 | #include "ns3/test.h" |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 22 | #include "ns3/ccnx-interest-header.h" |
| 23 | #include "ns3/uinteger.h" |
| 24 | #include "ns3/random-variable.h" |
| 25 | #include <limits> |
| 26 | #include "ns3/ccnx-header-helper.h" |
| 27 | #include "ns3/header.h" |
| 28 | #include "ns3/ccnx-name-components.h" |
| 29 | #include "ns3/nstime.h" |
| 30 | #include "ns3/buffer.h" |
| 31 | #include "ns3/log.h" |
| 32 | |
| 33 | #include <ctime> |
| 34 | #include <sstream> |
| 35 | |
| 36 | #include "ns3/internet-stack-helper.h" |
| 37 | #include "ns3/ipv4-list-routing-helper.h" |
| 38 | #include "ns3/ipv4-static-routing-helper.h" |
| 39 | #include "ns3/point-to-point-helper.h" |
| 40 | #include "ns3/application.h" |
| 41 | #include "ns3/ipv4-static-routing-helper.h" |
| 42 | #include "ns3/ipv4-list-routing-helper.h" |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 43 | |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 44 | #include <list> |
| 45 | |
| 46 | |
| 47 | using namespace ns3; |
| 48 | using namespace std; |
| 49 | |
| 50 | NS_LOG_COMPONENT_DEFINE ("CcnxBasicRegressionTest"); |
| 51 | |
| 52 | class BasicRegressionTest : public TestCase |
| 53 | { |
| 54 | public: |
| 55 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 56 | BasicRegressionTest (); |
| 57 | virtual ~BasicRegressionTest (); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 58 | |
| 59 | private: |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 60 | virtual void DoRun (void); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | BasicRegressionTest::BasicRegressionTest () |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 64 | : TestCase ("Basic regression test") |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 65 | { |
| 66 | } |
| 67 | |
| 68 | BasicRegressionTest::~BasicRegressionTest () |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | BasicRegressionTest::DoRun(void) |
| 74 | { |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 75 | //string input ("/Users/iliamo/ns3-abstract-ndn/ns-3.11/src/NDNabstraction/examples/simpletopology.txt"); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 77 | // Set up command line parameters used to control the experiment. |
| 78 | //CommandLine cmd; |
| 79 | //cmd.AddValue ("input", "Name of the input file.", |
| 80 | // input); |
| 81 | //cmd.Parse (argc, argv); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 82 | |
| 83 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 84 | // ------------------------------------------------------------ |
| 85 | // -- Read topology data. |
| 86 | // -------------------------------------------- |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 87 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 88 | // string input = NS_TEST_SOURCEDIR; |
| 89 | // input += "/testtopology.txt"; |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 90 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 91 | // Ptr<AnnotatedTopologyReader> reader = CreateObject<AnnotatedTopologyReader> (); |
| 92 | // reader->SetFileName (input); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 94 | // NodeContainer nodes; |
| 95 | // if (reader != 0) |
| 96 | // { |
| 97 | // nodes = reader->Read (); |
| 98 | // } |
| 99 | // else |
| 100 | // { |
| 101 | // NS_TEST_ASSERT_MSG_EQ (true, false, "file not found"); |
| 102 | // } |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 103 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 104 | // NS_TEST_ASSERT_MSG_EQ (7, reader->LinksSize (), "link count is wrong"); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 105 | |
| 106 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 107 | // // ------------------------------------------------------------ |
| 108 | // // -- Create nodes and network stacks |
| 109 | // // -------------------------------------------- |
| 110 | // NS_LOG_INFO ("creating internet stack"); |
| 111 | // InternetStackHelper stack; |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 112 | |
| 113 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 114 | // //routing |
| 115 | // /*Ipv4StaticRoutingHelper staticRouting; |
| 116 | // Ipv4ListRoutingHelper listRH; |
| 117 | // listRH.Add (staticRouting, 0); |
| 118 | // stack.SetRoutingHelper (listRH); // has effect on the next Install () |
| 119 | // stack.Install (nodes); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 120 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 121 | // NS_LOG_INFO ("creating ip4 addresses"); |
| 122 | // Ipv4AddressHelper address; |
| 123 | // address.SetBase ("10.0.0.0", "255.255.255.252");*/ |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 124 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 125 | // int totlinks = reader->LinksSize (); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 126 | |
| 127 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 128 | // /// applying settings |
| 129 | // NS_LOG_INFO ("creating node containers"); |
| 130 | // NodeContainer* nc = new NodeContainer[totlinks]; |
| 131 | // TopologyReader::ConstLinksIterator iter; |
| 132 | // int i = 0; |
| 133 | // for ( iter = reader->LinksBegin (); iter != reader->LinksEnd (); iter++, i++ ) |
| 134 | // { |
| 135 | // nc[i] = NodeContainer (iter->GetFromNode (), iter->GetToNode ()); |
| 136 | // } |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 137 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 138 | // NetDeviceContainer* ndc = new NetDeviceContainer[totlinks]; |
| 139 | // reader->ApplySettings(ndc,nc); |
| 140 | // /// settings applied |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 141 | |
| 142 | |
| 143 | |
| 144 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 145 | // it creates little subnets, one for each couple of nodes. |
| 146 | /*NS_LOG_INFO ("creating ipv4 interfaces"); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 147 | Ipv4InterfaceContainer* ipic = new Ipv4InterfaceContainer[totlinks]; |
| 148 | for (int i = 0; i < totlinks; i++) |
| 149 | { |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 150 | ipic[i] = address.Assign (ndc[i]); |
| 151 | address.NewNetwork (); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | // ------------------------------------------------------------ |
| 155 | // -- Run the simulation |
| 156 | // -------------------------------------------- |
| 157 | NS_LOG_INFO ("Run Simulation."); |
| 158 | Simulator::Stop (Seconds (20)); |
| 159 | Simulator::Run (); |
| 160 | Simulator::Destroy (); |
| 161 | |
| 162 | delete[] ipic; |
| 163 | delete[] ndc; |
| 164 | delete[] nc; |
| 165 | |
| 166 | NS_LOG_INFO ("Done."); |
| 167 | |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 168 | */ |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | class BasicRegressionTestSuite : public TestSuite |
| 172 | { |
| 173 | public: |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 174 | BasicRegressionTestSuite (); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | BasicRegressionTestSuite::BasicRegressionTestSuite () |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 178 | : TestSuite ("ccnx-basic-regression-test-suite", UNIT) |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 179 | { |
Alexander Afanasyev | 864522f | 2012-05-31 13:33:57 -0700 | [diff] [blame] | 180 | SetDataDir (NS_TEST_SOURCEDIR); |
| 181 | AddTestCase (new BasicRegressionTest); |
Ilya Moiseenko | 9d25869 | 2011-09-01 11:20:11 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static BasicRegressionTestSuite suite; |