コード例 #1
0
ファイル: HN05005.cs プロジェクト: furszy/iop-profile-server
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;

                // And close connection to clNonCustomer port.
                clientCaller.CloseConnection();


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");
                string callerMessage1 = "Message #1 to callee.";
                byte[] messageBytes   = Encoding.UTF8.GetBytes(callerMessage1);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                uint callerMessage1Id = requestMessageAppServiceCaller.Id;
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);


                // Step 6 Acceptance
                bool step6Ok = true;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                // Step 7
                log.Trace("Step 7");
                // Receive message #1.
                Message nodeRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray();
                bool   versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                bool   messageOk       = receivedMessage == callerMessage1;

                bool receiveMessageOk = versionOk && typeOk && messageOk;


                // ACK message #1.
                Message nodeResponseAppServiceCallee = mbCalleeAppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCallee);
                await clientCalleeAppService.SendMessageAsync(nodeResponseAppServiceCallee);


                // Send our message #1.
                string calleeMessage1 = "Message #1 to CALLER.";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage1);
                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes);
                uint calleeMessage1Id = requestMessageAppServiceCallee.Id;
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);



                // Step 7 Acceptance
                bool step7Ok = receiveMessageOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                // Step 8
                log.Trace("Step 8");
                // Receive ACK message #1.
                responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage1Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = responseMessageAppServiceCaller.Response.SingleResponse.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                bool receiveAckOk = idOk && statusOk && versionOk;


                // Receive message #1 from callee.
                Message nodeRequestAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                receivedVersion = nodeRequestAppServiceCaller.Request.SingleRequest.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                typeOk = (nodeRequestAppServiceCaller.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (nodeRequestAppServiceCaller.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (nodeRequestAppServiceCaller.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCaller.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                messageOk       = receivedMessage == calleeMessage1;

                receiveMessageOk = versionOk && typeOk && messageOk;


                // ACK message #1 from callee.
                Message nodeResponseAppServiceCaller = mbCallerAppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCaller);
                await clientCallerAppService.SendMessageAsync(nodeResponseAppServiceCaller);


                // Step 8 Acceptance
                bool step8Ok = receiveAckOk && receiveMessageOk;

                log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED");


                // Step 9
                log.Trace("Step 9");
                // Receive ACK message #1.
                responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCallee.Id == calleeMessage1Id;
                statusOk        = responseMessageAppServiceCallee.Response.Status == Status.Ok;
                receivedVersion = responseMessageAppServiceCallee.Response.SingleResponse.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                receiveAckOk = idOk && statusOk && versionOk;

                log.Trace("Going to wait for 3 minutes...");
                await Task.Delay(180 * 1000);

                log.Trace("Waiting done.");


                // Step 9 Acceptance
                bool step9Ok = receiveAckOk;

                log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED");


                // Step 10
                string callerMessage2 = "Message #1 to callee.";
                messageBytes = Encoding.UTF8.GetBytes(callerMessage2);
                requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);

                // We should be disconnected now, send or receive should throw.
                bool disconnectedOk = false;
                try
                {
                    await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                    await clientCallerAppService.ReceiveMessageAsync();
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectedOk = true;
                }

                // Step 10 Acceptance
                bool step10Ok = disconnectedOk;

                log.Trace("Step 10: {0}", step10Ok ? "PASSED" : "FAILED");



                // Step 11
                string calleeMessage2 = "Message #1 to CALLER.";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage2);
                requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, messageBytes);

                // We should be disconnected now, send or receive should throw.
                disconnectedOk = false;
                try
                {
                    await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);

                    await clientCalleeAppService.ReceiveMessageAsync();
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectedOk = true;
                }

                // Step 11 Acceptance
                bool step11Ok = disconnectedOk;

                log.Trace("Step 11: {0}", step11Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok && step10Ok && step11Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
コード例 #2
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, "Test Service Invalid");
                await clientCaller.SendMessageAsync(requestMessage);

                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool idOk           = responseMessage.Id == requestMessage.Id;
                bool statusOk       = responseMessage.Response.Status == Status.ErrorInvalidValue;
                bool detailsOk      = responseMessage.Response.Details == "serviceName";
                bool callIdentityOk = idOk && statusOk && detailsOk;


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk && callIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
コード例 #3
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Step 4 Acceptance
                bool step4Ok = callIdentityOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                await Task.Delay(35 * 1000);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);

                // Step 5 Acceptance
                bool step5Ok = true;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.ErrorNotFound;

                bool initAppServiceMessageOk = idOk && statusOk;


                // Step 6 Acceptance
                bool step6Ok = initAppServiceMessageOk;

                log.Trace("Step 6: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 7
                log.Trace("Step 7");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.ErrorNotFound;

                bool appServiceSendOk = idOk && statusOk;

                // Step 7 Acceptance
                bool step7Ok = appServiceSendOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
コード例 #4
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public async Task <bool> RunAsyncInternal(int Index)
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1},Index:{2})", NodeIp, PrimaryPort, Index);

            bool res = false;

            PassedArray[Index] = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");


                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;

                // And close connection to clNonCustomer port.
                clientCaller.CloseConnection();


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                UnfinishedRequestCounter callerCounter = new UnfinishedRequestCounter()
                {
                    Name = string.Format("Caller-{0}", Index)
                };
                UnfinishedRequestCounter calleeCounter = new UnfinishedRequestCounter()
                {
                    Name = string.Format("Callee-{0}", Index)
                };
                SemaphoreSlim callerWriteLock = new SemaphoreSlim(1);
                SemaphoreSlim calleeWriteLock = new SemaphoreSlim(1);

                Task <byte[]> messageReceivingTaskCaller = MessageReceivingLoop(clientCallerAppService, mbCallerAppService, "CallerReceiving", callerWriteLock, callerCounter);
                Task <byte[]> messageReceivingTaskCallee = MessageReceivingLoop(clientCalleeAppService, mbCalleeAppService, "CalleeReceiving", calleeWriteLock, calleeCounter);

                Task <byte[]> messageSendingTaskCaller = MessageSendingLoop(clientCallerAppService, mbCallerAppService, "CallerSending", callerToken, callerWriteLock, callerCounter);
                Task <byte[]> messageSendingTaskCallee = MessageSendingLoop(clientCalleeAppService, mbCalleeAppService, "CalleeSending", calleeToken, calleeWriteLock, calleeCounter);

                byte[] callerSendMessageHash = messageSendingTaskCaller.Result;
                byte[] calleeSendMessageHash = messageSendingTaskCallee.Result;

                byte[] callerReceiveMessageHash = messageReceivingTaskCaller.Result;
                byte[] calleeReceiveMessageHash = messageReceivingTaskCallee.Result;


                bool callerMessageHashOk = StructuralComparisons.StructuralComparer.Compare(callerSendMessageHash, calleeReceiveMessageHash) == 0;
                bool calleeMessageHashOk = StructuralComparisons.StructuralComparer.Compare(calleeSendMessageHash, callerReceiveMessageHash) == 0;


                // Step 6 Acceptance
                bool step6Ok = callerMessageHashOk && calleeMessageHashOk;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                PassedArray[Index] = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok;
                log.Trace("PassedArray[{0}] = {1}", Index, PassedArray[Index]);

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
コード例 #5
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee           = new ProtocolClient();
            ProtocolClient clientCalleeAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller           = new ProtocolClient();
            ProtocolClient clientCallerAppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee           = clientCallee.MessageBuilder;
                MessageBuilder mbCalleeAppService = clientCalleeAppService.MessageBuilder;

                MessageBuilder mbCaller           = clientCaller.MessageBuilder;
                MessageBuilder mbCallerAppService = clientCallerAppService.MessageBuilder;

                // Step 1
                log.Trace("Step 1");
                // Get port list.
                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller     = clientCaller.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller = clientCaller.GetIdentityId();


                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk = await clientCaller.VerifyIdentityAsync();

                Message requestMessage = mbCaller.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                await clientCaller.SendMessageAsync(requestMessage);


                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk = pubKeyOk && serviceNameOk;

                byte[] calleeToken = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);


                // Connect to clAppService and send initialization message.
                await clientCalleeAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCalleeAppService.CreateApplicationServiceSendMessageRequest(calleeToken, null);
                await clientCalleeAppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");



                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller.ReceiveMessageAsync();

                bool   idOk        = responseMessage.Id == requestMessage.Id;
                bool   statusOk    = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCallerAppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, null);
                await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCallerAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk = idOk && statusOk;

                clientCaller.CloseConnection();


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk && initAppServiceMessageOk;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool appServiceSendOk = idOk && statusOk;


                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");

                bool error             = false;
                int  messagesDelivered = 0;
                int  messagesSent      = 0;
                bool disconnectedOk    = false;
                for (int i = 0; i < 20; i++)
                {
                    try
                    {
                        // Caller sends message.
                        string callerMessage = string.Format("Message #{0} to callee.", i + 1);
                        byte[] messageBytes  = Encoding.UTF8.GetBytes(callerMessage);
                        requestMessageAppServiceCaller = mbCallerAppService.CreateApplicationServiceSendMessageRequest(callerToken, messageBytes);
                        await clientCallerAppService.SendMessageAsync(requestMessageAppServiceCaller);

                        messagesSent++;


                        // Callee receives message.
                        Message nodeRequestAppServiceCallee = await clientCalleeAppService.ReceiveMessageAsync();

                        byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray();
                        bool   versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                        bool typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                                      (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                                      (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                        string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                        bool   messageOk       = receivedMessage == callerMessage;

                        bool receiveMessageOk = versionOk && typeOk && messageOk;

                        if (receiveMessageOk)
                        {
                            messagesDelivered++;
                            log.Trace("Delivery of message #{0} succeeded.", i + 1);
                        }
                        else
                        {
                            log.Trace("Delivery of message #{0} failed.", i + 1);
                            error = true;
                            break;
                        }

                        await Task.Delay(10 * 1000);
                    }
                    catch
                    {
                        log.Trace("Expected exception occurred.");
                        disconnectedOk = true;
                        break;
                    }
                }



                // Step 6 Acceptance
                bool step6Ok = !error && disconnectedOk && (messagesDelivered < 20);

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCalleeAppService.Dispose();
            clientCaller.Dispose();
            clientCallerAppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
コード例 #6
0
ファイル: HN05025.cs プロジェクト: furszy/iop-profile-server
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient clientCallee            = new ProtocolClient();
            ProtocolClient clientCallee1AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());
            ProtocolClient clientCallee2AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCallee.GetIdentityKeys());

            ProtocolClient clientCaller1           = new ProtocolClient();
            ProtocolClient clientCaller1AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller1.GetIdentityKeys());

            ProtocolClient clientCaller2           = new ProtocolClient();
            ProtocolClient clientCaller2AppService = new ProtocolClient(0, new byte[] { 1, 0, 0 }, clientCaller2.GetIdentityKeys());

            try
            {
                MessageBuilder mbCallee            = clientCallee.MessageBuilder;
                MessageBuilder mbCallee1AppService = clientCallee1AppService.MessageBuilder;
                MessageBuilder mbCallee2AppService = clientCallee2AppService.MessageBuilder;

                MessageBuilder mbCaller1           = clientCaller1.MessageBuilder;
                MessageBuilder mbCaller1AppService = clientCaller1AppService.MessageBuilder;

                MessageBuilder mbCaller2           = clientCaller2.MessageBuilder;
                MessageBuilder mbCaller2AppService = clientCaller2AppService.MessageBuilder;


                // Step 1
                log.Trace("Step 1");

                byte[] pubKeyCallee     = clientCallee.GetIdentityKeys().PublicKey;
                byte[] identityIdCallee = clientCallee.GetIdentityId();

                byte[] pubKeyCaller1     = clientCaller1.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller1 = clientCaller1.GetIdentityId();

                byte[] pubKeyCaller2     = clientCaller2.GetIdentityKeys().PublicKey;
                byte[] identityIdCaller2 = clientCaller2.GetIdentityId();

                // Get port list.

                await clientCallee.ConnectAsync(NodeIp, PrimaryPort, false);

                Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>();
                bool listPortsOk = await clientCallee.ListNodePorts(rolePorts);

                clientCallee.CloseConnection();


                // Establish home node for identity 1.
                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool establishHomeNodeOk = await clientCallee.EstablishHomeNodeAsync();

                clientCallee.CloseConnection();


                // Check-in and initialize the profile of identity 1.

                await clientCallee.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClCustomer], true);

                bool checkInOk = await clientCallee.CheckInAsync();

                bool initializeProfileOk = await clientCallee.InitializeProfileAsync("Test Identity", null, 0x12345678, null);


                // Add application service to the current session.
                string serviceName     = "Test Service";
                bool   addAppServiceOk = await clientCallee.AddApplicationServicesAsync(new List <string>() { serviceName });


                // Step 1 Acceptance
                bool step1Ok = listPortsOk && establishHomeNodeOk && checkInOk && initializeProfileOk && addAppServiceOk;

                log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED");



                // Step 2
                log.Trace("Step 2");
                await clientCaller1.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk1 = await clientCaller1.VerifyIdentityAsync();

                Message requestMessage       = mbCaller1.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                uint    initMessageCaller1Id = requestMessage.Id;
                await clientCaller1.SendMessageAsync(requestMessage);


                await clientCaller2.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClNonCustomer], true);

                bool verifyIdentityOk2 = await clientCaller2.VerifyIdentityAsync();

                requestMessage = mbCaller2.CreateCallIdentityApplicationServiceRequest(identityIdCallee, serviceName);
                uint initMessageCaller2Id = requestMessage.Id;
                await clientCaller2.SendMessageAsync(requestMessage);



                // Step 2 Acceptance
                bool step2Ok = verifyIdentityOk1 && verifyIdentityOk2;

                log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED");



                // Step 3
                log.Trace("Step 3");
                Message nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                byte[] receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                bool   pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller1) == 0;
                bool   serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk1 = pubKeyOk && serviceNameOk;

                byte[] calleeToken1 = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                Message nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);



                nodeRequestMessage = await clientCallee.ReceiveMessageAsync();

                receivedPubKey = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CallerPublicKey.ToByteArray();
                pubKeyOk       = StructuralComparisons.StructuralComparer.Compare(receivedPubKey, pubKeyCaller2) == 0;
                serviceNameOk  = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.ServiceName == serviceName;

                bool incomingCallNotificationOk2 = pubKeyOk && serviceNameOk;

                byte[] calleeToken2 = nodeRequestMessage.Request.ConversationRequest.IncomingCallNotification.CalleeToken.ToByteArray();

                nodeResponseMessage = mbCallee.CreateIncomingCallNotificationResponse(nodeRequestMessage);
                await clientCallee.SendMessageAsync(nodeResponseMessage);



                // Connect to clAppService and send initialization message (FIRST connection).
                await clientCallee1AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCallee = mbCallee1AppService.CreateApplicationServiceSendMessageRequest(calleeToken1, null);
                await clientCallee1AppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Connect to clAppService and send initialization message (SECOND connection).
                await clientCallee2AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                requestMessageAppServiceCallee = mbCallee2AppService.CreateApplicationServiceSendMessageRequest(calleeToken2, null);
                await clientCallee2AppService.SendMessageAsync(requestMessageAppServiceCallee);


                // Step 3 Acceptance
                bool step3Ok = incomingCallNotificationOk1 && incomingCallNotificationOk2;

                log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED");



                // Step 4
                log.Trace("Step 4");
                Message responseMessage = await clientCaller1.ReceiveMessageAsync();

                bool   idOk         = responseMessage.Id == initMessageCaller1Id;
                bool   statusOk     = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken1 = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk1 = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCaller1AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                Message requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken1, null);
                await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller);

                Message responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk1 = idOk && statusOk;



                responseMessage = await clientCaller2.ReceiveMessageAsync();

                idOk     = responseMessage.Id == initMessageCaller1Id;
                statusOk = responseMessage.Response.Status == Status.Ok;
                byte[] callerToken2 = responseMessage.Response.ConversationResponse.CallIdentityApplicationService.CallerToken.ToByteArray();

                bool callIdentityOk2 = idOk && statusOk;

                // Connect to clAppService and send initialization message.
                await clientCaller2AppService.ConnectAsync(NodeIp, (int)rolePorts[ServerRoleType.ClAppService], true);

                requestMessageAppServiceCaller = mbCaller2AppService.CreateApplicationServiceSendMessageRequest(callerToken2, null);
                await clientCaller2AppService.SendMessageAsync(requestMessageAppServiceCaller);

                responseMessageAppServiceCaller = await clientCaller2AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCaller.Id == requestMessageAppServiceCaller.Id;
                statusOk = responseMessageAppServiceCaller.Response.Status == Status.Ok;

                bool initAppServiceMessageOk2 = idOk && statusOk;


                // Step 4 Acceptance
                bool step4Ok = callIdentityOk1 && initAppServiceMessageOk1 && callIdentityOk2 && initAppServiceMessageOk2;

                log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED");



                // Step 5
                log.Trace("Step 5");
                Message responseMessageAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                bool typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                              (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                              (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk1 = idOk && statusOk && typeOk;


                responseMessageAppServiceCallee = await clientCallee2AppService.ReceiveMessageAsync();

                idOk     = responseMessageAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseMessageAppServiceCallee.Response.Status == Status.Ok;

                typeOk = (responseMessageAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Response) &&
                         (responseMessageAppServiceCallee.Response.ConversationTypeCase == Response.ConversationTypeOneofCase.SingleResponse) &&
                         (responseMessageAppServiceCallee.Response.SingleResponse.ResponseTypeCase == SingleResponse.ResponseTypeOneofCase.ApplicationServiceSendMessage);

                bool appServiceSendOk2 = idOk && statusOk && typeOk;

                // Step 5 Acceptance
                bool step5Ok = appServiceSendOk1 && appServiceSendOk2;

                log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED");



                // Step 6
                log.Trace("Step 6");
                string caller1Message1 = "Message #1 to callee from caller1.";
                byte[] messageBytes    = Encoding.UTF8.GetBytes(caller1Message1);
                requestMessageAppServiceCaller = mbCaller1AppService.CreateApplicationServiceSendMessageRequest(callerToken1, messageBytes);
                uint callerMessage1Id = requestMessageAppServiceCaller.Id;
                await clientCaller1AppService.SendMessageAsync(requestMessageAppServiceCaller);


                // Step 6 Acceptance
                bool step6Ok = true;

                log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED");


                // Step 7
                log.Trace("Step 7");
                // Receive message #1.
                Message nodeRequestAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync();

                byte[] receivedVersion = nodeRequestAppServiceCallee.Request.SingleRequest.Version.ToByteArray();
                bool   versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                typeOk = (nodeRequestAppServiceCallee.MessageTypeCase == Message.MessageTypeOneofCase.Request) &&
                         (nodeRequestAppServiceCallee.Request.ConversationTypeCase == Request.ConversationTypeOneofCase.SingleRequest) &&
                         (nodeRequestAppServiceCallee.Request.SingleRequest.RequestTypeCase == SingleRequest.RequestTypeOneofCase.ApplicationServiceReceiveMessageNotification);

                string receivedMessage = Encoding.UTF8.GetString(nodeRequestAppServiceCallee.Request.SingleRequest.ApplicationServiceReceiveMessageNotification.Message.ToByteArray());
                bool   messageOk       = receivedMessage == caller1Message1;

                bool receiveMessageOk = versionOk && typeOk && messageOk;


                // ACK message #1.
                Message nodeResponseAppServiceCallee = mbCallee1AppService.CreateApplicationServiceReceiveMessageNotificationResponse(nodeRequestAppServiceCallee);
                await clientCallee1AppService.SendMessageAsync(nodeResponseAppServiceCallee);



                // Send invalid message - over the FIRST connection with token from the SECOND connection.
                await Task.Delay(3000);

                string calleeMessage = "Invalid Message";
                messageBytes = Encoding.UTF8.GetBytes(calleeMessage);
                requestMessageAppServiceCallee = mbCallee1AppService.CreateApplicationServiceSendMessageRequest(calleeToken2, messageBytes);
                await clientCallee1AppService.SendMessageAsync(requestMessageAppServiceCallee);

                Message responseAppServiceCallee = await clientCallee1AppService.ReceiveMessageAsync();

                idOk     = responseAppServiceCallee.Id == requestMessageAppServiceCallee.Id;
                statusOk = responseAppServiceCallee.Response.Status == Status.ErrorNotFound;

                bool sendMessageOk = idOk && statusOk;


                // Step 7 Acceptance
                bool step7Ok = sendMessageOk;

                log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED");


                // Step 8
                log.Trace("Step 8");
                await Task.Delay(3000);

                string caller2Message1 = "Message #1 to callee from caller2.";
                messageBytes = Encoding.UTF8.GetBytes(caller2Message1);
                requestMessageAppServiceCaller = mbCaller2AppService.CreateApplicationServiceSendMessageRequest(callerToken2, messageBytes);

                // Either the third client is disconnected and this should prevent sending a message or receiving a response,
                // OR just the relay was destroyed and the client will receive error not found.
                bool disconnectOk = false;
                messageOk = false;
                try
                {
                    await clientCaller2AppService.SendMessageAsync(requestMessageAppServiceCaller);

                    responseMessage = await clientCaller2AppService.ReceiveMessageAsync();

                    idOk      = responseMessage.Id == requestMessageAppServiceCaller.Id;
                    statusOk  = responseMessage.Response.Status == Status.ErrorNotFound;
                    messageOk = idOk && statusOk;
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectOk = true;
                }

                // Step 8 Acceptance
                bool step8Ok = disconnectOk || messageOk;

                log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED");


                // Step 9
                log.Trace("Step 9");

                // Receive ACK message #1.
                responseMessageAppServiceCaller = await clientCaller1AppService.ReceiveMessageAsync();

                idOk            = responseMessageAppServiceCaller.Id == callerMessage1Id;
                statusOk        = responseMessageAppServiceCaller.Response.Status == Status.Ok;
                receivedVersion = responseMessageAppServiceCaller.Response.SingleResponse.Version.ToByteArray();
                versionOk       = StructuralComparisons.StructuralComparer.Compare(receivedVersion, new byte[] { 1, 0, 0 }) == 0;

                bool receiveAckOk = idOk && statusOk && versionOk;

                // Step 9 Acceptance
                bool step9Ok = receiveAckOk;

                log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED");

                Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            clientCallee.Dispose();
            clientCallee1AppService.Dispose();
            clientCallee2AppService.Dispose();
            clientCaller1.Dispose();
            clientCaller1AppService.Dispose();
            clientCaller2.Dispose();
            clientCaller2AppService.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }