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 00021 #ifndef INTERNET_STACK_HELPER_H 00022 #define INTERNET_STACK_HELPER_H 00023 00024 #include "node-container.h" 00025 #include "net-device-container.h" 00026 #include "ns3/pcap-writer.h" 00027 #include "ns3/packet.h" 00028 00029 namespace ns3 { 00030 00031 /** 00032 * \brief aggregate IP/TCP/UDP functionality to existing Nodes. 00033 */ 00034 class InternetStackHelper 00035 { 00036 public: 00037 InternetStackHelper(void); 00038 00039 /** 00040 * Aggregate implementations of the ns3::Ipv4, ns3::Udp, and ns3::Tcp classes 00041 * onto the provided node. This method will assert if called on a node that 00042 * already has an Ipv4 object aggregated to it. 00043 * 00044 * \param node The node on which to install the stack. 00045 */ 00046 void Install (Ptr<Node> node) const; 00047 00048 /** 00049 * For each node in the input container, aggregate implementations of the 00050 * ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes. The program will assert 00051 * if this method is called on a container with a node that already has 00052 * an Ipv4 object aggregated to it. 00053 * 00054 * \param c NodeContainer that holds the set of nodes on which to install the 00055 * new stacks. 00056 */ 00057 void Install (NodeContainer c) const; 00058 00059 /** 00060 * \brief Enable or disable use of the Network Simulation Cradle stack. 00061 * 00062 * Give the NSC stack a shared library file name to use when creating the 00063 * statck implementation. By providing a non-empty string as a parameter, you 00064 * select the NSC version of the stack. By providing an empty string, you 00065 * select the ns-3 default version. 00066 * 00067 * \param soname name of the shared library with the nsc tcp stack 00068 * to use, e.g. 'liblinux2.6.26.so'. 00069 */ 00070 void SetNscStack(std::string soname); 00071 00072 /** 00073 * \param os output stream 00074 * \param n node container 00075 * 00076 * Enable ascii output on these drop traces, for each node in the NodeContainer.. 00077 * /NodeList/[i]/$ns3ArpL3Protocol/Drop 00078 * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop 00079 */ 00080 static void EnableAscii (std::ostream &os, NodeContainer n); 00081 00082 /** 00083 * \param os output stream 00084 * 00085 * Enable ascii output on these drop traces, for all nodes. 00086 * /NodeList/[i]/$ns3ArpL3Protocol/Drop 00087 * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop 00088 */ 00089 static void EnableAsciiAll (std::ostream &os); 00090 00091 /** 00092 * Enable pcap output on each protocol instance which is of the 00093 * ns3::Ipv4L3Protocol type. Both Tx and Rx events will be logged. 00094 * 00095 * \param filename filename prefix to use for pcap files. 00096 * 00097 * \warning If you perform multiple simulations in a single script, 00098 * each iteration of the simulation will result in the trace files 00099 * being overwritten. We don't attempt to anticipate what a user 00100 * might actually want to do, so we leave it up to them. If you want 00101 * to save any particular data, do so manually at inter-simulation 00102 * time. 00103 */ 00104 static void EnablePcapAll (std::string filename); 00105 00106 private: 00107 std::string m_nscLibrary; 00108 static void Cleanup (void); 00109 static void LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId); 00110 static void LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId); 00111 static Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t interfaceId); 00112 struct Trace { 00113 uint32_t nodeId; 00114 uint32_t interfaceId; 00115 Ptr<PcapWriter> writer; 00116 }; 00117 static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet); 00118 static std::string m_pcapBaseFilename; 00119 static uint32_t GetNodeIndex (std::string context); 00120 static std::vector<Trace> m_traces; 00121 }; 00122 00123 } // namespace ns3 00124 00125 #endif /* INTERNET_STACK_HELPER_H */