src/node/internet-node.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 03 May 2007 14:20:04 +0200
changeset 519 b045a3ab4595
parent 516 3d330150ab6d
child 520 92160600f7f2
permissions -rw-r--r--
define and implement IUdp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
// All rights reserved.
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
// This program is free software; you can redistribute it and/or modify
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
// it under the terms of the GNU General Public License version 2 as
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
// published by the Free Software Foundation;
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
// This program is distributed in the hope that it will be useful,
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
// GNU General Public License for more details.
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
// You should have received a copy of the GNU General Public License
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
// along with this program; if not, write to the Free Software
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
// Author: George F. Riley<riley@ece.gatech.edu>
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
//
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
// Implementation of the InternetNode class for ns3.
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
// George F. Riley, Georgia Tech, Fall 2006
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    24
#include "ns3/composite-trace-resolver.h"
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    25
381
83b52d112c99 Add ApplicationList and Capability
Tom Henderson <tomh@tomh.org>
parents: 359
diff changeset
    26
#include "application-list.h"
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include "l3-demux.h"
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include "ipv4-l4-demux.h"
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include "internet-node.h"
240
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 234
diff changeset
    30
#include "udp.h"
7da682f99bf9 add non-debugged udp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 234
diff changeset
    31
#include "ipv4.h"
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
    32
#include "arp.h"
451
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
    33
#include "net-device.h"
519
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    34
#include "i-udp-impl.h"
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
namespace ns3 {
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
359
91b7ad7fa784 OnOffApplication functioning; some Node class cleanup
Tom Henderson <tomh@tomh.org>
parents: 345
diff changeset
    38
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
InternetNode::InternetNode()
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
{
519
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    41
  Ipv4 *ipv4 = new Ipv4 (this);
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    42
  Arp *arp = new Arp (this);
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    43
  Udp *udp = new Udp (this);
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    44
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    45
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
  // Instantiate the capabilities
516
3d330150ab6d make ApplicationList an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 514
diff changeset
    47
  ApplicationList *applicationList = new ApplicationList(this);
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
    48
  L3Demux *l3Demux = new L3Demux(this);
514
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
    49
  Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this);
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
    50
519
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    51
  l3Demux->Insert (ipv4);
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    52
  l3Demux->Insert (arp);
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    53
  ipv4L4Demux->Insert (udp);
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    54
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    55
  IUdpImpl *udpImpl = new IUdpImpl (udp);
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    56
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    57
  NsUnknown::AddInterface (udpImpl);
516
3d330150ab6d make ApplicationList an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 514
diff changeset
    58
  NsUnknown::AddInterface (applicationList);
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
    59
  NsUnknown::AddInterface (l3Demux);
514
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
    60
  NsUnknown::AddInterface (ipv4L4Demux);
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
    61
503
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 499
diff changeset
    62
516
3d330150ab6d make ApplicationList an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 514
diff changeset
    63
  applicationList->Unref ();
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
    64
  l3Demux->Unref ();
514
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
    65
  ipv4L4Demux->Unref ();
503
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 499
diff changeset
    66
  ipv4->Unref ();
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 499
diff changeset
    67
  arp->Unref ();
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 499
diff changeset
    68
  udp->Unref ();
519
b045a3ab4595 define and implement IUdp
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 516
diff changeset
    69
  udpImpl->Unref ();
242
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
    70
}
a44932709b47 add arp stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 241
diff changeset
    71
248
a912210e52ac fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 247
diff changeset
    72
InternetNode::~InternetNode ()
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
    73
{}
248
a912210e52ac fix memory leaks for simple sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 247
diff changeset
    74
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 496
diff changeset
    75
void
308
768db459baaa Added tracing support to simple.tcl.cc (Craig)
tomh@ubuntu
parents: 295
diff changeset
    76
