src/helper/internet-stack-helper.h
author Tom Henderson <tomh@tomh.org>
Fri, 07 Nov 2008 06:54:21 -0800
changeset 3863 4222173d1e6d
parent 3848 affd0834debc
child 4140 6bbf05bf4826
permissions -rw-r--r--
Add an InternetStackHelper method to do ascii tracing on drop events
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2833
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     2
/*
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     3
 * Copyright (c) 2008 INRIA
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     4
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     7
 * published by the Free Software Foundation;
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     8
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    12
 * GNU General Public License for more details.
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    13
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    14
 * You should have received a copy of the GNU General Public License
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    15
 * along with this program; if not, write to the Free Software
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    17
 *
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
f3474fd850b2 add missing license headers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2709
diff changeset
    19
 */
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    20
2708
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#ifndef INTERNET_STACK_HELPER_H
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#define INTERNET_STACK_HELPER_H
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include "node-container.h"
2845
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    25
#include "net-device-container.h"
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    26
#include "ns3/pcap-writer.h"
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    27
#include "ns3/packet.h"
2708
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
namespace ns3 {
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
/**
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    32
 * \brief aggregate IP/TCP/UDP functionality to existing Nodes.
2708
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
 */
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
class InternetStackHelper
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
{
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
public:
3579
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
    37
  InternetStackHelper(void);
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
    38
2709
eecedcae731d doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2708
diff changeset
    39
  /**
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    40
   * Aggregate implementations of the ns3::Ipv4, ns3::Udp, and ns3::Tcp classes
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    41
   * onto the provided node.  This method will assert if called on a node that 
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    42
   * already has an Ipv4 object aggregated to it.
2995
b72805b3ca69 Align helper API use of Install()
Tom Henderson <tomh@tomh.org>
parents: 2887
diff changeset
    43
   * 
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    44
   * \param node The node on which to install the stack.
2709
eecedcae731d doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2708
diff changeset
    45
   */
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    46
  void Install (Ptr<Node> node) const;
2845
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    47
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    48
  /**
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    49
   * For each node in the input container, aggregate implementations of the 
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    50
   * ns3::Ipv4, ns3::Udp, and, ns3::Tcp classes.  The program will assert 
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    51
   * if this method is called on a container with a node that already has
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    52
   * an Ipv4 object aggregated to it.
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    53
   * 
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    54
   * \param c NodeContainer that holds the set of nodes on which to install the
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    55
   * new stacks.
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    56
   */
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    57
  void Install (NodeContainer c) const;
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    58
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    59
  /**
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    60
   * \brief Enable or disable use of the Network Simulation Cradle stack.  
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    61
   *
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    62
   * Give the NSC stack a shared library file name to use when creating the 
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    63
   * statck implementation.  By providing a non-empty string as a parameter, you
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    64
   * select the NSC version of the stack.  By providing an empty string, you 
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    65
   * select the ns-3 default version.
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    66
   *
3579
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
    67
   * \param soname name of the shared library with the nsc tcp stack
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    68
   * to use, e.g. 'liblinux2.6.26.so'.
3579
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
    69
   */
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
    70
  void SetNscStack(std::string soname);
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
    71
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
    72
  /**
3863
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    73
   * \param os output stream
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    74
   * \param n node container
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    75
   *
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    76
   * Enable ascii output on these drop traces, for each node in the NodeContainer..
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    77
   * /NodeList/[i]/$ns3ArpL3Protocol/Drop 
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    78
   * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop 
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    79
   */
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    80
  static void EnableAscii (std::ostream &os, NodeContainer n);
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    81
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    82
  /**
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    83
   * \param os output stream
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    84
   *
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    85
   * Enable ascii output on these drop traces, for all nodes.
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    86
   * /NodeList/[i]/$ns3ArpL3Protocol/Drop 
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    87
   * /NodeList/[i]/$ns3Ipv4L3Protocol/Drop 
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    88
   */
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    89
  static void EnableAsciiAll (std::ostream &os);
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    90
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
    91
  /**
2845
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    92
   * Enable pcap output on each protocol instance which is of the
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    93
   * ns3::Ipv4L3Protocol type.  Both Tx and Rx events will be logged.
3009
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
    94
   *
3848
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    95
   * \param filename filename prefix to use for pcap files.
affd0834debc address bug 393 (need to overload Install methods for python)
Craig Dowell <craigdo@ee.washington.edu>
parents: 3579
diff changeset
    96
   *
3009
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
    97
   * \warning If you perform multiple simulations in a single script,
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
    98
   * each iteration of the simulation will result in the trace files
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
    99
   * being overwritten.  We don't attempt to anticipate what a user
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
   100
   * might actually want to do, so we leave it up to them.  If you want
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
   101
   * to save any particular data, do so manually at inter-simulation 
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
   102
   * time.
2845
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   103
   */
2996
a83b94e277d4 EnablePcap()->EnablePcapAll(); EnableAscii()->EnableAsciiAll()
Tom Henderson <tomh@tomh.org>
parents: 2995
diff changeset
   104
  static void EnablePcapAll (std::string filename);
2845
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   105
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   106
private:
3579
9e5eaef3e082 nsc: enable network simulation cradle
Florian Westphal <fw@strlen.de>
parents: 3009
diff changeset
   107
  std::string m_nscLibrary;
3009
db5fab391eac bug 170
Craig Dowell <craigdo@ee.washington.edu>
parents: 2996
diff changeset
   108
  static void Cleanup (void);
2845
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   109
  static void LogRxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   110
  static void LogTxIp (std::string context, Ptr<const Packet> packet, uint32_t deviceId);
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   111
  static Ptr<PcapWriter> GetStream (uint32_t nodeId, uint32_t interfaceId);
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   112
  struct Trace {
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   113
    uint32_t nodeId;
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   114
    uint32_t interfaceId;
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   115
    Ptr<PcapWriter> writer;
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   116
  };
3863
4222173d1e6d Add an InternetStackHelper method to do ascii tracing on drop events
Tom Henderson <tomh@tomh.org>
parents: 3848
diff changeset
   117
  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
2845
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   118
  static std::string m_pcapBaseFilename;
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   119
  static uint32_t GetNodeIndex (std::string context);
2398826af6b4 Add IP layer tracing helpers to InternetStackHelper
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   120
  static std::vector<Trace> m_traces;
2708
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
};
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
} // namespace ns3
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
83cc896e501c InternetStackHelper.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
#endif /* INTERNET_STACK_HELPER_H */