• Status: Solved
• Priority: Medium
• Security: Public
• Views: 330

# routing table for router

I am writing a program that implements on how a router works... basically it implements a distance vector protocol. Say I have a router A. A will receive a routing update from each of it's neighbors indicating the cost of reaching various other routers through it. So in my mind I have two idea here, first the router needs to know if it wants to forward packet to say X, then it needs to know where to forward that data next in order to achieve the shortest path. So in the routing table entries it needs to know the whole topology of the network right?? I am just confused on how can I actually implement this table... I am planning to create it as a 2d array... but still not sure if it's the way to go. As of now I just have am array of structs, the struct represents a neighbor objects.. In this case it holds all the information of the neighbor that is directly connected to A, but it doesn't know where to forward a packet as it doesn't know the shortest path... I hope this makes sense... all suggestions are welcomed
0
kuntilanak
1 Solution

IT AssociateCommented:
Hi,

You can check the code implementation of Quagga or Xorp or zebra. They all are open source so you can see the code of Implementation of routing algorithms like Distance Vector, OSPF.

www.zebra.org
www.quagga.net
www.xorp.org/
0

Author Commented:
but talking specifically about my implementation, I was thinking to have to classify two neighbors, which is the direct and indirect neighbors... if I send a routing update to my routing table then what I send is just the direct neighbors but the indirect neighbors is used to forward data
0

Commented:
Can you define what you mean by "direct" and "indirect" neighbors?

In my terms you would route to a direct neighbor because they would be on the same subnet as me.  An indirect neighbor would be somebody that is not on the same subnet and therefor I would need to route to them.

Also, in your design you may want to take into account something other than the "shortest" path.  Typically the shortest path is the one with the least number of hops.  The problem with this is that path may not have the fastest link or could be saturated with traffic and therefore may not provide the quickest path to the remote host.
0

Author Commented:
an indirect neighbor is a neighbor that can be reached via a direct neighbor
0

Commented:
When you go to talk to a IP host there are 3 possibility:

1) They are on the same subnet as me and I can talk directly to them.
2) They are not on the same subnet as me and I have a defined route to them.
3) They are not on the same subnet as me and I have no defined route to them.

A defined route can be either a route for that specific host, a route for that hosts specific subnet, or a route for a network that  includes that hosts IP address.

In situation #1 you would send the data directly to the host.
In situation #2 you would forward packet data to the next hop based on the defined route that includes that host's IP address.
In situation #3 if there is a default gateway/route, you would forward the packet to the default gateway/router and let it handled it.

You may want to read up on OSPF, or even RIPV2 and see how these dynamic routing protocols work.

0

Author Commented:
I think you just overkilled my initial problem, the assignment instructions just asks me to send routing table to it's routing tables.. and in my case, case no. 3 doesn't apply here... I guess if the router are connected to each other then it can always reach it...
0

Commented:
Say you have two routers that are connected via a telephone line, what happens when that line gets cut?  Even if you have a direct crossover cable between to routers, the cable could get unplugged, cut or the physical interface they are connected to could die.  There are many possibilities of two routers loosing communications with each other.

You can't assume that just because two routers are connected to each they can always reach each other.  That is why when using dynamic routing there are timers that will flush the routing table if there has not been updates or communications between the routers that are participating in the dynamic routing.

Again, if you read just a bit about OSPF or RIP V2 you can get an idea of how it is done.
0

Author Commented:
okay.. I got it..
0

Commented:
Generally routers keep a forwarding table, a hashed table of L2 destinations per L3 destination, sort of aglobal arp table for non connected networks.

But your problem, is to rewrite rip, version 2. The router needs to be able to do a most specific match on the routing table and then figire out which entry if any best matches a particular ip using a most specific route algorithm.

Good luck by the way.

Essentially rip works by advertising every route ( network + subnet mask + metric  in its route table every update period.

Add routes for interfaces it is connected to to the route table with a hopcount of 1. If you get a update from another router, add it to your route table , incrementing the metrics on each route by one hopcount.
Keep a local route table that has the route, netmask, metric , router learned from and interface learned on.

Do not advertise routes out interfaces they are learned on. Do not advertise routes that have a metric of a certain number (16 for rip). Purge routes that you have not received in three update periods.

This is rip in a nutshell.
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.