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