src/internet/model/ipv4-interface.cc
changeset 11954 5916e41a6f07
parent 11666 e8634b0101f7
child 11959 84c6ea472ffb
equal deleted inserted replaced
11953:bcc6faa9dd0e 11954:5916e41a6f07
    27 #include "ns3/net-device.h"
    27 #include "ns3/net-device.h"
    28 #include "ns3/log.h"
    28 #include "ns3/log.h"
    29 #include "ns3/packet.h"
    29 #include "ns3/packet.h"
    30 #include "ns3/node.h"
    30 #include "ns3/node.h"
    31 #include "ns3/pointer.h"
    31 #include "ns3/pointer.h"
       
    32 #include "ns3/traffic-control-layer.h"
    32 
    33 
    33 namespace ns3 {
    34 namespace ns3 {
    34 
    35 
    35 NS_LOG_COMPONENT_DEFINE ("Ipv4Interface");
    36 NS_LOG_COMPONENT_DEFINE ("Ipv4Interface");
    36 
    37 
    62   : m_ifup (false),
    63   : m_ifup (false),
    63     m_forwarding (true),
    64     m_forwarding (true),
    64     m_metric (1),
    65     m_metric (1),
    65     m_node (0), 
    66     m_node (0), 
    66     m_device (0),
    67     m_device (0),
       
    68     m_tc (0),
    67     m_cache (0)
    69     m_cache (0)
    68 {
    70 {
    69   NS_LOG_FUNCTION (this);
    71   NS_LOG_FUNCTION (this);
    70 }
    72 }
    71 
    73 
    78 Ipv4Interface::DoDispose (void)
    80 Ipv4Interface::DoDispose (void)
    79 {
    81 {
    80   NS_LOG_FUNCTION (this);
    82   NS_LOG_FUNCTION (this);
    81   m_node = 0;
    83   m_node = 0;
    82   m_device = 0;
    84   m_device = 0;
       
    85   m_tc = 0;
       
    86   m_cache = 0;
    83   Object::DoDispose ();
    87   Object::DoDispose ();
    84 }
    88 }
    85 
    89 
    86 void 
    90 void 
    87 Ipv4Interface::SetNode (Ptr<Node> node)
    91 Ipv4Interface::SetNode (Ptr<Node> node)
    95 Ipv4Interface::SetDevice (Ptr<NetDevice> device)
    99 Ipv4Interface::SetDevice (Ptr<NetDevice> device)
    96 {
   100 {
    97   NS_LOG_FUNCTION (this << device);
   101   NS_LOG_FUNCTION (this << device);
    98   m_device = device;
   102   m_device = device;
    99   DoSetup ();
   103   DoSetup ();
       
   104 }
       
   105 
       
   106 void
       
   107 Ipv4Interface::SetTrafficControl (Ptr<TrafficControlLayer> tc)
       
   108 {
       
   109   NS_LOG_FUNCTION (this << tc);
       
   110   m_tc = tc;
   100 }
   111 }
   101 
   112 
   102 void
   113 void
   103 Ipv4Interface::DoSetup (void)
   114 Ipv4Interface::DoSetup (void)
   104 {
   115 {
   203   NS_LOG_FUNCTION (this << *p << dest);
   214   NS_LOG_FUNCTION (this << *p << dest);
   204   if (!IsUp ())
   215   if (!IsUp ())
   205     {
   216     {
   206       return;
   217       return;
   207     }
   218     }
   208   // Check for a loopback device
   219 
       
   220   // Check for a loopback device, if it's the case we don't pass through
       
   221   // traffic control layer
   209   if (DynamicCast<LoopbackNetDevice> (m_device))
   222   if (DynamicCast<LoopbackNetDevice> (m_device))
   210     {
   223     {
   211       /// \todo additional checks needed here (such as whether multicast
   224       /// \todo additional checks needed here (such as whether multicast
   212       /// goes to loopback)?
   225       /// goes to loopback)?
   213       m_device->Send (p, m_device->GetBroadcast (), 
   226       m_device->Send (p, m_device->GetBroadcast (), Ipv4L3Protocol::PROT_NUMBER);
   214                       Ipv4L3Protocol::PROT_NUMBER);
       
   215       return;
   227       return;
   216     } 
   228     } 
       
   229 
       
   230   NS_ASSERT (m_tc != 0);
       
   231 
   217   // is this packet aimed at a local interface ?
   232   // is this packet aimed at a local interface ?
   218   for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i != m_ifaddrs.end (); ++i)
   233   for (Ipv4InterfaceAddressListCI i = m_ifaddrs.begin (); i != m_ifaddrs.end (); ++i)
   219     {
   234     {
   220       if (dest == (*i).GetLocal ())
   235       if (dest == (*i).GetLocal ())
   221         {
   236         {
   222           Ptr<Ipv4L3Protocol> ipv4 = m_node->GetObject<Ipv4L3Protocol> ();
   237           m_tc->Receive (m_device, p, Ipv4L3Protocol::PROT_NUMBER,
   223 
       
   224           ipv4->Receive (m_device, p, Ipv4L3Protocol::PROT_NUMBER, 
       
   225                          m_device->GetBroadcast (),
   238                          m_device->GetBroadcast (),
   226                          m_device->GetBroadcast (),
   239                          m_device->GetBroadcast (),
   227                          NetDevice::PACKET_HOST // note: linux uses PACKET_LOOPBACK here
   240                          NetDevice::PACKET_HOST);
   228                          );
       
   229           return;
   241           return;
   230         }
   242         }
   231     }
   243     }
   232   if (m_device->NeedsArp ())
   244   if (m_device->NeedsArp ())
   233     {
   245     {
   271         }
   283         }
   272 
   284 
   273       if (found)
   285       if (found)
   274         {
   286         {
   275           NS_LOG_LOGIC ("Address Resolved.  Send.");
   287           NS_LOG_LOGIC ("Address Resolved.  Send.");
   276           m_device->Send (p, hardwareDestination,
   288           m_tc->Send (m_device, p, hardwareDestination, Ipv4L3Protocol::PROT_NUMBER);
   277                           Ipv4L3Protocol::PROT_NUMBER);
       
   278         }
   289         }
   279     }
   290     }
   280   else
   291   else
   281     {
   292     {
   282       NS_LOG_LOGIC ("Doesn't need ARP");
   293       NS_LOG_LOGIC ("Doesn't need ARP");
   283       m_device->Send (p, m_device->GetBroadcast (), 
   294       m_tc->Send (m_device, p, m_device->GetBroadcast (), Ipv4L3Protocol::PROT_NUMBER);
   284                       Ipv4L3Protocol::PROT_NUMBER);
       
   285     }
   295     }
   286 }
   296 }
   287 
   297 
   288 uint32_t
   298 uint32_t
   289 Ipv4Interface::GetNAddresses (void) const
   299 Ipv4Interface::GetNAddresses (void) const