public bool checkManualRoutingNodesReachability(int nodeA, int nodeB) { if (RoutingController.findAnyManualRoute(this.manual_routes, nodeA, nodeB) == null) { return(false); } else { //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ } return(true); }
public void SimulationTick(int tick_no) { for (int n = 0; n < SimulationParams.lambda; n++) { if (SimulationParams.network_size < 2) { throw new IndexOutOfRangeException(); } int from = -1; int to = -1; while (true) { from = random_gen_for_packet_generation.Next(1, nodes.Count); to = random_gen_for_packet_generation.Next(1, nodes.Count); if (from != to) { break; } } if (SimulationParams.routing_algorithm == 3 || SimulationParams.routing_algorithm == 2) { int retries = 100; List <int> route = new List <int>(); if (SimulationParams.routing_algorithm == 2) { route = findRandomRoute(from, to, 10); } else { route = RoutingController.findAnyManualRoute(manual_routes, from, to); } getNodeById(from).buffer_in.Enqueue(new Packet(from, to, route, SimulationParams.TTL)); getNodeById(from).stat_packets_gen++; } else { throw new NotImplementedException("not implemented"); } } foreach (NetworkNode n in nodes) { //handle 1 packet from in queue if (n.buffer_in.Count > 0 && n.buffer_in.Peek().last_tick_id_which_transitioned != tick_no) { if (n.buffer_in.Peek().last_tick_id_which_transitioned > tick_no) { throw new Exception("invalid tick_no"); } //packet was sent in one of previous ticks Packet p = n.buffer_in.Dequeue().copy(); p.TTL--; if (p.TTL <= 0) { n.stat_TTL_exceeded_packet_count++; } else { if (p.uuid == 4) { int visited = p.stat_nodes_visited; List <int> through = p.node_through; long uuid = p.uuid; } //TTL indicates that packet can be forwarded if (p.node_to == n.id) //packet reaches destination { n.stat_packets_term++; n.stat_reached_dest_TTL_sum += p.TTL; n.stat_total_hops_count += p.node_visited_history.Count; //n.stat_total_hops_count += p.stat_nodes_visited; } else //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!@#$ { if (p.node_through.Count > 0 && p.node_through[0] == n.id) { p.node_through.RemoveAt(0); if (p.uuid == 4) { } p.stat_nodes_visited++; n.stat_packets_trans++; if (p.node_through.Count > 0) { if (getNodeById(p.node_through[0]).buffer_in.Count >= SimulationParams.buffer_size) { getNodeById(p.node_through[0]).stat_buffer_full_packet_count++; } else { forward_history[p.node_through[0]] += p.uuid + ", "; p.node_visited_history.Add(n.id); getNodeById(p.node_through[0]).buffer_in.Enqueue(p.getPacketCopyWithLastTickSet(tick_no)); } } else { //throw new Exception("this packet should have been terminated"); Console.WriteLine("this packet: " + p.uuid + " should have been terminated, count: " + (++invalid_termination)); } } else { throw new Exception("invalid node_through entry or structure"); } } } } else { //do nothing; as the packet was sent in this tick and //because of that if could not have been received //on the dest node already } } }