src/internet-stack/ipv4-loopback-interface.cc
changeset 5028 01f02baebba9
parent 5025 fc820a3a1975
parent 4475 a232dcbbe7a8
child 5029 141a8e5fd047
equal deleted inserted replaced
5025:fc820a3a1975 5028:01f02baebba9
     1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2007 INRIA
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License version 2 as
       
     7  * published by the Free Software Foundation;
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17  *
       
    18  * Authors: 
       
    19  *  Mathieu Lacage <mathieu.lacage@sophia.inria.fr>,
       
    20  */
       
    21 
       
    22 #include "ns3/log.h"
       
    23 #include "ns3/net-device.h"
       
    24 #include "ns3/node.h"
       
    25 #include "ns3/mac48-address.h"
       
    26 #include "ns3/packet.h"
       
    27 #include "ipv4-loopback-interface.h"
       
    28 #include "ipv4-l3-protocol.h"
       
    29 
       
    30 NS_LOG_COMPONENT_DEFINE ("Ipv4LoopbackInterface");
       
    31 
       
    32 namespace ns3 {
       
    33 
       
    34 TypeId 
       
    35 Ipv4LoopbackInterface::GetTypeId (void)
       
    36 {
       
    37   static TypeId tid = TypeId ("ns3::Ipv4LoopbackInterface")
       
    38     .SetParent<Ipv4Interface> ()
       
    39     ;
       
    40   return tid;
       
    41 }
       
    42 
       
    43 Ipv4LoopbackInterface::Ipv4LoopbackInterface ()
       
    44   : m_node (0)
       
    45 {
       
    46   NS_LOG_FUNCTION (this);
       
    47 }
       
    48 
       
    49 Ipv4LoopbackInterface::~Ipv4LoopbackInterface ()
       
    50 {
       
    51   NS_LOG_FUNCTION (this);
       
    52   NS_ASSERT (m_node != 0);
       
    53 }
       
    54 
       
    55 Ptr<NetDevice> 
       
    56 Ipv4LoopbackInterface::GetDevice (void) const
       
    57 {
       
    58   return 0;
       
    59 }
       
    60 
       
    61 void 
       
    62 Ipv4LoopbackInterface::SetNode (Ptr<Node> node)
       
    63 {
       
    64   m_node = node;
       
    65 }
       
    66 
       
    67 void 
       
    68 Ipv4LoopbackInterface::SendTo (Ptr<Packet> packet, Ipv4Address dest)
       
    69 {
       
    70   NS_LOG_FUNCTION (this << packet << dest);
       
    71 
       
    72   Ptr<Ipv4L3Protocol> ipv4 = 
       
    73     m_node->GetObject<Ipv4L3Protocol> ();
       
    74 
       
    75   ipv4->Receive (0, packet, Ipv4L3Protocol::PROT_NUMBER, 
       
    76                  Mac48Address ("ff:ff:ff:ff:ff:ff"),
       
    77                  Mac48Address ("ff:ff:ff:ff:ff:ff"),
       
    78                  NetDevice::PACKET_HOST // note: linux uses PACKET_LOOPBACK here
       
    79                  );
       
    80 }
       
    81 
       
    82 }//namespace ns3