00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef CSMA_HELPER_H 00021 #define CSMA_HELPER_H 00022 00023 #include <string> 00024 #include <ostream> 00025 #include "ns3/attribute.h" 00026 #include "ns3/object-factory.h" 00027 #include "ns3/net-device-container.h" 00028 #include "ns3/node-container.h" 00029 #include "ns3/csma-channel.h" 00030 #include "ns3/deprecated.h" 00031 00032 namespace ns3 { 00033 00034 class Packet; 00035 class PcapWriter; 00036 00037 /** 00038 * \brief build a set of CsmaNetDevice objects 00039 */ 00040 class CsmaHelper 00041 { 00042 public: 00043 CsmaHelper (); 00044 00045 /** 00046 * \param type the type of queue 00047 * \param n1 the name of the attribute to set on the queue 00048 * \param v1 the value of the attribute to set on the queue 00049 * \param n2 the name of the attribute to set on the queue 00050 * \param v2 the value of the attribute to set on the queue 00051 * \param n3 the name of the attribute to set on the queue 00052 * \param v3 the value of the attribute to set on the queue 00053 * \param n4 the name of the attribute to set on the queue 00054 * \param v4 the value of the attribute to set on the queue 00055 * 00056 * Set the type of queue to create and associated to each 00057 * CsmaNetDevice created through CsmaHelper::Install. 00058 */ 00059 void SetQueue (std::string type, 00060 std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), 00061 std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), 00062 std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), 00063 std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); 00064 00065 /** 00066 * \param n1 the name of the attribute to set 00067 * \param v1 the value of the attribute to set 00068 * 00069 * Set these attributes on each ns3::CsmaNetDevice created 00070 * by CsmaHelper::Install 00071 */ 00072 void SetDeviceAttribute (std::string n1, const AttributeValue &v1); 00073 00074 /** 00075 * \param n1 the name of the attribute to set 00076 * \param v1 the value of the attribute to set 00077 * 00078 * Set these attributes on each ns3::CsmaChannel created 00079 * by CsmaHelper::Install 00080 */ 00081 void SetChannelAttribute (std::string n1, const AttributeValue &v1); 00082 00083 void SetDeviceParameter (std::string n1, const AttributeValue &v1) NS_DEPRECATED; 00084 void SetChannelParameter (std::string n1, const AttributeValue &v1) NS_DEPRECATED; 00085 00086 /** 00087 * \param filename filename prefix to use for pcap files. 00088 * \param nodeid the id of the node to generate pcap output for. 00089 * \param deviceid the id of the device to generate pcap output for. 00090 * 00091 * Generate a pcap file which contains the link-level data observed 00092 * by the specified deviceid within the specified nodeid. The pcap 00093 * data is stored in the file prefix-nodeid-deviceid.pcap. 00094 * 00095 * This method should be invoked after the network topology has 00096 * been fully constructed. 00097 */ 00098 static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid); 00099 /** 00100 * \param filename filename prefix to use for pcap files. 00101 * \param d container of devices of type ns3::CsmaNetDevice 00102 * 00103 * Enable pcap output on each input device which is of the 00104 * ns3::CsmaNetDevice type. 00105 */ 00106 static void EnablePcap (std::string filename, NetDeviceContainer d); 00107 /** 00108 * \param filename filename prefix to use for pcap files. 00109 * \param n container of nodes. 00110 * 00111 * Enable pcap output on each device which is of the 00112 * ns3::CsmaNetDevice type and which is located in one of the 00113 * input nodes. 00114 */ 00115 static void EnablePcap (std::string filename, NodeContainer n); 00116 /** 00117 * \param filename filename prefix to use for pcap files. 00118 * 00119 * Enable pcap output on each device which is of the 00120 * ns3::CsmaNetDevice type 00121 */ 00122 static void EnablePcapAll (std::string filename); 00123 00124 /** 00125 * \param os output stream 00126 * \param nodeid the id of the node to generate ascii output for. 00127 * \param deviceid the id of the device to generate ascii output for. 00128 * 00129 * Enable ascii output on the specified deviceid within the 00130 * specified nodeid if it is of type ns3::CsmaNetDevice and dump 00131 * that to the specified stdc++ output stream. 00132 */ 00133 static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid); 00134 /** 00135 * \param os output stream 00136 * \param d device container 00137 * 00138 * Enable ascii output on each device which is of the 00139 * ns3::CsmaNetDevice type and which is located in the input 00140 * device container and dump that to the specified 00141 * stdc++ output stream. 00142 */ 00143 static void EnableAscii (std::ostream &os, NetDeviceContainer d); 00144 /** 00145 * \param os output stream 00146 * \param n node container 00147 * 00148 * Enable ascii output on each device which is of the 00149 * ns3::CsmaNetDevice type and which is located in one 00150 * of the input node and dump that to the specified 00151 * stdc++ output stream. 00152 */ 00153 static void EnableAscii (std::ostream &os, NodeContainer n); 00154 /** 00155 * \param os output stream 00156 * 00157 * Enable ascii output on each device which is of the 00158 * ns3::CsmaNetDevice type and dump that to the specified 00159 * stdc++ output stream. 00160 */ 00161 static void EnableAsciiAll (std::ostream &os); 00162 00163 /** 00164 * This method creates an ns3::CsmaChannel with the attributes configured by 00165 * CsmaHelper::SetChannelAttribute, an ns3::CsmaNetDevice with the attributes 00166 * configured by CsmaHelper::SetDeviceAttribute and then adds the device 00167 * to the node and attaches the channel to the device. 00168 * 00169 * \param node The node to install the device in 00170 * \returns A containter holding the added net device. 00171 */ 00172 NetDeviceContainer Install (Ptr<Node> node) const; 00173 00174 /** 00175 * This method creates an ns3::CsmaNetDevice with the attributes configured by 00176 * CsmaHelper::SetDeviceAttribute and then adds the device to the node and 00177 * attaches the provided channel to the device. 00178 * 00179 * \param node The node to install the device in 00180 * \param channel The chanel to attach to the device. 00181 * \returns A containter holding the added net device. 00182 */ 00183 NetDeviceContainer Install (Ptr<Node> node, Ptr<CsmaChannel> channel) const; 00184 00185 /** 00186 * This method creates an ns3::CsmaChannel with the attributes configured by 00187 * CsmaHelper::SetChannelAttribute. For each Ptr<node> in the provided 00188 * container: it creates an ns3::CsmaNetDevice (with the attributes 00189 * configured by CsmaHelper::SetDeviceAttribute); adds the device to the 00190 * node; and attaches the channel to the device. 00191 * 00192 * \param c The NodeContainer holding the nodes to be changed. 00193 * \returns A containter holding the added net devices. 00194 */ 00195 NetDeviceContainer Install (const NodeContainer &c) const; 00196 00197 /** 00198 * For each Ptr<node> in the provided container, this method creates an 00199 * ns3::CsmaNetDevice (with the attributes configured by 00200 * CsmaHelper::SetDeviceAttribute); adds the device to the node; and attaches 00201 * the provided channel to the device. 00202 * 00203 * \param c The NodeContainer holding the nodes to be changed. 00204 * \param channel The channel to attach to the devices. 00205 * \returns A containter holding the added net devices. 00206 */ 00207 NetDeviceContainer Install (const NodeContainer &c, Ptr<CsmaChannel> channel) const; 00208 00209 /** 00210 * \brief Make a star network topology. 00211 * 00212 * Given a pointer to a node that will become the hub of the star, and a 00213 * NodeContainer containing pointers to the nodes that will become the 00214 * spokes; we construct CSMA net devices on the hub (corresponding to the 00215 * spokes) and store them in the hubDevices NetDeviceContainer. We add a 00216 * net device to each spoke node and store them in the spokeDevices 00217 * NetDeviceContainer. A CSMA is created for each spoke. 00218 * 00219 * Usually when one thinks of a star network, one thinks of point-to-point 00220 * links. We're just using a single pair of devices on a multi-point-to-point 00221 * network "drops" as the link. You are free to add any number of other 00222 * devices on the link if you want. 00223 * 00224 * The ordering of the devices in the hubDevices container is according to 00225 * the order of the spokes container -- that is, hubDevices[0] will be the 00226 * net device used on the hub that talks to spokes[0]. the container entry 00227 * spokeDevices[0] will have the device that hubDevices[0] talks to -- those 00228 * two devices are the ones that connect hub to spokes[0]. 00229 * 00230 * \param hub The central node of the star network 00231 * \param spokes A NodeContainer of the nodes that will be the spoke (leaf) 00232 * nodes 00233 * \param hubDevices A NetDeviceContainer that will be filled with pointers 00234 * to the point-to-point net devices created on the hub. 00235 * \param spokeDevices A NetDeviceContainer that will be filled with pointers 00236 * to the point-to-point net devices created on each of 00237 * the spokes. 00238 */ 00239 void InstallStar (Ptr<Node> hub, NodeContainer spokes, 00240 NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices); 00241 00242 private: 00243 Ptr<NetDevice> InstallPriv (Ptr<Node> node, Ptr<CsmaChannel> channel) const; 00244 00245 static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet); 00246 static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet); 00247 static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00248 static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00249 static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00250 static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00251 ObjectFactory m_queueFactory; 00252 ObjectFactory m_deviceFactory; 00253 ObjectFactory m_channelFactory; 00254 }; 00255 00256 00257 } // namespace ns3 00258 00259 #endif /* CSMA_HELPER_H */