/// <summary> /// Initialize protocol adapter. /// </summary> /// <param name="testSite">The test site instance associated with the current adapter.</param> public override void Initialize(ITestSite testSite) { base.Initialize(ReqConfigurableSite.GetReqConfigurableSite(testSite)); // The protocol name. Site.DefaultProtocolDocShortName = "MS-PCHC"; PchcBothRoleCaptureCode.Initialize(testSite); this.InitializePchcClient(testSite); }
/// <summary> /// Initialize protocol adapter. /// </summary> /// <param name="testSite">The test site.</param> public override void Initialize(ITestSite testSite) { base.Initialize(ReqConfigurableSite.GetReqConfigurableSite(testSite)); Site.DefaultProtocolDocShortName = "MS-PCHC"; PchcBothRoleCaptureCode.Initialize(testSite); this.pchcServer = new PCHCServer( TransferProtocol.HTTPS, int.Parse(this.GetProperty("PCHC.Protocol.NewPort")), IPAddressType.IPv4, new Logger(testSite)); this.pchcServer.Start(); }
/// <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> /// Receive a SegmentInfoMessage from the Client. /// </summary> /// <param name="timeout">Waiting for specified timeout to receive the specified request.</param> /// <returns>Return the reveived SegmentInfoMessage.</returns> public SegmentInfoMessage ExpectSegmentInfoMessage(TimeSpan timeout) { try { SEGMENT_INFO_MESSAGE segmentInfoMsgStack = this.pchcServer.ExpectSegmentInfoMessage( this.GetProperty("Environment.SecondContentClient.IPAddress"), timeout); this.ValidateSegmentInfoMessage( segmentInfoMsgStack, this.GetProperty("Environment.SecondContentClient.OSVersion")); PchcBothRoleCaptureCode.ValidateTransport(this.pchcServer.HttpRequestUri.Scheme); this.ValidateTransport(this.pchcServer.HttpRequestMethod); SegmentInfoMessage segmentInfoMsg = ClientHelper.ConvertFromStackForSegmentInfoMsg(segmentInfoMsgStack); return(segmentInfoMsg); } catch (NoSEGMENTINFOMESSAGEReceivedException e) { throw new NoSegmentInfoMessageException(e.Message); } }
/// <summary> /// Receive a InitialOfferMessage from the Client. /// </summary> /// <param name="timeout">Waiting for specified timeout to receive the specified request.</param> /// <returns>Return the reveived InitialOfferMessage.</returns> public InitialOfferMessage ExpectInitialOfferMessage(TimeSpan timeout) { try { INITIAL_OFFER_MESSAGE intiailOfferMsgStack = this.pchcServer.ExpectInitialOfferMessage( this.GetProperty("Environment.SecondContentClient.IPAddress"), timeout); this.ValidateInitialOfferMessage(intiailOfferMsgStack); PchcBothRoleCaptureCode.ValidateTransport(this.pchcServer.HttpRequestUri.Scheme); this.ValidateTransport(this.pchcServer.HttpRequestMethod); this.ValidateClientInitialization( this.pchcServer.HttpRequestUri.Host.ToString(), this.pchcServer.HttpRequestUri.Port.ToString(), this.pchcServer.HttpRequestUri.Scheme); InitialOfferMessage intiailOfferMsg = ClientHelper.ConvertFromStackForInitialOfferMsg(intiailOfferMsgStack); return(intiailOfferMsg); } catch (NoINITIALOFFERMESSAGEReceivedException e) { throw new NoInitialOfferMessageException(e.Message); } }