public void CheckCost(IRouter From, IRouter To, int AdvertisedCost) { if (From == null || To == null) { throw new ArgumentNullException("Null router given"); } if (To == this) { //Do Nothing return; } /* * Get the link that the message is from. * Check that we actually link to it */ Link sourcelink; int cost = AdvertisedCost; sourcelink = links.FirstOrDefault(link => link.Target() == From); if (sourcelink == null) { throw new ArgumentException("This rouer doesn't link to sending router"); } /* * Add local edge cost advertised cost */ cost += sourcelink.Cost(); /* * If this costs less, add it to the routing table */ if (LowerCost(To, cost)) { table[To] = new RoutingTableEntry(AdvertisedCost + sourcelink.Cost(), sourcelink); } }
public void CheckCost(IRouter From, IRouter To, int AdvertisedCost) { if (From == null || To == null) { throw new ArgumentNullException("Null router given"); } if (To == this) { //Do Nothing return; } /* * Get the link that the message is from. * Check that we actually link to it */ Link sourcelink; int cost= AdvertisedCost; sourcelink = links.FirstOrDefault(link => link.Target() == From); if (sourcelink == null) { throw new ArgumentException("This rouer doesn't link to sending router"); } /* * Add local edge cost advertised cost */ cost += sourcelink.Cost(); /* * If this costs less, add it to the routing table */ if (LowerCost(To, cost)) { table[To] = new RoutingTableEntry(AdvertisedCost + sourcelink.Cost(), sourcelink); } }
/// <summary> /// Initialize an entry in the routing table from a router /// </summary> /// <param name="Target">Router to add with null next hop</param> private void Initialize(IRouter Target) { table[Target] = new RoutingTableEntry(999, null); }