コード例 #1
0
        /// <summary>
        /// Reset the adapter
        /// </summary>
        public override void Reset()
        {
            base.Reset();

            this.isReceived     = false;
            this.pccrtpResponse = null;
            if (this.pccrrServer != null)
            {
                this.pccrrServer.CloseConnections();
                this.pccrrServer = null;
            }
        }
コード例 #2
0
        public void HostedCacheServer_PchcServer_BatchedOffer_SegmentDescriptorTooMany()
        {
            CheckApplicability();

            var contentInformation = contentInformationUtility.CreateContentInformationV2();

            using (var pccrrServer = new PccrrServer(testConfig.ClientContentRetrievalListenPort))
            {
                pccrrServer.StartListening();

                pccrrServer.MessageArrived += new MessageArrivedEventArgs(delegate(IPEndPoint sender, PccrrPacket pccrrPacket)
                {
                    BaseTestSite.Assert.Fail("Hosted cache server should not retrieve content information with more than 128 segment descriptions");
                });

                PCHCClient pchcClient = new PCHCClient(
                    TransferProtocol.HTTP,
                    testConfig.HostedCacheServerComputerName,
                    testConfig.HostedCacheServerHTTPListenPort,
                    PchcConsts.HttpUrl,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword);

                var batchedOffer = pchcClient.CreateBatchedOfferMessage(
                    testConfig.ClientContentRetrievalListenPort,
                    contentInformation);

                List <SegmentDescriptor> segmentDescriptors = new List <SegmentDescriptor>();
                for (int i = 0; i < 129; i++)
                {
                    segmentDescriptors.Add(batchedOffer.SegmentDescriptors[0]);
                }
                batchedOffer.SegmentDescriptors = segmentDescriptors.ToArray();

                bool passed = false;
                try
                {
                    pchcClient.SendBatchedOfferMessage(batchedOffer);
                }
                catch
                {
                    passed = true;
                }

                BaseTestSite.Assert.IsTrue(passed, "Hosted cache server should drop invalid batched offer request");
            }
        }
コード例 #3
0
        public void Start(int port, CryptoAlgoId_Values cryptoAlgoId, byte[] content, EventQueue eventQueue)
        {
            this.cryptoAlgoId = cryptoAlgoId;
            this.content      = content;
            this.eventQueue   = eventQueue;
            this.aes          = PccrrUtitlity.CreateAes(cryptoAlgoId);
            this.iv           = new byte[16];
            for (int i = 0; i < iv.Length; i++)
            {
                this.iv[i] = (byte)i;
            }

            pccrrServer = new PccrrServer(port);

            pccrrServer.MessageArrived += new MessageArrivedEventArgs(pccrrServer_MessageArrived);

            pccrrServer.StartListening();
        }
コード例 #4
0
        /// <summary>
        /// Initialize adapter data and create connection.
        /// </summary>
        /// <param name="testSite">the test site</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(ReqConfigurableSite.GetReqConfigurableSite(testSite));
            this.Site.DefaultProtocolDocShortName = "MS-PCCRR";
            this.isDistributedMode = bool.Parse(this.GetProperty("Environment.IsDistributedMode"));

            if (!this.isDistributedMode)
            {
                this.isWindows = string.Equals(
                    testSite.Properties["Environment.SecondContentClient.OSVersion"],
                    "win2k8r2",
                    StringComparison.OrdinalIgnoreCase);
            }
            else
            {
                this.isWindows = string.Equals(
                    testSite.Properties["Environment.DistributedSUT.OSVersion"],
                    "win2k8r2",
                    StringComparison.OrdinalIgnoreCase);
            }

            this.cryptoAlgo = (CryptoAlgoId_Values)Enum.Parse(typeof(CryptoAlgoId_Values), this.GetProperty("PCCRR.Protocol.CryptoAlgoId_Value"));
            this.port       = int.Parse(this.GetProperty("PCCRR.Protocol.HttpPort"));
            PccrrBothRoleCaptureCode.Initialize(this.Site);

            this.minSupV.MinorVersion       = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MinSupportedProtocolVersion.MinorVer"));
            this.minSupV.MajorVersion       = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MinSupportedProtocolVersion.MajorVer"));
            this.maxSupV.MinorVersion       = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MinorVer"));
            this.maxSupV.MajorVersion       = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer"));
            this.minErrorSupV.MinorVersion  = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.Error.MinSupportedProtocolVersion"));
            this.minErrorSupV.MajorVersion  = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer"));
            this.maxErrorSupV.MinorVersion  = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.Error.MaxSupportedProtocolVersion"));
            this.maxErrorSupV.MajorVersion  = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer"));
            this.protoVer.MinorVersion      = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MinorVer"));
            this.protoVer.MajorVersion      = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.MinSupportedProtocolVersion.MajorVer"));
            this.protoErrorVer.MinorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_REQ.ErrorProtocolVersion"));
            this.protoErrorVer.MajorVersion = ushort.Parse(this.GetProperty("PCCRR.Protocol.MSG_NEGO_RESP.MaxSupportedProtocolVersion.MajorVer"));

            this.pccrrStackSer = new PccrrServer(this.port, string.Empty, IPAddressType.IPv4);
            this.pccrrStackSer.MessageArrived += new MessageArrivedEventArgs(this.RetrievalTransport_Receive);

            this.pccrrStackSer.StartListening();
        }
