0

For one of my courses I am writing a Java Applet that simulates network activity. I have a host machine which keeps an ARP table of MAC to IP address, and then I have the switch keeps track of what MAC is attached to what physical port. (interface)

My question is, how should I simulate the router. From my understanding, the host will perform a computation on the outgoing IP to determine if that IP is on the network, assuming it is not, the host sends the packet to the default gateway (by looking up the MAC address of the IP address of the default gateway), in this case the router. Now the router will have at least two interfaces on two different networks.

So, my theory is that the router will look at the destination IP address and pipe the packet down the right interface that has that network on it. But then, do routers have "default gateways" where if none of those interfaces are on the destination network, can the router just pass it off to some other router?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Matthew
  • 3,886
  • 7
  • 47
  • 84

2 Answers2

1

Not exactly. Routers have routing tables. They take the destination address of a a packet and find the route to that destination. The algorithm they use is, basically, "longest match" (or "most specific match").

To implement the equivalent of a default gateway, you place a default route, that is, a route with a destination of 0.0.0.0/0. That will match every packet (since every packet is in that network), but it will always be the worst match.

Here's an anonymized routing table from one of my routers:

C    x.y.z.104/29 is directly connected, FastEthernet0/0
S    10.0.0.0/8 is directly connected, Null0
S    192.168.0.0/24 [1/0] is directory connected, FastEthernet 1/0
S*   0.0.0.0/0 [1/0] via x.y.z.1
S    192.168.0.0/16 is directly connected, Null0

The first route is the public LAN. The third route is the private LAN. Notice the two "Null0" routes to stop traffic to unused private IP addresses from going out the default route to my ISP. The second to last route is the default route.

Note that most devices that we typically think of as end systems are really routers anyway. Typical PC and server operating systems have router capabilities too, so they internally use routing tables, metrics, and longest match too.

David Schwartz
  • 179,497
  • 17
  • 214
  • 278
0

Routers can have default routes. In a longest prefix match then the /0 entry will point to the default route.

kgunjikar
  • 455
  • 4
  • 17