private void CallRequest(CommandLibrary.Command command, Socket handler) { Connection conn = new Connection(); conn.bandwidth = command.bandwidth; conn.connectionId = connectionList.Count; conn.domainOfRequester = command.domainOfRequestingClient; conn.startId = command.startClientId; conn.endId = command.endClientId; connectionList.Add(conn); CommandLibrary.Command directoryRequest = new CommandLibrary.Command("Directory Request"); directoryRequest.sourceId = nccId; directoryRequest.destinationId = self.ReturnName() + ":PC"; directoryRequest.endClientId = command.endClientId; directoryRequest.startClientId = command.startClientId; directoryRequest.domainOfRequestingClient = command.domainOfRequestingClient; directoryRequest.bandwidth = command.bandwidth; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, directoryRequest); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Directory Request ({directoryRequest.endClientId})' sent to {directoryRequest.destinationId}" + Environment.NewLine)); }
private void Receive(Socket handler) { NetworkStream stream = new NetworkStream(handler); BinaryFormatter bformatter = new BinaryFormatter(); CommandLibrary.Command message = null; while (true) { if (stream.DataAvailable == true) { message = (CommandLibrary.Command)bformatter.Deserialize(stream); int port = 0; bool isExisting = componentPorts.TryGetValue(message.destinationId, out port); if (isExisting) { int index = handlers.FindIndex(x => ((IPEndPoint)x.RemoteEndPoint).Port == port); if (index != -1) { NetworkStream senderStream = new NetworkStream(handlers[index]); bformatter.Serialize(senderStream, message); senderStream.Flush(); senderStream.Close(); } } } Thread.Sleep(10) ; } }
// LRM odbiera tablice linków, linki mają mieć wypełnione ID private void LinkDelete(CommandLibrary.Command command, Socket handler) { foreach (CommandLibrary.Link l in linkList) { //zmienna if (l.linkID == command.deletedLinkId) { CommandLibrary.Command response = new CommandLibrary.Command("Link Deleted"); response.destinationId = self.ReturnName() + ":CC"; response.sourceId = LRMName; //zmienna response.deletedLinkId = command.deletedLinkId; response.domainOfRequestedClient = command.domainOfRequestedClient; response.domainOfRequestingClient = command.domainOfRequestingClient; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, response); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> Link " + l.linkID + " deleted" + Environment.NewLine)); } } // zmienna linkList.Remove(new CommandLibrary.Link() { linkID = command.deletedLinkId }); }
// LRM odbiera tablice linków, linki mają mieć wypełnione ID i sloty private void LinkSlotsUnlock(CommandLibrary.Command command, Socket handler) { // CommandLibrary.Command response = new CommandLibrary.Command("SLOTS UNLOCKED"); // response.destinationId = command.sourceId; // response.sourceId = LRMName; // foreach (CommandLibrary.Link l in linkList) // { // foreach (CommandLibrary.Link ll in command.linkList) // { // if (l.linkID == ll.linkID) // { // foreach (int k in ll.usedSlots) // { // if (l.usedSlots.Contains(k)) // { // l.usedSlots.Remove(k); // } // else // { // self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + " >> LRM >> ERROR slot byl pusty !!!!" + Environment.NewLine)); // } // } // } // } // } // using (var stream = new NetworkStream(handler)) // { // BinaryFormatter bformatter = new BinaryFormatter(); // bformatter.Serialize(stream, response); // stream.Flush(); // stream.Close(); // } // self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> SLOTS UNLOCKED from {response.destinationId}" + Environment.NewLine)); }
private void LinkUsage(CommandLibrary.Command command, Socket handler) { CommandLibrary.Command response = new CommandLibrary.Command("Links Ready"); response.destinationId = self.ReturnName() + ":CC"; response.sourceId = LRMName; response.domainOfRequestedClient = command.domainOfRequestedClient; response.domainOfRequestingClient = command.domainOfRequestingClient; response.linkList = new List <CommandLibrary.Link>(); response.bandwidth = command.bandwidth; foreach (CommandLibrary.Link l in command.linkList) { foreach (CommandLibrary.Link ll in linkList) { if (l.linkID == ll.linkID) { l.usedSlots.AddRange(ll.usedSlots); response.linkList.Add(l); } } } using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, response); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> Checking usage of links" + Environment.NewLine)); }
private void CallConfirmation(CommandLibrary.Command command) { if (!allowedClients.Exists(x => x.Equals(command.callConfirmedClientId))) { allowedClients.Add(command.callConfirmedClientId); } client.mainWindow.Invoke(new Action(() => client.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> CPCC >> CONFIRMATION OF CALL TO {command.callConfirmedClientId} RECEIVED" + Environment.NewLine)); }
private void OXCCleared(CommandLibrary.Command command, Socket handler) { CommandLibrary.Command request = new CommandLibrary.Command("Call Request"); request.bandwidth = clearedConnection.bandwidth; request.startClientId = clearedConnection.startId; request.endClientId = clearedConnection.endId; request.domainOfRequestingClient = clearedConnection.domainOfRequester; CallRequest(request, handler); }
private void CCReceive(Socket s) { NetworkStream stream = new NetworkStream(s); BinaryFormatter bformatter = new BinaryFormatter(); CommandLibrary.Command command = null; while (true) { if (stream.DataAvailable == true) { try { command = (CommandLibrary.Command)bformatter.Deserialize(stream); } catch (Exception exc) { Console.WriteLine(exc); } if (command.record != null) { command.record.routerName = nodeName; portMatchList.Add(command.record); CommandLibrary.PortMatch temp = new CommandLibrary.PortMatch(command.record.destinationPort, command.record.receivedPort, 0, 0); temp.modulation = command.record.modulation; temp.routerName = command.record.routerName; temp.startFreq = command.record.startFreq; temp.endFreq = command.record.endFreq; temp.connectionFreq = command.record.connectionFreq; portMatchList.Add(temp); mainWindow.Invoke(new Action(() => Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> {nodeName} >> Table update: ports " + command.record.receivedPort + " and " + command.record.destinationPort + " matched, freqency: " + command.record.startFreq + " - " + command.record.endFreq + " THz (modulation " + command.record.modulation + ")" + Environment.NewLine)); } else { if (command.commandType == "PortMatch Delete") { List <CommandLibrary.PortMatch> tempList = new List <CommandLibrary.PortMatch>(); tempList.AddRange(portMatchList); foreach (CommandLibrary.PortMatch pm in portMatchList) { if (pm.destinationPort == command.linkList[0].portObject1 || pm.destinationPort == command.linkList[0].portObject2) { mainWindow.Invoke(new Action(() => Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> {nodeName} >> Table update: deleted PortMatch between " + pm.receivedPort + " and " + pm.destinationPort + Environment.NewLine)); } tempList.Remove(pm); } } } } Thread.Sleep(10); } }
private void crackButton_Click(object sender, EventArgs e) { int linkID = Int32.Parse(textBox1.Text); CommandLibrary.Link l = new CommandLibrary.Link(); l.linkID = linkID; string destination = null; if (linkID == 10) { destination = "A:SN1:SN4:LRM"; } if (linkID == 3 || linkID == 4 || linkID == 5) { destination = "A:SN1:SN17:LRM"; } if (linkID == 8) { destination = "B:SN2:SN5:LRM"; } if (linkID == 9 || linkID == 6 || linkID == 1) { destination = "B:SN2:LRM"; } if (linkID == 0 || linkID == 1 || linkID == 2 || linkID == 7 || linkID == 6) { destination = "A:SN1:LRM"; } IPEndPoint ipe = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 60000); Socket handler = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp); handler.Connect("127.0.0.1", 50000); CommandLibrary.Command message = new CommandLibrary.Command("Link Delete"); message.linkList = new List <CommandLibrary.Link>(); l.usedSlots.Add(1); //Test!!!!! l.usedSlots.Add(2); message.linkList.Add(l); message.sourceId = "Cracker"; message.destinationId = destination; message.deletedLinkId = linkID; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, message); stream.Flush(); stream.Close(); } handler.Close(); }
private void CheckInput(CommandLibrary.Command input, Socket handler) { switch (input.commandType) { case "Directory Request": DirectoryRequest(input, handler); break; case "Policy Out": PolicyOut(input, handler); break; } }
private void CheckInput(CommandLibrary.Command input, Socket handler) { switch (input.commandType) { case "Call Indication": CallIndication(input, handler); break; case "Call confirmed": CallConfirmation(input); break; } }
private void SlotsLocked(CommandLibrary.Command command, Socket handler) { command.destinationId = self.ReturnName() + ":CC"; command.sourceId = LRMName; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, command); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> 'Subcarrier Slots Lock Request' sent to {command.destinationId}" + Environment.NewLine)); }
private void ClearLink(CommandLibrary.Command command, Socket handler) { //linkList.Remove(new CommandLibrary.Link() { linkID = command.deletedLinkId }); foreach (CommandLibrary.Link l in command.linkList) { foreach (CommandLibrary.Link ll in linkList) { if (l.linkID == ll.linkID) { ll.usedSlots.Clear(); self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> Link {ll.linkID} cleared" + Environment.NewLine)); } } } }
private void PolicyOutConfirmed(CommandLibrary.Command command, Socket handler) { if (command.isClientAccessible) { if (command.domainOfRequestedClient == self.ReturnName()) { CommandLibrary.Command callIndication = new CommandLibrary.Command("Call Indication"); callIndication.sourceId = nccId; callIndication.destinationId = command.domainOfRequestedClient + ":" + command.endClientId + ":CPCC"; callIndication.endClientId = command.endClientId; callIndication.startClientId = command.startClientId; callIndication.domainOfRequestedClient = command.domainOfRequestedClient; callIndication.domainOfRequestingClient = command.domainOfRequestingClient; callIndication.callIndicationClientId = command.startClientId; callIndication.bandwidth = command.bandwidth; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, callIndication); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Call Indication' sent to {callIndication.destinationId}" + Environment.NewLine)); } else { //klient w innej domenie, trzeb wysłać Call Coordination CommandLibrary.Command callCoordination = new CommandLibrary.Command("Call Coordination"); callCoordination.sourceId = nccId; callCoordination.destinationId = command.domainOfRequestedClient + ":NCC"; callCoordination.endClientId = command.endClientId; callCoordination.startClientId = command.startClientId; callCoordination.domainOfRequestedClient = command.domainOfRequestedClient; callCoordination.domainOfRequestingClient = command.domainOfRequestingClient; callCoordination.callIndicationClientId = command.startClientId; callCoordination.bandwidth = command.bandwidth; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, callCoordination); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Call Coordination' sent to {callCoordination.destinationId}" + Environment.NewLine)); } } }
private void CriticalLinkDeleted(CommandLibrary.Command command, Socket handler) { clearedConnection = connectionList.Find(x => x.connectionId == command.connectionId); CommandLibrary.Command response = new CommandLibrary.Command("Clear OXC"); response.connectionId = command.connectionId; response.deletedLinkId = command.deletedLinkId; response.destinationId = self.ReturnMainSubnetwork().ReturnName() + ":CC"; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, response); stream.Flush(); stream.Close(); } connectionList.Remove(clearedConnection); }
private void CheckInput(CommandLibrary.Command input, Socket handler) { switch (input.commandType) { case "Call Request": callRequester = input.sourceId; callDestination = input.endClientId; self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Call Request (destination: {input.endClientId}, bandwidth: " + input.bandwidth + $"Gb/s)' from { input.sourceId }" + Environment.NewLine)); CallRequest(input, handler); break; case "Directory Request confirmed": self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + " >> NCC >> 'Directory Request Confirmed'" + Environment.NewLine)); DirectoryRequestConfirmed(input, handler); break; case "Policy Out confirmed": self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + " >> NCC >> 'Policy Out Confirmed'" + Environment.NewLine)); PolicyOutConfirmed(input, handler); break; case "Call Coordination": //to przy 2 domenach, na razie zostaje callRequester = input.startClientId; self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Call Coordination' from {input.sourceId}" + Environment.NewLine)); CallCoordination(input, handler); break; case "Call confirmed": self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Call Confirmed' from {input.sourceId}" + Environment.NewLine)); CallConfirmed(input, handler); break; case "Connection confirmed": self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Connection Confirmed' from {input.sourceId}" + Environment.NewLine)); ConnectionConfirmed(input, handler); break; case "Critical Link Deleted": CriticalLinkDeleted(input, handler); break; case "OXC Cleared": OXCCleared(input, handler); break; } }
public void CallRequest(string requestedDestination, int bandwidth) { CommandLibrary.Command command = new CommandLibrary.Command("Call Request"); command.startClientId = client.ReturnName(); command.endClientId = requestedDestination; command.bandwidth = bandwidth; command.destinationId = client.ReturnDomainName() + ":NCC"; command.sourceId = client.ReturnDomainName() + ":" + client.ReturnName() + ":CPCC"; command.domainOfRequestingClient = client.ReturnDomainName(); using (var stream = new NetworkStream(socket)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, command); stream.Flush(); stream.Close(); } client.mainWindow.Invoke(new Action(() => client.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> CPCC >> MAKING CALL REQUEST TO '{command.endClientId}'" + Environment.NewLine)); }
private void DirectoryRequestConfirmed(CommandLibrary.Command command, Socket handler) { CommandLibrary.Command policyOut = new CommandLibrary.Command("Policy Out"); policyOut.sourceId = nccId; policyOut.destinationId = self.ReturnName() + ":PC"; policyOut.endClientId = command.endClientId; policyOut.startClientId = command.startClientId; policyOut.bandwidth = command.bandwidth; policyOut.domainOfRequestedClient = command.domainOfRequestedClient; policyOut.domainOfRequestingClient = command.domainOfRequestingClient; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, policyOut); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Policy Out (from {policyOut.startClientId} to {policyOut.endClientId})' sent to {policyOut.destinationId}" + Environment.NewLine)); }
private void CheckInput(CommandLibrary.Command input, Socket handler) { switch (input.commandType) { case "Link Usage": LinkUsage(input, handler); break; case "Link Slots Lock": //self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> LINK SLOTS LOCK from {input.sourceId}" + Environment.NewLine)); LinkSlotsLock(input, handler); counter = 1; break; case "Link Slots Unlock": //self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> LINK SLOTS UNLOCK from {input.sourceId}" + Environment.NewLine)); LinkSlotsUnlock(input, handler); break; case "Link Add": //self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> LINK ADD from {input.sourceId}" + Environment.NewLine)); LinkAdd(input, handler); break; case "Link Delete": //self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> LINK DELETE from {input.sourceId}" + Environment.NewLine)); LinkDelete(input, handler); break; case "Clear Link": ClearLink(input, handler); break; case "Slots Locked": if (counter == 1) { SlotsLocked(input, handler); counter = 0; } break; } }
private void DirectoryRequest(CommandLibrary.Command command, Socket handler) { self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + " >> PC >> Translating destination address..." + Environment.NewLine)); CommandLibrary.Command callConfirmed = new CommandLibrary.Command("Directory Request confirmed"); callConfirmed.sourceId = pcId; callConfirmed.destinationId = self.ReturnName() + ":NCC"; callConfirmed.endClientId = command.endClientId; callConfirmed.startClientId = command.startClientId; callConfirmed.bandwidth = command.bandwidth; clientsAndDomains.TryGetValue(command.endClientId, out callConfirmed.domainOfRequestedClient); callConfirmed.domainOfRequestingClient = command.domainOfRequestingClient; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, callConfirmed); stream.Flush(); stream.Close(); } }
private void PolicyOut(CommandLibrary.Command command, Socket handler) { self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> PC >> Checking if call is possible..." + Environment.NewLine)); CommandLibrary.Command callConfirmed = new CommandLibrary.Command("Policy Out confirmed"); callConfirmed.sourceId = pcId; callConfirmed.destinationId = self.ReturnName() + ":NCC"; callConfirmed.endClientId = command.endClientId; callConfirmed.startClientId = command.startClientId; callConfirmed.bandwidth = command.bandwidth; callConfirmed.domainOfRequestedClient = command.domainOfRequestedClient; callConfirmed.domainOfRequestingClient = command.domainOfRequestingClient; callConfirmed.isClientAccessible = true; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, callConfirmed); stream.Flush(); stream.Close(); } }
// LRM odbiera tablice linków, linki mają mieć wypełnione ID private void LinkAdd(CommandLibrary.Command command, Socket handler) { //CommandLibrary.Command response = new CommandLibrary.Command("LINK ADDED"); //response.destinationId = command.sourceId; //response.sourceId = LRMName; //foreach (CommandLibrary.Link l in command.linkList) //{ // if (!linkList.Contains(new CommandLibrary.Link { linkID = l.linkID })) // { // linkList.Add(l); // } //} //using (var stream = new NetworkStream(handler)) //{ // BinaryFormatter bformatter = new BinaryFormatter(); // bformatter.Serialize(stream, response); // stream.Flush(); // stream.Close(); //} //self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> LINK ADDED from {response.destinationId}" + Environment.NewLine)); }
private void Receive(Socket handler) { NetworkStream stream = new NetworkStream(handler); BinaryFormatter bformatter = new BinaryFormatter(); CommandLibrary.Command message = null; while (flag) { if (stream.DataAvailable == true) { try { message = (CommandLibrary.Command)bformatter.Deserialize(stream); } catch (Exception exc) { Console.WriteLine(exc); } CheckInput(message, handler); } Thread.Sleep(10); } }
private void CallIndication(CommandLibrary.Command command, Socket handler) { CommandLibrary.Command response = new CommandLibrary.Command("Call confirmed"); response.isClientAccepting = true;//zawsze akceptujemy żądanie drugiego klienta response.destinationId = client.ReturnDomainName() + ":NCC"; response.sourceId = client.ReturnDomainName() + ":" + client.ReturnName() + ":CPCC"; response.startClientId = command.startClientId; response.endClientId = command.endClientId; response.domainOfRequestedClient = command.domainOfRequestedClient; response.domainOfRequestingClient = command.domainOfRequestingClient; response.bandwidth = command.bandwidth; if (!allowedClients.Exists(x => x.Equals(command.callIndicationClientId))) { allowedClients.Add(command.callIndicationClientId); } using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, response); stream.Flush(); stream.Close(); } client.mainWindow.Invoke(new Action(() => client.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> CPCC >> CONFIRMING THE CALL FROM '{command.callIndicationClientId}'" + Environment.NewLine)); }
// LRM odbiera tablice linków, linki mają mieć wypełnione ID i sloty private void LinkSlotsLock(CommandLibrary.Command command, Socket handler) { List <int> distinctID = new List <int>(); List <CommandLibrary.Link> distinctLink = new List <CommandLibrary.Link>(); string linkString = ""; foreach (CommandLibrary.Link l in command.linkList) { if (!distinctID.Contains(l.linkID)) { distinctLink.Add(l); distinctID.Add(l.linkID); } } if (distinctLink.Count() != 0) { if (distinctLink[0].usedSlots.Count() != 0) { int min = distinctLink[0].usedSlots.Min(); int max = distinctLink[0].usedSlots.Max(); foreach (CommandLibrary.Link l in linkList) { foreach (CommandLibrary.Link ll in distinctLink) { if (l.linkID == ll.linkID) { linkString += l.linkID.ToString() + " "; foreach (int k in ll.usedSlots) { if (!(l.usedSlots.Contains(k))) { l.usedSlots.Add(k); } else { // Console.WriteLine("proba nadpisania slotow w " + LRMName); } } } } } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> Subcarrier slots locked from " + min + " to " + max + " in links " + linkString + Environment.NewLine)); if (self.ReturnSubnetworks() == null || self.ReturnSubnetworks().Count == 0) { command.commandType = "Slots Locked"; command.destinationId = command.sourceId; command.sourceId = LRMName; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, command); stream.Flush(); stream.Close(); } //self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> SLOTS LOCKED sent to {command.destinationId}" + Environment.NewLine)); } else { foreach (Subnetwork s in self.ReturnSubnetworks()) { command.destinationId = s.ReturnName() + ":LRM"; command.sourceId = LRMName; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, command); stream.Flush(); stream.Close(); } // self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> LRM >> LINK SLOTS LOCK sent to {command.destinationId}" + Environment.NewLine)); } } } } }
private void ConnectionConfirmed(CommandLibrary.Command command, Socket handler) { if (self.ReturnName() == command.domainOfRequestingClient) { CommandLibrary.Command callConfirmed = new CommandLibrary.Command("Call confirmed"); callConfirmed.sourceId = nccId; callConfirmed.destinationId = callRequester; callConfirmed.endClientId = command.endClientId; callConfirmed.startClientId = command.startClientId; callConfirmed.bandwidth = command.bandwidth; callConfirmed.isClientAccepting = true; callConfirmed.isClientAccessible = true; callConfirmed.callConfirmedClientId = callDestination; callConfirmed.domainOfRequestedClient = command.domainOfRequestedClient; callConfirmed.domainOfRequestingClient = command.domainOfRequestingClient; //dodane: callConfirmed.endCrack = command.endCrack; callConfirmed.startCrack = command.startCrack; callConfirmed.record = new CommandLibrary.PortMatch(0, 0, 0, 0); callConfirmed.record.modulation = command.record.modulation; // using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, callConfirmed); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Call Confirmed' sent to {callConfirmed.destinationId}" + Environment.NewLine)); } else { CommandLibrary.Command callConfirmed = new CommandLibrary.Command("Call confirmed"); callConfirmed.sourceId = nccId; callConfirmed.destinationId = command.domainOfRequestingClient + ":NCC"; callConfirmed.endClientId = command.endClientId; callConfirmed.startClientId = command.startClientId; callConfirmed.bandwidth = command.bandwidth; callConfirmed.callConfirmedClientId = callDestination; callConfirmed.isClientAccepting = true; callConfirmed.isClientAccessible = true; callConfirmed.domainOfRequestedClient = command.domainOfRequestedClient; callConfirmed.domainOfRequestingClient = command.domainOfRequestingClient; //callConfirmed.linkList = new List<CommandLibrary.Link>(); //callConfirmed.linkList.AddRange(command.linkList); //dodane: callConfirmed.endCrack = command.endCrack; callConfirmed.startCrack = command.startCrack; callConfirmed.record = new CommandLibrary.PortMatch(0, 0, 0, 0); callConfirmed.record.modulation = command.record.modulation; // //modulacja using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, callConfirmed); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Call Confirmed' sent to {callConfirmed.destinationId}" + Environment.NewLine)); } }
private void CallConfirmed(CommandLibrary.Command command, Socket handler) { if (command.isClientAccepting) { if (command.domainOfRequestingClient == self.ReturnName()) { string[] temp = command.sourceId.Split(':'); if (temp.ElementAt(temp.Length - 1) == "NCC")//jeśli dostajemy request od drugiego NCC { //dodajemy połączenie Connection conn = new Connection(); try { conn.connectionId = command.connectionId; } catch { }; conn.usedLinks = command.linkList; conn.startId = command.startClientId; conn.endId = command.endClientId; connectionList.Add(conn); // CommandLibrary.Command connectionRequest = new CommandLibrary.Command("Connection Request"); connectionRequest.sourceId = nccId; connectionRequest.destinationId = self.ReturnMainSubnetwork().ReturnName() + ":CC"; connectionRequest.endClientId = callDestination; connectionRequest.startClientId = callRequester; connectionRequest.startOfPath = command.startClientId; connectionRequest.endOfPath = command.domainOfRequestedClient; connectionRequest.domainOfRequestedClient = command.domainOfRequestedClient; connectionRequest.domainOfRequestingClient = command.domainOfRequestingClient; connectionRequest.endCrack = command.endCrack; //connectionRequest.linkList = new List<CommandLibrary.Link>(); //connectionRequest.linkList.AddRange(command.linkList); connectionRequest.startCrack = command.startCrack; connectionRequest.record = new CommandLibrary.PortMatch(0, 0, 0, 0); connectionRequest.record.modulation = command.record.modulation; connectionRequest.bandwidth = command.bandwidth; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, connectionRequest); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Connection Request' sent to {connectionRequest.destinationId}" + Environment.NewLine)); } else//jeśli dostajemy request od CPCC { //dodajemy połączenie Connection conn = new Connection(); conn.connectionId = connectionList.Count; conn.usedLinks = command.linkList; conn.startId = command.startClientId; conn.endId = command.endClientId; connectionList.Add(conn); // CommandLibrary.Command connectionRequest = new CommandLibrary.Command("Connection Request"); connectionRequest.sourceId = nccId; connectionRequest.destinationId = self.ReturnMainSubnetwork().ReturnName() + ":CC"; connectionRequest.endClientId = command.endClientId; connectionRequest.startClientId = command.startClientId; connectionRequest.startOfPath = command.startClientId; connectionRequest.endOfPath = command.endClientId; connectionRequest.domainOfRequestedClient = command.domainOfRequestedClient; connectionRequest.domainOfRequestingClient = command.domainOfRequestingClient; connectionRequest.bandwidth = command.bandwidth; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, connectionRequest); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Connection Request' sent to {connectionRequest.destinationId}" + Environment.NewLine)); } } else//jesteśmy w innej domenie { string[] temp = command.sourceId.Split(':'); if (temp.ElementAt(temp.Length - 1) == "NCC")//jeśli dostajemy request od NCC, chyba nigdy się nie zdarzy { CommandLibrary.Command connectionRequest = new CommandLibrary.Command("Connection Request"); connectionRequest.sourceId = nccId; connectionRequest.destinationId = self.ReturnMainSubnetwork().ReturnName() + ":CC"; connectionRequest.endClientId = command.endClientId; connectionRequest.startClientId = callRequester; connectionRequest.startOfPath = command.startClientId; connectionRequest.endOfPath = command.endClientId; connectionRequest.domainOfRequestedClient = command.domainOfRequestedClient; connectionRequest.domainOfRequestingClient = command.domainOfRequestingClient; connectionRequest.bandwidth = command.bandwidth; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, connectionRequest); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Connection Reuqest' sent to {connectionRequest.destinationId}" + Environment.NewLine)); } else//dostajemy request od CPCC { //dodajemy połączenie Connection conn = new Connection(); conn.connectionId = connectionList.Count; conn.usedLinks = command.linkList; connectionList.Add(conn); // CommandLibrary.Command connectionRequest = new CommandLibrary.Command("Connection Request"); connectionRequest.sourceId = nccId; connectionRequest.destinationId = self.ReturnMainSubnetwork().ReturnName() + ":CC"; connectionRequest.endClientId = command.endClientId; connectionRequest.startClientId = callRequester; connectionRequest.startOfPath = command.domainOfRequestingClient;//granica drugiej domeny connectionRequest.endOfPath = command.endClientId; connectionRequest.domainOfRequestedClient = command.domainOfRequestedClient; connectionRequest.domainOfRequestingClient = command.domainOfRequestingClient; connectionRequest.bandwidth = command.bandwidth; using (var stream = new NetworkStream(handler)) { BinaryFormatter bformatter = new BinaryFormatter(); bformatter.Serialize(stream, connectionRequest); stream.Flush(); stream.Close(); } self.mainWindow.Invoke(new Action(() => self.Logs += DateTime.UtcNow.ToString("HH:mm:ss.fff") + $" >> NCC >> 'Connection Request' sent to {connectionRequest.destinationId}" + Environment.NewLine)); } } } else { //klient nie zezwala na nawiązanie połączenia } }