Hi,
I don't see any NextHop in Ipv4RoutingTableEntry... except for the function parameters names (which might be misleading).
Let me clarify this a bit, perhaps it will help.
First and foremost: I'm not the responsible for cleaning up a mess made my years of history. And I'm not talking about ns-3, I'm talking about *everything*. We can just see the mess, ¯\_(ツ)_/¯, and say "oh, well".
- First fact: there's no "Gateway". Technically speaking, a Gateway is a L7 appliance, here we're talking about L3, so they're Routers. However, historically, they're called Gateway, mostly because it looked simpler in the configuration interfaces of computers. I't's easier to tell the user to set the Gateway (to Internet) than to explain them what's a Router, so the name did stick. And this also did reflect in the Linux programming APIs.
- Second fact: ns-3 heavily re-uses Linux APIs conventions and naming, so that it's easier (?) for users that are used to Linux.
- Third fact: there's no "NextHop" - unless you're in a mesh network.
And now the lengthy one... mind I'll use a language that applies both to IPv4 and IPv6, so I'll not write "subnet", I'll write "link-level domain".
If you're in a non-mesh network your host (or router) needs to find the next device to send the packet to. This can be seen as the "next hop", but if you look at it it's just another router: the next one toward the destination. This "next router" can be responsible for forwarding packets to a single IP, to a group of them, or to the whole Internet - it doesn't really matter. From the point of view of a device, we can (colloquially) call it the Gateway toward this (or these) addresses. So "Next Hop" and "Gateway" are synonyms.
Now, if we look at it from the point of view of code, when you ask the routing protocol for a Route, it will return it, and the Route will have a Gateway (again, it's the Next Hop). If it's zero, it means that either you can deliver the packet directly, or that you're in trouble.
If it's a valid node, you take its IP address, you convert the IP address into a MAC address, and you send the packet to it - simple as that.
In a mesh network this is slightly different, but I guess you're not interested into that complication (it depends on if the mesh is made at L3 or L2).
So, to summarise... Next Hop === Gateway.
About why your simulation breaks if you use "route->SetGateway (gateway)"... no idea, but typically the Lookup function is a lookup, so it shouldn't change the routing table entry. It *might*, as you could want to use late-invalidation, so it's not marked as const, but that's it.