00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Authors: 00019 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr>, 00020 */ 00021 00022 #include "ns3/log.h" 00023 #include "ns3/net-device.h" 00024 #include "ns3/node.h" 00025 #include "ns3/mac48-address.h" 00026 #include "ns3/packet.h" 00027 #include "ipv4-loopback-interface.h" 00028 #include "ipv4-l3-protocol.h" 00029 00030 NS_LOG_COMPONENT_DEFINE ("Ipv4LoopbackInterface"); 00031 00032 namespace ns3 { 00033 00034 TypeId 00035 Ipv4LoopbackInterface::GetTypeId (void) 00036 { 00037 static TypeId tid = TypeId ("ns3::Ipv4LoopbackInterface") 00038 .SetParent<Ipv4Interface> () 00039 ; 00040 return tid; 00041 } 00042 00043 Ipv4LoopbackInterface::Ipv4LoopbackInterface () 00044 : m_node (0) 00045 { 00046 NS_LOG_FUNCTION (this); 00047 } 00048 00049 Ipv4LoopbackInterface::~Ipv4LoopbackInterface () 00050 { 00051 NS_LOG_FUNCTION (this); 00052 NS_ASSERT (m_node != 0); 00053 } 00054 00055 Ptr<NetDevice> 00056 Ipv4LoopbackInterface::GetDevice (void) const 00057 { 00058 return 0; 00059 } 00060 00061 void 00062 Ipv4LoopbackInterface::SetNode (Ptr<Node> node) 00063 { 00064 m_node = node; 00065 } 00066 00067 void 00068 Ipv4LoopbackInterface::SendTo (Ptr<Packet> packet, Ipv4Address dest) 00069 { 00070 NS_LOG_FUNCTION (this << packet << dest); 00071 00072 Ptr<Ipv4L3Protocol> ipv4 = 00073 m_node->GetObject<Ipv4L3Protocol> (); 00074 00075 ipv4->Receive (0, packet, Ipv4L3Protocol::PROT_NUMBER, 00076 Mac48Address ("ff:ff:ff:ff:ff:ff"), 00077 Mac48Address ("ff:ff:ff:ff:ff:ff"), 00078 NetDevice::PACKET_HOST // note: linux uses PACKET_LOOPBACK here 00079 ); 00080 } 00081 00082 }//namespace ns3