src/internet-stack/ipv4-l3-protocol.cc
changeset 4377 2a05a47dba22
parent 4375 db81fdcb06e7
child 4379 44c7757fb216
equal deleted inserted replaced
4376:ac217f25fe70 4377:2a05a47dba22
    51 
    51 
    52 TypeId 
    52 TypeId 
    53 Ipv4L3Protocol::GetTypeId (void)
    53 Ipv4L3Protocol::GetTypeId (void)
    54 {
    54 {
    55   static TypeId tid = TypeId ("ns3::Ipv4L3Protocol")
    55   static TypeId tid = TypeId ("ns3::Ipv4L3Protocol")
    56     .SetParent<Object> ()
    56     .SetParent<Ipv4> ()
    57     .AddConstructor<Ipv4L3Protocol> ()
    57     .AddConstructor<Ipv4L3Protocol> ()
    58     .AddAttribute ("DefaultTtl", "The TTL value set by default on all outgoing packets generated on this node.",
    58     .AddAttribute ("DefaultTtl", "The TTL value set by default on all outgoing packets generated on this node.",
    59                    UintegerValue (64),
    59                    UintegerValue (64),
    60                    MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
    60                    MakeUintegerAccessor (&Ipv4L3Protocol::m_defaultTtl),
    61                    MakeUintegerChecker<uint8_t> ())
    61                    MakeUintegerChecker<uint8_t> ())
   296   routeReply (false, Ipv4Route (), packet, ipHeader);
   296   routeReply (false, Ipv4Route (), packet, ipHeader);
   297 }
   297 }
   298 
   298 
   299 void
   299 void
   300 Ipv4L3Protocol::AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
   300 Ipv4L3Protocol::AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
   301                                     int priority)
   301                                     int16_t priority)
   302 {
   302 {
   303   NS_LOG_FUNCTION (this << &routingProtocol << priority);
   303   NS_LOG_FUNCTION (this << &routingProtocol << priority);
   304   m_routingProtocols.push_back
   304   m_routingProtocols.push_back
   305     (std::pair<int, Ptr<Ipv4RoutingProtocol> > (-priority, routingProtocol));
   305     (std::pair<int, Ptr<Ipv4RoutingProtocol> > (-priority, routingProtocol));
   306   m_routingProtocols.sort ();
   306   m_routingProtocols.sort ();
   311 {
   311 {
   312   NS_LOG_FUNCTION_NOARGS ();
   312   NS_LOG_FUNCTION_NOARGS ();
   313   return m_staticRouting->GetNRoutes ();
   313   return m_staticRouting->GetNRoutes ();
   314 }
   314 }
   315 
   315 
   316 Ipv4Route *
   316 Ipv4Route 
   317 Ipv4L3Protocol::GetRoute (uint32_t index)
   317 Ipv4L3Protocol::GetRoute (uint32_t index)
   318 {
   318 {
   319   NS_LOG_FUNCTION_NOARGS ();
   319   NS_LOG_FUNCTION_NOARGS ();
   320   return m_staticRouting->GetRoute (index);
   320   return *m_staticRouting->GetRoute (index);
   321 }
   321 }
   322 
   322 
   323 void 
   323 void 
   324 Ipv4L3Protocol::RemoveRoute (uint32_t index)
   324 Ipv4L3Protocol::RemoveRoute (uint32_t index)
   325 {
   325 {
   352 {
   352 {
   353   NS_LOG_FUNCTION_NOARGS ();
   353   NS_LOG_FUNCTION_NOARGS ();
   354   return m_staticRouting->GetNMulticastRoutes ();
   354   return m_staticRouting->GetNMulticastRoutes ();
   355 }
   355 }
   356 
   356 
   357 Ipv4MulticastRoute *
   357 Ipv4MulticastRoute 
   358 Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const
   358 Ipv4L3Protocol::GetMulticastRoute (uint32_t index) const
   359 {
   359 {
   360   NS_LOG_FUNCTION (this << index);
   360   NS_LOG_FUNCTION (this << index);
   361   return m_staticRouting->GetMulticastRoute (index);
   361   return *m_staticRouting->GetMulticastRoute (index);
   362 }
   362 }
   363 
   363 
   364 void 
   364 void 
   365 Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin,
   365 Ipv4L3Protocol::RemoveMulticastRoute (Ipv4Address origin,
   366                                        Ipv4Address group,
   366                                        Ipv4Address group,
   474     "Interface not found for masked IP address");
   474     "Interface not found for masked IP address");
   475   return 0;
   475   return 0;
   476 }
   476 }
   477 
   477 
   478 int32_t 
   478 int32_t 
   479 Ipv4L3Protocol::FindInterfaceIndexForDevice (Ptr<NetDevice> device) const
   479 Ipv4L3Protocol::FindInterfaceForDevice (Ptr<NetDevice> device) const
   480 {
   480 {
   481   NS_LOG_FUNCTION (this << device);
   481   NS_LOG_FUNCTION (this << device);
   482 
   482 
   483   uint32_t interface = 0;
   483   uint32_t interface = 0;
   484   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
   484   for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); 
  1099   while (modified)
  1099   while (modified)
  1100     {
  1100     {
  1101       modified = false;
  1101       modified = false;
  1102       for (uint32_t i = 0; i < GetNRoutes (); i++)
  1102       for (uint32_t i = 0; i < GetNRoutes (); i++)
  1103         {
  1103         {
  1104           Ipv4Route *route = GetRoute (i);
  1104           Ipv4Route route = GetRoute (i);
  1105           if (route->GetInterface () == ifaceIndex)
  1105           if (route.GetInterface () == ifaceIndex)
  1106             {
  1106             {
  1107               RemoveRoute (i);
  1107               RemoveRoute (i);
  1108               modified = true;
  1108               modified = true;
  1109               break;
  1109               break;
  1110             }
  1110             }
  1141 //
  1141 //
  1142       return Ipv4Address::GetAny ();
  1142       return Ipv4Address::GetAny ();
  1143     }
  1143     }
  1144 }
  1144 }
  1145 
  1145 
       
  1146 Ptr<NetDevice>
       
  1147 Ipv4L3Protocol::GetNetDevice (uint32_t i)
       
  1148 {
       
  1149   return GetInterface (i)-> GetDevice ();
       
  1150 }
       
  1151 
       
  1152 
  1146 
  1153 
  1147 }//namespace ns3
  1154 }//namespace ns3