InternetNode::SetName (std::string name)
768db459baaa Added tracing support to simple.tcl.cc (Craig)
tomh@ubuntu
parents: 295
diff changeset
    77
{
768db459baaa Added tracing support to simple.tcl.cc (Craig)
tomh@ubuntu
parents: 295
diff changeset
    78
  m_name = name;
768db459baaa Added tracing support to simple.tcl.cc (Craig)
tomh@ubuntu
parents: 295
diff changeset
    79
}
768db459baaa Added tracing support to simple.tcl.cc (Craig)
tomh@ubuntu
parents: 295
diff changeset
    80
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    81
TraceResolver *
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    82
InternetNode::CreateTraceResolver (TraceContext const &context)
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    83
{
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    84
  CompositeTraceResolver *resolver = new CompositeTraceResolver (context);
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    85
  Ipv4 *ipv4 = GetIpv4 ();
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    86
  resolver->Add ("ipv4",
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    87
                 MakeCallback (&Ipv4::CreateTraceResolver, ipv4),
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    88
                 InternetNode::IPV4);
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    89
  ipv4->Unref ();
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    90
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    91
  Arp *arp = GetArp ();
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    92
  resolver->Add ("arp",
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    93
                 MakeCallback (&Arp::CreateTraceResolver, arp),
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    94
                 InternetNode::ARP);
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    95
  arp->Unref ();
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    96
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    97
  Udp *udp = GetUdp ();
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
    98
  resolver->Add ("udp",
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
    99
                 MakeCallback (&Udp::CreateTraceResolver, udp),
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
   100
                 InternetNode::UDP);
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   101
  udp->Unref ();
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   102
345
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
   103
  return resolver;
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
   104
}
47b41507a45a move channel.cc channel.h to node directory; merge ns-3-tracing from mathieu
Tom Henderson <tomh@tomh.org>
parents: 341
diff changeset
   105
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   106
void 
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   107
InternetNode::DoDispose()
465
7f620ea278f4 merge in raj's dispose early work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 451
diff changeset
   108
{
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   109
  Node::DoDispose ();
465
7f620ea278f4 merge in raj's dispose early work
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 451
diff changeset
   110
}
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
247
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   112
Ipv4 *
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   113
InternetNode::GetIpv4 (void) const
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   114
{
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   115
  L3Demux *l3Demux = QueryInterface<L3Demux> (L3Demux::iid);
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   116
  Ipv4 *ipv4 = static_cast<Ipv4*> (l3Demux->PeekProtocol (Ipv4::PROT_NUMBER));
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   117
  l3Demux->Unref ();
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   118
  ipv4->Ref ();
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   119
  return ipv4;
247
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   120
}
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   121
Udp *
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   122
InternetNode::GetUdp (void) const
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   123
{
514
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
   124
  Ipv4L4Demux *demux = QueryInterface<Ipv4L4Demux> (Ipv4L4Demux::iid);
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
   125
  Udp *udp = static_cast<Udp*> (demux->PeekProtocol (Udp::PROT_NUMBER));
7c9a037a32b7 make Ipv4L4Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 513
diff changeset
   126
  demux->Unref ();
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   127
  udp->Ref ();
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   128
  return udp;
247
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   129
}
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   130
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   131
Arp *
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   132
InternetNode::GetArp (void) const
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   133
{
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   134
  L3Demux *l3Demux = QueryInterface<L3Demux> (L3Demux::iid);
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   135
  Arp *arp = static_cast<Arp*> (l3Demux->PeekProtocol (Arp::PROT_NUMBER));
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   136
  l3Demux->Unref ();
499
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   137
  arp->Ref ();
8a469663f7ea implement properly the refcounting rules for the capability getters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 498
diff changeset
   138
  return arp;
247
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   139
}
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   140
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 444
diff changeset
   141
void 
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 444
diff changeset
   142
InternetNode::DoAddDevice (NetDevice *device) const
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 444
diff changeset
   143
{
451
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   144
  device->SetReceiveCallback (MakeCallback (&InternetNode::ReceiveFromDevice, this));
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   145
}
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   146
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   147
bool
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   148
InternetNode::ReceiveFromDevice (NetDevice *device, const Packet &p, uint16_t protocolNumber) const
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   149
{
513
b7c7ea629de9 make L3Demux an NsUnknown object.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 503
diff changeset
   150
  L3Demux *demux = QueryInterface<L3Demux> (L3Demux::iid);
503
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 499
diff changeset
   151
  L3Protocol *target = demux->PeekProtocol (protocolNumber);
38f16e0e5513 fix last leaks with new refcounted mechanism
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 499
diff changeset
   152
  demux->Unref ();
451
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   153
  if (target != 0) 
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   154
    {
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   155
      Packet packet = p;
474
7457c2a417ba manage NetDevice objects with refcounts
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 468
diff changeset
   156
      target->Receive(packet, device);
451
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   157
      return true;
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   158
    }
3fe2c883cb47 add NetDevice::SetReceiveCallback and use it
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 449
diff changeset
   159
  return false;
447
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 444
diff changeset
   160
}
180117abfb04 add NetDevice list into Node base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 444
diff changeset
   161
247
fb7375bb43d7 make the sample code compile and link.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 242
diff changeset
   162
234
6124bda39cb3 code from all trees.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
}//namespace ns3