From acbf3cc0d66a42036f9bfa5fa5ca72f74af4df59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez-L=C3=B3pez?= <58361045+mgonzalezlopezudc@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:43:22 +0100 Subject: [PATCH 1/5] [IPv6] [ --- src/inet/networklayer/ipv6/Ipv6.cc | 32 ++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/inet/networklayer/ipv6/Ipv6.cc b/src/inet/networklayer/ipv6/Ipv6.cc index 404736ab199..644a9a2fc43 100644 --- a/src/inet/networklayer/ipv6/Ipv6.cc +++ b/src/inet/networklayer/ipv6/Ipv6.cc @@ -366,8 +366,36 @@ void Ipv6::datagramLocalOut(Packet *packet, const NetworkInterface *destIE, Ipv6 { const auto& ipv6Header = packet->peekAtFront(); // route packet - if (destIE != nullptr) - fragmentPostRouting(packet, destIE, MacAddress::BROADCAST_ADDRESS, true); // FIXME what MAC address to use? + if (destIE != nullptr) { + Ipv6Address destAddress = ipv6Header->getDestAddress(); + MacAddress macAddr = MacAddress::UNSPECIFIED_ADDRESS; + + if (!destAddress.isMulticast()) { + EV_INFO << "next hop for " << destAddress << " is " << requestedNextHopAddress << ", interface " << destIE->getInterfaceName() << "\n"; + + macAddr = nd->resolveNeighbour(requestedNextHopAddress, destIE->getInterfaceId()); // might initiate NUD + if (macAddr.isUnspecified()) { + if (!destIE->isPointToPoint()) { + EV_INFO << "no link-layer address for next hop yet, passing datagram to Neighbour Discovery module\n"; + Ipv6NdControlInfo *ctrl = new Ipv6NdControlInfo(); + ctrl->setFromHL(true); + ctrl->setNextHop(requestedNextHopAddress); + ctrl->setInterfaceId(destIE->getInterfaceId()); + packet->cMessage::setControlInfo(ctrl); + send(packet, "ndOut"); + return; + } + } + else + EV_DETAIL << "link-layer address: " << macAddr << "\n"; + + } + else + macAddr = ipv6Header->getDestAddress().mapToMulticastMacAddress(); + + // send out datagram + fragmentPostRouting(packet, destIE, macAddr, true); + } else if (!ipv6Header->getDestAddress().isMulticast()) routePacket(packet, destIE, nullptr, requestedNextHopAddress, true); else From 62770e4b1e045c86077d4333efbf27d23220b4ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez-L=C3=B3pez?= Date: Sat, 23 Nov 2024 13:04:23 +0100 Subject: [PATCH 2/5] Update Ipv6.cc --- src/inet/networklayer/ipv6/Ipv6.cc | 32 ++---------------------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/inet/networklayer/ipv6/Ipv6.cc b/src/inet/networklayer/ipv6/Ipv6.cc index 644a9a2fc43..404736ab199 100644 --- a/src/inet/networklayer/ipv6/Ipv6.cc +++ b/src/inet/networklayer/ipv6/Ipv6.cc @@ -366,36 +366,8 @@ void Ipv6::datagramLocalOut(Packet *packet, const NetworkInterface *destIE, Ipv6 { const auto& ipv6Header = packet->peekAtFront(); // route packet - if (destIE != nullptr) { - Ipv6Address destAddress = ipv6Header->getDestAddress(); - MacAddress macAddr = MacAddress::UNSPECIFIED_ADDRESS; - - if (!destAddress.isMulticast()) { - EV_INFO << "next hop for " << destAddress << " is " << requestedNextHopAddress << ", interface " << destIE->getInterfaceName() << "\n"; - - macAddr = nd->resolveNeighbour(requestedNextHopAddress, destIE->getInterfaceId()); // might initiate NUD - if (macAddr.isUnspecified()) { - if (!destIE->isPointToPoint()) { - EV_INFO << "no link-layer address for next hop yet, passing datagram to Neighbour Discovery module\n"; - Ipv6NdControlInfo *ctrl = new Ipv6NdControlInfo(); - ctrl->setFromHL(true); - ctrl->setNextHop(requestedNextHopAddress); - ctrl->setInterfaceId(destIE->getInterfaceId()); - packet->cMessage::setControlInfo(ctrl); - send(packet, "ndOut"); - return; - } - } - else - EV_DETAIL << "link-layer address: " << macAddr << "\n"; - - } - else - macAddr = ipv6Header->getDestAddress().mapToMulticastMacAddress(); - - // send out datagram - fragmentPostRouting(packet, destIE, macAddr, true); - } + if (destIE != nullptr) + fragmentPostRouting(packet, destIE, MacAddress::BROADCAST_ADDRESS, true); // FIXME what MAC address to use? else if (!ipv6Header->getDestAddress().isMulticast()) routePacket(packet, destIE, nullptr, requestedNextHopAddress, true); else From b15ff678064a7b46822fa0ad0db452643b0720df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez-L=C3=B3pez?= <58361045+mgonzalezlopezudc@users.noreply.github.com> Date: Sat, 23 Nov 2024 13:06:18 +0100 Subject: [PATCH 3/5] [IPv6] [FIX] Send packet to correct MAC address instead of sending it to MAC broadcast address --- src/inet/networklayer/ipv6/Ipv6.cc | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/inet/networklayer/ipv6/Ipv6.cc b/src/inet/networklayer/ipv6/Ipv6.cc index 404736ab199..a3baca796c6 100644 --- a/src/inet/networklayer/ipv6/Ipv6.cc +++ b/src/inet/networklayer/ipv6/Ipv6.cc @@ -366,8 +366,34 @@ void Ipv6::datagramLocalOut(Packet *packet, const NetworkInterface *destIE, Ipv6 { const auto& ipv6Header = packet->peekAtFront(); // route packet - if (destIE != nullptr) - fragmentPostRouting(packet, destIE, MacAddress::BROADCAST_ADDRESS, true); // FIXME what MAC address to use? + if (destIE != nullptr) { + Ipv6Address destAddress = ipv6Header->getDestAddress(); + MacAddress macAddr = MacAddress::UNSPECIFIED_ADDRESS; + if (!destAddress.isMulticast()) { + EV_INFO << "next hop for " << destAddress << " is " << requestedNextHopAddress << ", interface " << destIE->getInterfaceName() << "\n"; + + macAddr = nd->resolveNeighbour(requestedNextHopAddress, destIE->getInterfaceId()); // might initiate NUD + if (macAddr.isUnspecified()) { + if (!destIE->isPointToPoint()) { + EV_INFO << "no link-layer address for next hop yet, passing datagram to Neighbour Discovery module\n"; + Ipv6NdControlInfo *ctrl = new Ipv6NdControlInfo(); + ctrl->setFromHL(true); + ctrl->setNextHop(requestedNextHopAddress); + ctrl->setInterfaceId(destIE->getInterfaceId()); + packet->cMessage::setControlInfo(ctrl); + send(packet, "ndOut"); + return; + } + } + else + EV_DETAIL << "link-layer address: " << macAddr << "\n"; + } + else + macAddr = ipv6Header->getDestAddress().mapToMulticastMacAddress(); + + // send out datagram + fragmentPostRouting(packet, destIE, macAddr, true); + } else if (!ipv6Header->getDestAddress().isMulticast()) routePacket(packet, destIE, nullptr, requestedNextHopAddress, true); else From fce385fe700d00fbd2eefec0df82cb6640fcfb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez-L=C3=B3pez?= Date: Tue, 26 Nov 2024 20:14:44 +0100 Subject: [PATCH 4/5] [IPv6][FIX] ND now confirms NCE reachability by receiving TCP ACK --- .../networklayer/icmpv6/Ipv6NeighbourDiscovery.cc | 12 +++++++++--- src/inet/transportlayer/tcp/TcpConnectionBase.cc | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/inet/networklayer/icmpv6/Ipv6NeighbourDiscovery.cc b/src/inet/networklayer/icmpv6/Ipv6NeighbourDiscovery.cc index 8efb3370d7d..b11cf85f21f 100644 --- a/src/inet/networklayer/icmpv6/Ipv6NeighbourDiscovery.cc +++ b/src/inet/networklayer/icmpv6/Ipv6NeighbourDiscovery.cc @@ -369,10 +369,13 @@ void Ipv6NeighbourDiscovery::reachabilityConfirmed(const Ipv6Address& neighbour, cMessage *msg = nce->nudTimeoutEvent; if (msg != nullptr) { - EV_INFO << "NUD in progress. Cancelling NUD Timer\n"; - bubble("Reachability Confirmed via NUD."); + EV_INFO << "NUD in progress. Cancelling NUD Timer because TCP ACK received from neighbour.\n"; + bubble("Reachability Confirmed via NUD. Received TCP ACK."); cancelAndDelete(msg); nce->nudTimeoutEvent = nullptr; + EV_INFO << "Set Neighbour Cache Entry state to REACHABLE\n"; + nce->reachabilityExpires = simTime() + ift->getInterfaceById(interfaceId)->getProtocolData()->_getReachableTime(); + nce->reachabilityState = Ipv6NeighbourCache::REACHABLE; } // TODO (see header file for description) @@ -479,7 +482,7 @@ void Ipv6NeighbourDiscovery::initiateNeighbourUnreachabilityDetection(Neighbour ASSERT(nce->reachabilityState == Ipv6NeighbourCache::STALE); ASSERT(nce->nudTimeoutEvent == nullptr); const Key *nceKey = nce->nceKey; - EV_INFO << "Initiating Neighbour Unreachability Detection"; + EV_INFO << "Initiating Neighbour Unreachability Detection.\n"; NetworkInterface *ie = ift->getInterfaceById(nceKey->interfaceID); EV_INFO << "Setting NCE state to DELAY.\n"; /*The first time a node sends a packet to a neighbor whose entry is @@ -2091,6 +2094,9 @@ void Ipv6NeighbourDiscovery::sendSolicitedNa(Packet *packet, const Ipv6Neighbour auto naPacket = new Packet("NApacket"); Icmpv6::insertCrc(crcMode, na, packet); naPacket->insertAtFront(na); + + EV_INFO << "Sending solicited NA to " << naDestAddr << "\n"; + sendPacketToIpv6Module(naPacket, naDestAddr, myIPv6Addr, ie->getInterfaceId()); } diff --git a/src/inet/transportlayer/tcp/TcpConnectionBase.cc b/src/inet/transportlayer/tcp/TcpConnectionBase.cc index 9ae4b5a9acc..012238c9434 100644 --- a/src/inet/transportlayer/tcp/TcpConnectionBase.cc +++ b/src/inet/transportlayer/tcp/TcpConnectionBase.cc @@ -16,6 +16,10 @@ #include "inet/transportlayer/tcp/TcpSackRexmitQueue.h" #include "inet/transportlayer/tcp/TcpSendQueue.h" #include "inet/transportlayer/tcp_common/TcpHeader.h" +#ifdef INET_WITH_IPv6 +#include "inet/linklayer/common/InterfaceTag_m.h" +#include "inet/networklayer/icmpv6/Ipv6NeighbourDiscovery.h" +#endif namespace inet { namespace tcp { @@ -206,6 +210,14 @@ bool TcpConnection::processTCPSegment(Packet *tcpSegment, const Ptr(this->getModuleByPath("^.^.ipv6.neighbourDiscovery")); + if(nd !=nullptr) + nd->reachabilityConfirmed(segSrcAddr.toIpv6(), tcpSegment->getTag()->getInterfaceId()); + } +#endif + // then state transitions return performStateTransition(event); } From 13720812ae775d7e2ff25f44713c3d6a7d062264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez-L=C3=B3pez?= Date: Tue, 26 Nov 2024 21:01:04 +0100 Subject: [PATCH 5/5] [IPv6][FIX] TCP connection only calls ND if the node has IPv6 --- src/inet/transportlayer/tcp/TcpConnectionBase.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inet/transportlayer/tcp/TcpConnectionBase.cc b/src/inet/transportlayer/tcp/TcpConnectionBase.cc index 012238c9434..05471044381 100644 --- a/src/inet/transportlayer/tcp/TcpConnectionBase.cc +++ b/src/inet/transportlayer/tcp/TcpConnectionBase.cc @@ -212,7 +212,7 @@ bool TcpConnection::processTCPSegment(Packet *tcpSegment, const Ptr(this->getModuleByPath("^.^.ipv6.neighbourDiscovery")); + auto nd = dynamic_cast(findModuleByPath("^.^.ipv6.neighbourDiscovery")); if(nd !=nullptr) nd->reachabilityConfirmed(segSrcAddr.toIpv6(), tcpSegment->getTag()->getInterfaceId()); }