OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 Telum (www.telum.ru) |
| 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: Kirill Andreev <andreev@telum.ru> written after AdhocAlohaNoackIdeal
PhyHelper by Nicola Baldo <nbaldo@cttc.es> |
| 19 */ |
| 20 |
| 21 #include "lrr-device-helper.h" |
| 22 |
| 23 #include "ns3/mobility-model.h" |
| 24 #include "ns3/mac48-address.h" |
| 25 //#include "ns3/spectrum-type.h" |
| 26 #include "ns3/string.h" |
| 27 #include "ns3/names.h" |
| 28 #include "ns3/queue.h" |
| 29 |
| 30 #include "ns3/lrr-channel.h" |
| 31 #include "ns3/lrr-range-error-model.h" |
| 32 #include "ns3/lrr-phy.h" |
| 33 namespace ns3 |
| 34 { |
| 35 |
| 36 NeighborAwareDeviceHelper::NeighborAwareDeviceHelper () : |
| 37 m_txPsd (0), |
| 38 m_noisePsd (0), |
| 39 m_rxFilter (0) |
| 40 { |
| 41 // Phy, device and MAC can not be changed now: |
| 42 m_phy.SetTypeId ("ns3::lrr::Phy"); |
| 43 m_mac.SetTypeId ("ns3::lrr::CollisionFreeMacImpl"); |
| 44 m_queue.SetTypeId ("ns3::DropTailQueue"); |
| 45 m_device.SetTypeId ("ns3::lrr::NeighborAwareDevice"); |
| 46 } |
| 47 |
| 48 NeighborAwareDeviceHelper::~NeighborAwareDeviceHelper () |
| 49 { |
| 50 m_channel = 0; |
| 51 m_txPsd = 0; |
| 52 m_noisePsd = 0; |
| 53 } |
| 54 |
| 55 void |
| 56 NeighborAwareDeviceHelper::SetChannel (Ptr<lrr::NeighborAwareSpectrumChannel> ch
annel) |
| 57 { |
| 58 m_channel = channel; |
| 59 } |
| 60 |
| 61 void |
| 62 NeighborAwareDeviceHelper::SetType (std::string type, |
| 63 std::string n0, const AttributeValue &v0, |
| 64 std::string n1, const AttributeValue &v1, |
| 65 std::string n2, const AttributeValue &v2, |
| 66 std::string n3, const AttributeValue &v3, |
| 67 std::string n4, const AttributeValue &v4, |
| 68 std::string n5, const AttributeValue &v5, |
| 69 std::string n6, const AttributeValue &v6, |
| 70 std::string n7, const AttributeValue &v7) |
| 71 { |
| 72 m_mac.SetTypeId (type); |
| 73 m_mac.Set (n0, v0); |
| 74 m_mac.Set (n1, v1); |
| 75 m_mac.Set (n2, v2); |
| 76 m_mac.Set (n3, v3); |
| 77 m_mac.Set (n4, v4); |
| 78 m_mac.Set (n5, v5); |
| 79 m_mac.Set (n6, v6); |
| 80 m_mac.Set (n7, v7); |
| 81 } |
| 82 |
| 83 Ptr<lrr::NeighborAwareDevice> |
| 84 NeighborAwareDeviceHelper::CreateDevice (Ptr<Node> node, Address address) |
| 85 { |
| 86 Ptr<lrr::Phy> phy = m_phy.Create<lrr::Phy> (); |
| 87 Ptr<lrr::Mac> mac = m_mac.Create<lrr::Mac> (); |
| 88 Ptr<Queue> queue = m_queue.Create<Queue> (); |
| 89 Ptr<lrr::NeighborAwareDevice> dev = m_device.Create<lrr::NeighborAwareDevice>
(); |
| 90 |
| 91 NS_ASSERT (phy); |
| 92 NS_ASSERT (mac); |
| 93 NS_ASSERT (queue); |
| 94 NS_ASSERT (dev); |
| 95 NS_ASSERT_MSG (m_txPsd, "you forgot to call NeighborAwareDeviceHelper::SetTxPo
werSpectralDensity ()"); |
| 96 NS_ASSERT_MSG (m_noisePsd, "you forgot to call NeighborAwareDeviceHelper::SetN
oisePowerSpectralDensity ()"); |
| 97 NS_ASSERT_MSG (m_rxFilter, "you forgot to call NeighborAwareDeviceHelper::SetR
xFilter ()"); |
| 98 |
| 99 mac->SetPhy (phy); |
| 100 mac->SetQueue (queue); |
| 101 |
| 102 dev->SetMac (mac); |
| 103 dev->SetAddress (address); |
| 104 |
| 105 NS_ASSERT (node->GetObject<MobilityModel> () != 0); |
| 106 phy->SetMobility (node->GetObject<MobilityModel> ()); |
| 107 phy->SetDevice (dev); |
| 108 phy->SetRxFilter (m_rxFilter); |
| 109 phy->SetTxPowerSpectralDensity (m_txPsd); |
| 110 phy->SetNoisePowerSpectralDensity (m_noisePsd); |
| 111 phy->SetGenericPhyRxEndOkCallback (MakeCallback (&lrr::Mac::Receive, mac)); |
| 112 phy->SetErrorModel (CreateObject<lrr::RangeSpectrumErrorModel> ()); |
| 113 |
| 114 m_channel->AddRx (phy); |
| 115 node->AddDevice (dev); |
| 116 return dev; |
| 117 } |
| 118 |
| 119 void |
| 120 NeighborAwareDeviceHelper::SetTxPowerSpectralDensity (Ptr<SpectrumValue> txPsd) |
| 121 { |
| 122 m_txPsd = txPsd; |
| 123 } |
| 124 |
| 125 void |
| 126 NeighborAwareDeviceHelper::SetNoisePowerSpectralDensity (Ptr<SpectrumValue> nois
ePsd) |
| 127 { |
| 128 m_noisePsd = noisePsd; |
| 129 } |
| 130 |
| 131 void |
| 132 NeighborAwareDeviceHelper::SetRxFilter (Ptr<SpectrumValue> rxFilter) |
| 133 { |
| 134 m_rxFilter = rxFilter; |
| 135 } |
| 136 |
| 137 void |
| 138 NeighborAwareDeviceHelper::SetPhyAttribute (std::string name, const AttributeVal
ue &v) |
| 139 { |
| 140 m_phy.Set (name, v); |
| 141 } |
| 142 |
| 143 void |
| 144 NeighborAwareDeviceHelper::SetDeviceAttribute (std::string name, const Attribute
Value &v) |
| 145 { |
| 146 m_device.Set (name, v); |
| 147 } |
| 148 |
| 149 NetDeviceContainer |
| 150 NeighborAwareDeviceHelper::Install (NodeContainer c) |
| 151 { |
| 152 NetDeviceContainer retval; |
| 153 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++) |
| 154 { |
| 155 retval.Add (Install (*i)); |
| 156 } |
| 157 return retval; |
| 158 } |
| 159 |
| 160 NetDeviceContainer |
| 161 NeighborAwareDeviceHelper::Install (Ptr<Node> node) |
| 162 { |
| 163 Ptr<lrr::NeighborAwareDevice> device = CreateDevice (node, Mac48Address::Alloc
ate ()); |
| 164 return NetDeviceContainer (device); |
| 165 } |
| 166 |
| 167 NetDeviceContainer |
| 168 NeighborAwareDeviceHelper::Install (std::string nodeName) |
| 169 { |
| 170 Ptr<Node> node = Names::Find<Node> (nodeName); |
| 171 return Install (node); |
| 172 } |
| 173 |
| 174 } // namespace ns3 |
OLD | NEW |