예제 #1
0
        public static void AddMessage(ISignalingMessage message, string from, string to)
        {
            var dataModel = GetDataModel(from, to);

            if (dataModel == null)
            {
                dataModel = new DataModel
                {
                    From = from,
                    To   = to,
                    SnpLinkConnectionRequestReq = new List <SNPLinkConnectionRequest_req>(),
                    SnpLinkConnectionRequestRsp = new List <SNPLinkConnectionRequest_rsp>()
                };

                Data.Add(dataModel);
            }

            switch (message)
            {
            case SNPLinkConnectionRequest_rsp rsp:
                Data.Single(x => x.From == from && x.To == to).SnpLinkConnectionRequestRsp.Add(rsp);
                break;

            case SNPLinkConnectionRequest_req req:
                Data.Single(x => x.From == from && x.To == to).SnpLinkConnectionRequestReq.Add(req);
                break;
            }
        }
예제 #2
0
        private void SendReleaseAndDeleteModel(ISignalingMessage signalingMessage)
        {
            var dataModel = DataHolder.GetDataModel(signalingMessage.Guid);

            if (dataModel == null)
            {
                return;
            }

            foreach (var connRequest in dataModel.ConnectionRequestReq)
            {
                connRequest.Action = AllocationAction.Release;
                _logService.LogInfo($"Sending {connRequest}");
                SendMessage(connRequest, _domainCcrcName);
            }

            DataHolder.Data.Remove(dataModel);
        }
예제 #3
0
 public void SendMessage(ISignalingMessage signalingMessage)
 {
     //_logService.LogInfo("Sending signalling message to NCC");
     _client.Post(_objectSerializerService.Serialize(signalingMessage));
 }
