src/internet-stack/nsc-tcp-l4-protocol.cc
author Tom Henderson <tomh@tomh.org>
Thu, 28 May 2009 21:37:25 -0700
changeset 4472 e20a31541404
parent 4375 db81fdcb06e7
child 4669 8aaa5e83939e
permissions -rw-r--r--
src/ and utils/ changes for IPv4 routing rework
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     2
/*
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     6
 *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    10
 * GNU General Public License for more details.
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    11
 *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    15
 *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    16
 * based on earlier integration work by Tom Henderson and Sam Jansen.
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    17
 * 2008 Florian Westphal <fw@strlen.de>
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    18
 */
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    19
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    20
#include "ns3/assert.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    21
#include "ns3/log.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    22
#include "ns3/nstime.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    23
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    24
#include "ns3/packet.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    25
#include "ns3/node.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    26
#include "ns3/ipv4-route.h"
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    27
4283
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    28
#include "ns3/object-vector.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    29
#include "ns3/string.h"
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    30
#include "tcp-header.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    31
#include "ipv4-end-point-demux.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    32
#include "ipv4-end-point.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    33
#include "ipv4-l3-protocol.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    34
#include "nsc-tcp-l4-protocol.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    35
#include "nsc-sysctl.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    36
#include "nsc-tcp-socket-factory-impl.h"
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    37
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    38
#include "tcp-typedefs.h"
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    39
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    40
#include <vector>
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    41
#include <sstream>
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    42
#include <dlfcn.h>
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    43
#include <iomanip>
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    44
3711
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
    45
#include <netinet/in.h>
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
    46
