void handleRouteRequest(AodvRReq request, NetworkInterface netInt) { setRoute(request.Source, netInt); if (request.Destination == node) { AodvRRep reply = new AodvRRep(node); RoutingInfoBundle bundle = new RoutingInfoBundle(node, request.Source, reply); Route(bundle); } }
public void Handle(Bundle bundle, NetworkInterface netInt) { ++receivedBundles; if (bundle.LifeTimeEnd < Timer.CurrentTime) { ++timeoutedBundles; return; //too old. Ignore. } if (broadcasted.Contains(bundle)) { ++ignoredBundles; return; } if (bundle is RoutingInfoBundle) { RoutingInfoBundle routingInfoBundle = (RoutingInfoBundle)bundle; handleRoutingInfo(routingInfoBundle.RoutingInfo, netInt); if (routingInfoBundle.Destination == null)//broadcast { broadcast(routingInfoBundle, netInt); } else { if (routingInfoBundle.Destination != node) { Route(routingInfoBundle, netInt); } } return; } if (bundle.Destination == node) { bundleInstance.Handle(bundle); } else { if (node.IsCustodian && bundle is DataBundle) { bundleInstance.Handle(bundle); return; } Route(bundle, netInt); } }
void onSendState(TimerEntry entry) { Timer.Schedule(Timer.CurrentTime + Configuration.Protocols.Dijkstra.StateSendingPeriod, onSendState, null); if (!node.IsAvailable) { return; } List <DijkstraLinkState> linkStates = new List <DijkstraLinkState>(); foreach (NetworkInterface netInt in node.NetworkInterfaces.Interfaces.Values) { DijkstraLinkState linkState = new DijkstraLinkState(netInt.Link, netInt.LinkSide.IsBroken); linkStates.Add(linkState); } DijkstraState state = new DijkstraState(Timer.CurrentTime, linkStates.ToArray()); RoutingInfoBundle bundle = new RoutingInfoBundle(node, null, state); broadcast(bundle, null); }
public override void Route(Bundle bundle, NetworkInterface source) { ++requestsToRoute; if (routingTable.Contains(bundle.Destination)) { routingTable[bundle.Destination].NetworkInterface.Send(bundle); ++routedBundles; return; } double bundleDelay = Math.Min(bundle.LifeTimeEnd, Timer.CurrentTime + Configuration.Protocols.Aodv.MaxBundleWaitingTime); TimerEntry timerEntry = Timer.Schedule(bundleDelay, onBundleDelayTooBig, bundle); delayedBundles.Add(bundle, timerEntry); if (!pendingRequests.Contains(bundle.Destination)) { TimerEntry pendingTimeout = Timer.Schedule(Timer.CurrentTime + Configuration.Protocols.Aodv.MaxBundleWaitingTime, onPendingRequestTimeout, bundle.Destination); pendingRequests.Add(bundle.Destination, pendingTimeout); AodvRReq aodvRReq = new AodvRReq(node, bundle.Destination); RoutingInfoBundle routingInfoBundle = new RoutingInfoBundle(node, null, aodvRReq); broadcast(routingInfoBundle, null); } }
//CALLBACKS void onLinkBreakChange(LinkSide linkSide) { if (!node.IsAvailable) { return; } LinkEntry entry = links[linkSide.Link]; entry.IsBroken = linkSide.IsBroken; entry.WhenUpdated = Timer.CurrentTime; List <DijkstraLinkStateUpdate> list = new List <DijkstraLinkStateUpdate>(); foreach (LinkEntry linkEntry in links.Values) { DijkstraLinkStateUpdate linkUpdate = new DijkstraLinkStateUpdate(linkEntry.Link, linkEntry.WhenUpdated, linkEntry.IsBroken); list.Add(linkUpdate); } DijkstraUpdate update = new DijkstraUpdate(list.ToArray()); RoutingInfoBundle bundle = new RoutingInfoBundle(node, null, update); NetworkInterface ignore = linkSide.IsBroken? node.NetworkInterfaces.Find(linkSide.Link):null; broadcast(bundle, ignore); }