예제 #4
0
        private void ProcessMessage(ISignalingMessage signalingMessage) // wiadomosc przychodzaca do NCC jako do serwera (MASTER)
        {
            try
            {
                switch (signalingMessage)
                {
                case CallRequest_req callRequestReq:
                {
                    _logService.LogInfo(
                        $"Getting {callRequestReq}");

                    // TODO CHECK ALL POSSIBILITIES
                    if (DataHolder.GetDataModel(callRequestReq.To).Count > 0)
                    {
                        var callRequestRsp = new CallRequest_rsp()
                        {
                            From     = callRequestReq.From,
                            To       = callRequestReq.To,
                            Capacity = callRequestReq.Capacity,
                            Guid     = callRequestReq.Guid,
                            Result   = RequestResult.Rejected,
                            Slots    = new List <int>()
                        };
                        SendMessage(callRequestRsp, "CPCC" + callRequestReq.From[1]);
                        return;
                    }
                    // TODO

                    var directoryEntry = DirectoryGetToNode(callRequestReq.To);
                    var node           = directoryEntry.ToNode;

                    var newModel = new DataModel
                    {
                        From     = callRequestReq.From,
                        To       = callRequestReq.To,
                        Capacity = callRequestReq.Capacity
                    };

                    var connectionRequestReq = new ConnectionRequest_req
                    {
                        AddressFrom       = callRequestReq.From,
                        AddressTo         = node,
                        Capacity          = callRequestReq.Capacity,
                        Action            = AllocationAction.Setup,
                        Guid              = callRequestReq.Guid,
                        EstimatedDistance = directoryEntry.EstimatedDistance
                    };

                    newModel.CallRequestReq.Add(callRequestReq);

                    newModel.ConnectionRequestReq.Add(connectionRequestReq);
                    DataHolder.Data.Add(newModel);

                    _logService.LogInfo(
                        $"Sending ConnectionRequest_req to {_domainCcrcName}, AddresFrom: {callRequestReq.From}, AddressTo: {node}, Capacity: {callRequestReq.Capacity}, Action: {AllocationAction.Setup}, guid: {callRequestReq.Guid}");
                    SendMessage(connectionRequestReq, _domainCcrcName);
                    break;
                }

                case ConnectionRequest_rsp connectionRequestRsp:
                {
                    _logService.LogInfo(
                        $"Getting {connectionRequestRsp}");

                    var datamodel = DataHolder.GetDataModel(connectionRequestRsp.Guid);

                    var client = DirectoryGetToNode(datamodel.To);

                    var dataModel = DataHolder.GetDataModel(connectionRequestRsp.Guid);
                    dataModel.ConnectionRequestRsp.Add(connectionRequestRsp);

                    if (connectionRequestRsp.Result == RequestResult.Confirmed)
                    {
                        if (client.LocalClient)
                        {
                            var callAcceptReq = new CallAccept_req
                            {
                                From     = datamodel.From,
                                To       = datamodel.To,
                                Capacity = connectionRequestRsp.Capacity,
                                Slots    = connectionRequestRsp.Slots,
                                Guid     = connectionRequestRsp.Guid
                            };

                            datamodel.CallAcceptReq.Add(callAcceptReq);
                            _logService.LogInfo($"Sending {callAcceptReq}");
                            SendMessage(callAcceptReq, "CPCC" + datamodel.To[1]);

                            return;
                        }

                        var msg = new CallCoordination_req
                        {
                            From         = dataModel.From,
                            To           = dataModel.To,
                            Guid         = connectionRequestRsp.Guid,
                            Capacity     = connectionRequestRsp.Capacity,
                            Slots        = connectionRequestRsp.Slots,
                            StartingNode = connectionRequestRsp.AddressTo
                        };


                        dataModel.CallCoordinationReq.Add(msg);

                        if (_nccConfig.DomainSlave)
                        {
                            _logService.LogInfo($"Sending {msg} to NCC1");
                            _client.Post(_objectSerializerService.Serialize(msg));
                        }
                        else
                        {
                            _logService.LogInfo($"Sending {msg} to {_secondNccName}");
                            SendMessage(msg, _secondNccName);
                        }
                    }
                    else
                    {
                        if (dataModel.CallCoordinationReq.Count == 0)
                        {
                            var req     = dataModel.CallRequestReq.First();
                            var message = new CallRequest_rsp
                            {
                                Capacity = req.Capacity,
                                From     = req.From,
                                Guid     = req.Guid,
                                Result   = RequestResult.Rejected,
                                To       = req.To
                            };
                            SendMessage(message, "CPCC" + req.From[1]);
                        }
                        else
                        {
                            var req     = dataModel.CallCoordinationReq.First();
                            var message = new CallCoordination_rsp
                            {
                                Capacity     = req.Capacity,
                                From         = req.From,
                                Guid         = req.Guid,
                                Result       = RequestResult.Rejected,
                                Slots        = req.Slots,
                                StartingNode = req.StartingNode,
                                To           = req.To
                            };
                            if (_nccConfig.DomainSlave)
                            {
                                SendMessageToMaster(message);
                            }
                            else
                            {
                                SendMessage(message, _secondNccName);
                            }
                        }
                        DataHolder.Data.Remove(dataModel);
                    }

                    break;
                }

                case CallCoordination_req callCoordinationReq:
                {
                    _logService.LogInfo($"Getting {callCoordinationReq}");

                    // TODO CHECK ALL POSSIBILITIES
                    if (DataHolder.GetDataModel(callCoordinationReq.To).Count > 0)
                    {
                        var callCoordinationRsp = new CallCoordination_rsp
                        {
                            From         = callCoordinationReq.From,
                            To           = callCoordinationReq.To,
                            Capacity     = callCoordinationReq.Capacity,
                            Guid         = callCoordinationReq.Guid,
                            Result       = RequestResult.Rejected,
                            Slots        = new List <int>(),
                            StartingNode = "H0"
                        };

                        _logService.LogInfo($"Sending {callCoordinationRsp}");

                        if (_nccConfig.DomainSlave)
                        {
                            SendMessageToMaster(callCoordinationRsp);
                        }
                        else
                        {
                            SendMessage(callCoordinationRsp, _secondNccName);
                        }

                        return;
                    }
                    // TODO

                    var dataModel = new DataModel
                    {
                        From  = callCoordinationReq.From,
                        To    = callCoordinationReq.To,
                        Slots = callCoordinationReq.Slots
                    };

                    var connectionRequest = new ConnectionRequest_req()
                    {
                        Action      = AllocationAction.Setup,
                        AddressFrom = callCoordinationReq.StartingNode,
                        AddressTo   = callCoordinationReq.To,
                        Capacity    = callCoordinationReq.Capacity,
                        Guid        = callCoordinationReq.Guid,
                        Slots       = callCoordinationReq.Slots
                    };

                    dataModel.ConnectionRequestReq.Add(connectionRequest);
                    DataHolder.Data.Add(dataModel);

                    _logService.LogInfo($"Sending {connectionRequest}");
                    SendMessage(connectionRequest, _domainCcrcName);
                    break;
                }

                case CallAccept_rsp callAcceptRsp:
                {
                    _logService.LogInfo($"Getting {callAcceptRsp}");
                    var dataModel = DataHolder.GetDataModel(callAcceptRsp.Guid);
                    dataModel.CallAcceptRsp.Add(callAcceptRsp);

                    if (!DirectoryGetToNode(callAcceptRsp.To).LocalClient || !DirectoryGetToNode(callAcceptRsp.From).LocalClient)
                    {
                        var callCoordinationRsp = new CallCoordination_rsp
                        {
                            From   = callAcceptRsp.From,
                            Guid   = callAcceptRsp.Guid,
                            Result = callAcceptRsp.Result,
                            Slots  = callAcceptRsp.Slots,
                            To     = callAcceptRsp.To
                        };

                        _logService.LogInfo($"Sending {callCoordinationRsp}");

                        if (_nccConfig.DomainSlave)
                        {
                            SendMessageToMaster(callCoordinationRsp);
                        }
                        else
                        {
                            SendMessage(callCoordinationRsp, _secondNccName);
                        }
                    }
                    else
                    {
                        var callRequestRsp = new CallRequest_rsp
                        {
                            Capacity = callAcceptRsp.Capacity,
                            From     = callAcceptRsp.From,
                            Guid     = callAcceptRsp.Guid,
                            Slots    = callAcceptRsp.Slots,
                            To       = callAcceptRsp.To
                        };

                        if (callAcceptRsp.Result == RequestResult.Confirmed)
                        {
                            callRequestRsp.Result = RequestResult.Confirmed;
                        }
                        else
                        {
                            callRequestRsp.Result = RequestResult.Rejected;
                            SendReleaseAndDeleteModel(callAcceptRsp);
                        }

                        _logService.LogInfo($"Sending {callRequestRsp}");
                        SendMessage(callRequestRsp, "CPCC" + callAcceptRsp.From[1]);
                    }

                    // TODO: CHECK
                    if (callAcceptRsp.Result == RequestResult.Rejected)
                    {
                        SendReleaseAndDeleteModel(callAcceptRsp);
                    }

                    break;
                }

                case CallCoordination_rsp callCoordinationRsp:
                {
                    _logService.LogInfo($"Getting {callCoordinationRsp}");

                    var callRequestRsp = new CallRequest_rsp
                    {
                        Capacity = callCoordinationRsp.Capacity,
                        From     = callCoordinationRsp.From,
                        Guid     = callCoordinationRsp.Guid,
                        Slots    = callCoordinationRsp.Slots,
                        To       = callCoordinationRsp.To
                    };

                    DataHolder.GetDataModel(callCoordinationRsp.Guid).CallCoordinationRsp.Add(callCoordinationRsp);

                    if (callCoordinationRsp.Result == RequestResult.Confirmed)
                    {
                        callRequestRsp.Result = RequestResult.Confirmed;
                    }
                    else
                    {
                        callRequestRsp.Result = RequestResult.Rejected;
                        SendReleaseAndDeleteModel(callCoordinationRsp);
                    }

                    _logService.LogInfo($"Sending {callRequestRsp}");
                    SendMessage(callRequestRsp, "CPCC" + callCoordinationRsp.From[1]);

                    break;
                }

                case CallTeardown_req callTeardownReq:
                {
                    var dataModel = DataHolder.GetDataModel(callTeardownReq.Guid);
                    if (dataModel == null)
                    {
                        return;
                    }

                    _logService.LogInfo($"Getting {callTeardownReq}");


                    _logService.LogInfo($"Sending callTeardownReq to {callTeardownReq.To}");
                    if (DirectoryGetToNode(callTeardownReq.To).LocalClient)
                    {
                        SendMessage(callTeardownReq, "CPCC" + callTeardownReq.To[1]);
                    }
                    else
                    {
                        if (_nccConfig.DomainSlave)
                        {
                            SendMessageToMaster(callTeardownReq);
                        }
                        else
                        {
                            SendMessage(callTeardownReq, _secondNccName);
                        }
                    }



                    SendReleaseAndDeleteModel(callTeardownReq);

                    break;
                }

                case NoRouteMessage noRouteMessage:
                {
                    _logService.LogInfo($"Getting {nameof(NoRouteMessage)}");
                    var dataModel = DataHolder.GetDataModel(noRouteMessage.Guid);

                    if (dataModel == null)
                    {
                        return;
                    }

                    _logService.LogInfo($"Sending {nameof(NoRouteMessage)}");

                    if (DirectoryGetToNode(dataModel.To).LocalClient)
                    {
                        SendMessage(noRouteMessage, "CPCC" + dataModel.To[1]);
                    }
                    if (DirectoryGetToNode(dataModel.From).LocalClient)
                    {
                        SendMessage(noRouteMessage, "CPCC" + dataModel.From[1]);
                    }

                    if (_nccConfig.DomainSlave)
                    {
                        SendMessageToMaster(noRouteMessage);
                    }
                    else
                    {
                        SendMessage(noRouteMessage, _secondNccName);
                    }

                    SendReleaseAndDeleteModel(noRouteMessage);
                    break;
                }
                }
            }
            catch (Exception e)
            {
                _logService.LogError(e.StackTrace);
            }
        }
