/// <summary> /// This action is used to send SEGMENT_INFO_MESSAGE request to and receive the /// correspondent Response Message from the hosted cache server. /// </summary> /// <param name="paddingInMessageHeader">An array formed by bytes for message header padding</param> /// <param name="pccrrPort">The port on which MS-PCCRR server-role will be listening. </param> /// <param name="paddingInConnectionInformation">An array formed by bytes for connection information padding</param> /// <param name="segmentInformation">The segment information.</param> /// <returns>Return the response message of the SegmentInfoMessage</returns> public ResponseMessage SendSegmentInfoMessage( byte[] paddingInMessageHeader, int pccrrPort, byte[] paddingInConnectionInformation, SegmentInformation segmentInformation) { // Convert the struct segmentInformation in adapter to the format in stack Content_Information_Data_Structure segmentInformationStack = ServerHelper.ConvertTostackForContentInfo(segmentInformation); // Create the SEGMENT_INFO_MESSAGE struct defined in stack for SendSegmentInfoMessage method SEGMENT_INFO_MESSAGE segmentInfoMessage = this.pchcClient.CreateSegmentInfoMessage( pccrrPort, segmentInformationStack); segmentInfoMessage.MsgHeader.Padding = paddingInMessageHeader; segmentInfoMessage.ConnectionInfo.Padding = paddingInConnectionInformation; this.ValidateSegmentInfoMessage(segmentInfoMessage); try { RESPONSE_MESSAGE responseMessageStack = this.pchcClient.SendSegmentInfoMessage(segmentInfoMessage); ResponseMessage responseMessage = ServerHelper.ConvertFromStackForResponseMsg(responseMessageStack); this.ValidateSegmentInfoResponse(responseMessage); return(responseMessage); } catch (NoRESPONSEMESSAGEException) { throw new NoResponseMessageException(); } }
/// <summary> /// Send message MSG_NEGO_REQ /// </summary> public void SendMsgNegoReq() { PccrrNegoRequestPacket packet = this.pccrrStack.CreateMsgNegoRequest(this.minSupV, this.maxSupV, this.cryptoAlgo, MsgType_Values.MSG_NEGO_REQ, this.protoVer); this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout)); PccrrPacket respMSG = this.pccrrStack.ExpectPacket(); PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket; MSG_NEGO_RESP msgNegoResp = pccrrNegoResponsePacket.MsgNegoResp; MESSAGE_HEADER messageHeader = pccrrNegoResponsePacket.MessageHeader; TRANSPORT_RESPONSE_HEADER transportRespH = pccrrNegoResponsePacket.TransportResponseHeader; RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE(); respMessage.MESSAGEBODY = msgNegoResp; respMessage.MESSAGEHEADER = messageHeader; respMessage.TRANSPORTRESPONSEHEADER = transportRespH; this.uiPayload = Marshal.SizeOf(messageHeader) + Marshal.SizeOf(msgNegoResp); this.VerifyHttpResponse(); PccrrBothRoleCaptureCode.CaptureHttpRequirements(); this.VerifyMsgNegoResp(msgNegoResp); this.VerifyMessageHeader(messageHeader); PccrrBothRoleCaptureCode.CaptureMessageHeaderRequirements(messageHeader, this.uiPayload); this.VerifyTransportResponseHeader(transportRespH); PccrrBothRoleCaptureCode.CaptureMessageRequirements(); this.VerifyResponseMessage(respMessage); this.ReceiveMsgNegoResp(); }
/// <summary> /// Convert the responsemessage struct defined in adapter to stack /// </summary> /// <param name="responseMessageStack">The response message of send initialInfoMeaage or segmentInfoMessage</param> /// <returns>Return the ResponseMessage type defined in adapter</returns> public static ResponseMessage ConvertFromStackForResponseMsg(RESPONSE_MESSAGE responseMessageStack) { ResponseMessage responseMessage; responseMessage.ResponseCode = ConvertFromStackForResponseCode(responseMessageStack.ResponseCode); responseMessage.TransportHeader = ConvertFromStackForTransHeader(responseMessageStack.TransportHeader); return(responseMessage); }
/// <summary> /// Send message MSG_GETBLKLIST. /// </summary> /// <param name="sid">segment id.</param> /// <param name="blockRang">Block ranges client wants to get.</param> /// <param name="isVersionSupported">The version in message is supported by server or not.</param> public void SendMsgGetBlkList(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported) { PccrrGETBLKLISTRequestPacket packet; BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang); if (!isVersionSupported) { packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoErrorVer); } else { packet = this.pccrrStack.CreateMsgGetBlkListRequest(sid, blockRanges, this.cryptoAlgo, MsgType_Values.MSG_GETBLKLIST, this.protoVer); } this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout)); PccrrPacket respMSG = this.pccrrStack.ExpectPacket(); if (!isVersionSupported) { PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket; if (pccrrNegoResponsePacket != null) { this.ReceiveMsgNegoResp(); } } else { PccrrBLKLISTResponsePacket pccrrBLKLISTResponsePacket = respMSG as PccrrBLKLISTResponsePacket; MSG_BLKLIST msgBLKLIST = pccrrBLKLISTResponsePacket.MsgBLKLIST; MESSAGE_HEADER messageHeader = pccrrBLKLISTResponsePacket.MessageHeader; TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKLISTResponsePacket.TransportResponseHeader; RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE(); respMessage.MESSAGEBODY = msgBLKLIST; respMessage.MESSAGEHEADER = messageHeader; respMessage.TRANSPORTRESPONSEHEADER = transportRespH; if (msgBLKLIST.BlockRanges.Length != 0) { BLOCK_RANGE blockRange = pccrrBLKLISTResponsePacket.MsgBLKLIST.BlockRanges[0]; PccrrBothRoleCaptureCode.CaptureBlockRangeRequirements(blockRange); } this.VerifyMsgBlkList(msgBLKLIST); PccrrBothRoleCaptureCode.CaptureCommonDataTypesRequirements(msgBLKLIST); this.VerifyResponseMessage(respMessage); BLOCKRANGE[] blkRanges = Helper.ConvertFromStackBLOCKRANGEArray(msgBLKLIST.BlockRanges); this.ReceiveMsgBlkList(msgBLKLIST.BlockRangeCount, blkRanges, msgBLKLIST.NextBlockIndex); } }
/// <summary> /// This action is used to send INITIAL_OFFER_MESSAGE request to and receive the /// correspondent Response Message from the hosted cache server. /// </summary> /// <param name="paddingInMessageHeader">An array formed by bytes for message header padding</param> /// <param name="pccrrPort"> /// The port on which MS-PCCRR server-role will be listening if the hosted cache server initiates the /// Peer Content Caching and Retrieval: Retrieval Protocol (PCCRR) framework [MS-PCCRR] as a client-role peer to /// retrieve the missing blocks from the test suite. /// </param> /// <param name="paddingInConnectionInformation">An array formed by bytes for connection information padding</param> /// <param name="hash">Include segment id</param> /// <returns>Return the response message of the InitialOfferMessage</returns> public ResponseMessage SendInitialOfferMessage( byte[] paddingInMessageHeader, int pccrrPort, byte[] paddingInConnectionInformation, byte[] hash) { // Create the INITIAL_OFFER_MESSAGE struct defined in stack for SendInitialOfferMessage method INITIAL_OFFER_MESSAGE initialOfferMessageStack = this.pchcClient.CreateInitialOfferMessage( pccrrPort, hash); initialOfferMessageStack.MsgHeader.Padding = paddingInMessageHeader; initialOfferMessageStack.ConnectionInfo.Padding = paddingInConnectionInformation; try { RESPONSE_MESSAGE responseMessageStack = this.pchcClient.SendInitialOfferMessage(initialOfferMessageStack); if (responseMessageStack.ResponseCode == RESPONSE_CODE.INTERESTED || responseMessageStack.ResponseCode == RESPONSE_CODE.OK) { this.contentUri = this.transportType.ToString().ToLower() + "://" + this.hostedCacheMachineName + ":" + this.httpsListenPort + "/" + PCHCRESOURCE; PchcBothRoleCaptureCode.ValidateTransport(this.transportType.ToString()); this.ValidateTransport(this.pchcClient.HTTPMethod, this.contentUri); this.ValidateServerInitialization(this.httpsListenPort); } // Convert the RESPONSE_MESSAGE to the ResponseMessage struct defined in adapter ResponseMessage responseMessage = ServerHelper.ConvertFromStackForResponseMsg(responseMessageStack); this.ValidateInitialOfferMessageResponse(responseMessage); return(responseMessage); } catch (HttpStatusCode401Exception e) { throw new HttpUnauthenticationException(e.Message); } catch (NoRESPONSEMESSAGEException) { throw new NoResponseMessageException(); } }
/// <summary> /// Capture RESPONSE_MESSAGE structure related requirements. /// </summary> /// <param name="responseMessage">RESPONSE_MESSAGE object</param> private void VerifyResponseMessage(RESPONSE_MESSAGE responseMessage) { // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R127"); // Verify MS-PCCRR requirement: MS-PCCRR_R127 Site.CaptureRequirementIfAreEqual <int>( 4, Marshal.SizeOf(responseMessage.TRANSPORTRESPONSEHEADER), 127, @"[In Response Message]TRANSPORT_RESPONSE_HEADER (4 bytes): Transport response header."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R128"); // Verify MS-PCCRR requirement: MS-PCCRR_R128 Site.CaptureRequirementIfAreEqual <int>( 16, Marshal.SizeOf(responseMessage.MESSAGEHEADER), 128, @"[In Response Message]MESSAGE_HEADER (16 bytes): Message header."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-PCCRR_R129"); // Verify MS-PCCRR requirement: MS-PCCRR_R129 bool isVerifyR129 = responseMessage.MESSAGEBODY is MSG_BLKLIST || responseMessage.MESSAGEBODY is MSG_BLK || responseMessage.MESSAGEBODY is MSG_NEGO_RESP; Site.CaptureRequirementIfIsTrue( isVerifyR129, 129, @"[In Response Message]MESSAGE_BODY (variable): Message body, which may contain either a MSG_BLKLIST or a MSG_BLK message."); // MS-PCCRR_R127,MS-PCCRR_R128 and MS-PCCRR_R129 have been verified it successfully, so capture it directly. Site.CaptureRequirement( 126, @"[In Response Message]The complete layout of a response-type Peer Content Caching and Retrieval: Retrieval Protocol message is as follows[TRANSPORT_RESPONSE_HEADER,MESSAGE_HEADER,MESSAGE_BODY (variable)]."); }
/// <summary> /// Send message MSG_GETBLKS /// </summary> /// <param name="sid">segment id.</param> /// <param name="blockRang">Block ranges client wants to get</param> /// <param name="isVersionSupported">The version in this message is supported in server.</param> public void SendMsgGetBlks(byte[] sid, BLOCKRANGE[] blockRang, bool isVersionSupported) { PccrrGETBLKSRequestPacket packet; BLOCK_RANGE[] blockRanges = Helper.ConvertToStackBLOCKRANGEArray(blockRang); if (!isVersionSupported) { packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoErrorVer); } else { packet = this.pccrrStack.CreateMsgGetBlksRequest(sid, this.cryptoAlgo, MsgType_Values.MSG_GETBLKS, this.protoVer); } for (int i = 0; i < blockRanges.Length; i++) { if (blockRanges.Length == 1) { packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index; packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count; } else { MSG_GETBLKS msgGETBLKS = packet.MsgGetBLKS; msgGETBLKS.ReqBlockRanges = new BLOCK_RANGE[blockRanges.Length]; msgGETBLKS.ReqBlockRangeCount = (uint)blockRanges.Length; packet.MsgGetBLKS = msgGETBLKS; packet.MsgGetBLKS.ReqBlockRanges[i].Index = blockRanges[i].Index; packet.MsgGetBLKS.ReqBlockRanges[i].Count = blockRanges[i].Count; } } this.pccrrStack.SendPacket(packet, new TimeSpan(0, 0, this.timeout)); PccrrPacket respMSG = this.pccrrStack.ExpectPacket(); if (!isVersionSupported) { PccrrNegoResponsePacket pccrrNegoResponsePacket = respMSG as PccrrNegoResponsePacket; if (pccrrNegoResponsePacket != null) { this.ReceiveMsgNegoResp(); } } else { PccrrBLKResponsePacket pccrrBLKResponsePacket = respMSG as PccrrBLKResponsePacket; MSG_BLK msgBLK = pccrrBLKResponsePacket.MsgBLK; MESSAGE_HEADER messageHeader = pccrrBLKResponsePacket.MessageHeader; TRANSPORT_RESPONSE_HEADER transportRespH = pccrrBLKResponsePacket.TransportResponseHeader; RESPONSE_MESSAGE respMessage = new RESPONSE_MESSAGE(); respMessage.MESSAGEBODY = msgBLK; respMessage.MESSAGEHEADER = messageHeader; respMessage.TRANSPORTRESPONSEHEADER = transportRespH; this.VerifyMsgBlk(msgBLK); PccrrBothRoleCaptureCode.CaptureSegmentIdRequirements(msgBLK.SegmentId); this.VerifyResponseMessage(respMessage); bool isSizeOfBlockZero = false; if (msgBLK.SizeOfBlock == 0) { isSizeOfBlockZero = true; } else { isSizeOfBlockZero = false; } bool isBlockEmpty = false; if (msgBLK.Block.Length == 0) { isBlockEmpty = true; } else { isBlockEmpty = false; } CryptoAlgoIdValues crypAlgoId = Helper.ConvertFromStackCryptoAlgoIdValues(pccrrBLKResponsePacket.MessageHeader.CryptoAlgoId); this.ReceiveMsgBlk(msgBLK.BlockIndex, msgBLK.NextBlockIndex, isSizeOfBlockZero, isBlockEmpty, crypAlgoId); } }