internet: make NeighborCacheHelper::PopulateNeighborCache robust against missing IPv4 or IPv6 stack

This commit is contained in:
Tommaso Pecorella
2022-11-28 01:32:14 +01:00
parent 520865a919
commit cc985b7860
4 changed files with 71 additions and 14 deletions

View File

@@ -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
------------

View File

@@ -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> 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)

View File

@@ -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);

View File

@@ -64,16 +64,36 @@ NeighborCacheHelper::PopulateNeighborCache(Ptr<Channel> channel) const
{
Ptr<NetDevice> netDevice = channel->GetDevice(i);
Ptr<Node> node = netDevice->GetNode();
int32_t ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
int32_t ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
int32_t ipv4InterfaceIndex = -1;
if (node->GetObject<Ipv4>())
{
ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
}
int32_t ipv6InterfaceIndex = -1;
if (node->GetObject<Ipv6>())
{
ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
}
for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
{
Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
Ptr<Node> neighborNode = neighborDevice->GetNode();
int32_t ipv4NeighborInterfaceIndex =
neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
int32_t ipv6NeighborInterfaceIndex =
neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
int32_t ipv4NeighborInterfaceIndex = -1;
if (neighborNode->GetObject<Ipv4>())
{
ipv4NeighborInterfaceIndex =
neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
}
int32_t ipv6NeighborInterfaceIndex = -1;
if (neighborNode->GetObject<Ipv6>())
{
ipv6NeighborInterfaceIndex =
neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
}
if (neighborDevice != netDevice)
{
if (ipv4InterfaceIndex != -1)
@@ -114,16 +134,36 @@ NeighborCacheHelper::PopulateNeighborCache(const NetDeviceContainer& c) const
Ptr<NetDevice> netDevice = c.Get(i);
Ptr<Channel> channel = netDevice->GetChannel();
Ptr<Node> node = netDevice->GetNode();
int32_t ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
int32_t ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
int32_t ipv4InterfaceIndex = -1;
if (node->GetObject<Ipv4>())
{
ipv4InterfaceIndex = node->GetObject<Ipv4>()->GetInterfaceForDevice(netDevice);
}
int32_t ipv6InterfaceIndex = -1;
if (node->GetObject<Ipv6>())
{
ipv6InterfaceIndex = node->GetObject<Ipv6>()->GetInterfaceForDevice(netDevice);
}
for (std::size_t j = 0; j < channel->GetNDevices(); ++j)
{
Ptr<NetDevice> neighborDevice = channel->GetDevice(j);
Ptr<Node> neighborNode = neighborDevice->GetNode();
int32_t ipv4NeighborInterfaceIndex =
neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
int32_t ipv6NeighborInterfaceIndex =
neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
int32_t ipv4NeighborInterfaceIndex = -1;
if (neighborNode->GetObject<Ipv4>())
{
ipv4NeighborInterfaceIndex =
neighborNode->GetObject<Ipv4>()->GetInterfaceForDevice(neighborDevice);
}
int32_t ipv6NeighborInterfaceIndex = -1;
if (neighborNode->GetObject<Ipv6>())
{
ipv6NeighborInterfaceIndex =
neighborNode->GetObject<Ipv6>()->GetInterfaceForDevice(neighborDevice);
}
if (neighborDevice != netDevice)
{
if (ipv4InterfaceIndex != -1)