private int GetNextFreeLabel(SNPP first, SNPP second, int index_in_list) { bool sendRejectedResponse = false; //sprawdzamy, czy wgl jest jakas wolna lambda if (first._availableLabels.Count == 0) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - No free label available in SNPP with id " + first._localID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - No free label available in SNPP with id " + first._localID); sendRejectedResponse = true; } else if (second._availableLabels.Count == 0) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - No free label available in SNPP with id " + second._localID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - No free label available in SNPP with id " + second._localID); sendRejectedResponse = true; } if (sendRejectedResponse) { return(-1); } else { if (first._availableLabels.Count < index_in_list) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - No more free label available in SNPP with id " + first._localID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - No more free label available in SNPP with id " + first._localID); return(-1); } else { return(first._availableLabels[index_in_list]); } } }
private void SNPRealise(int dealocationID, int snppID, int connectionID, string sourcePcIpAddress) { #region Odszukuje_obiekt_SNPP_o_zadanym_id SNPP requestedSnpp = null; for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snppID) { requestedSnpp = _snppList[i]; break; } } //jeżeli nie ma takiego obiektu to zwróć błąd if (requestedSnpp == null) { //jest jakiś błąd i trzeba to zakomunikować SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR (SnppRealise)- Cannot find the SNPP with ID equals " + snppID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR (SnppRealise)- Cannot find the SNPP with ID equals " + snppID); //zwróć odpowiedź negatywną SignalMessage rejectedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealiseResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationID, IsAccepted = false }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(rejectedMessage); return; } #endregion #region Znajduję_SNP_związane_z_connectionID SNP localSNP = null; for (int i = 0; i < requestedSnpp._allocatedSNP.Count; i++) { if (requestedSnpp._allocatedSNP[i]._connectionID == connectionID) { localSNP = requestedSnpp._allocatedSNP[i]; break; } } //jeżeli nie ma to zwróc negatywną odpowiedź if (localSNP == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + connectionID + " in SNPP with ID: " + requestedSnpp._localID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + connectionID + " in SNPP with ID: " + requestedSnpp._localID); //wyślij wiadomość odmowną SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealiseResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationID, IsAccepted = false }; SendMessageToPC(message); //zakończ działanie metody return; } #endregion #region Zwolnij_etykiete_i_usun_localSNP int freeLabel = localSNP._allocatedLabel; requestedSnpp._availableLabels.Add(freeLabel); requestedSnpp._allocatedSNP.Remove(localSNP); #endregion #region Wyslij_odpowiedź SignalMessage acceptedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealiseResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationID, IsAccepted = true }; SendMessageToPC(acceptedMessage); #endregion }
private void LinkConnectionDealocation(int connectionID, SignalMessage.Pair snpp_id_pair) { #region Odnajdywanie_SNPP_i_sprawdzenie_czy_istnieją //odnajdz pierwszy i drugi SNPP SNPP first = null; SNPP second = null; //wyszukuje pierwszą wartość w liście for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snpp_id_pair.first) { first = _snppList[i]; break; } } //jeżeli nie ma takiego elementu to zwróć bład if (first == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); } else { //wyszukuje drugą wartość w liście for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snpp_id_pair.second) { second = _snppList[i]; break; } } //jeżeli nie ma takiego elementu to zwróć bład if (second == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); } } if (first == null || second == null) { SignalMessage rejectedResponse = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LinkConnectionDealocationResponse, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "CC", IsAccepted = false, }; SendMessageToPC(rejectedResponse); //zakończ działanie metody return; } #endregion #region Znajdź_SNP_związane_z_tym_connectionID SNP localSNP = null; for (int i = 0; i < first._allocatedSNP.Count; i++) { if (first._allocatedSNP[i]._connectionID == connectionID) { localSNP = first._allocatedSNP[i]; break; } } if (localSNP == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + snpp_id_pair.first + " in SNPP with ID: " + first._localID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNP with connectionID equals " + snpp_id_pair.first + " in SNPP with ID: " + first._localID); //wyślij wiadomość odmowną SignalMessage rejectedResponse = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LinkConnectionDealocationResponse, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "CC", IsAccepted = false }; SendMessageToPC(rejectedResponse); //zakończ działanie metody return; } #endregion #region Wyslij_lokalne_i_zewnętrzne_snpRealise_i_czekaj_na_odp bool accept = false; List <int> dealocationIDList = new List <int>(); Random rnd = new Random(); while (!accept) { //losuje identyfikator negocjacji dealocationIDList.Add(rnd.Next()); while (_isSnpRealiseAnswerBack.ContainsKey(dealocationIDList[0])) { dealocationIDList[0] = rnd.Next(); } //utwórz wpis w słowniku z danym ID _isSnpRealiseAnswerBack.Add(dealocationIDList[0], false); //wysyłamy SNPRealise do lokalnego LRM SignalMessage snmInsideNegotiation = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealise, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationIDList[0], Negotiation_SnppID = second._localID, Negotiation_ConnectionID = connectionID }; SendMessageToPC(snmInsideNegotiation); //wysyłamy SNPRealise do pozostałych podsieci jeżeli jest taka konieczność if (first._areaName != _areaName) { dealocationIDList.Add(rnd.Next()); while (_isSnpRealiseAnswerBack.ContainsKey(dealocationIDList[dealocationIDList.Count - 1])) { dealocationIDList[dealocationIDList.Count - 1] = rnd.Next(); } //utwórz wpisy w słownikach _isSnpRealiseAnswerBack.Add(dealocationIDList[dealocationIDList.Count - 1], false); //znajdź adres PC odpowiedzialnego za dany LRM w sieci first._areaName string destinationIpAddr = _lrmToSubnetworksDictionary[first._areaName]; SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealise, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = destinationIpAddr, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationIDList[dealocationIDList.Count - 1], Negotiation_SnppID = first._areaNameSnppID, Negotiation_ConnectionID = connectionID }; SendMessageToPC(message); } if (second._areaName != _areaName) { dealocationIDList.Add(rnd.Next()); while (_isSnpRealiseAnswerBack.ContainsKey(dealocationIDList[dealocationIDList.Count - 1])) { dealocationIDList[dealocationIDList.Count - 1] = rnd.Next(); } //utwórz wpisy w słownikach _isSnpRealiseAnswerBack.Add(dealocationIDList[dealocationIDList.Count - 1], false); //znajdź adres PC odpowiedzialnego za dany LRM w sieci first._areaName string destinationIpAddr = _lrmToSubnetworksDictionary[second._areaName]; SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPRealise, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = destinationIpAddr, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = dealocationIDList[dealocationIDList.Count - 1], Negotiation_SnppID = second._areaNameSnppID, Negotiation_ConnectionID = connectionID }; SendMessageToPC(message); } //czekamy biernie na odpowiedzi wszystkie (min 1 max 3) int waitingAnswerstToGet = dealocationIDList.Count; while (waitingAnswerstToGet != 0) { for (int i = 0; i < dealocationIDList.Count; i++) { if (_isSnpRealiseAnswerBack[(dealocationIDList[i])] == true) { waitingAnswerstToGet--; } } } //sprawdzamy, czy wszystkie odpowiedzi były prawidłowe int numberOfAcceptAnswers = 0; for (int i = 0; i < dealocationIDList.Count; i++) { if (_snpRealiseAnswerBack[dealocationIDList[i]] == true) { numberOfAcceptAnswers++; } } if (numberOfAcceptAnswers == dealocationIDList.Count) { accept = true; } else { accept = false; //tutaj trzeba namierzyć tą która jest zła i wysłać Realise i ponownie spróbować losować jakąć czy coś } }//end while(!accept) #endregion #region Zwalnianie_etykiety_i_usuwanie_localSNP //zwalnianie etykiety int freeLabel = localSNP._allocatedLabel; first._availableLabels.Add(freeLabel); //usuwanie local SNP first._allocatedSNP.Remove(localSNP); #endregion #region Wysyłanie_wiadomości_wstecznej SignalMessage acceptedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LinkConnectionDealocationResponse, General_DestinationIpAddress = _localPcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "CC", IsAccepted = true, }; SendMessageToPC(acceptedMessage); #endregion }
private void SNPNegotiation_Analyse(int negotiationID, int connectionID, int label, int snppID, int connectionCapacity, string sourcePcIpAddress) { #region Odszukuje_obiekt_SNPP_o_zadanym_id SNPP requestedSnpp = null; for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snppID) { requestedSnpp = _snppList[i]; break; } } //jeżeli nie ma takiego obiektu to zwróć błąd if (requestedSnpp == null) { //jest jakiś błąd i trzeba to zakomunikować SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR (SnppNegotiation)- Cannot find the SNPP with ID equals " + snppID); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR (SnppNegotiation)- Cannot find the SNPP with ID equals " + snppID); //zwróć odpowiedź negatywną SignalMessage rejectedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPNegotiationResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = negotiationID, IsAccepted = false }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(rejectedMessage); return; } #endregion #region Sprawdzam_czy_etykieta_jest_wolna_i_wyslij_odpowiednia_wiadomosc if (requestedSnpp._availableLabels.Contains(label)) { //etykieta jest wolna int index = requestedSnpp._allocatedSNP.Count; SNP allocatedSnp = new SNP { _snpID = index, _snppID = requestedSnpp._localID, _allocatedCapacity = connectionCapacity, _allocatedLabel = label, _connectionID = connectionID }; requestedSnpp._allocatedSNP.Add(allocatedSnp); //wyślij odpowiedź zawierającą zaalokowane SNP SignalMessage accepteddMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPNegotiationResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = negotiationID, IsAccepted = true, Negotiation_AllocatedSNP = allocatedSnp }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(accepteddMessage); } else { //etykieta jest zajęta SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR (SnppNegotiation)- Lable already in use: " + label); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR (SnppNegotiation)- Lable already in use: " + label); //zwróć odpowiedź negatywną SignalMessage rejectedMessage = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.SNPNegotiationResponse, General_DestinationIpAddress = sourcePcIpAddress, General_SourceIpAddress = _localPcIpAddress, General_SourceModule = "LRM", General_DestinationModule = "LRM", Negotiation_ID = negotiationID, IsAccepted = false }; //wyslij wiadomość i wyjdź z metody SendMessageToPC(rejectedMessage); return; } #endregion }
private void LinkConnectionRequest(int connectionID, SignalMessage.Pair snpp_id_pair, int connectionCapacity) //DOKOŃCZYC { #region Odnajdywanie_SNPP_i_sprawdzenie_czy_istnieją //odnajdz pierwszy i drugi SNPP SNPP first = null; SNPP second = null; //wyszukuje pierwszą wartość w liście for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snpp_id_pair.first) { first = _snppList[i]; break; } } //jeżeli nie ma takiego elementu to zwróć bład if (first == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); } else { //wyszukuje drugą wartość w liście for (int i = 0; i < _snppList.Count; i++) { if (_snppList[i]._localID == snpp_id_pair.second) { second = _snppList[i]; break; } } //jeżeli nie ma takiego elementu to zwróć bład if (second == null) { SignallingNodeDeviceClass.MakeSignallingLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); SignallingNodeDeviceClass.MakeSignallingConsoleLog("LRM", "ERROR - Cannot find the SNPP with ID equals " + snpp_id_pair.first); } } if (first == null || second == null) { //wyślij wiadomośc negatywną LinkConnectionResponse(connectionID, false, null, null); //zakończ działanie metody return; } #endregion #region Sprawdzenie_czy_nie_ma_jakiegos_SNP_zwiazanego_z_tym_connectionID //Sprawdz, czy nie ma jakiegoś SNP związanego z tym connectionID int labelToForward = -1; for (int i = 0; i < first._allocatedSNP.Count; i++) { if (first._allocatedSNP[i]._connectionID == connectionID) { labelToForward = first._allocatedSNP[i]._allocatedLabel; break; } } // Jeżeli nie ma, to sprawdz w drugim if (labelToForward == -1) { for (int i = 0; i < second._allocatedSNP.Count; i++) { if (second._allocatedSNP[i]._connectionID == connectionID) { labelToForward = second._allocatedSNP[i]._allocatedLabel; break; } } } #endregion #region Ewentualne_losowanie_i_negocjacja_wybranej_etykiety int numberOfIterations = 0; bool accept = false; List <int> negotiationIDList = new List <int>(); Random rnd = new Random(); while (!accept) { numberOfIterations++; if (labelToForward == -1) { labelToForward = GetNextFreeLabel(first, second, numberOfIterations - 1); } if (labelToForward == -1) { //wyślij wiadomośc negatywną LinkConnectionResponse(connectionID, false, null, null); } else { //losuje identyfikator negocjacji negotiationIDList.Add(rnd.Next()); while (_isSnpNegotiationAnswerBack.ContainsKey(negotiationIDList[0])) { negotiationIDList[0] = rnd.Next(); } _isSnpNegotiationAnswerBack.Add(negotiationIDList[0], false); _snpNegotiatinAnswerBackAreaName.Add(negotiationIDList[0], _areaName); //wysyłamy SNMNegotiation do lokalnego LRM SNPNegotiation(negotiationIDList[0], connectionID, labelToForward, second._localID, connectionCapacity); //wysyłamy SNMNegotiation do pozostałych podsieci jeżeli jest taka konieczność if (first._areaName != _areaName) { negotiationIDList.Add(rnd.Next()); while (_isSnpNegotiationAnswerBack.ContainsKey(negotiationIDList[negotiationIDList.Count - 1])) { negotiationIDList[negotiationIDList.Count - 1] = rnd.Next(); } //utwórz wpisy w słownikach _isSnpNegotiationAnswerBack.Add(negotiationIDList[negotiationIDList.Count - 1], false); _snpNegotiatinAnswerBackAreaName.Add(negotiationIDList[negotiationIDList.Count - 1], first._areaName); //znajdź adres PC odpowiedzialnego za dany LRM w sieci first._areaName string destinationIpAddr = _lrmToSubnetworksDictionary[first._areaName]; //wyslij wiadomość SNPNegotiation( negotiationIDList[negotiationIDList.Count - 1], connectionID, labelToForward, first._areaNameSnppID, connectionCapacity, destinationIpAddr); } if (second._areaName != _areaName) { negotiationIDList.Add(rnd.Next()); while (_isSnpNegotiationAnswerBack.ContainsKey(negotiationIDList[negotiationIDList.Count - 1])) { negotiationIDList[negotiationIDList.Count - 1] = rnd.Next(); } //utwórz wpisy w słownikach _isSnpNegotiationAnswerBack.Add(negotiationIDList[negotiationIDList.Count - 1], false); _snpNegotiatinAnswerBackAreaName.Add(negotiationIDList[negotiationIDList.Count - 1], second._areaName); //znajdź adres PC odpowiedzialnego za dany LRM w sieci second._areaName string destinationIpAddr = _lrmToSubnetworksDictionary[second._areaName]; //wyslij wiadomość SNPNegotiation( negotiationIDList[negotiationIDList.Count - 1], connectionID, labelToForward, second._areaNameSnppID, connectionCapacity, destinationIpAddr); } //czekamy biernie na odpowiedzi wszystkie (min 1 max 3) int waitingAnswerstToGet = negotiationIDList.Count; while (waitingAnswerstToGet != 0) { for (int i = 0; i < negotiationIDList.Count; i++) { if (_isSnpNegotiationAnswerBack[(negotiationIDList[i])] == true) { waitingAnswerstToGet--; } } } //sprawdzamy, czy wszystkie odpowiedzi były prawidłowe int numberOfAcceptAnswers = 0; for (int i = 0; i < negotiationIDList.Count; i++) { if (_snpNegotiationAnswerBack[negotiationIDList[i]].IsAccepted == true) { numberOfAcceptAnswers++; } } if (numberOfAcceptAnswers == negotiationIDList.Count) { accept = true; } else { accept = false; //tutaj trzeba namierzyć tą która jest zła i wysłać Realise i ponownie spróbować losować jakąć czy coś } } } //------------------------------------------------------------------ // alokujemy SNP lokalnie (tylko pierwsza, bo druga mam w odpowiedzi) int firstSnpID = first._allocatedSNP.Count + 1; first._allocatedSNP.Add(new SNP { _snpID = firstSnpID, _snppID = first._localID, _connectionID = connectionID, _allocatedCapacity = connectionCapacity, _allocatedLabel = labelToForward }); //------------------------------------------------------------------ // tworzymy odpowiedz (odpowiedz skłąda sie z listy SNP zaalokowanych oraz w takiej samej kolejności wypisanych areaName w drugij liscie List <SNP> receivedSnps = new List <SNP>(); List <string> receivedSnpsAreaNames = new List <string>(); //dodaj stwój lokalnie dodany SNP do listy receivedSnps.Add(first._allocatedSNP[firstSnpID]); receivedSnpsAreaNames.Add(_areaName); //dodaj resztę wpisów for (int i = 0; i < negotiationIDList.Count; i++) { receivedSnps.Add(_snpNegotiationAnswerBack[(negotiationIDList[i])].Negotiation_AllocatedSNP); receivedSnpsAreaNames.Add(_snpNegotiatinAnswerBackAreaName[(negotiationIDList[i])]); } //wyślij wiadomość potwierdzającą LinkConnectionResponse(connectionID, true, receivedSnps, receivedSnpsAreaNames); #endregion }