internal void sendEntry(Node n, string s) { String[] entry = s.Split('/'); int[] val = new int[entry.Length]; if (val.Length != 4) { log("Wrong entry.", ConsoleColor.Red); return; } for (int i = 0; i < entry.Length; i++) { int.TryParse(entry[i], out val[i]); } FIB f = new FIB(val[0], val[1], val[2], val[3]); try { protocol.State = ManagmentProtocol.ROUTINGENTRY; protocol.RoutingEntry = f; string data = JSON.Serialize(JSON.FromValue(protocol)); n.SocketWriter.Write(data); } catch (IOException e) { log("Error: " + e.Message, ConsoleColor.Red); } }
public Trail(List <Node> path, List <NodeConnection> con, bool createdByUser, bool vc4 = false) { if (path == null) { return; } this.from = path.First(); this.to = path.Last(); this.Name = from.Name + "<>" + to.Name; this.componentNodes = new List <Node>(path); if (createdByUser) { priority = Priority.USER_CREATED; int portIn, portOut; int slot = 0; for (int n = 0; n < path.Count(); n++) { //points.Add(path.ElementAt(n).Position); if (n == 0) { //Start of path portFrom = findConnection(path.ElementAt(0), path.ElementAt(1), con).From.Equals(path.ElementAt(0)) ? findConnection(path.ElementAt(0), path.ElementAt(1), con).VirtualPortFrom : findConnection(path.ElementAt(0), path.ElementAt(1), con).VirtualPortTo; StartingSlot = findFirstFreeSlot(findConnection(from, path.ElementAt(n + 1), con), vc4); slot = StartingSlot; if (slot == -1) { clearTrail(this); break; } findConnection(from, path.ElementAt(n + 1), con).OccupiedSlots.Add(slot); findConnection(from, path.ElementAt(n + 1), con).AutoOccupiedSlots.Add(slot); connectionDictionary.Add(findConnection(from, path.ElementAt(n + 1), con), slot); continue; } if (n == path.Count() - 1) { //End of path portTo = findConnection(path.ElementAt(n - 1), path.ElementAt(n), con).To.Equals(path.ElementAt(n)) ? findConnection(path.ElementAt(n - 1), path.ElementAt(n), con).VirtualPortTo : findConnection(path.ElementAt(n - 1), path.ElementAt(n), con).VirtualPortFrom; continue; } NodeConnection conIn = findConnection(path.ElementAt(n - 1), path.ElementAt(n), con); NodeConnection conOut = findConnection(path.ElementAt(n), path.ElementAt(n + 1), con); portIn = conIn.To.Equals(path.ElementAt(n)) ? conIn.VirtualPortTo : conIn.VirtualPortFrom; portOut = conOut.From.Equals(path.ElementAt(n)) ? conOut.VirtualPortFrom : conOut.VirtualPortTo; int slotTemp = findFirstFreeSlot(conOut, vc4); if (slotTemp == -1) { clearTrail(this); break; } if (slot == -1) { clearTrail(this); break; } endingSlot = slotTemp; //StartingSlot = startinS; FIB newFibFrom = new FIB(portIn, slot, portOut, slotTemp); FIB newFibTo = new FIB(portOut, slotTemp, portIn, slot); slot = slotTemp; findConnection(path.ElementAt(n), path.ElementAt(n + 1), con).OccupiedSlots.Add(slot); findConnection(path.ElementAt(n), path.ElementAt(n + 1), con).AutoOccupiedSlots.Add(slot); connectionDictionary.Add(findConnection(path.ElementAt(n), path.ElementAt(n + 1), con), slot); ComponentFIBs.Add(path.ElementAt(n), newFibFrom); //ComponentFIBs.Add(path.ElementAt(n), newFibTo); } } else { priority = Priority.AUTO; int portIn, portOut; int slot = 0; for (int n = 0; n < path.Count(); n++) { //points.Add(path.ElementAt(n).Position); if (n == 0) { //Start of path portFrom = findConnection(path.ElementAt(0), path.ElementAt(1), con).From.Equals(path.ElementAt(0)) ? findConnection(path.ElementAt(0), path.ElementAt(1), con).VirtualPortFrom : findConnection(path.ElementAt(0), path.ElementAt(1), con).VirtualPortTo; StartingSlot = findFirstAutoFreeSlot(findConnection(from, path.ElementAt(n + 1), con)); slot = StartingSlot; NodeConnection connection = findConnection(from, path.ElementAt(n + 1), con); connection.AutoOccupiedSlots.Add(slot); connectionDictionary.Add(connection, slot); continue; } if (n == path.Count() - 1) { //End of path portTo = findConnection(path.ElementAt(n - 1), path.ElementAt(n), con).To.Equals(path.ElementAt(n)) ? findConnection(path.ElementAt(n - 1), path.ElementAt(n), con).VirtualPortTo : findConnection(path.ElementAt(n - 1), path.ElementAt(n), con).VirtualPortFrom; continue; } NodeConnection conIn = findConnection(path.ElementAt(n - 1), path.ElementAt(n), con); NodeConnection conOut = findConnection(path.ElementAt(n), path.ElementAt(n + 1), con); portIn = conIn.To.Equals(path.ElementAt(n)) ? conIn.VirtualPortTo : conIn.VirtualPortFrom; portOut = conOut.From.Equals(path.ElementAt(n)) ? conOut.VirtualPortFrom : conOut.VirtualPortTo; int slotTemp = findFirstAutoFreeSlot(conOut); if (slotTemp == -1) { clearTrail(this); break; } if (slot == -1) { clearTrail(this); break; } //StartingSlot = startinS; FIB newFib = new FIB(portIn, slot, portOut, slotTemp); slot = slotTemp; NodeConnection connectionTemp2 = findConnection(path.ElementAt(n), path.ElementAt(n + 1), con); connectionTemp2.AutoOccupiedSlots.Add(slot); connectionDictionary.Add(connectionTemp2, slot); ComponentFIBs.Add(path.ElementAt(n), newFib); } } }