#include <arpa/inet.h>
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    47
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    48
NS_LOG_COMPONENT_DEFINE ("NscTcpL4Protocol");
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    49
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    50
namespace ns3 {
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    51
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    52
NS_OBJECT_ENSURE_REGISTERED (NscTcpL4Protocol);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    53
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    54
/* see http://www.iana.org/assignments/protocol-numbers */
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    55
const uint8_t NscTcpL4Protocol::PROT_NUMBER = 6;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    56
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    57
ObjectFactory
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    58
NscTcpL4Protocol::GetDefaultRttEstimatorFactory (void)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    59
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    60
  ObjectFactory factory;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    61
  factory.SetTypeId (RttMeanDeviation::GetTypeId ());
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    62
  return factory;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    63
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    64
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    65
TypeId 
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    66
NscTcpL4Protocol::GetTypeId (void)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    67
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    68
  static TypeId tid = TypeId ("ns3::NscTcpL4Protocol")
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    69
    .SetParent<Ipv4L4Protocol> ()
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    70
    .AddConstructor<NscTcpL4Protocol>()
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    71
    .AddAttribute ("RttEstimatorFactory",
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    72
                   "How RttEstimator objects are created.",
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    73
                   ObjectFactoryValue (GetDefaultRttEstimatorFactory ()),
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    74
                   MakeObjectFactoryAccessor (&NscTcpL4Protocol::m_rttFactory),
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    75
                   MakeObjectFactoryChecker ())
4283
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    76
    .AddAttribute ("SocketList", "The list of sockets associated to this protocol.",
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    77
                   ObjectVectorValue (),
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    78
                   MakeObjectVectorAccessor (&NscTcpL4Protocol::m_sockets),
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
    79
                   MakeObjectVectorChecker<NscTcpSocketImpl> ())
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    80
    .AddAttribute ("Library",
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    81
                   "Set the linux library to be used to create the stack",
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    82
                   TypeId::ATTR_GET|TypeId::ATTR_CONSTRUCT,
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    83
                   StringValue("liblinux2.6.26.so"),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    84
                   MakeStringAccessor (&NscTcpL4Protocol::GetNscLibrary,&NscTcpL4Protocol::SetNscLibrary),
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    85
                   MakeStringChecker ())
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    86
    ;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    87
  return tid;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    88
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    89
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    90
int external_rand()
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    91
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    92
    return 1; // TODO
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    93
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    94
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    95
NscTcpL4Protocol::NscTcpL4Protocol ()
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    96
  : m_endPoints (new Ipv4EndPointDemux ()),
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    97
    m_nscStack (0),
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    98
    m_softTimer (Timer::CANCEL_ON_DESTROY)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
    99
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   100
  m_dlopenHandle = NULL;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   101
  NS_LOG_LOGIC("Made a NscTcpL4Protocol "<<this);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   102
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   103
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   104
NscTcpL4Protocol::~NscTcpL4Protocol ()
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   105
{
3710
ad0c222a18be nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents: 3578
diff changeset
   106
  NS_LOG_FUNCTION (this);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   107
  dlclose(m_dlopenHandle);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   108
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   109
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   110
void
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   111
NscTcpL4Protocol::SetNscLibrary(const std::string &soname)
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   112
{    
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   113
  if (soname!="")
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   114
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   115
      m_nscLibrary = soname;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   116
      NS_ASSERT(!m_dlopenHandle);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   117
      m_dlopenHandle = dlopen(soname.c_str (), RTLD_NOW);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   118
      if (m_dlopenHandle == NULL)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   119
        NS_FATAL_ERROR (dlerror());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   120
    }
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   121
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   122
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   123
std::string 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   124
NscTcpL4Protocol::GetNscLibrary () const
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   125
{
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   126
  return m_nscLibrary;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   127
}
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   128
void 
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   129
NscTcpL4Protocol::SetNode (Ptr<Node> node)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   130
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   131
  m_node = node;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   132
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   133
  if (m_nscStack)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   134
    { // stack has already been loaded...
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   135
      return;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   136
    }
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   137
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   138
  NS_ASSERT(m_dlopenHandle);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   139
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   140
  FCreateStack create = (FCreateStack)dlsym(m_dlopenHandle, "nsc_create_stack");
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   141
  NS_ASSERT(create);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   142
  m_nscStack = create(this, this, external_rand);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   143
  int hzval = m_nscStack->get_hz();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   144
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   145
  NS_ASSERT(hzval > 0);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   146
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   147
  m_softTimer.SetFunction (&NscTcpL4Protocol::SoftInterrupt, this);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   148
  m_softTimer.SetDelay (MilliSeconds (1000/hzval));
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   149
  m_nscStack->init(hzval);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   150
  // This enables stack and NSC debug messages
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   151
  // m_nscStack->set_diagnostic(1000);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   152
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   153
  Ptr<Ns3NscStack> nscStack = Create<Ns3NscStack> ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   154
  nscStack->SetStack (m_nscStack);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   155
  node->AggregateObject (nscStack);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   156
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   157
  m_softTimer.Schedule ();
3717
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   158
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   159
  // its likely no ns-3 interface exits at this point, so
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   160
  // we dealy adding the nsc interface until the start of the simulation.
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   161
  Simulator::ScheduleNow (&NscTcpL4Protocol::AddInterface, this);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   162
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   163
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   164
void
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   165
NscTcpL4Protocol::NotifyNewAggregate ()
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   166
{ 
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   167
  bool is_not_initialized = (m_node == 0);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   168
  Ptr<Node>node = this->GetObject<Node> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   169
  Ptr<Ipv4L3Protocol> ipv4 = this->GetObject<Ipv4L3Protocol> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   170
  if (is_not_initialized && node!= 0 && ipv4 != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   171
    {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   172
      this->SetNode (node);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   173
      ipv4->Insert (this);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   174
      Ptr<NscTcpSocketFactoryImpl> tcpFactory = CreateObject<NscTcpSocketFactoryImpl> ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   175
      tcpFactory->SetTcp (this);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   176
      node->AggregateObject (tcpFactory);
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   177
    }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   178
  Object::NotifyNewAggregate ();
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   179
}
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   180
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   181
int 
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   182
NscTcpL4Protocol::GetProtocolNumber (void) const
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   183
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   184
  return PROT_NUMBER;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   185
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   186
int 
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   187
NscTcpL4Protocol::GetVersion (void) const
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   188
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   189
  return 2;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   190
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   191
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   192
void
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   193
NscTcpL4Protocol::DoDispose (void)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   194
{
3710
ad0c222a18be nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents: 3578
diff changeset
   195
  NS_LOG_FUNCTION (this);
4283
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   196
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   197
  for (std::vector<Ptr<NscTcpSocketImpl> >::iterator i = m_sockets.begin (); i != m_sockets.end (); i++)
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   198
    {
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   199
      *i = 0;
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   200
    }
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   201
  m_sockets.clear ();
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   202
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   203
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   204
  if (m_endPoints != 0)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   205
    {
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   206
      delete m_endPoints;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   207
      m_endPoints = 0;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   208
    }
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   209
  m_node = 0;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   210
  Ipv4L4Protocol::DoDispose ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   211
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   212
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   213
Ptr<Socket>
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   214
NscTcpL4Protocol::CreateSocket (void)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   215
{
3710
ad0c222a18be nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents: 3578
diff changeset
   216
  NS_LOG_FUNCTION (this);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   217
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   218
  Ptr<RttEstimator> rtt = m_rttFactory.Create<RttEstimator> ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   219
  Ptr<NscTcpSocketImpl> socket = CreateObject<NscTcpSocketImpl> ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   220
  socket->SetNode (m_node);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   221
  socket->SetTcp (this);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   222
  socket->SetRtt (rtt);
4283
5854cddf4493 Bugs 458, swap 2 LOC for 526
Craig Dowell <craigdo@ee.washington.edu>
parents: 3820
diff changeset
   223
  m_sockets.push_back (socket);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   224
  return socket;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   225
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   226
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   227
Ipv4EndPoint *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   228
NscTcpL4Protocol::Allocate (void)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   229
{
3710
ad0c222a18be nsc: make sure nsc has a configured interface
Florian Westphal <fw@strlen.de>
parents: 3578
diff changeset
   230
  NS_LOG_FUNCTION (this);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   231
  return m_endPoints->Allocate ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   232
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   233
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   234
Ipv4EndPoint *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   235
NscTcpL4Protocol::Allocate (Ipv4Address address)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   236
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   237
  NS_LOG_FUNCTION (this << address);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   238
  return m_endPoints->Allocate (address);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   239
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   240
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   241
Ipv4EndPoint *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   242
NscTcpL4Protocol::Allocate (uint16_t port)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   243
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   244
  NS_LOG_FUNCTION (this << port);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   245
  return m_endPoints->Allocate (port);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   246
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   247
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   248
Ipv4EndPoint *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   249
NscTcpL4Protocol::Allocate (Ipv4Address address, uint16_t port)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   250
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   251
  NS_LOG_FUNCTION (this << address << port);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   252
  return m_endPoints->Allocate (address, port);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   253
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   254
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   255
Ipv4EndPoint *
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   256
NscTcpL4Protocol::Allocate (Ipv4Address localAddress, uint16_t localPort,
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   257
                         Ipv4Address peerAddress, uint16_t peerPort)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   258
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   259
  NS_LOG_FUNCTION (this << localAddress << localPort << peerAddress << peerPort);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   260
  return m_endPoints->Allocate (localAddress, localPort,
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   261
                                peerAddress, peerPort);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   262
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   263
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   264
void 
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   265
NscTcpL4Protocol::DeAllocate (Ipv4EndPoint *endPoint)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   266
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   267
  NS_LOG_FUNCTION (this << endPoint);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   268
  // NSC m_endPoints->DeAllocate (endPoint);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   269
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   270
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3717
diff changeset
   271
Ipv4L4Protocol::RxStatus
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   272
NscTcpL4Protocol::Receive (Ptr<Packet> packet,
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   273
             Ipv4Address const &source,
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   274
             Ipv4Address const &destination,
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   275
             Ptr<Ipv4Interface> incomingInterface)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   276
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   277
  NS_LOG_FUNCTION (this << packet << source << destination << incomingInterface);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   278
  Ipv4Header ipHeader;
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   279
  uint32_t packetSize = packet->GetSize();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   280
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   281
  // The way things work at the moment, the IP header has been removed
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   282
  // by the ns-3 IPv4 processing code. However, the NSC stack expects
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   283
  // a complete IP packet, so we add the IP header back.
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   284
  // Since the original header is already gone, we create a new one
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   285
  // based on the information we have.
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   286
  ipHeader.SetSource (source);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   287
  ipHeader.SetDestination (destination);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   288
  ipHeader.SetProtocol (PROT_NUMBER);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   289
  ipHeader.SetPayloadSize (packetSize);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   290
  ipHeader.SetTtl (1);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   291
  // all NSC stacks check the IP checksum
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   292
  ipHeader.EnableChecksum ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   293
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   294
  packet->AddHeader(ipHeader);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   295
  packetSize = packet->GetSize();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   296
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   297
  const uint8_t *data = const_cast<uint8_t *>(packet->PeekData());
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   298
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   299
  // deliver complete packet to the NSC network stack
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   300
  m_nscStack->if_receive_packet(0, data, packetSize);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   301
  wakeup ();
3820
c04ecfdce1ef apply icmp patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3717
diff changeset
   302
  return Ipv4L4Protocol::RX_OK;
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   303
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   304
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   305
void NscTcpL4Protocol::SoftInterrupt (void)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   306
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   307
  m_nscStack->timer_interrupt ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   308
  m_nscStack->increment_ticks ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   309
  m_softTimer.Schedule ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   310
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   311
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   312
void NscTcpL4Protocol::send_callback(const void* data, int datalen)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   313
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   314
  Ptr<Packet> p;
3711
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   315
  uint32_t ipv4Saddr, ipv4Daddr;
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   316
3711
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   317
  NS_ASSERT(datalen > 20);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   318
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   319
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   320
  // create packet, without IP header. The TCP header is not touched.
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   321
  // Not using the IP header makes integration easier, but it destroys
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   322
  // eg. ECN.
3711
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   323
  const uint8_t *rawdata = reinterpret_cast<const uint8_t *>(data);
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   324
  rawdata += 20; // skip IP header. IP options aren't supported at this time.
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   325
  datalen -= 20;
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   326
  p = Create<Packet> (rawdata, datalen);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   327
3711
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   328
  // we need the real source/destination ipv4 addresses for Send ().
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   329
  const uint32_t *ipheader = reinterpret_cast<const uint32_t *>(data);
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   330
  ipv4Saddr = *(ipheader+3);
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   331
  ipv4Daddr = *(ipheader+4);
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   332
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   333
  Ipv4Address saddr(ntohl(ipv4Saddr));
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   334
  Ipv4Address daddr(ntohl(ipv4Daddr));
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   335
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   336
  Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
3711
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   337
  NS_ASSERT_MSG (ipv4, "nsc callback invoked, but node has no ipv4 object");
fed597b0583e nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents: 3710
diff changeset
   338
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   339
  ipv4->Send (p, saddr, daddr, PROT_NUMBER, 0);
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   340
  m_nscStack->if_send_finish(0);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   341
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   342
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   343
void NscTcpL4Protocol::wakeup()
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   344
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   345
  // TODO
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   346
  // this should schedule a timer to read from all tcp sockets now... this is
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   347
  // an indication that data might be waiting on the socket
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   348
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   349
  Ipv4EndPointDemux::EndPoints endPoints = m_endPoints->GetAllEndPoints ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   350
  for (Ipv4EndPointDemux::EndPointsI endPoint = endPoints.begin ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   351
       endPoint != endPoints.end (); endPoint++) {
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   352
          // NSC HACK: (ab)use TcpSocket::ForwardUp for signalling
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   353
          (*endPoint)->ForwardUp (NULL, Ipv4Address(), 0);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   354
  }
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   355
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   356
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   357
void NscTcpL4Protocol::gettime(unsigned int* sec, unsigned int* usec)
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   358
{
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   359
  // Only used by the Linux network stack, e.g. during ISN generation
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   360
  // and in the kernel rng initialization routine. Also used in Linux
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   361
  // printk output.
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   362
  Time t = Simulator::Now ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   363
  int64_t us = t.GetMicroSeconds ();
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   364
  *sec = us / (1000*1000);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   365
  *usec = us - *sec * (1000*1000);
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   366
}
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   367
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   368
3717
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   369
void NscTcpL4Protocol::AddInterface(void)
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   370
{
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   371
  Ptr<Ipv4> ip = m_node->GetObject<Ipv4> ();
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   372
  const uint32_t nInterfaces = ip->GetNInterfaces ();
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   373
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   374
  NS_ASSERT_MSG (nInterfaces <= 2, "nsc does not support multiple interfaces per node");
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   375
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   376
  // start from 1, ignore the loopback interface (HACK)
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   377
  // we really don't need the loop, but its here to illustrate
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   378
  // how things _should_ be (once nsc can deal with multiple interfaces...)
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   379
  for (uint32_t i = 1; i < nInterfaces; i++)
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   380
    {
4375
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4283
diff changeset
   381
      Ipv4InterfaceAddress ifAddr = ip->GetAddress (i, 0);
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4283
diff changeset
   382
      Ipv4Address addr = ifAddr.GetLocal ();
db81fdcb06e7 Implementation cut over to use Ipv4InterfaceAddress
Tom Henderson <tomh@tomh.org>
parents: 4283
diff changeset
   383
      Ipv4Mask mask = ifAddr.GetMask ();
3717
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   384
      uint16_t mtu = ip->GetMtu (i);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   385
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   386
      std::ostringstream addrOss, maskOss;
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   387
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   388
      addr.Print(addrOss);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   389
      mask.Print(maskOss);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   390
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   391
      NS_LOG_LOGIC ("if_attach " << addrOss.str().c_str() << " " << maskOss.str().c_str() << " " << mtu);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   392
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   393
      std::string addrStr = addrOss.str();
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   394
      std::string maskStr = maskOss.str();
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   395
      const char* addrCStr = addrStr.c_str();
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   396
      const char* maskCStr = maskStr.c_str();
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   397
      m_nscStack->if_attach(addrCStr, maskCStr, mtu);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   398
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   399
      if (i == 1)
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   400
      {
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   401
        // We need to come up with a default gateway here. Can't guarantee this to be
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   402
        // correct really...
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   403
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   404
        uint8_t addrBytes[4];
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   405
        addr.Serialize(addrBytes);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   406
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   407
        // XXX: this is all a bit of a horrible hack
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   408
        //
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   409
        // Just increment the last octet, this gives a decent chance of this being
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   410
        // 'enough'.
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   411
        //
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   412
        // All we need is another address on the same network as the interface. This
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   413
        // will force the stack to output the packet out of the network interface.
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   414
        addrBytes[3]++;
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   415
        addr.Deserialize(addrBytes);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   416
        addrOss.str("");
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   417
        addr.Print(addrOss);
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   418
        m_nscStack->add_default_gateway(addrOss.str().c_str());
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   419
      }
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   420
  }
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   421
}
36bddd3732c7 nsc: delay creating nsc interface using ScheduleNow ().
Florian Westphal <fw@strlen.de>
parents: 3711
diff changeset
   422
3578
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   423
}; // namespace ns3
e6374560e19e nsc: core files.
Florian Westphal <fw@strlen.de>
parents:
diff changeset
   424