Пример #1
0
 public Call(int connectionID, bool interDomainConnection, int startAsID, bool throughSubnetwork, HostConnection startHostConnection, HostConnection targetHostConnection, Path path)
 {
     this.connectionID          = connectionID;
     this.interDomainConnection = interDomainConnection;
     this.startAsID             = startAsID;
     this.startHostConnection   = startHostConnection;
     this.targetHostConnection  = targetHostConnection;
     this.throughSubnetwork     = throughSubnetwork;
     this.path = path;
 }
Пример #2
0
        private Tuple <HostConnection, HostConnection> GetHostConnections(Path path)
        {
            HostConnection hc1 = null, hc2 = null;

            foreach (HostConnection hostConnection in Server.GetHostConnections())
            {
                if (hostConnection.GetHost() == path.endPoints.Item1)
                {
                    hc1 = hostConnection;
                }

                if (hostConnection.GetHost() == path.endPoints.Item2)
                {
                    hc2 = hostConnection;
                }
            }

            return(new Tuple <HostConnection, HostConnection>(hc1, hc2));
        }
Пример #3
0
        private void RefuseConnection(HostConnection caller)
        {
            string message = "component:CPCC;name:CallRequestResponse;succeeded:false";

            caller.SendMessage(message);
        }
Пример #4
0
        public void HandleRequest(Dictionary <string, string> data, HostConnection caller)
        {
            try {
                switch (data["name"])
                {
                case "CallRequest":
                    GUIWindow.PrintLog("NCC: Received CallRequest(" + data["hostX"] + ", " + data["hostY"] + ", " + data["speed"] + " Gb/s) from CPCC");

                    Tuple <string, string, int, int> routerData = HandleDirectory(data["hostX"], data["hostY"]);
                    if (routerData.Item1.Equals("WRONG NAME") || routerData.Item2.Equals("WRONG NAME"))
                    {
                        GUIWindow.PrintLog("NCC: Host name does not exist");
                        GUIWindow.PrintLog("NCC: Sent CallRequestResponse(UNSUCCESSFUL)");
                        RefuseConnection(caller);
                        break;
                    }
                    else if (routerData.Item1.Equals(routerData.Item2))
                    {
                        GUIWindow.PrintLog("NCC: Target Host name is the same as the source one");
                        GUIWindow.PrintLog("NCC: Sent CallRequestResponse(UNUSCCESSFUL)");
                        RefuseConnection(caller);
                        break;
                    }
                    HandlePolicy();

                    lastCaller    = caller;
                    lastRouterXIP = routerData.Item1;
                    lastRouterYIP = routerData.Item2;;
                    lastSpeed     = Convert.ToInt32(data["speed"]);
                    lastIDC       = routerData.Item3 != routerData.Item4;

                    if (!lastIDC)
                    {
                        string         hostYIP1        = routerData.Item2.Remove(routerData.Item2.Length - 1, 1) + "2";
                        HostConnection hostConnection1 = Server.GetHostConnectionByIP(hostYIP1);
                        string         message1        = "component:CPCC;name:CallAccept;routerX:" + data["hostX"] + ";routerY:" + data["hostY"] + ";speed:" + data["speed"];
                        hostConnection1.SendMessage(message1);
                        cachedHostYConnection = hostConnection1;
                        GUIWindow.PrintLog("NCC: Sent CallAccept(" + data["hostX"] + ", " + data["hostY"] + ", " + data["speed"] + " Gb/s) to other NCC");
                        break;
                    }

                    string message = "component:NCC;name:CallCoordination;routerX:" + routerData.Item1 + ";routerY:" + routerData.Item2 + ";speed:" + data["speed"] + ";IDC:" + lastIDC.ToString();
                    Program.peerConnection.SendMessage(message);
                    GUIWindow.PrintLog("NCC: Sent CallCoordination(" + routerData.Item1 + ", " + routerData.Item2 + ", " + data["speed"] + " Gb/s) to other NCC");

                    break;

                case "CallCoordination":

                    GUIWindow.PrintLog("NCC: Received CallCoordination(" + data["routerX"] + ", " + data["routerY"] + ", " + data["speed"] + " Gb/s) from other NCC");
                    lastIDC = Convert.ToBoolean(data["IDC"]);

                    //odwrotne dzialanie funkcji -- dajemy IP dostajemy nazwy
                    routerData = HandleDirectory(data["routerX"], data["routerY"]);
                    HandlePolicy();
                    string         hostYIP        = data["routerY"].Remove(data["routerY"].Length - 1, 1) + "2";
                    HostConnection hostConnection = Server.GetHostConnectionByIP(hostYIP);
                    cachedHostYConnection = hostConnection;
                    message = "component:CPCC;name:CallAccept;routerX:" + routerData.Item1 + ";routerY:" + routerData.Item2 + ";speed:" + data["speed"];
                    hostConnection.SendMessage(message);
                    GUIWindow.PrintLog("NCC: Sent CallAccept(" + routerData.Item1 + ", " + routerData.Item2 + ", " + data["speed"] + " Gb/s) to other NCC");
                    break;

                case "CallCoordinationResponse":
                    if (!Convert.ToBoolean(data["succeeded"]))
                    {
                        GUIWindow.PrintLog("NCC: Received CallRequestResponse(DENIED) from other NCC");
                        RefuseConnection(lastCaller);
                    }
                    else
                    {
                        GUIWindow.PrintLog("NCC: Received CallRequestResponse(ACCEPTED) from other NCC");
                        ConnectionRequest(lastIDC);
                        //message = "component:CPCC;name:CallRequestResponse;succeeded:true;connectionID:0"; //hard-kodowane connID na razie
                        //lastCaller.SendMessage(message);
                    }
                    break;

                case "CallAcceptResponse":
                    string status = "ACCEPTED";
                    if (lastIDC)
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            message = "component:NCC;name:CallCoordinationResponse;succeeded:false";
                            status  = "DENIED";
                        }
                        else
                        {
                            message = "component:NCC;name:CallCoordinationResponse;succeeded:true";
                        }
                        Program.peerConnection.SendMessage(message);
                        GUIWindow.PrintLog("NCC: Sent CallCoordinationResponse(" + status + ") to other NCC");
                    }
                    else
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            GUIWindow.PrintLog("NCC: Received CallAcceptResponse(DENIED) from CPCC");
                            RefuseConnection(lastCaller);
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Received CallAcceptResponse(ACCEPTED) from CPCC");
                            ConnectionRequest(lastIDC);
                        }
                    }
                    break;

                case "CallTeardownCPCC":
                    GUIWindow.PrintLog("NCC: Received CallTeardownCPCC(" + data["connectionID"] + ") from CPCC");

                    GUIWindow.PrintLog("NCC: Sent ConnectionRequest(" + data["connectionID"] + ") to CC");
                    message = "component:CC;name:ConnectionTeardown;connectionID:" + data["connectionID"];
                    Program.cc.HandleRequest(Util.DecodeRequest(message));
                    break;

                case "ConnectionTeardownResponse":
                    GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(" + data["connectionID"] + ") from CC : OK");

                    if (callRegister[Int32.Parse(data["connectionID"])].GetStartAsID() == ConfigLoader.ccID)
                    {
                        // Pierwszy AS
                        if (!callRegister[Int32.Parse(data["connectionID"])].GetInterDomainConnectionFlag())
                        {
                            //polaczenie wewnatrzdomenowe
                            GUIWindow.PrintLog("NCC: Sent CallTeardownCPCC(" + data["connectionID"] + ") to CPCC");
                            message = "component:CPCC;name:CallTeardownCPCC;connectionID:" + data["connectionID"];
                            callRegister[Int32.Parse(data["connectionID"])].GetTargetHostConnection().SendMessage(message);
                            break;
                        }
                        else
                        {
                            //polaczenie zewnatrzdomenowe
                            GUIWindow.PrintLog("NCC: Sent CallTeardownNCC(" + data["connectionID"] + ") to other AS NCC");
                            message = "component:NCC;name:CallTeardownNCC;connectionID:" + data["connectionID"];
                            Program.peerConnection.SendMessage(message);
                        }
                    }
                    else
                    {
                        // Drugi AS
                        GUIWindow.PrintLog("NCC: Sent CallTeardownNCCResponse(" + data["connectionID"] + ") to other AS NCC : OK");
                        message = "component:NCC;name:CallTeardownNCCResponse;connectionID:" + data["connectionID"];
                        Program.peerConnection.SendMessage(message);
                    }
                    break;

                case "CallTeardownNCC":
                    GUIWindow.PrintLog("NCC: Received CallTeardownNCC(" + data["connectionID"] + ") from other AS NCC");

                    GUIWindow.PrintLog("NCC: Sent CallTeardownCPCC(" + data["connectionID"] + ") to CPCC");
                    message = "component:CPCC;name:CallTeardownCPCC;connectionID:" + data["connectionID"];
                    callRegister[Int32.Parse(data["connectionID"])].GetTargetHostConnection().SendMessage(message);
                    break;

                case "CallTeardownCPCCResponse":
                    GUIWindow.PrintLog("NCC: Received CallTeardownCPCCResponse(" + data["connectionID"] + ") from CPCC: OK");
                    if (!callRegister[Int32.Parse(data["connectionID"])].GetInterDomainConnectionFlag())
                    {
                        //polaczenie wewnatrzdomenowe
                        GUIWindow.PrintLog("NCC: Sent CallTeardownCPCCResponse(" + data["connectionID"] + ") to CPCC : OK");
                        message = "component:CPCC;name:CallTeardownCPCCResponse;connectionID:" + data["connectionID"];
                        callRegister[Int32.Parse(data["connectionID"])].GetStartHostConnection().SendMessage(message);
                    }
                    else
                    {
                        //polaczenie zewnatrzdomenowe
                        GUIWindow.PrintLog("NCC: Sent ConnectionRequest(" + data["connectionID"] + ") to CC");
                        message = "component:CC;name:ConnectionTeardown;connectionID:" + data["connectionID"];
                        Program.cc.HandleRequest(Util.DecodeRequest(message));
                    }
                    break;

                case "CallTeardownNCCResponse":
                    GUIWindow.PrintLog("NCC: Received CallTeardownNCCResponse(" + data["connectionID"] + ") from other AS NCC : OK");
                    GUIWindow.PrintLog("NCC: Sent CallTeardownCPCCResponse(" + data["connectionID"] + ") to CPCC : OK");
                    message = "component:CPCC;name:CallTeardownCPCCResponse;connectionID:" + data["connectionID"];
                    callRegister[Int32.Parse(data["connectionID"])].GetStartHostConnection().SendMessage(message);
                    break;

                case "CallConfirmation":
                    if (!Convert.ToBoolean(data["succeeded"]))
                    {
                        GUIWindow.PrintLog("NCC: Received CallConfirmation(SUCCEEDED: false) from other NCC");
                        GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: false) to CPCC");
                        cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;IDC:" + data["IDC"] + ";succeeded:false");
                    }
                    else
                    {
                        GUIWindow.PrintLog("NCC: Received CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") from other NCC");
                        GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") to CPCC");
                        cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;IDC:" + data["IDC"] + ";succeeded:true;connID:" + data["connID"]);
                    }
                    break;

                case "CallConfirmationResponse":
                    switch (data["sender"])
                    {
                    case "CPCC":
                        GUIWindow.PrintLog("NCC: Received CallConfirmationResponse() from CPCC");
                        if (Convert.ToBoolean(data["IDC"]))
                        {
                            GUIWindow.PrintLog("NCC: Sent CallConfirmationResponse() to other NCC");
                            Program.peerConnection.SendMessage("component:NCC;name:CallConfirmationResponse;sender:NCC");
                        }
                        else
                        {
                            if (!cachedSuccess)
                            {
                                GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: false) to CPCC");
                                lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:false");
                            }
                            else
                            {
                                GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: true, connectionID: " + RC.currentConnectionID + ") to CPCC");
                                lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:true;connectionID:" + RC.currentConnectionID);
                            }
                        }
                        break;

                    case "NCC":
                        GUIWindow.PrintLog("NCC: Received CallConfirmationResponse() from other NCC");
                        if (!cachedSuccess)
                        {
                            GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: false) to CPCC");
                            lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:false");
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Sent CallRequestResponse(SUCCEEDED: true, connectionID: " + RC.currentConnectionID + ") to CPCC");
                            lastCaller.SendMessage("component:CPCC;name:CallRequestResponse;succeeded:true;connectionID:" + RC.currentConnectionID);
                        }
                        break;
                    }
                    break;

                case "ConnectionRequestResponse":
                    cachedSuccess = Convert.ToBoolean(data["succeeded"]);
                    if (lastIDC)
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: false) from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: false) to other NCC");
                            Program.peerConnection.SendMessage("component:NCC;name:CallConfirmation;IDC:true;succeeded:false");
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: true, connectionID: " + data["connID"] + ") from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") to other NCC");
                            Program.peerConnection.SendMessage("component:NCC;name:CallConfirmation;IDC:true;succeeded:true;connID:" + data["connID"]);
                        }
                    }
                    else
                    {
                        if (!Convert.ToBoolean(data["succeeded"]))
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: false) from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: false) to CPCC");
                            cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;succeeded:false;IDC:false");
                        }
                        else
                        {
                            GUIWindow.PrintLog("NCC: Received ConnectionRequestResponse(SUCCEEDED: true, connectionID: " + data["connID"] + ") from CC");
                            GUIWindow.PrintLog("NCC: Sent CallConfirmation(SUCCEEDED: true, connectionID: " + data["connID"] + ") to CPCC");
                            cachedHostYConnection.SendMessage("component:CPCC;name:CallConfirmation;succeeded:true;IDC:false;connID:" + data["connID"]);
                        }
                    }
                    break;
                }
            } catch (Exception e) {
                GUIWindow.PrintLog(e.Message);
                GUIWindow.PrintLog(e.StackTrace);
            }
        }
Пример #5
0
 public void RemoveHostConnection(HostConnection hostConnection)
 {
     GUIWindow.PrintLog("Host #" + hostConnection.GetID() + " has disconnected");
     hostConnections.Remove(hostConnection);
 }