00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 University of Washington 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 00019 #ifndef EMU_HELPER_H 00020 #define EMU_HELPER_H 00021 00022 #include <string> 00023 #include <ostream> 00024 #include "ns3/attribute.h" 00025 #include "ns3/object-factory.h" 00026 #include "ns3/net-device-container.h" 00027 #include "ns3/node-container.h" 00028 #include "ns3/emu-net-device.h" 00029 00030 namespace ns3 { 00031 00032 class Packet; 00033 class PcapWriter; 00034 00035 /** 00036 * \brief build a set of EmuNetDevice objects 00037 */ 00038 class EmuHelper 00039 { 00040 public: 00041 EmuHelper (); 00042 00043 /** 00044 * \param type the type of queue 00045 * \param n1 the name of the attribute to set on the queue 00046 * \param v1 the value of the attribute to set on the queue 00047 * \param n2 the name of the attribute to set on the queue 00048 * \param v2 the value of the attribute to set on the queue 00049 * \param n3 the name of the attribute to set on the queue 00050 * \param v3 the value of the attribute to set on the queue 00051 * \param n4 the name of the attribute to set on the queue 00052 * \param v4 the value of the attribute to set on the queue 00053 * 00054 * Set the type of queue to create and associated to each 00055 * EmuNetDevice created through EmuHelper::Install. 00056 */ 00057 void SetQueue (std::string type, 00058 std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (), 00059 std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (), 00060 std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (), 00061 std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ()); 00062 00063 /** 00064 * \param n1 the name of the attribute to set 00065 * \param v1 the value of the attribute to set 00066 * 00067 * Set these attributes on each ns3::EmuNetDevice created 00068 * by EmuHelper::Install 00069 */ 00070 void SetAttribute (std::string n1, const AttributeValue &v1); 00071 00072 /** 00073 * \param filename filename prefix to use for pcap files. 00074 * \param nodeid the id of the node to generate pcap output for. 00075 * \param deviceid the id of the device to generate pcap output for. 00076 * 00077 * Generate a pcap file which contains the link-level data observed 00078 * by the specified deviceid within the specified nodeid. The pcap 00079 * data is stored in the file prefix-nodeid-deviceid.pcap. 00080 * 00081 * This method should be invoked after the network topology has 00082 * been fully constructed. 00083 */ 00084 static void EnablePcap (std::string filename, uint32_t nodeid, 00085 uint32_t deviceid); 00086 00087 /** 00088 * \param filename filename prefix to use for pcap files. 00089 * \param d container of devices of type ns3::EmuNetDevice 00090 * 00091 * Enable pcap output on each input device which is of the 00092 * ns3::EmuNetDevice type. 00093 */ 00094 static void EnablePcap (std::string filename, NetDeviceContainer d); 00095 00096 /** 00097 * \param filename filename prefix to use for pcap files. 00098 * \param n container of nodes. 00099 * 00100 * Enable pcap output on each device which is of the 00101 * ns3::EmuNetDevice type and which is located in one of the 00102 * input nodes. 00103 */ 00104 static void EnablePcap (std::string filename, NodeContainer n); 00105 00106 /** 00107 * \param filename filename prefix to use for pcap files. 00108 * 00109 * Enable pcap output on each device which is of the 00110 * ns3::EmuNetDevice type 00111 */ 00112 static void EnablePcapAll (std::string filename); 00113 00114 /** 00115 * \param os output stream 00116 * \param nodeid the id of the node to generate ascii output for. 00117 * \param deviceid the id of the device to generate ascii output for. 00118 * 00119 * Enable ascii output on the specified deviceid within the 00120 * specified nodeid if it is of type ns3::EmuNetDevice and dump 00121 * that to the specified stdc++ output stream. 00122 */ 00123 static void EnableAscii (std::ostream &os, uint32_t nodeid, 00124 uint32_t deviceid); 00125 00126 /** 00127 * \param os output stream 00128 * \param d device container 00129 * 00130 * Enable ascii output on each device which is of the 00131 * ns3::EmuNetDevice type and which is located in the input 00132 * device container and dump that to the specified 00133 * stdc++ output stream. 00134 */ 00135 static void EnableAscii (std::ostream &os, NetDeviceContainer d); 00136 00137 /** 00138 * \param os output stream 00139 * \param n node container 00140 * 00141 * Enable ascii output on each device which is of the 00142 * ns3::EmuNetDevice type and which is located in one 00143 * of the input node and dump that to the specified 00144 * stdc++ output stream. 00145 */ 00146 static void EnableAscii (std::ostream &os, NodeContainer n); 00147 00148 /** 00149 * \param os output stream 00150 * 00151 * Enable ascii output on each device which is of the 00152 * ns3::EmuNetDevice type and dump that to the specified 00153 * stdc++ output stream. 00154 */ 00155 static void EnableAsciiAll (std::ostream &os); 00156 00157 /** 00158 * This method creates an ns3::EmuNetDevice with the attributes configured by 00159 * EmuHelper::SetDeviceAttribute and then adds the device to the node. 00160 * 00161 * \param node The node to install the device in 00162 * \returns A containter holding the added net device. 00163 */ 00164 NetDeviceContainer Install (Ptr<Node> node) const; 00165 00166 /** 00167 * For each Ptr<node> in the provided container this method creates an 00168 * ns3::EmuNetDevice (with the attributes configured by 00169 * EmuHelper::SetDeviceAttribute); adds the device to the node. 00170 * 00171 * \param c The NodeContainer holding the nodes to be changed. 00172 * \returns A containter holding the added net devices. 00173 */ 00174 NetDeviceContainer Install (const NodeContainer &c) const; 00175 00176 private: 00177 Ptr<NetDevice> InstallPriv (Ptr<Node> node) const; 00178 static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet); 00179 static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet); 00180 static void AsciiEnqueueEvent (std::ostream *os, std::string path, 00181 Ptr<const Packet> packet); 00182 static void AsciiDequeueEvent (std::ostream *os, std::string path, 00183 Ptr<const Packet> packet); 00184 static void AsciiDropEvent (std::ostream *os, std::string path, 00185 Ptr<const Packet> packet); 00186 static void AsciiRxEvent (std::ostream *os, std::string path, 00187 Ptr<const Packet> packet); 00188 00189 ObjectFactory m_queueFactory; 00190 ObjectFactory m_deviceFactory; 00191 }; 00192 00193 00194 } // namespace ns3 00195 00196 #endif /* EMU_HELPER_H */