public ModelReplayFileOperationRequest(ModelReplayChannel channel, ReplayModelSwitchChannelType switchChannelType, ModelDialectRevision maxSmbVersionClientSupported, ReplayModelRequestCommand requestCommand, ReplayModelChannelSequenceType channelSequence, ReplayModelSetReplayFlag isSetReplayFlag, ReplayModelRequestCommandParameters requestCommandParameters ) : base(0) { this.channel = channel; this.switchChannelType = switchChannelType; this.requestCommand = requestCommand; this.channelSequence = channelSequence; this.isSetReplayFlag = isSetReplayFlag; this.requestCommandParameters = requestCommandParameters; }
public void FileOperationRequest( ReplayModelSwitchChannelType switchChannelType, ModelDialectRevision maxSmbVersionClientSupported, ReplayModelRequestCommand requestCommand, ReplayModelChannelSequenceType channelSequence, ReplayModelSetReplayFlag isReplay, ReplayModelRequestCommandParameters requestCommandParameters) { if (requestCommand == ReplayModelRequestCommand.IoCtl) { testConfig.CheckIOCTL(CtlCode_Values.FSCTL_LMR_REQUEST_RESILIENCY); } uint status = Smb2Status.STATUS_SUCCESS; Smb2FunctionalClient client = null; #region Switch channel switch (switchChannelType) { case ReplayModelSwitchChannelType.MainChannel: if (smb2ClientMainChannel == null) { InitializeMainChannel( maxSmbVersionClientSupported, clientGuidMainChannel, ReplayModelShareType.NonCAShare, out treeIdMainChannel); #region Create Smb2CreateContextResponse[] serverCreateContexts = null; status = smb2ClientMainChannel.Create( treeIdMainChannel, fileNameMainChannel, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileIdMainChannel, out serverCreateContexts, RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE, null, shareAccess: ShareAccess_Values.NONE); #endregion } client = smb2ClientMainChannel; break; case ReplayModelSwitchChannelType.AlternativeChannelWithMainChannel: InitializeAlternativeChannel( clientGuidMainChannel, treeIdMainChannel); client = smb2ClientAlternativeChannel; break; case ReplayModelSwitchChannelType.AlternativeChannelWithDisconnectMainChannel: InitializeAlternativeChannel( clientGuidMainChannel, treeIdMainChannel); smb2ClientMainChannel.Disconnect(); smb2ClientMainChannel = null; client = smb2ClientAlternativeChannel; break; case ReplayModelSwitchChannelType.MainChannelWithAlternativeChannel: InitializeAlternativeChannel( clientGuidMainChannel, treeIdMainChannel); client = smb2ClientMainChannel; break; default: Site.Assume.Fail("Unknown ReplayModelSwitchChannelType {0}.", switchChannelType); break; } #endregion #region Prepare data for read if (switchChannelType == ReplayModelSwitchChannelType.MainChannel && !prepared && requestCommand == ReplayModelRequestCommand.Read) { status = smb2ClientMainChannel.Write( treeIdMainChannel, fileIdMainChannel, writeContent); } #endregion FillChannelSequence(client, channelSequence); if (requestCommand == ReplayModelRequestCommand.Write) { #region Write status = client.Write( treeIdMainChannel, fileIdMainChannel, requestCommandParameters == ReplayModelRequestCommandParameters.DefaultParameters ? writeContent : Smb2Utility.CreateRandomString(testConfig.WriteBufferLengthInKb), checker: (header, response) => { }, isReplay: isReplay == ReplayModelSetReplayFlag.WithReplayFlag); #endregion } else if (requestCommand == ReplayModelRequestCommand.SetInfo) { #region SetInfo if (requestCommandParameters == ReplayModelRequestCommandParameters.AlternativeParameters) { endOfFileInformation.EndOfFile = 512; } byte[] buffer = TypeMarshal.ToBytes <FileEndOfFileInformation>(endOfFileInformation); status = client.SetFileAttributes( treeIdMainChannel, (byte)FileInformationClasses.FileEndOfFileInformation, fileIdMainChannel, buffer, checker: (header, response) => { }, isReplay: isReplay == ReplayModelSetReplayFlag.WithReplayFlag); #endregion } else if (requestCommand == ReplayModelRequestCommand.IoCtl) { #region IOCtl Packet_Header ioCtlHeader; IOCTL_Response ioCtlResponse; byte[] inputInResponse; byte[] outputInResponse; status = client.ResiliencyRequest( treeIdMainChannel, fileIdMainChannel, (uint)(requestCommandParameters == ReplayModelRequestCommandParameters.DefaultParameters ? 0 : 2000), (uint)Marshal.SizeOf(typeof(NETWORK_RESILIENCY_Request)), out ioCtlHeader, out ioCtlResponse, out inputInResponse, out outputInResponse, checker: (header, response) => { // do nothing, skip the exception } ); #endregion } else if (requestCommand == ReplayModelRequestCommand.Read) { #region Read string data; status = client.Read( treeIdMainChannel, fileIdMainChannel, 0, requestCommandParameters == ReplayModelRequestCommandParameters.DefaultParameters ? (uint)testConfig.WriteBufferLengthInKb * 1024 : 512, out data, isReplay: isReplay == ReplayModelSetReplayFlag.WithReplayFlag); #endregion } FileOperationResponse((ModelSmb2Status)status, replayConfig); }
public static void FileOperationRequest( ReplayModelSwitchChannelType switchChannelType, ModelDialectRevision maxSmbVersionClientSupported, ReplayModelRequestCommand requestCommand, ReplayModelChannelSequenceType channelSequence, ReplayModelSetReplayFlag isSetReplayFlag, ReplayModelRequestCommandParameters requestCommandParameters) { Condition.IsNull(Request); Condition.IfThen(ModelRequestCommand != ReplayModelRequestCommand.NoRequest, ModelRequestCommand == requestCommand); Condition.IsTrue(requestCommand != ReplayModelRequestCommand.Create && requestCommand != ReplayModelRequestCommand.NoRequest); Condition.IsTrue(switchChannelType != ReplayModelSwitchChannelType.ReconnectMainChannel); Combination.NWise(2, switchChannelType, maxSmbVersionClientSupported, requestCommand, channelSequence, isSetReplayFlag, requestCommandParameters); ModelReplayChannel channel = null; if (State == ModelState.Initialized) { Condition.IsTrue(switchChannelType == ReplayModelSwitchChannelType.MainChannel); Condition.IsTrue(requestCommandParameters == ReplayModelRequestCommandParameters.DefaultParameters); MainChannel = new ModelReplayChannel(ModelHelper.DetermineNegotiateDialect(maxSmbVersionClientSupported, Config.MaxSmbVersionSupported)); Open = new ReplayOpen(); channel = MainChannel; } else { Condition.IsNotNull(MainChannel); Condition.IsNotNull(Open); Condition.IsTrue(maxSmbVersionClientSupported == ModelUtility.GetModelDialectRevision(MainChannel.Connection_NegotiateDialect)); if (switchChannelType == ReplayModelSwitchChannelType.MainChannel) { channel = MainChannel; } else { AlternativeChannel = new ModelReplayChannel(MainChannel.Connection_NegotiateDialect); channel = AlternativeChannel; } } ModelReplayFileOperationRequest operationRequest = new ModelReplayFileOperationRequest(channel, switchChannelType, maxSmbVersionClientSupported, requestCommand, channelSequence, isSetReplayFlag, requestCommandParameters); Request = operationRequest; State = ModelState.Connected; }
public void FileOperationRequest( ReplayModelSwitchChannelType switchChannelType, ModelDialectRevision maxSmbVersionClientSupported, ReplayModelRequestCommand requestCommand, ReplayModelChannelSequenceType channelSequence, ReplayModelSetReplayFlag isReplay, ReplayModelRequestCommandParameters requestCommandParameters) { if (requestCommand == ReplayModelRequestCommand.IoCtl) { testConfig.CheckIOCTL(CtlCode_Values.FSCTL_LMR_REQUEST_RESILIENCY); } uint status = Smb2Status.STATUS_SUCCESS; Smb2FunctionalClient client = null; #region Switch channel switch (switchChannelType) { case ReplayModelSwitchChannelType.MainChannel: if (smb2ClientMainChannel == null) { InitializeMainChannel( maxSmbVersionClientSupported, clientGuidMainChannel, ReplayModelShareType.NonCAShare, out treeIdMainChannel); #region Create Smb2CreateContextResponse[] serverCreateContexts = null; status = smb2ClientMainChannel.Create( treeIdMainChannel, fileNameMainChannel, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileIdMainChannel, out serverCreateContexts, RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE, null, shareAccess: ShareAccess_Values.NONE); #endregion } client = smb2ClientMainChannel; break; case ReplayModelSwitchChannelType.AlternativeChannelWithMainChannel: InitializeAlternativeChannel( clientGuidMainChannel, treeIdMainChannel); client = smb2ClientAlternativeChannel; break; case ReplayModelSwitchChannelType.AlternativeChannelWithDisconnectMainChannel: InitializeAlternativeChannel( clientGuidMainChannel, treeIdMainChannel); smb2ClientMainChannel.Disconnect(); smb2ClientMainChannel = null; client = smb2ClientAlternativeChannel; break; case ReplayModelSwitchChannelType.MainChannelWithAlternativeChannel: InitializeAlternativeChannel( clientGuidMainChannel, treeIdMainChannel); client = smb2ClientMainChannel; break; default: Site.Assume.Fail("Unknown ReplayModelSwitchChannelType {0}.", switchChannelType); break; } #endregion #region Prepare data for read if (switchChannelType == ReplayModelSwitchChannelType.MainChannel && !prepared && requestCommand == ReplayModelRequestCommand.Read) { status = smb2ClientMainChannel.Write( treeIdMainChannel, fileIdMainChannel, writeContent); } #endregion FillChannelSequence(client, channelSequence); if (requestCommand == ReplayModelRequestCommand.Write) { #region Write status = client.Write( treeIdMainChannel, fileIdMainChannel, requestCommandParameters == ReplayModelRequestCommandParameters.DefaultParameters ? writeContent : Smb2Utility.CreateRandomString(testConfig.WriteBufferLengthInKb), checker: (header, response) => { }, isReplay: isReplay == ReplayModelSetReplayFlag.WithReplayFlag); #endregion } else if (requestCommand == ReplayModelRequestCommand.SetInfo) { #region SetInfo if (requestCommandParameters == ReplayModelRequestCommandParameters.AlternativeParameters) { endOfFileInformation.EndOfFile = 512; } byte[] buffer = TypeMarshal.ToBytes<FileEndOfFileInformation>(endOfFileInformation); status = client.SetFileAttributes( treeIdMainChannel, (byte)FileInformationClasses.FileEndOfFileInformation, fileIdMainChannel, buffer, checker: (header, response) => { }, isReplay: isReplay == ReplayModelSetReplayFlag.WithReplayFlag); #endregion } else if (requestCommand == ReplayModelRequestCommand.IoCtl) { #region IOCtl Packet_Header ioCtlHeader; IOCTL_Response ioCtlResponse; byte[] inputInResponse; byte[] outputInResponse; status = client.ResiliencyRequest( treeIdMainChannel, fileIdMainChannel, (uint)(requestCommandParameters == ReplayModelRequestCommandParameters.DefaultParameters ? 0 : 2000), (uint)Marshal.SizeOf(typeof(NETWORK_RESILIENCY_Request)), out ioCtlHeader, out ioCtlResponse, out inputInResponse, out outputInResponse, checker: (header, response) => { // do nothing, skip the exception } ); #endregion } else if (requestCommand == ReplayModelRequestCommand.Read) { #region Read string data; status = client.Read( treeIdMainChannel, fileIdMainChannel, 0, requestCommandParameters == ReplayModelRequestCommandParameters.DefaultParameters ? (uint)testConfig.WriteBufferLengthInKb * 1024 : 512, out data, isReplay: isReplay == ReplayModelSetReplayFlag.WithReplayFlag); #endregion } FileOperationResponse((ModelSmb2Status)status, replayConfig); }