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 POINT_TO_POINT_HELPER_H 00021 #define POINT_TO_POINT_HELPER_H 00022 00023 #include "ns3/object-factory.h" 00024 #include "ns3/net-device-container.h" 00025 #include "ns3/node-container.h" 00026 #include "ns3/deprecated.h" 00027 #include <string> 00028 00029 namespace ns3 { 00030 00031 class Queue; 00032 class NetDevice; 00033 class Node; 00034 class PcapWriter; 00035 00036 /** 00037 * \brief build a set of PointToPointNetDevice objects 00038 */ 00039 class PointToPointHelper 00040 { 00041 public: 00042 // by default, create queues of type DropTailQueue. 00043 PointToPointHelper (); 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 * PointToPointNetDevice created through PointToPointHelper::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 name the name of the attribute to set 00067 * \param value the value of the attribute to set 00068 * 00069 * Set these attributes on each ns3::PointToPointNetDevice created 00070 * by PointToPointHelper::Install 00071 */ 00072 void SetDeviceAttribute (std::string name, const AttributeValue &value); 00073 /** 00074 * \param name the name of the attribute to set 00075 * \param value the value of the attribute to set 00076 * 00077 * Set these attribute on each ns3::PointToPointChannel created 00078 * by PointToPointHelper::Install 00079 */ 00080 void SetChannelAttribute (std::string name, const AttributeValue &value); 00081 00082 void SetDeviceParameter (std::string name, const AttributeValue &value) NS_DEPRECATED; 00083 void SetChannelParameter (std::string name, const AttributeValue &value) NS_DEPRECATED; 00084 00085 /** 00086 * \param filename filename prefix to use for pcap files. 00087 * \param nodeid the id of the node to generate pcap output for. 00088 * \param deviceid the id of the device to generate pcap output for. 00089 * 00090 * Generate a pcap file which contains the link-level data observed 00091 * by the specified deviceid within the specified nodeid. The pcap 00092 * data is stored in the file prefix-nodeid-deviceid.pcap. 00093 * 00094 * This method should be invoked after the network topology has 00095 * been fully constructed. 00096 */ 00097 static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid); 00098 /** 00099 * \param filename filename prefix to use for pcap files. 00100 * \param d container of devices of type ns3::PointToPointNetDevice 00101 * 00102 * Enable pcap output on each input device which is of the 00103 * ns3::PointToPointNetDevice type. 00104 */ 00105 static void EnablePcap (std::string filename, NetDeviceContainer d); 00106 /** 00107 * \param filename filename prefix to use for pcap files. 00108 * \param n container of nodes. 00109 * 00110 * Enable pcap output on each device which is of the 00111 * ns3::PointToPointNetDevice type and which is located in one of the 00112 * input nodes. 00113 */ 00114 static void EnablePcap (std::string filename, NodeContainer n); 00115 /** 00116 * \param filename filename prefix to use for pcap files. 00117 * 00118 * Enable pcap output on each device which is of the 00119 * ns3::PointToPointNetDevice type 00120 */ 00121 static void EnablePcapAll (std::string filename); 00122 00123 /** 00124 * \param os output stream 00125 * \param nodeid the id of the node to generate ascii output for. 00126 * \param deviceid the id of the device to generate ascii output for. 00127 * 00128 * Enable ascii output on the specified deviceid within the 00129 * specified nodeid if it is of type ns3::PointToPointNetDevice and dump 00130 * that to the specified stdc++ output stream. 00131 */ 00132 static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid); 00133 /** 00134 * \param os output stream 00135 * \param d device container 00136 * 00137 * Enable ascii output on each device which is of the 00138 * ns3::PointToPointNetDevice type and which is located in the input 00139 * device container and dump that to the specified 00140 * stdc++ output stream. 00141 */ 00142 static void EnableAscii (std::ostream &os, NetDeviceContainer d); 00143 /** 00144 * \param os output stream 00145 * \param n node container 00146 * 00147 * Enable ascii output on each device which is of the 00148 * ns3::PointToPointNetDevice type and which is located in one 00149 * of the input node and dump that to the specified 00150 * stdc++ output stream. 00151 */ 00152 static void EnableAscii (std::ostream &os, NodeContainer n); 00153 /** 00154 * \param os output stream 00155 * 00156 * Enable ascii output on each device which is of the 00157 * ns3::PointToPointNetDevice type and dump that to the specified 00158 * stdc++ output stream. 00159 */ 00160 static void EnableAsciiAll (std::ostream &os); 00161 00162 /** 00163 * \param c a set of nodes 00164 * 00165 * This method creates a ns3::PointToPointChannel with the 00166 * attributes configured by PointToPointHelper::SetChannelAttribute, 00167 * then, for each node in the input container, we create a 00168 * ns3::PointToPointNetDevice with the requested attributes, 00169 * a queue for this ns3::NetDevice, and associate the resulting 00170 * ns3::NetDevice with the ns3::Node and ns3::PointToPointChannel. 00171 */ 00172 NetDeviceContainer Install (NodeContainer c); 00173 00174 /** 00175 * \param a first node 00176 * \param b second node 00177 * 00178 * Saves you from having to construct a temporary NodeContainer. 00179 */ 00180 NetDeviceContainer Install (Ptr<Node> a, Ptr<Node> b); 00181 00182 /** 00183 * \brief Make a star network topology. 00184 * 00185 * Given a pointer to a node that will become the hub of the star, and a 00186 * NodeContainer containing pointers to the nodes that will become the 00187 * spokes; we construct point to point net devices on the hub (corresponding 00188 * to the spokes) and store them in the hubDevices NetDeviceContainer. We 00189 * add a net device to each spoke node and store them in the spokeDevices 00190 * NetDeviceContainer. A point-to-point channel is created for each spoke. 00191 * 00192 * The ordering of the devices in the hubDevices container is according to 00193 * the order of the spokes container -- that is, hubDevices[0] will be the 00194 * net device used on the hub that talks to spokes[0]. the container entry 00195 * spokeDevices[0] will have the device that hubDevices[0] talks to -- those 00196 * two devices are the ones that connect hub to spokes[0]. 00197 * 00198 * \param hub The central node of the star network 00199 * \param spokes A NodeContainer of the nodes that will be the spoke (leaf) 00200 * nodes 00201 * \param hubDevices A NetDeviceContainer that will be filled with pointers 00202 * to the point-to-point net devices created on the hub. 00203 * \param spokeDevices A NetDeviceContainer that will be filled with pointers 00204 * to the point-to-point net devices created on each of 00205 * the spokes. 00206 */ 00207 void InstallStar (Ptr<Node> hub, NodeContainer spokes, 00208 NetDeviceContainer& hubDevices, NetDeviceContainer& spokeDevices); 00209 00210 private: 00211 void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue); 00212 void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device); 00213 static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet); 00214 static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet); 00215 static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00216 static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00217 static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00218 static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00219 ObjectFactory m_queueFactory; 00220 ObjectFactory m_channelFactory; 00221 ObjectFactory m_deviceFactory; 00222 }; 00223 00224 00225 } // namespace ns3 00226 00227 #endif /* POINT_TO_POINT_HELPER_H */