OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2010 CTTC |
| 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: Nicola Baldo <nbaldo@cttc.es> |
| 19 */ |
| 20 #include "spectrum-helper.h" |
| 21 #include <ns3/simulator.h> |
| 22 #include <ns3/config.h> |
| 23 #include <ns3/names.h> |
| 24 #include <ns3/spectrum-propagation-loss-model.h> |
| 25 #include <ns3/propagation-delay-model.h> |
| 26 #include <ns3/spectrum-channel.h> |
| 27 #include <ns3/spectrum-phy.h> |
| 28 #include <ns3/single-model-spectrum-channel.h> |
| 29 #include <ns3/multi-model-spectrum-channel.h> |
| 30 #include <ns3/half-duplex-ideal-ofdm-phy.h> |
| 31 |
| 32 |
| 33 namespace ns3 { |
| 34 |
| 35 |
| 36 SpectrumChannelHelper |
| 37 SpectrumChannelHelper::Default (void) |
| 38 { |
| 39 SpectrumChannelHelper h; |
| 40 h.SetChannel ("ns3::SingleModelSpectrumChannel"); |
| 41 h.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); |
| 42 h.AddSpectrumPropagationLoss ("ns3::FriisSpectrumPropagationLossModel"); |
| 43 return h; |
| 44 } |
| 45 |
| 46 void |
| 47 SpectrumChannelHelper::SetChannel (std::string type, |
| 48 std::string n0, const AttributeValue &v0, |
| 49 std::string n1, const AttributeValue &v1, |
| 50 std::string n2, const AttributeValue &v2, |
| 51 std::string n3, const AttributeValue &v3, |
| 52 std::string n4, const AttributeValue &v4, |
| 53 std::string n5, const AttributeValue &v5, |
| 54 std::string n6, const AttributeValue &v6, |
| 55 std::string n7, const AttributeValue &v7) |
| 56 { |
| 57 ObjectFactory factory; |
| 58 m_channel.SetTypeId (type); |
| 59 m_channel.Set (n0, v0); |
| 60 m_channel.Set (n1, v1); |
| 61 m_channel.Set (n2, v2); |
| 62 m_channel.Set (n3, v3); |
| 63 m_channel.Set (n4, v4); |
| 64 m_channel.Set (n5, v5); |
| 65 m_channel.Set (n6, v6); |
| 66 m_channel.Set (n7, v7); |
| 67 } |
| 68 |
| 69 |
| 70 void |
| 71 SpectrumChannelHelper::AddSpectrumPropagationLoss (std::string type, |
| 72 std::string n0, const Attribu
teValue &v0, |
| 73 std::string n1, const Attribu
teValue &v1, |
| 74 std::string n2, const Attribu
teValue &v2, |
| 75 std::string n3, const Attribu
teValue &v3, |
| 76 std::string n4, const Attribu
teValue &v4, |
| 77 std::string n5, const Attribu
teValue &v5, |
| 78 std::string n6, const Attribu
teValue &v6, |
| 79 std::string n7, const Attribu
teValue &v7) |
| 80 { |
| 81 ObjectFactory factory; |
| 82 factory.SetTypeId (type); |
| 83 factory.Set (n0, v0); |
| 84 factory.Set (n1, v1); |
| 85 factory.Set (n2, v2); |
| 86 factory.Set (n3, v3); |
| 87 factory.Set (n4, v4); |
| 88 factory.Set (n5, v5); |
| 89 factory.Set (n6, v6); |
| 90 factory.Set (n7, v7); |
| 91 m_spectrumPropagationLoss.push_back (factory); |
| 92 } |
| 93 |
| 94 void |
| 95 SpectrumChannelHelper::SetPropagationDelay (std::string type, |
| 96 std::string n0, const AttributeValue
&v0, |
| 97 std::string n1, const AttributeValue
&v1, |
| 98 std::string n2, const AttributeValue
&v2, |
| 99 std::string n3, const AttributeValue
&v3, |
| 100 std::string n4, const AttributeValue
&v4, |
| 101 std::string n5, const AttributeValue
&v5, |
| 102 std::string n6, const AttributeValue
&v6, |
| 103 std::string n7, const AttributeValue
&v7) |
| 104 { |
| 105 ObjectFactory factory; |
| 106 factory.SetTypeId (type); |
| 107 factory.Set (n0, v0); |
| 108 factory.Set (n1, v1); |
| 109 factory.Set (n2, v2); |
| 110 factory.Set (n3, v3); |
| 111 factory.Set (n4, v4); |
| 112 factory.Set (n5, v5); |
| 113 factory.Set (n6, v6); |
| 114 factory.Set (n7, v7); |
| 115 m_propagationDelay = factory; |
| 116 } |
| 117 |
| 118 Ptr<SpectrumChannel> |
| 119 SpectrumChannelHelper::Create (void) const |
| 120 { |
| 121 Ptr<SpectrumChannel> channel = (m_channel.Create ())->GetObject<SpectrumChanne
l> (); |
| 122 Ptr<SpectrumPropagationLossModel> prev = 0; |
| 123 for (std::vector<ObjectFactory>::const_iterator i = m_spectrumPropagationLoss.
begin (); i != m_spectrumPropagationLoss.end (); ++i) |
| 124 { |
| 125 Ptr<SpectrumPropagationLossModel> cur = (*i).Create<SpectrumPropagationLos
sModel> (); |
| 126 if (prev == 0) |
| 127 { |
| 128 channel->AddSpectrumPropagationLossModel (cur); |
| 129 } |
| 130 else |
| 131 { |
| 132 prev->SetNext (cur); |
| 133 } |
| 134 prev = cur; |
| 135 } |
| 136 Ptr<PropagationDelayModel> delay = m_propagationDelay.Create<PropagationDelayM
odel> (); |
| 137 channel->SetPropagationDelayModel (delay); |
| 138 return channel; |
| 139 } |
| 140 |
| 141 |
| 142 |
| 143 |
| 144 |
| 145 |
| 146 void |
| 147 SpectrumPhyHelper::SetPhy (std::string type, |
| 148 std::string n0, const AttributeValue &v0, |
| 149 std::string n1, const AttributeValue &v1, |
| 150 std::string n2, const AttributeValue &v2, |
| 151 std::string n3, const AttributeValue &v3, |
| 152 std::string n4, const AttributeValue &v4, |
| 153 std::string n5, const AttributeValue &v5, |
| 154 std::string n6, const AttributeValue &v6, |
| 155 std::string n7, const AttributeValue &v7) |
| 156 { |
| 157 m_phy.SetTypeId (type); |
| 158 m_phy.Set (n0, v0); |
| 159 m_phy.Set (n1, v1); |
| 160 m_phy.Set (n2, v2); |
| 161 m_phy.Set (n3, v3); |
| 162 m_phy.Set (n4, v4); |
| 163 m_phy.Set (n5, v5); |
| 164 m_phy.Set (n6, v6); |
| 165 m_phy.Set (n7, v7); |
| 166 } |
| 167 |
| 168 |
| 169 |
| 170 void |
| 171 SpectrumPhyHelper::SetChannel (Ptr<SpectrumChannel> channel) |
| 172 { |
| 173 m_channel = channel; |
| 174 } |
| 175 |
| 176 void |
| 177 SpectrumPhyHelper::SetChannel (std::string channelName) |
| 178 { |
| 179 Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName); |
| 180 m_channel = channel; |
| 181 } |
| 182 |
| 183 void |
| 184 SpectrumPhyHelper::SetPhyAttribute (std::string name, const AttributeValue &v) |
| 185 { |
| 186 m_phy.Set (name, v); |
| 187 } |
| 188 |
| 189 |
| 190 Ptr<SpectrumPhy> |
| 191 SpectrumPhyHelper::Create (Ptr<Node> node, Ptr<NetDevice> device) const |
| 192 { |
| 193 NS_ASSERT (m_channel); |
| 194 Ptr<SpectrumPhy> phy = (m_phy.Create ())->GetObject<SpectrumPhy> (); |
| 195 phy->SetChannel (m_channel); |
| 196 phy->SetMobility (node); |
| 197 phy->SetDevice (device); |
| 198 return phy; |
| 199 } |
| 200 |
| 201 |
| 202 } // namespace ns3 |
OLD | NEW |