diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b76fb58b0..4c66f606d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -29,6 +29,7 @@ Release 3-dev - (build) #815 - Configure find_program to search for programs in PATH first, then AppBundles in MacOS - (network) !1229 - Fixed a bug in `Ipv4Address::IsSubnetDirectedBroadcast` - (internet) !1229 - Fixed a bug in `Icmpv4Header::HandleEcho` when replying to broadcast-type Echo requests, and two bugs in `Ipv4RawSocketImpl::SendTo` in handling sockets bound to a specific address and directed to a broadcast-type address. +- (internet) - `NeighborCacheHelper::PopulateNeighborCache` is now robust against missing IPv4 or IPv6 stack in nodes. Release 3.37 ------------ diff --git a/src/internet/examples/neighbor-cache-dynamic.cc b/src/internet/examples/neighbor-cache-dynamic.cc index bbe968ed1..1ed9dabb9 100644 --- a/src/internet/examples/neighbor-cache-dynamic.cc +++ b/src/internet/examples/neighbor-cache-dynamic.cc @@ -116,7 +116,7 @@ fe80::200:ff:fe00:1 dev 0 lladdr 02-06-00:00:00:00:00:01 STATIC_AUTOGENERATED fe80::200:ff:fe00:2 dev 0 lladdr 02-06-00:00:00:00:00:02 STATIC_AUTOGENERATED - Arp caches after remove the second address (2001:1::200:ff:fe00:1) from n1 + Ndisc caches after remove the second address (2001:1::200:ff:fe00:1) from n1 NDISC Cache of node 0 at time +2s 2001:1::200:ff:fe00:2 dev 0 lladdr 02-06-00:00:00:00:00:02 STATIC_AUTOGENERATED 2001:1::200:ff:fe00:3 dev 0 lladdr 02-06-00:00:00:00:00:03 STATIC_AUTOGENERATED @@ -169,7 +169,7 @@ void RemoveIpv6Address(Ptr ipv6Interface, uint32_t index) { ipv6Interface->RemoveAddress(index); - std::cout << "\nArp caches after remove the second address (2001:1::200:ff:fe00:1) from n1" + std::cout << "\nNdisc caches after remove the second address (2001:1::200:ff:fe00:1) from n1" << std::endl; } @@ -202,6 +202,14 @@ main(int argc, char* argv[]) csmaDevices = csma.Install(csmaNodes); InternetStackHelper stack; + if (!useIpv6) + { + stack.SetIpv6StackInstall(false); + } + else + { + stack.SetIpv4StackInstall(false); + } stack.Install(csmaNodes); if (!useIpv6) diff --git a/src/internet/examples/neighbor-cache-example.cc b/src/internet/examples/neighbor-cache-example.cc index a923afb83..b955a5b1d 100644 --- a/src/internet/examples/neighbor-cache-example.cc +++ b/src/internet/examples/neighbor-cache-example.cc @@ -409,6 +409,14 @@ NeighborCacheExample::Run() csmaDevicesRight = csmaRight.Install(csmaNodesRight); InternetStackHelper stack; + if (!m_useIpv6) + { + stack.SetIpv6StackInstall(false); + } + else + { + stack.SetIpv4StackInstall(false); + } // disabled Ipv4ArpJitter and Ipv6NsRsJitter to avoid the influence on packet dropped stack.SetIpv4ArpJitter(false); stack.SetIpv6NsRsJitter(false); diff --git a/src/internet/helper/neighbor-cache-helper.cc b/src/internet/helper/neighbor-cache-helper.cc index c422e7a84..8bf615915 100644 --- a/src/internet/helper/neighbor-cache-helper.cc +++ b/src/internet/helper/neighbor-cache-helper.cc @@ -64,16 +64,36 @@ NeighborCacheHelper::PopulateNeighborCache(Ptr channel) const { Ptr netDevice = channel->GetDevice(i); Ptr node = netDevice->GetNode(); - int32_t ipv4InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); - int32_t ipv6InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); + + int32_t ipv4InterfaceIndex = -1; + if (node->GetObject()) + { + ipv4InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); + } + int32_t ipv6InterfaceIndex = -1; + if (node->GetObject()) + { + ipv6InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); + } + for (std::size_t j = 0; j < channel->GetNDevices(); ++j) { Ptr neighborDevice = channel->GetDevice(j); Ptr neighborNode = neighborDevice->GetNode(); - int32_t ipv4NeighborInterfaceIndex = - neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); - int32_t ipv6NeighborInterfaceIndex = - neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); + + int32_t ipv4NeighborInterfaceIndex = -1; + if (neighborNode->GetObject()) + { + ipv4NeighborInterfaceIndex = + neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); + } + int32_t ipv6NeighborInterfaceIndex = -1; + if (neighborNode->GetObject()) + { + ipv6NeighborInterfaceIndex = + neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); + } + if (neighborDevice != netDevice) { if (ipv4InterfaceIndex != -1) @@ -114,16 +134,36 @@ NeighborCacheHelper::PopulateNeighborCache(const NetDeviceContainer& c) const Ptr netDevice = c.Get(i); Ptr channel = netDevice->GetChannel(); Ptr node = netDevice->GetNode(); - int32_t ipv4InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); - int32_t ipv6InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); + + int32_t ipv4InterfaceIndex = -1; + if (node->GetObject()) + { + ipv4InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); + } + int32_t ipv6InterfaceIndex = -1; + if (node->GetObject()) + { + ipv6InterfaceIndex = node->GetObject()->GetInterfaceForDevice(netDevice); + } + for (std::size_t j = 0; j < channel->GetNDevices(); ++j) { Ptr neighborDevice = channel->GetDevice(j); Ptr neighborNode = neighborDevice->GetNode(); - int32_t ipv4NeighborInterfaceIndex = - neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); - int32_t ipv6NeighborInterfaceIndex = - neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); + + int32_t ipv4NeighborInterfaceIndex = -1; + if (neighborNode->GetObject()) + { + ipv4NeighborInterfaceIndex = + neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); + } + int32_t ipv6NeighborInterfaceIndex = -1; + if (neighborNode->GetObject()) + { + ipv6NeighborInterfaceIndex = + neighborNode->GetObject()->GetInterfaceForDevice(neighborDevice); + } + if (neighborDevice != netDevice) { if (ipv4InterfaceIndex != -1)