src/internet-stack/ipv4-loopback-interface.cc
author Tom Henderson <tomh@tomh.org>
Wed, 19 Nov 2008 16:41:17 -0800
changeset 3877 5091e3a14b26
parent 3448 0bd851bb1225
permissions -rw-r--r--
Drop trace notification when outgoing interface is down
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Authors: 
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    21
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    22
#include "ns3/log.h"
524
082ffdd8fbd7 move code around
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 522
diff changeset
    23
#include "ns3/net-device.h"
729
b5e744285e92 rename i-node to node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 728
diff changeset
    24
#include "ns3/node.h"
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1451
diff changeset
    25
#include "ns3/mac48-address.h"
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
    26
#include "ns3/packet.h"
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include "ipv4-loopback-interface.h"
1176
4894ea885c0f implement the Node::ProtocolHandler support.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 746
diff changeset
    28
#include "ipv4-l3-protocol.h"
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    30
NS_LOG_COMPONENT_DEFINE ("Ipv4LoopbackInterface");
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    31
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
namespace ns3 {
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
3147
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    34
TypeId 
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    35
Ipv4LoopbackInterface::GetTypeId (void)
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    36
{
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    37
  static TypeId tid = TypeId ("ns3::Ipv4LoopbackInterface")
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    38
    .SetParent<Ipv4Interface> ()
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    39
    ;
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    40
  return tid;
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    41
}
e0c2a7c2eb5f re-organize the ARP code to expose arp cache attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2983
diff changeset
    42
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    43
Ipv4LoopbackInterface::Ipv4LoopbackInterface ()
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    44
  : m_node (0)
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    45
{
3148
87ee5483cef9 more logging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    46
  NS_LOG_FUNCTION (this);
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    47
}
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    48
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    50
{
3148
87ee5483cef9 more logging output
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3147
diff changeset
    51
  NS_LOG_FUNCTION (this);
2592
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    52
  NS_ASSERT (m_node != 0);
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    53
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    54
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    55
Ptr<NetDevice> 
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    56
Ipv4LoopbackInterface::GetDevice (void) const
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    57
{
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    58
  return 0;
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    59
}
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    60
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    61
void 
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    62
Ipv4LoopbackInterface::SetNode (Ptr<Node> node)
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    63
{
3ebf97150166 get rid of CreateObjectWith
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    64
  m_node = node;
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    65
}
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
void 
1866
e7dbcc4df546 do not use Packet objects directly. Use Ptr<Packet> instead
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1504
diff changeset
    68
Ipv4LoopbackInterface::SendTo (Ptr<Packet> packet, Ipv4Address dest)
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
{
2983
e3a416fe9dd5 NS_LOG_FUNCTION -> NS_LOG_FUNCTION_NOARGS and NS_LOG_PARAMS -> NS_LOG_FUNCTION
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2834
diff changeset
    70
  NS_LOG_FUNCTION (this << packet << dest);
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    71
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    72
  Ptr<Ipv4L3Protocol> ipv4 = 
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
    73
    m_node->GetObject<Ipv4L3Protocol> ();
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1271
diff changeset
    74
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1451
diff changeset
    75
  ipv4->Receive (0, packet, Ipv4L3Protocol::PROT_NUMBER, 
3448
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
    76
                 Mac48Address ("ff:ff:ff:ff:ff:ff"),
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
    77
                 Mac48Address ("ff:ff:ff:ff:ff:ff"),
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
    78
                 NetDevice::PACKET_HOST // note: linux uses PACKET_LOOPBACK here
0bd851bb1225 Simplify promiscuous mode API: NetDevices always operate in promiscuous mode, normal receive callbacks receive extra destination address and packet type.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3260
diff changeset
    79
                 );
246
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
}
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
612b3c16b24e implement ipv4 loopback for testing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
}//namespace ns3