src/uan/examples/uan-cw-example.cc
author Vedran Miletić <rivanvx@gmail.com>
Sat, 01 Sep 2012 20:57:21 +0200
changeset 9063 32755d0516f4
parent 8980 0202e0b04282
child 9840 ffe6c110c1ad
permissions -rw-r--r--
Bug 1237 - code cleanups related to includes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7256
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     2
/*
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     3
 * Copyright (c) 2009 University of Washington
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     4
 *
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as 
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     8
 *
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    13
 *
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    17
 *
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    18
 * Author: Leonard Tracy <lentracy@gmail.com>
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    19
 */
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    20
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    21
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    22
/**
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    23
 * \file uan-cw-example.cc
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    24
 * \ingroup uan
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    25
 * 
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    26
 * This example showcases the "CW-MAC" described in System Design Considerations for Undersea Networks
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    27
 * article in the IEEE Journal on Selected Areas of Communications 2008 by Nathan Parrish, Leonard Tracy
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    28
 * and Sumit Roy.  The MAC protocol is implemented in the class UanMacCw.  CW-MAC is similar in nature
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    29
 * to the IEEE 802.11 DCF with a constant backoff window.  It requires two parameters to be set,
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    30
 * the slot time and the contention window size.  The contention window size is the backoff window
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    31
 * size in slots, and the slot time is the duration of each slot.  These parameters should be set
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    32
 * according to the overall network size, internode spacing and the number of nodes in the network.
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    33
 * 
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    34
 * This example deploys nodes randomly (according to RNG seed of course) in a finite square region with
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    35
 * the X and Y coordinates of the nodes distributed uniformly.  The CW parameter is varied throughout
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    36
 * the simulation in order to show the variation in throughput with respect to changes in CW.
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    37
 */
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    38
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    39
#include "uan-cw-example.h"
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    40
#include "ns3/core-module.h"
6823
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6478
diff changeset
    41
#include "ns3/network-module.h"
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    42
#include "ns3/mobility-module.h"
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6865
diff changeset
    43
#include "ns3/tools-module.h"
6847
138f00c56381 Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents: 6823
diff changeset
    44
#include "ns3/applications-module.h"
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    45
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    46
#include <fstream>
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    47
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    48
using namespace ns3;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    49
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7130
diff changeset
    50