コード例 #5
0
        public void HostedCacheServer_PchcServer_SegmentInfo_SegmentsMultiple()
        {
            CheckApplicability();

            var contentInformation = contentInformationUtility.CreateContentInformationV1();

            using (var pccrrServer = new PccrrServer(testConfig.ClientContentRetrievalListenPort))
            {
                pccrrServer.StartListening();

                pccrrServer.MessageArrived += new MessageArrivedEventArgs(delegate(IPEndPoint sender, PccrrPacket pccrrPacket)
                {
                    BaseTestSite.Assert.Fail("Hosted cache server should not retrieve content information with multiple segments");
                });

                PCHCClient pchcClient = new PCHCClient(
                    TransferProtocol.HTTPS,
                    testConfig.HostedCacheServerComputerName,
                    testConfig.HostedCacheServerHTTPSListenPort,
                    PchcConsts.HttpsUrl,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword);

                var segmentInfo = pchcClient.CreateSegmentInfoMessage(
                    testConfig.ClientContentRetrievalListenPort,
                    contentInformation,
                    0);

                segmentInfo.SegmentInfo.cSegments = 2;
                segmentInfo.SegmentInfo.segments  = segmentInfo.SegmentInfo.segments.Concat(segmentInfo.SegmentInfo.segments).ToArray();

                var segmentInfoResponse = pchcClient.SendSegmentInfoMessage(segmentInfo);

                BaseTestSite.Assert.AreEqual(
                    RESPONSE_CODE.OK,
                    segmentInfoResponse.ResponseCode,
                    "Hosted cache server should return OK to segment info message");

                Thread.Sleep(testConfig.NegativeTestTimeout);
            }
        }
コード例 #6
0
        public void HostedCacheServer_PchcServer_BatchedOffer_HashAlgoInvalid()
        {
            CheckApplicability();

            var contentInformation = contentInformationUtility.CreateContentInformationV2();

            using (var pccrrServer = new PccrrServer(testConfig.ClientContentRetrievalListenPort))
            {
                pccrrServer.StartListening();

                pccrrServer.MessageArrived += new MessageArrivedEventArgs(delegate(IPEndPoint sender, PccrrPacket pccrrPacket)
                {
                    BaseTestSite.Assert.Fail("Hosted cache server should not retrieve content information with more than 128 segment descriptions");
                });

                PCHCClient pchcClient = new PCHCClient(
                    TransferProtocol.HTTP,
                    testConfig.HostedCacheServerComputerName,
                    testConfig.HostedCacheServerHTTPListenPort,
                    PchcConsts.HttpUrl,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword);

                var batchedOffer = pchcClient.CreateBatchedOfferMessage(
                    testConfig.ClientContentRetrievalListenPort,
                    contentInformation);

                batchedOffer.SegmentDescriptors[0].HashAlgorithm = 0xFE;

                var batchedOfferResponse = pchcClient.SendBatchedOfferMessage(batchedOffer);

                BaseTestSite.Assert.AreEqual(
                    RESPONSE_CODE.OK,
                    batchedOfferResponse.ResponseCode,
                    "Hosted cache server should return OK to batched offer message");

                Thread.Sleep(testConfig.NegativeTestTimeout);
            }
        }
