public bool SendDataPacket(MobileNode node, int wait, string tag) { controller.PrintToOutputPane(tag, "Sending DATA from " + nodeID + " to " + node.GetNodeID() + "."); /* If the node we're sendin to is partial selfish, drop the packet */ if (node.IsPartialSelfish()) { controller.PrintToOutputPane(tag, string.Format("Node {0} dropped DATA Packet.", node.GetNodeID())); TransmitDataDropped(this, node, wait, DATA_COLOUR); return(false); } /* Otherwise, transmission is successful */ TransmitData(this, node, wait, DATA_COLOUR); return(true); }
public bool SendMessageDSR(Message message, SessionData sData, int delay) { MobileNode sourceNode = message.GetSourceNode(); MobileNode destinationNode = message.GetDestinstationNode(); Route route = sourceNode.GetBestRouteDSR(destinationNode); /* If no known route, attempt to find one */ if (route == null) { controller.PrintToOutputPane(OutputTag.TAG_DSR, "No Known Route to Destination."); /* Perform Route Discovery */ sourceNode.DSRRouteDiscovery(destinationNode, this, sData, delay); route = sourceNode.GetBestRouteDSR(destinationNode); /* If no route found, abort transfer */ if (route == null) { controller.PrintToOutputPane(OutputTag.TAG_DSR, "No Route to Destination."); return(false); } } controller.PrintToOutputPane(OutputTag.TAG_DSR, string.Format("Sending Message #{0}.", message.GetMessageID())); controller.PrintToOutputPane(OutputTag.TAG_DSR, "Source Node: " + sourceNode.GetNodeID()); controller.PrintToOutputPane(OutputTag.TAG_DSR, "Destination Node: " + destinationNode.GetNodeID()); controller.PrintToOutputPane(OutputTag.TAG_DSR, "Route Chosen: " + route.GetRouteAsString()); List <MobileNode> nodes = route.GetNodeRoute(); /* Send DATA Packet */ for (int i = 1; i < nodes.Count; i++) { if (!nodes[i - 1].SendDataPacket(nodes[i], delay, OutputTag.TAG_DSR)) { return(false); } } /* Send ACK Packet */ for (int i = nodes.Count - 2; i >= 0; i--) { nodes[i + 1].SendAckPacket(nodes[i], delay, OutputTag.TAG_DSR); sData.IncrementNumberOfControlPackets(); } /* Calculate End-To-End Delay */ sData.IncrementNumberOfSuccessfulTransmissions(); sData.endToEndDelays.Add((route.GetTransmissionTime()) * 4); return(true); }
public List <Route> SADSRRouteDiscovery(MobileNode destNode, SimulationEnvironment env, SessionData sData, int delay, bool modVersion) { string tag = ""; if (modVersion) { tag = OutputTag.TAG_MSADSR; } else { tag = OutputTag.TAG_SADSR; } controller.PrintToOutputPane(tag, "Performing " + tag + " Route Discovery from Node " + nodeID + " to Node " + destNode.GetNodeID() + "."); List <Route> routes = SADSRRouteDiscoveryHelper(destNode, env, new Route(), sData, delay, modVersion, tag); if (routes == null) { return(null); } /* If there are already known routes, add if unique */ if (knownRoutes.ContainsKey(destNode.GetNodeID())) { foreach (Route r in routes) { bool exists = false; // for each route in the routing table corresponding to the destination node foreach (Route r2 in knownRoutes[destNode.GetNodeID()]) { // if they are equivalent routes, don't bother adding to routing table if (r2.RouteCompare(r)) { exists = true; break; } } // if the route isn't in the routing table, add it if (!exists) { knownRoutes[destNode.GetNodeID()].Add(r); } } } /* Otherwise, add all routes to routing table */ else { knownRoutes.Add(destNode.GetNodeID(), routes); } return(routes); }
public bool SendRREQPacket(MobileNode node, int wait, SessionData sessionData, string tag) { controller.PrintToOutputPane(tag, string.Format("Sending RREQ from Node {0} to Node {1}.", nodeID, node.GetNodeID())); /* If the node we're sending to is pure selfish, drop the packet */ if (node.IsPureSelfish()) { controller.PrintToOutputPane(tag, string.Format("Node {0} dropped RREQ Packet.", node.GetNodeID())); TransmitDataDropped(this, node, wait, RREQ_COLOUR); sessionData.IncrementNumberOfControlPackets(); return(false); } /* Otherwise, transmission is successful */ TransmitData(this, node, wait, RREQ_COLOUR); sessionData.IncrementNumberOfControlPackets(); return(true); }
public bool SendRREQPacketSelfish(MobileNode node, int wait, SessionData sessionData, string tag) { Random r = new Random(); double poll = r.NextDouble(); if (poll > node.GetForwardingProbability()) { return(SendRREQPacket(node, wait, sessionData, tag)); } else { controller.PrintToOutputPane(tag, string.Format("Node {0} dropped RREQ Packet due to Protocol Driven Selfish Behaviour.", node.GetNodeID())); TransmitDataDropped(this, node, wait, RREQ_COLOUR); sessionData.IncrementNumberOfControlPackets(); return(false); } }
// Add send message DSR here public bool SendMessageDSR(Message message) { MobileNode sourceNode = message.GetSourceNode(); MobileNode destinationNode = message.GetDestinstationNode(); RoutingPacket route = sourceNode.GetBestRouteDSR(destinationNode); // If no known route found if (route == null) { new OutputPaneController().PrintToOutputPane("DSR", "No Known Route to Destination."); sourceNode.RouteDiscoveryDSR(destinationNode, this); // Perform Route Discovery route = sourceNode.GetBestRouteDSR(destinationNode); // Attempt to assign newly found best route if (route == null) { new OutputPaneController().PrintToOutputPane("DSR", "No Route to Destination."); return(false); } } new OutputPaneController().PrintToOutputPane("DSR", "Sending Message:"); new OutputPaneController().PrintToOutputPane("DSR", "Source Node: " + sourceNode.GetNodeID()); new OutputPaneController().PrintToOutputPane("DSR", "Destination Node: " + destinationNode.GetNodeID()); new OutputPaneController().PrintToOutputPane("DSR", "Route Chosen: " + route.GetRouteAsString()); List <MobileNode> nodes = route.GetNodeRoute(); new OutputPaneController().PrintToOutputPane("DSR", "Beginning Message Transmission from Source Node " + sourceNode.GetNodeID()); for (int i = 1; i < nodes.Count; i++) { new OutputPaneController().PrintToOutputPane("DSR", "Sending Message from " + nodes[i - 1].GetNodeID() + " to " + nodes[i].GetNodeID() + "."); TransmitData(nodes[i - 1], nodes[i], 2000, DATA_COLOUR); } new OutputPaneController().PrintToOutputPane("DSR", "Received Message at Destination Node " + destinationNode.GetNodeID()); new OutputPaneController().PrintToOutputPane("DSR", "Beginning ACK Transmission from Destination Node " + destinationNode.GetNodeID()); for (int i = nodes.Count - 2; i >= 0; i--) { new OutputPaneController().PrintToOutputPane("DSR", "Sending ACK from " + nodes[i + 1].GetNodeID() + " to " + nodes[i].GetNodeID()); TransmitData(nodes[i + 1], nodes[i], 500, ACK_COLOUR); } new OutputPaneController().PrintToOutputPane("DSR", "Received ACK at Source Node " + sourceNode.GetNodeID()); return(true); }
// Get the route with the least number of selfish nodes public RoutingPacket GetLeastSelfishRouteMSADSR(MobileNode node) { List <RoutingPacket> routes = GetRoutesToNode(node); RoutingPacket optRoute = new RoutingPacket(); int minMisbehavedNodes = 999999; if (routes == null) { return(null); } foreach (RoutingPacket r in routes) { if (minMisbehavedNodes >= r.GetMisbehavedNodes().Count) { minMisbehavedNodes = r.GetMisbehavedNodes().Count; optRoute = r; } } return(optRoute); }
// DSR implementation public List <Route> DSRRouteDiscovery(MobileNode destNode, SimulationEnvironment env, SessionData sData, int delay) { controller.PrintToOutputPane(OutputTag.TAG_DSR, "Performing Route Discovery from Node " + nodeID + " to Node " + destNode.GetNodeID() + "."); /* Perform Recursive Route Discovery to Collect all Valid Routes to the Destination */ List <Route> routes = DSRRouteDiscoveryHelper(destNode, env, new Route(), sData, delay); if (routes == null) { return(null); } /* If there are already known routes, add if unique */ if (knownRoutes.ContainsKey(destNode.GetNodeID())) { foreach (Route r in routes) { bool exists = false; foreach (Route r2 in knownRoutes[destNode.GetNodeID()]) // for each route in the routing table corresponding to the destination node { if (r2.RouteCompare(r)) // if they are equivalent routes, don't bother adding to routing table { exists = true; break; } } if (!exists) // if the route isn't in the routing table, add it { knownRoutes[destNode.GetNodeID()].Add(r); } } } /* Otherwise, add all routes to routing table */ else { knownRoutes.Add(destNode.GetNodeID(), routes); } return(routes); }
// Get the optimal route for SA-DSR public RoutingPacket GetOptimalRouteSADSR(MobileNode node) { List <RoutingPacket> routes = GetRoutesToNode(node); RoutingPacket optRoute = new RoutingPacket(); double sdp = 0; if (routes == null) { return(null); } foreach (RoutingPacket r in routes) { r.CalcSDP(); } foreach (RoutingPacket r in routes) { if (sdp < r.getSDP()) { sdp = r.getSDP(); optRoute = r; } } return(optRoute); }
public Message(MobileNode src, MobileNode dst) { messageID = ++messageCount; sourceNode = src; destinationNode = dst; }
private List <RoutingPacket> DSRDiscovery(MobileNode destNode, SimulationEnvironment env, RoutingPacket route) { List <RoutingPacket> routes = new List <RoutingPacket>(); if (knownRoutes.ContainsKey(destNode.GetNodeID())) { foreach (RoutingPacket r in knownRoutes[destNode.GetNodeID()]) { RoutingPacket r2 = route.Copy(); r2.AddNodesToRoute(r.GetNodeRoute()); routes.Add(r2); } return(routes); } List <MobileNode> nodesWithinRange = GetNodesWithinRange(env); if (nodesWithinRange.Count == 0 && !destNode.Equals(this)) { return(null); } foreach (MobileNode node in nodesWithinRange) { // If node isn't in route yet... if (!route.IsInRouteAlready(node)) { // If node is the destination node... if (node.Equals(destNode)) { //Obtaining all possible routes RoutingPacket rPacket = route.Copy(); rPacket.AddNodeToRoute(this); // Adding nodes to route rPacket.AddNodeToRoute(node); routes.Add(rPacket); // Adding all possible routes new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREQ from Node {0} to Node {1}.", nodeID, node.GetNodeID())); env.TransmitData(this, node, 500, env.RREQ_COLOUR); new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREP from Node {0} to Node {1}.", node.GetNodeID(), nodeID)); env.TransmitData(node, this, 500, env.RREP_COLOUR); } else { RoutingPacket rPacket = route.Copy(); rPacket.AddNodeToRoute(this); new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREQ from Node {0} to Node {1}.", nodeID, node.GetNodeID())); env.TransmitData(this, node, 500, env.RREQ_COLOUR); routes.AddRange(node.DSRDiscovery(destNode, env, rPacket)); // Recursive call } } } foreach (RoutingPacket r in routes) { if (r.GetNodeRoute().Contains(destNode)) { List <MobileNode> rList = r.GetNodeRoute(); for (int i = 0; i < rList.Count; i++) { if (rList[i] == this && i != 0) { new OutputPaneController().PrintToOutputPane("DSR", string.Format("Sending RREP from Node {0} to Node {1}.", nodeID, rList[i - 1].GetNodeID())); env.TransmitData(this, rList[i - 1], 500, env.RREP_COLOUR); } } } } return(routes); }
public void SendTWOACKPacket(MobileNode node, int wait, string tag) { controller.PrintToOutputPane(tag, string.Format("Sending TWOACK from Node {0} to Node {1}.", nodeID, node.GetNodeID())); TransmitData(this, node, wait, TWOACK_COLOR); }
public void SendRREPPacket(MobileNode node, int wait, SessionData session, string tag) { controller.PrintToOutputPane(tag, string.Format("Sending RREP from Node {0} to Node {1}.", node.GetNodeID(), nodeID)); TransmitData(node, this, wait, RREP_COLOUR); session.IncrementNumberOfControlPackets(); }
public void SendAckPacket(MobileNode node, int wait, string tag) { controller.PrintToOutputPane(tag, "Sending ACK from " + nodeID + " to " + node.GetNodeID()); TransmitData(this, node, wait, ACK_COLOUR); }
public void AddNodeToRoute(MobileNode node) { nodeRoute.Add(node); }
private List <Route> SADSRRouteDiscoveryHelper(MobileNode destNode, SimulationEnvironment env, Route route, SessionData sData, int delay, bool modVersion, string tag) { /* Collect all known routes from here to destination */ List <Route> routes = new List <Route>(); if (knownRoutes.ContainsKey(destNode.GetNodeID()) && knownRoutes[destNode.GetNodeID()] != null) { foreach (Route r in knownRoutes[destNode.GetNodeID()]) { // create copy of route, add current node, and add to routes list Route r2 = route.Copy(); r2.AddNodesToRoute(r.GetNodeRoute()); routes.Add(r2); } return(routes); } /* Flood RREQ's to Nodes within Range */ List <MobileNode> nodesWithinRange = GetNodesWithinRange(env); if (nodesWithinRange.Count == 0 && !destNode.Equals(this)) { return(null); } /* For all nodes within range... */ foreach (MobileNode node in nodesWithinRange) { // If node isn't in route yet... if (!route.IsInRouteAlready(node)) { // If node is the destination node... if (node.Equals(destNode)) { /* Send RREQ from current node to the destination node */ if (SendRREQPacketSelfish(node, delay, sData, tag)) { // Add current node and dest node to route Route rPacket = route.Copy(); rPacket.AddNodeToRoute(this); rPacket.AddNodeToRoute(node); // Add new route to routes collection routes.Add(rPacket); } else { continue; } /* Send RREQ from destination node to the current node */ node.SendRREPPacket(this, delay, sData, tag); } // If node is not the destination node... else { /* Send RREQ from this node to node */ if (SendRREQPacketSelfish(node, delay, sData, tag)) { // Add current node to the route Route rPacket = route.Copy(); rPacket.AddNodeToRoute(this); /* Recursively perform discovery from this node, and collect all returned valid routes */ if (routes != null) { routes.AddRange(node.SADSRRouteDiscoveryHelper(destNode, env, rPacket, sData, delay, modVersion, tag)); } } else { continue; } } } } foreach (Route r in routes) { if (r.GetNodeRoute().Contains(destNode)) { // redundancy check List <MobileNode> rList = r.GetNodeRoute(); for (int i = 0; i < rList.Count; i++) { if (rList[i] == this && i != 0) { SendRREPPacket(rList[i - 1], delay, sData, OutputTag.TAG_SADSR); } } } } return(routes); }
public bool IsInRouteAlready(MobileNode node) { return(nodeRoute.Contains(node)); }
public double GetDistance(MobileNode node) { return(Math.Sqrt((Math.Pow((CenterX - node.CenterX), 2)) + (Math.Pow((CenterY - node.CenterY), 2)))); }
public bool SendMessageMSADSR(Message message, SessionData sData, int delay) { MobileNode sourceNode = message.GetSourceNode(); MobileNode destinationNode = message.GetDestinstationNode(); Route route = sourceNode.GetBestRouteMSADSR(destinationNode); /* If no route known, perform Route Discovery to find one */ List <Route> routes = null; if (route == null) { controller.PrintToOutputPane(OutputTag.TAG_MSADSR, "No Known Route to Destination."); routes = sourceNode.SADSRRouteDiscovery(destinationNode, this, sData, delay, true); // Route Discovery route = sourceNode.GetBestRouteMSADSR(destinationNode); // Get best known route // If still no route found, abort. if (route == null) { sourceNode.DecreaseAltruismCoefficient(); controller.PrintToOutputPane(OutputTag.TAG_MSADSR, "No Route to Destination."); return(false); } sourceNode.IncreaseAltruismCoefficient(); } int validCounter = 0; if (routes != null) { controller.PrintToOutputPane(OutputTag.TAG_NOTE, routes.Count + " routes found."); foreach (Route r in routes) { controller.PrintToOutputPane(OutputTag.TAG_NOTE, "SDP: " + r.CalcSDP()); controller.PrintToOutputPane(OutputTag.TAG_NOTE, "Delay: " + r.GetTransmissionTime()); if (route.GetTransmissionTime() < MobileNode.SA_TIMEOUT) { validCounter++; } } controller.PrintToOutputPane(OutputTag.TAG_NOTE, validCounter + " routes within timeframe"); } controller.PrintToOutputPane(OutputTag.TAG_MSADSR, "Route Selected: " + route.GetRouteAsString()); controller.PrintToOutputPane(OutputTag.TAG_MSADSR, "Selected Route's SDP: " + route.CalcSDP()); controller.PrintToOutputPane(OutputTag.TAG_MSADSR, "Selected Route's Transmission Time: " + route.GetTransmissionTime()); List <MobileNode> nodes = route.GetNodeRoute(); /* Send DATA Packet */ for (int i = 1; i < nodes.Count; i++) { if (!nodes[i - 1].SendDataPacket(nodes[i], delay, OutputTag.TAG_MSADSR)) { if (i >= 2) { // add nodes[i-1] to nodes[i-2].blacklist nodes[i - 2].blackList.Add(nodes[i - 1]); } return(false); } if (i >= 2) { nodes[i].SendAckPacket(nodes[i - 1], delay, OutputTag.TAG_MSADSR); sData.IncrementNumberOfControlPackets(); nodes[i - 1].SendAckPacket(nodes[i - 2], delay, OutputTag.TAG_MSADSR); sData.IncrementNumberOfControlPackets(); } } /* Send ACK Packet */ for (int i = nodes.Count - 2; i >= 0; i--) { nodes[i + 1].SendAckPacket(nodes[i], delay, OutputTag.TAG_MSADSR); sData.IncrementNumberOfControlPackets(); } /* Calculate End-To-End Delay */ sData.IncrementNumberOfSuccessfulTransmissions(); sData.endToEndDelays.Add((route.GetTransmissionTime()) * 4); // this is good for normal SA-DSR, not for MSA-DSR return(true); }
public bool IsWithinRangeOf(MobileNode node) { return(GetDistance(node) < 200); }
public void AddNode(MobileNode node) { mobileNodes.Add(node); }
public void AddNodeToMisbehaved(MobileNode node) { misbehavedNodes.Add(node); }