1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2008 INRIA 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 19 */ 20 #ifndef ON_OFF_HELPER_H 21 #define ON_OFF_HELPER_H 22 23 #include <stdint.h> 24 #include <string> 25 #include "ns3/object-factory.h" 26 #include "ns3/address.h" 27 #include "ns3/attribute.h" 28 #include "ns3/net-device.h" 29 #include "ns3/node-container.h" 30 #include "ns3/application-container.h" 31 #include "ns3/onoff-application.h" 32 33 namespace ns3 { 34 35 class DataRate; 36 37 /** 38 * \ingroup onoff 39 * \brief A helper to make it easier to instantiate an ns3::OnOffApplication 40 * on a set of nodes. 41 */ 42 class OnOffHelper 43 { 44 public: 45 /** 46 * Create an OnOffHelper to make it easier to work with OnOffApplications 47 * 48 * \param protocol the name of the protocol to use to send traffic 49 * by the applications. This string identifies the socket 50 * factory type used to create sockets for the applications. 51 * A typical value would be ns3::UdpSocketFactory. 52 * \param address the address of the remote node to send traffic 53 * to. 54 */ 55 OnOffHelper (std::string protocol, Address address); 56 57 /** 58 * Helper function used to set the underlying application attributes. 59 * 60 * \param name the name of the application attribute to set 61 * \param value the value of the application attribute to set 62 */ 63 void SetAttribute (std::string name, const AttributeValue &value); 64 65 /** 66 * Helper function to set a constant rate source. Equivalent to 67 * setting the attributes OnTime to constant 1000 seconds, OffTime to 68 * constant 0 seconds, and the DataRate and PacketSize set accordingly 69 * 70 * \param dataRate DataRate object for the sending rate 71 * \param packetSize size in bytes of the packet payloads generated 72 */ 73 void SetConstantRate (DataRate dataRate, uint32_t packetSize = 512); 74 75 /** 76 * Install an ns3::OnOffApplication on each node of the input container 77 * configured with all the attributes set with SetAttribute. 78 * 79 * \param c NodeContainer of the set of nodes on which an OnOffApplication 80 * will be installed. 81 * \returns Container of Ptr to the applications installed. 82 */ 83 ApplicationContainer Install (NodeContainer c) const; 84 85 /** 86 * Install an ns3::OnOffApplication on the node configured with all the 87 * attributes set with SetAttribute. 88 * 89 * \param node The node on which an OnOffApplication will be installed. 90 * \returns Container of Ptr to the applications installed. 91 */ 92 ApplicationContainer Install (Ptr<Node> node) const; 93 94 /** 95 * Install an ns3::OnOffApplication on the node configured with all the 96 * attributes set with SetAttribute. 97 * 98 * \param nodeName The node on which an OnOffApplication will be installed. 99 * \returns Container of Ptr to the applications installed. 100 */ 101 ApplicationContainer Install (std::string nodeName) const; 102 103 /** 104 * Assign a fixed random variable stream number to the random variables 105 * used by this model. Return the number of streams (possibly zero) that 106 * have been assigned. The Install() method should have previously been 107 * called by the user. 108 * 109 * \param stream first stream index to use 110 * \param c NodeContainer of the set of nodes for which the OnOffApplication 111 * should be modified to use a fixed stream 112 * \return the number of stream indices assigned by this helper 113 */ 114 int64_t AssignStreams (NodeContainer c, int64_t stream); 115 116 private: 117 /** 118 * Install an ns3::OnOffApplication on the node configured with all the 119 * attributes set with SetAttribute. 120 * 121 * \param node The node on which an OnOffApplication will be installed. 122 * \returns Ptr to the application installed. 123 */ 124 Ptr<Application> InstallPriv (Ptr<Node> node) const; 125 126 ObjectFactory m_factory; //!< Object factory. 127 }; 128 129 } // namespace ns3 130 131 #endif /* ON_OFF_HELPER_H */ 132 133