예제 #5
0
 public void SendMessageToMaster(ISignalingMessage message)
 {
     _client.Post(_objectSerializerService.Serialize(message));
 }
예제 #6
0
        public void SendMessage(ISignalingMessage message, string nodeName)
        {
            var handler = _socketOfNode[nodeName];

            handler.Send(_objectSerializerService.Serialize(message));
        }
예제 #7
0
 public void SendMessageToDomainCCRC(ISignalingMessage message)
 {
     _logService.LogInfo("Sending message to Domain");
     _clientDomain.Post(_objectSerializerService.Serialize(message));
 }
        Task <bool> ProcessMessage(ISignalingMessage message)
        {
            try
            {
                switch (message)
                {
                case SNPLinkConnectionRequest_req req:
                {
                    _logService.LogInfo($"Getting {req}");
                    var port = NetworkNodeConfig.Neighbors.First(n => n.Name == req.To).Port;

                    var msg = new SNPNegotiation_req
                    {
                        From              = req.From,
                        FromPort          = port,
                        ToPort            = req.ToPort,
                        To                = req.To,
                        Port              = port,
                        Slots             = req.Slots,
                        Guid              = req.Guid,
                        RequestFromDomain = req.RequestFromDomain,
                        Rerouting         = req.Rerouting,
                        Action            = req.Action,
                        Releasing         = req.Releasing
                    };

                    if (msg.Releasing)
                    {
                        var snpLinkConnectionRequest_rsp = new SNPLinkConnectionRequest_rsp
                        {
                            From              = req.From,
                            FromPort          = port,
                            To                = req.To,
                            ToPort            = req.ToPort,
                            Slots             = req.Slots,
                            Guid              = req.Guid,
                            RequestFromDomain = req.RequestFromDomain,
                            Result            = RequestResult.Confirmed,
                            Rerouting         = req.Rerouting,
                            Releasing         = req.Releasing
                        };

                        if (msg.RequestFromDomain)
                        {
                            _lrmService.SendMessageToDomainCCRC(snpLinkConnectionRequest_rsp);
                        }
                        else
                        {
                            _lrmService.SendMessageToCCRC(snpLinkConnectionRequest_rsp);
                        }

                        return(Task.FromResult(true));
                    }

                    _logService.LogInfo($"Sending {msg}");
                    _cableCloudConnectionService.SendSNPNegotiation(msg);
                    break;
                }

                case SNPNegotiation_req negreq:
                {
                    _logService.LogInfo($"Getting {negreq}");

                    var port = NetworkNodeConfig.Neighbors.First(n => n.Name == negreq.From).Port;

                    var areFree = _routingService.CheckFreeSlots(negreq.Slots);

                    var msg = new SNPNegotiation_rsp
                    {
                        From              = negreq.From,
                        FromPort          = negreq.FromPort,
                        To                = negreq.To,
                        ToPort            = port,
                        Port              = port,
                        Slots             = negreq.Slots,
                        Result            = areFree ? RequestResult.Confirmed : RequestResult.Rejected,
                        Guid              = negreq.Guid,
                        RequestFromDomain = negreq.RequestFromDomain,
                        Rerouting         = negreq.Rerouting,
                        Releasing         = negreq.Releasing
                    };

                    _logService.LogInfo($"Sending {msg}");

                    _cableCloudConnectionService.SendSNPNegotiation(msg);
                    break;
                }

                case SNPNegotiation_rsp negrsp:
                {
                    _logService.LogInfo($"Getting {negrsp}");

                    var port = NetworkNodeConfig.Neighbors.First(n => n.Name == negrsp.To).Port;

                    var snpLinkConnectionRequest_rsp = new SNPLinkConnectionRequest_rsp
                    {
                        From              = negrsp.From,
                        FromPort          = port,
                        To                = negrsp.To,
                        ToPort            = negrsp.ToPort,
                        Slots             = negrsp.Slots,
                        Guid              = negrsp.Guid,
                        RequestFromDomain = negrsp.RequestFromDomain,
                        Result            = negrsp.Result == RequestResult.Confirmed
                                    ? RequestResult.Confirmed
                                    : RequestResult.Rejected,
                        Rerouting = negrsp.Rerouting,
                        Releasing = negrsp.Releasing
                    };


                    _logService.LogInfo($"Sending {snpLinkConnectionRequest_rsp}");

                    if (negrsp.RequestFromDomain)
                    {
                        _lrmService.SendMessageToDomainCCRC(snpLinkConnectionRequest_rsp);
                    }
                    else
                    {
                        _lrmService.SendMessageToCCRC(snpLinkConnectionRequest_rsp);
                    }

                    break;
                }

                case CableAction cableAction:
                {
                    _logService.LogInfo("Sending LocalTopology to CC and RC");
                    _lrmService.SendMessageToCCRC(cableAction);
                    break;
                }
                }
            } catch (Exception ex)
            {
                _logService.LogError(ex.StackTrace);
            }

            return(Task.FromResult(true));
        }