コード例 #7
0
        /// <summary>
        /// Start the MS-PCCRR server listening to incoming MS-PCCRR request message.
        /// </summary>
        /// <param name="port">The listening port.</param>
        public void StartPccrrServerListening(int port)
        {
            try
            {
                this.pccrrServer =
                    new PccrrServer(
                        port,
                        string.Empty,
                        IPAddressType.IPv4);
                this.pccrrServer.MessageArrived
                    += new Microsoft.Protocols.TestTools.StackSdk.BranchCache.Pccrr.MessageArrivedEventArgs(
                           this.RetrievalTransport_Receive);

                this.pccrrServer.StartListening();
            }
            catch (ThreadStateException e)
            {
                Site.Log.Add(
                    LogEntryKind.Debug,
                    "Can't start pccrr server listening. Detailed information: {0}",
                    e.Message);
                throw;
            }
        }
コード例 #8
0
        public void HostedCacheServer_PchcServer_GetBlocks_SizeOfBlockNotMatch()
        {
            CheckApplicability();

            var contentInformation = contentInformationUtility.CreateContentInformationV1();

            using (var pccrrServer = new PccrrServer(testConfig.ClientContentRetrievalListenPort))
            {
                bool blockRetrieved = false;
                pccrrServer.MessageArrived += new MessageArrivedEventArgs(delegate(IPEndPoint sender, PccrrPacket pccrrPacket)
                {
                    var pccrrGetBlkRequest = (PccrrGETBLKSRequestPacket)pccrrPacket;

                    if (pccrrGetBlkRequest != null)
                    {
                        BaseTestSite.Log.Add(
                            LogEntryKind.Debug,
                            "PCCRR GetBlks request received from hosted cache server. Send malformed Blks response");

                        var pccrrBlocksResponse = pccrrServer.CreateMsgBlkResponse(
                            pccrrGetBlkRequest.MsgGetBLKS.SegmentID,
                            TestUtility.GenerateRandomArray(ContentInformationUtility.DefaultBlockSize),
                            CryptoAlgoId_Values.AES_128,
                            MsgType_Values.MSG_BLK,
                            TestUtility.GenerateRandomArray(16),
                            0,
                            0);
                        var blk                    = pccrrBlocksResponse.MsgBLK;
                        blk.SizeOfBlock            = 0;
                        pccrrBlocksResponse.MsgBLK = blk;
                        pccrrServer.SendPacket(pccrrBlocksResponse);

                        blockRetrieved = true;
                    }
                });
                pccrrServer.StartListening();

                PCHCClient pchcClient = new PCHCClient(
                    TransferProtocol.HTTPS,
                    testConfig.HostedCacheServerComputerName,
                    testConfig.HostedCacheServerHTTPSListenPort,
                    PchcConsts.HttpsUrl,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword);

                BaseTestSite.Log.Add(
                    LogEntryKind.Debug,
                    "Offer block to hosted cache server");

                SEGMENT_INFO_MESSAGE segmentInfoMessage = pchcClient.CreateSegmentInfoMessage(
                    testConfig.ClientContentRetrievalListenPort,
                    contentInformation,
                    0);
                pchcClient.SendSegmentInfoMessage(segmentInfoMessage);

                TestUtility.DoUntilSucceed(() =>
                {
                    return(blockRetrieved);
                }, testConfig.Timeout, testConfig.RetryInterval);
            }

            BaseTestSite.Log.Add(
                LogEntryKind.Debug,
                "Try to retrieve the block from hosted cache server");

            PccrrClient pccrrClient = new PccrrClient(
                testConfig.HostedCacheServerComputerName,
                testConfig.HostedCacheServerHTTPListenPort);

            PccrrGETBLKSRequestPacket pccrrBlkRequest = pccrrClient.CreateMsgGetBlksRequest(
                contentInformation.GetSegmentId(0),
                CryptoAlgoId_Values.AES_128,
                MsgType_Values.MSG_GETBLKS,
                0,
                1);

            pccrrClient.SendPacket(
                pccrrBlkRequest,
                testConfig.Timeout);
            PccrrBLKResponsePacket pccrrBlkResponse
                = (PccrrBLKResponsePacket)pccrrClient.ExpectPacket();

            BaseTestSite.Assert.AreEqual <uint>(
                0,
                pccrrBlkResponse.MsgBLK.SizeOfBlock,
                "The server MUST set the SizeOfBlock field to zero if blocks data is not available.");
        }