private void RouteQuery(int connectionID, string callingIpAddress, string calledIpAddress, int callingCapacity) { SignalMessage.Pair SNPPPair = new SignalMessage.Pair(); SNPPPair.first = IPTOIDDictionary[callingIpAddress]; SNPPPair.second = IPTOIDDictionary[calledIpAddress]; Vertex begin = graph.Vertices.Find(x => x.Id == SNPPPair.first); Vertex end = graph.Vertices.Find(x => x.Id == SNPPPair.second); List <string> areaNames = new List <string>(); List <SignalMessage.Pair> snppPairs = new List <SignalMessage.Pair>(); if (begin.AreaName.Equals(end.AreaName)) { areaNames = null; snppPairs.Add(SNPPPair); RouteQueryResponse(connectionID, snppPairs, areaNames); } else { //czy kris chce areaNames.Add(begin.AreaName); ? Wtedy areaNames to bedzie {Dom_1,Dom_2} areaNames.Add(end.AreaName); //Z ta linijka jest pairs = ({1,3},{3,201}) SNPPPair.second = interdomainLinksDictionary[end.Id]; //Kris czy ma byc pairs = ({1,3},{3,201}) CZY pairs = ({1,201},{3,201}) snppPairs.Add(SNPPPair); SignalMessage.Pair interdomainPair = new SignalMessage.Pair(); interdomainPair.first = interdomainLinksDictionary[end.Id]; interdomainPair.second = end.Id; snppPairs.Add(interdomainPair); RouteQueryResponse(connectionID, snppPairs, areaNames); } }
private void RouteQuery(int connectionID, SignalMessage.Pair snppIdPair, int callingCapacity) { Dijkstra dijkstra = new Dijkstra(_myAreaName); Vertex begin = graph.Vertices.Find(x => x.Id == snppIdPair.first); Vertex end = graph.Vertices.Find(x => x.Id == snppIdPair.second); List <SignalMessage.Pair> snppIdPairs = dijkstra.runAlgorithm(graph, begin, end, callingCapacity); List <string> areaNames = new List <string>(); foreach (SignalMessage.Pair pair in snppIdPairs) { //Vertex firstVertex = graph.Vertices.Find(x => x.Id == pair.first); Vertex secondVertex = graph.Vertices.Find(x => x.Id == pair.second); if (!secondVertex.AreaName.Equals(_myAreaName)) { String tmp = areaNames.Find(x => x == secondVertex.AreaName); if (tmp == null) { areaNames.Add(secondVertex.AreaName); } } } RouteQueryResponse(connectionID, snppIdPairs, areaNames); }
private List <SignalMessage.Pair> generatePairs(Vertex begin, Vertex end) { List <SignalMessage.Pair> list = new List <SignalMessage.Pair>(); Vertex currentVertex = end; while (currentVertex != begin) { if (currentVertex == null) { return(null); } String edgeId = Edge.CreateName(currentVertex.Prev, currentVertex); Edge tmpEdge = graph.Edges.Find(x => x.Id == edgeId); if (!tmpEdge.SubDomain) { SignalMessage.Pair pair = new SignalMessage.Pair() { first = currentVertex.Prev.Id, second = currentVertex.Id }; list.Insert(0, pair); } currentVertex = currentVertex.Prev; } return(list); }
private void LocalTopology(SignalMessage.Pair snppIdPair, double weight, int avaibleCapacity, string areaName) { int first = SN_1ToDomain[snppIdPair.first]; int second = SN_1ToDomain[snppIdPair.second]; if (((graph.Vertices.Find(x => x.Id == first)) != null) && ((graph.Vertices.Find(x => x.Id == second)) != null)) { Edge edge = new Edge(graph.Vertices.Find(x => x.Id == first), graph.Vertices.Find(x => x.Id == second), avaibleCapacity, weight); graph.Vertices.Find(x => x.Id == first).EdgesOut.Add(edge); graph.Edges.Add(edge); } }
private void ConnectionFailureAnalyse(int connectionId) { var res = _connectionsList.Find(x => x.ConnectionID == connectionId); if (res != null) { SignalMessage.Pair pair = new SignalMessage.Pair() { first = res.LocalBoundaryFirstSnppID, second = res.LocalBoundarySecondSnppID }; RouteQuery(connectionId, pair, res.AllocatedCapacity); } }
private void RouteQueryResponse(int connectionID, SignalMessage.Pair snppPair, int callingCapacity) { SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.RouteQueryResponse, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = _localPcIpAddress, General_SourceModule = "RC", General_DestinationModule = "CC", ConnnectionID = connectionID, SnppIdPair = snppPair }; _pc.SendSignallingMessage(message); }
public void OnNodeFailure(string areaName) { RemoteTopologyStatus(areaName); foreach (var record in _connectionsList) { var res = record.AllocatedSnpAreaName.Find(x => x.Equals(areaName)); if (res != null) { SignalMessage.Pair pair = new SignalMessage.Pair() { first = record.LocalBoundaryFirstSnppID, second = record.LocalBoundarySecondSnppID }; RouteQuery(record.ConnectionID, pair, record.AllocatedCapacity); } } }
private void LocalTopology(SignalMessage.Pair snppIdPair, double weight, int avaibleCapacity, string areaName, string domainIpAddress) { SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LocalTopology, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = domainIpAddress, General_SourceModule = "RC", General_DestinationModule = "RC", SnppIdPair = snppIdPair, LocalTopology_weight = weight, LocalTopology_availibleCapacity = avaibleCapacity, LocalTopology_areaName = areaName }; _pc.SendSignallingMessage(message); }
private void LinkConnectionRequest(int connectionID, SignalMessage.Pair connectionSnppIdPair, int callingCapacity) { SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.LinkConnectionRequest, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = _localPcIpAddress, General_SourceModule = "CC", General_DestinationModule = "LRM", ConnnectionID = connectionID, SnppIdPair = connectionSnppIdPair, CallingCapacity = callingCapacity }; //wysyłamy żądanie do RC _pc.SendSignallingMessage(message); }
private void RouteQuery(int connectionID, SignalMessage.Pair snppIdPair, int callingCapacity) { SignalMessage message = new SignalMessage() { General_SignalMessageType = SignalMessage.SignalType.RouteQuery, General_SourceIpAddress = _localPcIpAddress, General_DestinationIpAddress = _localPcIpAddress, General_SourceModule = "CC", General_DestinationModule = "RC", ConnnectionID = connectionID, SnppIdPair = snppIdPair, CallingCapacity = callingCapacity }; //wysyłam wiadomość _pc.SendSignallingMessage(message); }
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 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 }