예제 #9
0
 public void SendSNPNegotiation(ISignalingMessage request)
 {
     _client.Post(_objectSerializerService.Serialize(request));
 }
        private void ProcessMessage(TcpFrameArrivedEventArgs e, ISignalingMessage signalingMessage)
        {
            string incomingNode;
            int    incomingPort;

            switch (signalingMessage)
            {
            case SNPNegotiation_req req:
            {
                incomingNode = _nodeOfSocket[e.RemoteTcpPeer];
                incomingPort = req.Port;
                var cable = GetCable(incomingNode, incomingPort);


                if (cable == null)
                {
                    return;
                }

                var nextNode = cable.Node2;
                var nextPort = cable.Port2;

                if (nextNode == incomingNode)
                {
                    nextNode = cable.Node1;
                    nextPort = cable.Port1;
                }

                if (cable.Status)
                {
                    req.Port = nextPort;
                    if (!_socketOfNode.ContainsKey(nextNode))
                    {
                        _logService.LogWarning($"{nextNode} is not connected to CableCloud");
                        return;
                    }
                    SendMessage(_socketOfNode[nextNode], signalingMessage);
                    _logService.LogInfo("Sending package from: " + incomingNode + ":" + incomingPort + " to: " + nextNode + ":" + nextPort);
                }
                else
                {
                    _logService.LogInfo("Discarding package (cable disabled) from: " + incomingNode + ":" + incomingPort + " to: " + nextNode + ":" + nextPort);
                }
                break;
            }

            case SNPNegotiation_rsp rsp:
            {
                incomingNode = _nodeOfSocket[e.RemoteTcpPeer];
                incomingPort = rsp.Port;
                var cable = GetCable(incomingNode, incomingPort);


                if (cable == null)
                {
                    return;
                }

                var nextNode = cable.Node2;
                var nextPort = cable.Port2;

                if (nextNode == incomingNode)
                {
                    nextNode = cable.Node1;
                    nextPort = cable.Port1;
                }

                if (cable.Status)
                {
                    rsp.Port = nextPort;
                    if (!_socketOfNode.ContainsKey(nextNode))
                    {
                        _logService.LogWarning($"{nextNode} is not connected to CableCloud");
                        return;
                    }
                    SendMessage(_socketOfNode[nextNode], signalingMessage);
                    _logService.LogInfo("Sending package from: " + incomingNode + ":" + incomingPort + " to: " + nextNode + ":" + nextPort);
                }
                else
                {
                    _logService.LogInfo("Discarding package (cable disabled) from: " + incomingNode + ":" + incomingPort + " to: " + nextNode + ":" + nextPort);
                }
                break;
            }
            }
        }
 public void SendMessage(IRemoteTcpPeer handler, ISignalingMessage message)
 {
     handler.Post(_objectSerializerService.Serialize(message));
 }
 public void SendMessageToNCCorDomain(ISignalingMessage message)
 {
     _client.Post(_objectSerializerService.Serialize(message));
 }
 private void ProcessMessage(ISignalingMessage signalingMessage)
 {
     MessageReceived?.Invoke(this, new MessageReceivedEventArgs {
         Message = signalingMessage
     });
 }