OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2017 University of Padova |
| 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: Davide Magrin <magrinda@dei.unipd.it> |
| 19 */ |
| 20 |
| 21 #include "ns3/periodic-sender-helper.h" |
| 22 #include "ns3/random-variable-stream.h" |
| 23 #include "ns3/periodic-sender.h" |
| 24 #include "ns3/double.h" |
| 25 #include "ns3/string.h" |
| 26 #include "ns3/trace-source-accessor.h" |
| 27 #include "ns3/simulator.h" |
| 28 #include "ns3/log.h" |
| 29 |
| 30 namespace ns3 { |
| 31 |
| 32 NS_LOG_COMPONENT_DEFINE ("PeriodicSenderHelper"); |
| 33 |
| 34 PeriodicSenderHelper::PeriodicSenderHelper () |
| 35 { |
| 36 m_factory.SetTypeId ("ns3::PeriodicSender"); |
| 37 |
| 38 m_factory.Set ("PacketSize", StringValue |
| 39 ("ns3::ParetoRandomVariable[Bound=10|Shape=2.5]")); |
| 40 |
| 41 m_initialDelay = CreateObject<UniformRandomVariable> (); |
| 42 m_initialDelay->SetAttribute ("Min", DoubleValue (0)); |
| 43 |
| 44 m_intervalProb = CreateObject<UniformRandomVariable> (); |
| 45 m_intervalProb->SetAttribute ("Min", DoubleValue (0)); |
| 46 m_intervalProb->SetAttribute ("Max", DoubleValue (1)); |
| 47 } |
| 48 |
| 49 PeriodicSenderHelper::~PeriodicSenderHelper () |
| 50 { |
| 51 } |
| 52 |
| 53 void |
| 54 PeriodicSenderHelper::SetAttribute (std::string name, const AttributeValue &valu
e) |
| 55 { |
| 56 m_factory.Set (name, value); |
| 57 } |
| 58 |
| 59 ApplicationContainer |
| 60 PeriodicSenderHelper::Install (Ptr<Node> node) const |
| 61 { |
| 62 return ApplicationContainer (InstallPriv (node)); |
| 63 } |
| 64 |
| 65 ApplicationContainer |
| 66 PeriodicSenderHelper::Install (NodeContainer c) const |
| 67 { |
| 68 ApplicationContainer apps; |
| 69 for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 70 { |
| 71 apps.Add (InstallPriv (*i)); |
| 72 } |
| 73 |
| 74 return apps; |
| 75 } |
| 76 |
| 77 Ptr<Application> |
| 78 PeriodicSenderHelper::InstallPriv (Ptr<Node> node) const |
| 79 { |
| 80 NS_LOG_FUNCTION (this << node); |
| 81 |
| 82 Ptr<PeriodicSender> app = m_factory.Create<PeriodicSender> (); |
| 83 |
| 84 Time interval; |
| 85 if (m_period == Seconds (0)) |
| 86 { |
| 87 double intervalProb = m_intervalProb->GetValue (); |
| 88 NS_LOG_DEBUG ("IntervalProb = " << intervalProb); |
| 89 |
| 90 // Based on TR 45.820 |
| 91 if (intervalProb < 0.4) |
| 92 { |
| 93 interval = Days (1); |
| 94 } |
| 95 else if (0.4 <= intervalProb && intervalProb < 0.8) |
| 96 { |
| 97 interval = Hours (2); |
| 98 } |
| 99 else if (0.8 <= intervalProb && intervalProb < 0.95) |
| 100 { |
| 101 interval = Hours (1); |
| 102 } |
| 103 else interval = Minutes (30); |
| 104 } |
| 105 else interval = m_period; |
| 106 |
| 107 app->SetInterval (interval); |
| 108 NS_LOG_DEBUG ("Created an application with interval = " << |
| 109 interval.GetHours () << " hours"); |
| 110 |
| 111 app->SetInitialDelay (Seconds (m_initialDelay->GetValue (0, interval.GetSecond
s ()))); |
| 112 |
| 113 app->SetNode (node); |
| 114 node->AddApplication (app); |
| 115 |
| 116 return app; |
| 117 } |
| 118 |
| 119 void |
| 120 PeriodicSenderHelper::SetPeriod (Time period) |
| 121 { |
| 122 m_period = period; |
| 123 } |
| 124 } // namespace ns3 |
OLD | NEW |