Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
for (NetworkRoutesI i = m_networkRoutes.begin (); i != m_networkRoutes.end (); i++) {
..........
}
int32_tIpv4L3Protocol::GetInterfaceForDevice ( Ptr<const NetDevice> device) const{ NS_LOG_FUNCTION (this << device); int32_t interface = 0;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++, interface++) { if ((*i)->GetDevice () == device) { return interface; } }
return -1;}
Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
rtentry = Create<Ipv4Route> ();
rtentry->SetDestination (route->GetDest ());
rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetDest ()));
rtentry->SetGateway (route->GetGateway ());
rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
void Ipv4L3Protocol::Receive ( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType)
Ptr<Ipv4Interface> ipv4Interface;
for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++, interface++) {
ipv4Interface = *i; if (ipv4Interface->GetDevice () == device) { if (ipv4Interface->IsUp ()) { m_rxTrace (packet, m_node->GetObject<Ipv4> (), interface); break; } else { NS_LOG_LOGIC ("Dropping received packet -- interface is down"); Ipv4Header ipHeader; packet->RemoveHeader (ipHeader); m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv4> (), interface); return; } } }
int32_t interface = GetInterfaceForDevice(device);
Ptr<Ipv4Interface> ipv4Interface;
if (interface != -1) { ipv4Interface = m_interfaces[interface];
if (ipv4Interface->IsUp ()) { m_rxTrace (packet, m_node->GetObject<Ipv4> (), interface); } else { NS_LOG_LOGIC ("Dropping received packet -- interface is down"); Ipv4Header ipHeader; packet->RemoveHeader (ipHeader); m_dropTrace (ipHeader, packet, DROP_INTERFACE_DOWN, m_node->GetObject<Ipv4> (), interface); return; } }
Ipv4L3Protocol::Send
// Handle a few cases: // 1) packet is destined to limited broadcast address // 2) packet is destined to a subnet-directed broadcast address // 3) packet is not broadcast, and is passed in with a route entry // 4) packet is not broadcast, and is passed in with a route entry but route->GetGateway is not set (e.g., on-demand) // 5) packet is not broadcast, and route is NULL (e.g., a raw socket call, or ICMP)eben...
// 2) check: packet is destined to a subnet-directed broadcast address uint32_t ifaceIndex = 0; for (Ipv4InterfaceList::iterator ifaceIter = m_interfaces.begin (); ifaceIter != m_interfaces.end (); ifaceIter++, ifaceIndex++) { Ptr<Ipv4Interface> outInterface = *ifaceIter; for (uint32_t j = 0; j < GetNAddresses (ifaceIndex); j++) { Ipv4InterfaceAddress ifAddr = GetAddress (ifaceIndex, j); if (destination.IsSubnetDirectedBroadcast (ifAddr.GetMask ()) && destination.CombineMask (ifAddr.GetMask ()) == ifAddr.GetLocal ().CombineMask (ifAddr.GetMask ()) ) { ... return; } } }
Ipv4StaticRouting::LookupStatic (Ipv4Address dest, Ptr<NetDevice> oif)
if (masklen < longest_mask) // Not interested if got shorter mask { NS_LOG_LOGIC ("Previous match longer, skipping"); continue; }
Ipv4RoutingTableEntry* route = (j); uint32_t interfaceIdx = route->GetInterface ();
rtentry = Create<Ipv4Route> (); rtentry->SetDestination (route->GetDest ()); rtentry->SetSource (SourceAddressSelection (interfaceIdx, route->GetDest ())); rtentry->SetGateway (route->GetGateway ()); rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIdx));
if (masklen == 32) { break; }
for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++) { for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++) { Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i); Ipv4Address addr = iaddr.GetLocal (); if (addr.IsEqual (ipHeader.GetDestination ())) { if (j == iif) { NS_LOG_LOGIC ("For me (destination " << addr << " match)"); } else { NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << ipHeader.GetDestination ()); } lcb (p, ipHeader, iif); return true; } if (ipHeader.GetDestination ().IsEqual (iaddr.GetBroadcast ())) { NS_LOG_LOGIC ("For me (interface broadcast address)"); lcb (p, ipHeader, iif); return true; } NS_LOG_LOGIC ("Address "<< addr << " not a match"); } } }
if (m_ipv4->GetNInterfaces () < 100) {
// .. the above code
}