LEFT | RIGHT |
(no file at all) | |
| 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2009,2010 University of Washington |
| 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: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu> |
| 19 */ |
| 20 |
| 21 #include "wireless-module-utility-helper.h" |
| 22 #include "ns3/log.h" |
| 23 #include "ns3/config.h" |
| 24 #include "ns3/simulator.h" |
| 25 #include "ns3/names.h" |
| 26 #include "ns3/pointer.h" |
| 27 |
| 28 NS_LOG_COMPONENT_DEFINE ("WirelessModuleUtilityHelper"); |
| 29 |
| 30 namespace ns3 { |
| 31 |
| 32 WirelessModuleUtilityHelper::WirelessModuleUtilityHelper () |
| 33 { |
| 34 m_headerInclusionList.clear (); |
| 35 m_headerExclusionList.clear (); |
| 36 m_rssMeasurementCallback.Nullify (); |
| 37 m_wirelessUtility.SetTypeId ("ns3::WirelessModuleUtility"); |
| 38 } |
| 39 |
| 40 WirelessModuleUtilityHelper::~WirelessModuleUtilityHelper () |
| 41 { |
| 42 } |
| 43 |
| 44 void |
| 45 WirelessModuleUtilityHelper::SetWirelessModuleUtilityType (std::string type) |
| 46 { |
| 47 NS_LOG_FUNCTION (this); |
| 48 m_wirelessUtility.SetTypeId (type); |
| 49 } |
| 50 |
| 51 std::string |
| 52 WirelessModuleUtilityHelper::GetWirelessModuleUtilityType (void) const |
| 53 { |
| 54 NS_LOG_FUNCTION (this); |
| 55 return m_wirelessUtility.GetTypeId ().GetName (); |
| 56 } |
| 57 |
| 58 void |
| 59 WirelessModuleUtilityHelper::Set (std::string name, const AttributeValue &v) |
| 60 { |
| 61 NS_LOG_FUNCTION (this); |
| 62 m_wirelessUtility.Set (name, v); |
| 63 } |
| 64 |
| 65 void |
| 66 WirelessModuleUtilityHelper::SetInclusionList (std::vector<std::string> list) |
| 67 { |
| 68 NS_LOG_FUNCTION (this); |
| 69 std::vector<std::string>::iterator i; |
| 70 for (i = list.begin (); i != list.end (); i++) |
| 71 { |
| 72 m_headerInclusionList.push_back (*i); |
| 73 } |
| 74 } |
| 75 |
| 76 void |
| 77 WirelessModuleUtilityHelper::SetExclusionList (std::vector<std::string> list) |
| 78 { |
| 79 NS_LOG_FUNCTION (this); |
| 80 std::vector<std::string>::iterator i; |
| 81 for (i = list.begin (); i != list.end (); i++) |
| 82 { |
| 83 m_headerExclusionList.push_back (*i); |
| 84 } |
| 85 } |
| 86 |
| 87 void |
| 88 WirelessModuleUtilityHelper::SetRssMeasurementCallback (Callback<double> RssCall
back) |
| 89 { |
| 90 NS_LOG_FUNCTION (this); |
| 91 m_rssMeasurementCallback = RssCallback; |
| 92 } |
| 93 |
| 94 WirelessModuleUtilityContainer |
| 95 WirelessModuleUtilityHelper::Install (Ptr<Node> node) const |
| 96 { |
| 97 NS_LOG_FUNCTION (this << node); |
| 98 return Install (NodeContainer (node)); |
| 99 } |
| 100 |
| 101 WirelessModuleUtilityContainer |
| 102 WirelessModuleUtilityHelper::Install (NodeContainer c) const |
| 103 { |
| 104 NS_LOG_FUNCTION (this); |
| 105 WirelessModuleUtilityContainer container; |
| 106 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 107 { |
| 108 Ptr<WirelessModuleUtility> utility = DoInstall (*i); |
| 109 container.Add (utility); |
| 110 } |
| 111 return container; |
| 112 } |
| 113 |
| 114 WirelessModuleUtilityContainer |
| 115 WirelessModuleUtilityHelper::Install (std::string nodeName) const |
| 116 { |
| 117 Ptr<Node> node = Names::Find<Node> (nodeName); |
| 118 return Install (node); |
| 119 } |
| 120 |
| 121 WirelessModuleUtilityContainer |
| 122 WirelessModuleUtilityHelper::InstallAll (void) |
| 123 { |
| 124 return Install (NodeContainer::GetGlobal ()); |
| 125 } |
| 126 |
| 127 /* |
| 128 * Private function starts here |
| 129 */ |
| 130 |
| 131 Ptr<WirelessModuleUtility> |
| 132 WirelessModuleUtilityHelper::DoInstall (Ptr<Node> node) const |
| 133 { |
| 134 NS_LOG_FUNCTION (this << node); |
| 135 |
| 136 Ptr<WirelessModuleUtility> util = node->GetObject<WirelessModuleUtility> (); |
| 137 if (util == NULL) // check if utility object already exist on node |
| 138 { |
| 139 util = m_wirelessUtility.Create<WirelessModuleUtility> (); |
| 140 if (util == NULL) |
| 141 { |
| 142 NS_FATAL_ERROR ("Can not create requested wireless utility object:" << |
| 143 m_wirelessUtility.GetTypeId ().GetName ()); |
| 144 return NULL; |
| 145 } |
| 146 // setup |
| 147 util->SetInclusionList (m_headerInclusionList); |
| 148 util->SetExclusionList (m_headerExclusionList); |
| 149 util->SetRssMeasurementCallback (m_rssMeasurementCallback); |
| 150 // aggregate utility object to node |
| 151 node->AggregateObject (util); |
| 152 } |
| 153 else |
| 154 { |
| 155 NS_FATAL_ERROR ("WirelessModuleUtilityHelper:Utility already installed!"); |
| 156 return NULL; |
| 157 } |
| 158 |
| 159 return util; |
| 160 } |
| 161 |
| 162 } // namespace ns3 |
LEFT | RIGHT |