private void SentNewRouterRecord(SlotWindow slotWindow) { try { NewLog2($"CC: Get RouteTableQueryResponse from CC", myWindow, "LightSkyBlue"); //NewLog($"SentNewRouterRecord path.Length {path.Length}", myWindow); for (int i = 0; i < path.Length; i++) { NewLog2($"Send SNP LinkConnectionRequest to LRM {path[i]}", myWindow, "LightSkyBlue"); int nextNode = -1; if (i < (path.Length - 1)) { nextNode = path[i + 1]; } RouterMapRecord newRecord = new RouterMapRecord(slotWindow, nextNode); string str = XmlSerialization.SerializeObject(newRecord); string message = MessageNames.ADD_RECORD + " " + str; string ipaddress = nodeDict[path[i]]; SendMessage(ipaddress, message); } } catch (Exception E) { NewLog("SentNewRouterRecord : " + E.Message, myWindow); } }
//idroutera private void HandleAvaibleSlotsInNode(string[] msg) { string resultstring = XmlSerialization.GetStringToNormal(msg); MessageAvaibleSlotsInNode messageAvaibleSlots = XmlSerialization.DeserializeObject <MessageAvaibleSlotsInNode>(resultstring); int index = FindIndexOfNodeInPath(messageAvaibleSlots.ID); Responses[index] = messageAvaibleSlots.AvaibleSlots; //NewLog2($"CC: Get SNP LinkConnectionRequestResponse from {index+1}", myWindow, "LightSkyBlue"); if (AreAllResponsesReceivevd() && (Responses.Length > 0)) { //NewLog($"Areallresponsereceived", myWindow); //NewLog($"Responses {Responses.Length}", myWindow); List <int> unionOfSlots = Responses[0]; for (int i = 1; i < Responses.Length; i++) { for (int j = 0; j < unionOfSlots.Count;) { if (Responses[i].Contains(unionOfSlots[j])) { j++; } else { unionOfSlots.RemoveAt(j); } } } string unionStr = ""; foreach (int i in unionOfSlots) { unionStr += " " + i; } NewLog($"RC: Found union of available slots {unionStr}", myWindow); Responses = null; SlotWindow slotWindow = new SlotWindow(); if (FindSlotWindow(unionOfSlots, ref slotWindow)) { NewLog($"RC: Found Slot Window: FirstSlot: {slotWindow.FirstSlot} NumberOfSlots: {slotWindow.NumberofSlots}", myWindow); NewLog($"RC: {IPRC} Send RouteTableQueryResponse to CC", myWindow); SentNewRouterRecord(slotWindow); } else { //Zaloguj brak dostępnych slotow NewLog($"No available slots!", myWindow); } } }
public void SendConnectionToHost(string[] data) { try { //NewLog($"Send CallConfirmed to: {SourceIPAddress.ToString()}", myWindow, "LightSeaGreen"); SlotWindow slotWindow = XmlSerialization.DeserializeObject <SlotWindow>( XmlSerialization.GetStringToNormal(data)); Connections connection = new Connections(); connection.slotWindow = slotWindow; connection.Destination = DestinationIPAddress.ToString(); string message = MessageNames.ADD_CONNECTION + " " + XmlSerialization.SerializeObject(connection); SendMessage(message, SourceIPAddress.ToString(), 11000); } catch (Exception ex) { NewLog($"SendConnectionToHost {ex}", myWindow, "AntiqueWhite"); } }
private void GetResponses(string msg) { enm++; SlotWindow receivedWindow = XmlSerialization.DeserializeObject <SlotWindow>(msg); if (slotWindow.FirstSlot == 0 && slotWindow.NumberofSlots == 0) { slotWindow = receivedWindow; } else if (!slotWindow.Equals(receivedWindow)) { //fail } //NewLog($"GET RESPONSES {enm}", myWindow); //if(AreAllResponses()) if (enm == path.Length) { //wyslij call confirmed lub peercoordination if (FlagDomain == 0) { SendCallConfirmed(); } else if (FlagDomain == 1 && tmp1 == true) { PeerCoordinationReq(); } else { NewLog($"PeerCoordinationResponse", myWindow); tmp1 = true; //SendPeerCoordinationResponse to other CC //string data = MessageNames.PEER_COORDINATION_RESPONSE; //SendingMessage(other_cc,data); SendCallConfirmed(); } slotWindow = new SlotWindow(0, 0); enm = 0; } }
private bool FindSlotWindow(List <int> slots, ref SlotWindow outSlotWindow) { int consecutive = 1; for (int i = 0; i < slots.Count; i++) { bool areConsecutive = (i > 0) && (slots[i] == (slots[i - 1] + 1)); if (areConsecutive) { consecutive++; } else { consecutive = 1; } if (consecutive == SlotNumber) { outSlotWindow.NumberofSlots = SlotNumber; outSlotWindow.FirstSlot = slots[i + 1 - consecutive]; return(true); } } return(false); }