NS_LOG_COMPONENT_DEFINE ("UanCwExample");
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    51
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    52
Experiment::Experiment () 
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    53
  : m_numNodes (15),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    54
    m_dataRate (80),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    55
    m_depth (70),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    56
    m_boundary (500),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    57
    m_packetSize (32),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    58
    m_bytesTotal (0),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    59
    m_cwMin (10),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    60
    m_cwMax (400),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    61
    m_cwStep (10),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    62
    m_avgs (3),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    63
    m_slotTime (Seconds (0.2)),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    64
    m_simTime (Seconds (1000)),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    65
    m_gnudatfile ("uan-cw-example.gpl"),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    66
    m_asciitracefile ("uan-cw-example.asc"),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    67
    m_bhCfgFile ("uan-apps/dat/default.cfg")
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    68
{
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    69
}
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    70
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    71
void
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    72
Experiment::ResetData ()
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    73
{
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    74
  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << "  Resetting data");
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    75
  m_throughputs.push_back (m_bytesTotal * 8.0 / m_simTime.GetSeconds ());
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    76
  m_bytesTotal = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    77
}
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    78
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    79
void
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    80
Experiment::IncrementCw (uint32_t cw)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    81
{
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    82
  NS_ASSERT (m_throughputs.size () == m_avgs);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    83
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    84
  double avgThroughput = 0.0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    85
  for (uint32_t i=0; i<m_avgs; i++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    86
    {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    87
      avgThroughput += m_throughputs[i];
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    88
    }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    89
  avgThroughput /= m_avgs;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    90
  m_data.Add (cw, avgThroughput);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    91
  m_throughputs.clear ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    92
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    93
  Config::Set ("/NodeList/*/DeviceList/*/Mac/CW", UintegerValue (cw + m_cwStep));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    94
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    95
  SeedManager::SetRun (SeedManager::GetRun () + 1);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    96
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    97
  NS_LOG_DEBUG ("Average for cw=" << cw << " over " << m_avgs << " runs: " << avgThroughput);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    98
}
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    99
void
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   100
Experiment::UpdatePositions (NodeContainer &nodes)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   101
{
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   102
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   103
  NS_LOG_DEBUG (Simulator::Now ().GetSeconds () << " Updating positions");
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   104
  NodeContainer::Iterator it = nodes.Begin ();
8980
0202e0b04282 Replace src/uan usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8966
diff changeset
   105
  Ptr<UniformRandomVariable> uv = CreateObject<UniformRandomVariable> ();
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   106
  for (; it != nodes.End (); it++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   107
    {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   108
      Ptr<MobilityModel> mp = (*it)->GetObject<MobilityModel> ();
8980
0202e0b04282 Replace src/uan usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8966
diff changeset
   109
      mp->SetPosition (Vector (uv->GetValue (0, m_boundary), uv->GetValue (0, m_boundary), 70.0));
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   110
    }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   111
}
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   112
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   113
void
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   114
Experiment::ReceivePacket (Ptr<Socket> socket)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   115
{
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   116
  Ptr<Packet> packet;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   117
7736
d3c1e0eab341 Add parenthesis in while (packet = socket->Recv ()) to make clang++ (LLVM) happy
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7385
diff changeset
   118
  while ((packet = socket->Recv ()))
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   119
    {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   120
      m_bytesTotal += packet->GetSize ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   121
    }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   122
  packet = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   123
}
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   124
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   125
Gnuplot2dDataset
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   126
Experiment::Run (UanHelper &uan)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   127
{
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   128
  uan.SetMac ("ns3::UanMacCw", "CW", UintegerValue (m_cwMin), "SlotTime", TimeValue (m_slotTime));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   129
  NodeContainer nc = NodeContainer ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   130
  NodeContainer sink = NodeContainer ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   131
  nc.Create (m_numNodes);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   132
  sink.Create (1);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   133
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   134
  PacketSocketHelper socketHelper;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   135
  socketHelper.Install (nc);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   136
  socketHelper.Install (sink);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   137
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   138
#ifdef UAN_PROP_BH_INSTALLED
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   139
  Ptr<UanPropModelBh> prop = CreateObjectWithAttributes<UanPropModelBh> ("ConfigFile", StringValue ("exbhconfig.cfg"));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   140
#else 
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   141
  Ptr<UanPropModelIdeal> prop = CreateObjectWithAttributes<UanPropModelIdeal> ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   142
#endif //UAN_PROP_BH_INSTALLED
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   143
  Ptr<UanChannel> channel = CreateObjectWithAttributes<UanChannel> ("PropagationModel", PointerValue (prop));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   144
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   145
  //Create net device and nodes with UanHelper
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   146
  NetDeviceContainer devices = uan.Install (nc, channel);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   147
  NetDeviceContainer sinkdev = uan.Install (sink, channel);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   148
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   149
  MobilityHelper mobility;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   150
  Ptr<ListPositionAllocator> pos = CreateObject<ListPositionAllocator> ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   151
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   152
  {
8980
0202e0b04282 Replace src/uan usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8966
diff changeset
   153
    Ptr<UniformRandomVariable> urv = CreateObject<UniformRandomVariable> ();
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   154
    pos->Add (Vector (m_boundary / 2.0, m_boundary / 2.0, m_depth));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   155
    double rsum = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   156
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   157
    double minr = 2 * m_boundary;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   158
    for (uint32_t i = 0; i < m_numNodes; i++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   159
      {
8980
0202e0b04282 Replace src/uan usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8966
diff changeset
   160
        double x = urv->GetValue (0, m_boundary);
0202e0b04282 Replace src/uan usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 8966
diff changeset
   161
        double y = urv->GetValue (0, m_boundary);
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8980
diff changeset
   162
        double newr = std::sqrt ((x - m_boundary / 2.0) * (x - m_boundary / 2.0)
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   163
                            + (y - m_boundary / 2.0) * (y - m_boundary / 2.0));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   164
        rsum += newr;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   165
        minr = std::min (minr, newr);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   166
        pos->Add (Vector (x, y, m_depth));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   167
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   168
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   169
    NS_LOG_DEBUG ("Mean range from gateway: " << rsum / m_numNodes
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   170
                                              << "    min. range " << minr);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   171
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   172
    mobility.SetPositionAllocator (pos);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   173
    mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   174
    mobility.Install (sink);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   175
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   176
    NS_LOG_DEBUG ("Position of sink: "
7130
139a7e376f0a UAN module code style cleanup
Andrea Sacco
parents: 6941
diff changeset
   177
                  << sink.Get (0)->GetObject<MobilityModel> ()->GetPosition ());
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   178
    mobility.Install (nc);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   179
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   180
    PacketSocketAddress socket;
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7130
diff changeset
   181
    socket.SetSingleDevice (sinkdev.Get (0)->GetIfIndex ());
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7130
diff changeset
   182
    socket.SetPhysicalAddress (sinkdev.Get (0)->GetAddress ());
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   183
    socket.SetProtocol (0);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   184
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   185
    OnOffHelper app ("ns3::PacketSocketFactory", Address (socket));
8966
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7736
diff changeset
   186
    app.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
060dba23e9bb Replace src/application usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7736
diff changeset
   187
    app.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   188
    app.SetAttribute ("DataRate", DataRateValue (m_dataRate));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   189
    app.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   190
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   191
    ApplicationContainer apps = app.Install (nc);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   192
    apps.Start (Seconds (0.5));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   193
    Time nextEvent = Seconds (0.5);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   194
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   195
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   196
    for (uint32_t cw = m_cwMin; cw <= m_cwMax; cw += m_cwStep)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   197
      {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   198
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   199
        for (uint32_t an = 0; an < m_avgs; an++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   200
          {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   201
            nextEvent += m_simTime;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   202
            Simulator::Schedule (nextEvent, &Experiment::ResetData, this);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   203
            Simulator::Schedule (nextEvent, &Experiment::UpdatePositions, this, nc);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   204
          }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   205
        Simulator::Schedule (nextEvent, &Experiment::IncrementCw, this, cw);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   206
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   207
    apps.Stop (nextEvent + m_simTime);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   208
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   209
    Ptr<Node> sinkNode = sink.Get (0);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   210
    TypeId psfid = TypeId::LookupByName ("ns3::PacketSocketFactory");
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   211
    if (sinkNode->GetObject<SocketFactory> (psfid) == 0)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   212
      {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   213
        Ptr<PacketSocketFactory> psf = CreateObject<PacketSocketFactory> ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   214
        sinkNode->AggregateObject (psf);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   215
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   216
    Ptr<Socket> sinkSocket = Socket::CreateSocket (sinkNode, psfid);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   217
    sinkSocket->Bind (socket);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   218
    sinkSocket->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   219
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   220
    m_bytesTotal = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   221
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   222
    std::ofstream ascii (m_asciitracefile.c_str ());
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   223
    if (!ascii.is_open ())
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   224
      {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   225
        NS_FATAL_ERROR ("Could not open ascii trace file: "
7130
139a7e376f0a UAN module code style cleanup
Andrea Sacco
parents: 6941
diff changeset
   226
                        << m_asciitracefile);
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   227
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   228
    uan.EnableAsciiAll (ascii);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   229
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   230
    Simulator::Run ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   231
    sinkNode = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   232
    sinkSocket = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   233
    pos = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   234
    channel = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   235
    prop = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   236
    for (uint32_t i=0; i < nc.GetN (); i++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   237
      {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   238
        nc.Get (i) = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   239
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   240
    for (uint32_t i=0; i < sink.GetN (); i++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   241
      {
7130
139a7e376f0a UAN module code style cleanup
Andrea Sacco
parents: 6941
diff changeset
   242
        sink.Get (i) = 0;
6478
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   243
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   244
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   245
    for (uint32_t i=0; i < devices.GetN (); i++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   246
      {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   247
        devices.Get (i) = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   248
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   249
    for (uint32_t i=0; i < sinkdev.GetN (); i++)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   250
      {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   251
        sinkdev.Get (i) = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   252
      }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   253
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   254
    Simulator::Destroy ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   255
    return m_data;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   256
  }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   257
}
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   258
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   259
int
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   260
main (int argc, char **argv)
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   261
{
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   262
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   263
  LogComponentEnable ("UanCwExample", LOG_LEVEL_ALL);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   264
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   265
  Experiment exp;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   266
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   267
  std::string gnudatfile ("cwexpgnuout.dat");
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   268
  std::string perModel = "ns3::UanPhyPerGenDefault";
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   269
  std::string sinrModel = "ns3::UanPhyCalcSinrDefault";
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   270
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   271
  CommandLine cmd;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   272
  cmd.AddValue ("NumNodes", "Number of transmitting nodes", exp.m_numNodes);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   273
  cmd.AddValue ("Depth", "Depth of transmitting and sink nodes", exp.m_depth);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   274
  cmd.AddValue ("RegionSize", "Size of boundary in meters", exp.m_boundary);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   275
  cmd.AddValue ("PacketSize", "Generated packet size in bytes", exp.m_packetSize);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   276
  cmd.AddValue ("DataRate", "DataRate in bps", exp.m_dataRate);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   277
  cmd.AddValue ("CwMin", "Min CW to simulate", exp.m_cwMin);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   278
  cmd.AddValue ("CwMax", "Max CW to simulate", exp.m_cwMax);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   279
  cmd.AddValue ("SlotTime", "Slot time duration", exp.m_slotTime);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   280
  cmd.AddValue ("Averages", "Number of topologies to test for each cw point", exp.m_avgs);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   281
  cmd.AddValue ("GnuFile", "Name for GNU Plot output", exp.m_gnudatfile);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   282
  cmd.AddValue ("PerModel", "PER model name", perModel);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   283
  cmd.AddValue ("SinrModel", "SINR model name", sinrModel);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   284
  cmd.Parse (argc, argv);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   285
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   286
  ObjectFactory obf;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   287
  obf.SetTypeId (perModel);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   288
  Ptr<UanPhyPer> per = obf.Create<UanPhyPer> ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   289
  obf.SetTypeId (sinrModel);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   290
  Ptr<UanPhyCalcSinr> sinr = obf.Create<UanPhyCalcSinr> ();
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   291
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   292
  UanHelper uan;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   293
  UanTxMode mode;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   294
  mode = UanTxModeFactory::CreateMode (UanTxMode::FSK, exp.m_dataRate,
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   295
                                       exp.m_dataRate, 12000,
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   296
                                       exp.m_dataRate, 2,
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   297
                                       "Default mode");
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   298
  UanModesList myModes;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   299
  myModes.AppendMode (mode);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   300
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   301
  uan.SetPhy ("ns3::UanPhyGen",
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   302
              "PerModel", PointerValue (per),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   303
              "SinrModel", PointerValue (sinr),
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   304
              "SupportedModes", UanModesListValue (myModes));
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   305
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   306
  Gnuplot gp;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   307
  Gnuplot2dDataset ds;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   308
  ds = exp.Run (uan);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   309
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   310
  gp.AddDataset (ds);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   311
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   312
  std::ofstream of (exp.m_gnudatfile.c_str ());
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   313
  if (!of.is_open ())
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   314
    {
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   315
      NS_FATAL_ERROR ("Can not open GNU Plot outfile: " << exp.m_gnudatfile);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   316
    }
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   317
  gp.GenerateOutput (of);
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   318
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   319
  per = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   320
  sinr = 0;
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   321
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   322
}
b401db8531f5 Bug 970 - move UAN over to new directory structure
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   323