Browse Source

iSCSI default parameters have been moved to a separate class

Tal Aloni 8 years ago
parent
commit
c8bb23e40d

+ 1 - 5
ISCSI/ISCSI.Client/ConnectionParameters.cs

@@ -12,10 +12,6 @@ namespace ISCSI.Client
 {
     public class ConnectionParameters
     {
-        /// <summary>
-        /// The default MaxRecvDataSegmentLength is used during Login
-        /// </summary>
-        public const int DefaultMaxRecvDataSegmentLength = 8192;
         public static int DeclaredMaxRecvDataSegmentLength = 262144;
 
         public ushort CID; // connection ID, generated by the initiator
@@ -25,7 +21,7 @@ namespace ISCSI.Client
         /// maximum data segment length that the target (or initator) can receive in a single iSCSI PDU.
         /// </summary>
         public int InitiatorMaxRecvDataSegmentLength = DeclaredMaxRecvDataSegmentLength;
-        public int TargetMaxRecvDataSegmentLength = DefaultMaxRecvDataSegmentLength;
+        public int TargetMaxRecvDataSegmentLength = DefaultParameters.Connection.MaxRecvDataSegmentLength;
 
         public bool StatusNumberingStarted;
         public uint ExpStatSN;

+ 71 - 0
ISCSI/ISCSI.Client/DefaultParameters.cs

@@ -0,0 +1,71 @@
+/* Copyright (C) 2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+
+namespace ISCSI.Client
+{
+    /// <summary>
+    /// Default operational parameters for iSCSI session / connection, as specified in RFC 3720.
+    /// </summary>
+    public class DefaultParameters
+    {
+        public class Session
+        {
+            /// <summary>
+            /// The maximum number of connections per session.
+            /// </summary>
+            public const int MaxConnections = 1;
+
+            /// <summary>
+            /// Allow the initiator to start sending data to a target as if it has received an initial R2T
+            /// </summary>
+            public const bool InitialR2T = true;
+
+            public const bool ImmediateData = true;
+
+            /// <summary>
+            /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed MaxBurstLength.
+            /// Maximum SCSI data payload in bytes in a Data-In or a solicited Data-Out iSCSI sequence (i.e. that belongs to a single command).
+            /// Irrelevant to the target in general, the initiator instructs us using ExpectedDataTransferLength.
+            /// </summary>
+            public const int MaxBurstLength = 262144;
+
+            /// <summary>
+            /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed FirstBurstLength for unsolicited data.
+            /// Maximum amount in bytes of unsolicited [SCSI] data an iSCSI initiator may send to the target during the execution of a single SCSI command.
+            /// Irrelevant to the target in general, irrelevant when (InitialR2T = Yes and) ImmediateData = No.
+            /// </summary>
+            public const int FirstBurstLength = 65536;
+
+            /// <summary>
+            /// minimum time, in seconds, to wait before attempting an explicit/implicit logout after connection termination / reset.
+            /// </summary>
+            public const int DefaultTime2Wait = 2;
+
+            /// <summary>
+            /// maximum time, in seconds after an initial wait (Time2Wait), before which an active task reassignment
+            /// is still possible after an unexpected connection termination or a connection reset.
+            /// </summary>
+            public const int DefaultTime2Retain = 20;
+
+            public const int MaxOutstandingR2T = 1;
+
+            public const bool DataPDUInOrder = true;
+
+            public const bool DataSequenceInOrder = true;
+
+            public const int ErrorRecoveryLevel = 0;
+        }
+
+        public class Connection
+        {
+            /// <summary>
+            /// The default MaxRecvDataSegmentLength is used during Login
+            /// </summary>
+            public const int MaxRecvDataSegmentLength = 8192;
+        }
+    }
+}

+ 2 - 2
ISCSI/ISCSI.Client/ISCSIClient.cs

@@ -22,8 +22,8 @@ namespace ISCSI.Client
         // Offered Session Parameters:
         public static bool OfferedInitialR2T = true;
         public static bool OfferedImmediateData = true;
-        public static int OfferedMaxBurstLength = SessionParameters.DefaultMaxBurstLength;
-        public static int OfferedFirstBurstLength = SessionParameters.DefaultFirstBurstLength;
+        public static int OfferedMaxBurstLength = DefaultParameters.Session.MaxBurstLength;
+        public static int OfferedFirstBurstLength = DefaultParameters.Session.FirstBurstLength;
         public static int OfferedDefaultTime2Wait = 0;
         public static int OfferedDefaultTime2Retain = 20;
         public static int OfferedMaxOutstandingR2T = 1;

+ 11 - 13
ISCSI/ISCSI.Client/SessionParameters.cs

@@ -12,22 +12,20 @@ namespace ISCSI.Client
 {
     public class SessionParameters
     {
-        public const int DefaultMaxBurstLength = 262144;
-        public const int DefaultFirstBurstLength = 65536;
-
         public ulong ISID; // Initiator Session ID
         public ushort TSIH; // Target Session Identifying Handle
 
-        public bool InitialR2T;
-        public bool ImmediateData;
-        public int MaxBurstLength = DefaultMaxBurstLength;
-        public int FirstBurstLength = DefaultFirstBurstLength;
-        public int DefaultTime2Wait;
-        public int DefaultTime2Retain;
-        public int MaxOutstandingR2T;
-        public bool DataPDUInOrder;
-        public bool DataSequenceInOrder;
-        public int ErrorRecoveryLevel;
+        public int MaxConnections = DefaultParameters.Session.MaxConnections;
+        public bool InitialR2T = DefaultParameters.Session.InitialR2T;
+        public bool ImmediateData = DefaultParameters.Session.ImmediateData;
+        public int MaxBurstLength = DefaultParameters.Session.MaxBurstLength;
+        public int FirstBurstLength = DefaultParameters.Session.FirstBurstLength;
+        public int DefaultTime2Wait = DefaultParameters.Session.DefaultTime2Wait;
+        public int DefaultTime2Retain = DefaultParameters.Session.DefaultTime2Retain;
+        public int MaxOutstandingR2T = DefaultParameters.Session.MaxOutstandingR2T;
+        public bool DataPDUInOrder = DefaultParameters.Session.DataPDUInOrder;
+        public bool DataSequenceInOrder = DefaultParameters.Session.DataSequenceInOrder;
+        public int ErrorRecoveryLevel = DefaultParameters.Session.ErrorRecoveryLevel;
 
         private ushort m_nextCID = 1;
         private uint m_nextTaskTag = 1;

+ 1 - 5
ISCSI/ISCSI.Server/ConnectionParameters.cs

@@ -26,10 +26,6 @@ namespace ISCSI.Server
 
     public class ConnectionParameters
     {
-        /// <summary>
-        /// The default MaxRecvDataSegmentLength is used during Login
-        /// </summary>
-        public const int DefaultMaxRecvDataSegmentLength = 8192;
         public static int DeclaredMaxRecvDataSegmentLength = 262144;
 
         public ushort CID; // connection ID, generated by the initiator
@@ -40,7 +36,7 @@ namespace ISCSI.Server
         /// per direction parameter that the target or initator declares.
         /// maximum data segment length that the target (or initator) can receive in a single iSCSI PDU.
         /// </summary>
-        public int InitiatorMaxRecvDataSegmentLength = DefaultMaxRecvDataSegmentLength;
+        public int InitiatorMaxRecvDataSegmentLength = DefaultParameters.Connection.MaxRecvDataSegmentLength;
         public int TargetMaxRecvDataSegmentLength = DeclaredMaxRecvDataSegmentLength;
 
         public uint StatSN = 0; // Initial StatSN, any number will do

+ 71 - 0
ISCSI/ISCSI.Server/DefaultParameters.cs

@@ -0,0 +1,71 @@
+/* Copyright (C) 2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+
+namespace ISCSI.Server
+{
+    /// <summary>
+    /// Default operational parameters for iSCSI session / connection, as specified in RFC 3720.
+    /// </summary>
+    public class DefaultParameters
+    {
+        public class Session
+        {
+            /// <summary>
+            /// The maximum number of connections per session.
+            /// </summary>
+            public const int MaxConnections = 1;
+
+            /// <summary>
+            /// Allow the initiator to start sending data to a target as if it has received an initial R2T
+            /// </summary>
+            public const bool InitialR2T = true;
+
+            public const bool ImmediateData = true;
+
+            /// <summary>
+            /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed MaxBurstLength.
+            /// Maximum SCSI data payload in bytes in a Data-In or a solicited Data-Out iSCSI sequence (i.e. that belongs to a single command).
+            /// Irrelevant to the target in general, the initiator instructs us using ExpectedDataTransferLength.
+            /// </summary>
+            public const int MaxBurstLength = 262144;
+
+            /// <summary>
+            /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed FirstBurstLength for unsolicited data.
+            /// Maximum amount in bytes of unsolicited [SCSI] data an iSCSI initiator may send to the target during the execution of a single SCSI command.
+            /// Irrelevant to the target in general, irrelevant when (InitialR2T = Yes and) ImmediateData = No.
+            /// </summary>
+            public const int FirstBurstLength = 65536;
+
+            /// <summary>
+            /// minimum time, in seconds, to wait before attempting an explicit/implicit logout after connection termination / reset.
+            /// </summary>
+            public const int DefaultTime2Wait = 2;
+
+            /// <summary>
+            /// maximum time, in seconds after an initial wait (Time2Wait), before which an active task reassignment
+            /// is still possible after an unexpected connection termination or a connection reset.
+            /// </summary>
+            public const int DefaultTime2Retain = 20;
+
+            public const int MaxOutstandingR2T = 1;
+
+            public const bool DataPDUInOrder = true;
+
+            public const bool DataSequenceInOrder = true;
+
+            public const int ErrorRecoveryLevel = 0;
+        }
+
+        public class Connection
+        {
+            /// <summary>
+            /// The default MaxRecvDataSegmentLength is used during Login
+            /// </summary>
+            public const int MaxRecvDataSegmentLength = 8192;
+        }
+    }
+}

+ 2 - 2
ISCSI/ISCSI.Server/ISCSIServer.cs

@@ -24,8 +24,8 @@ namespace ISCSI.Server
         // Offered Session Parameters:
         public static bool OfferedInitialR2T = true;
         public static bool OfferedImmediateData = true;
-        public static int OfferedMaxBurstLength = SessionParameters.DefaultMaxBurstLength;
-        public static int OfferedFirstBurstLength = SessionParameters.DefaultFirstBurstLength;
+        public static int OfferedMaxBurstLength = DefaultParameters.Session.MaxBurstLength;
+        public static int OfferedFirstBurstLength = DefaultParameters.Session.FirstBurstLength;
         public static int OfferedDefaultTime2Wait = 0;
         public static int OfferedDefaultTime2Retain = 20;
         public static int OfferedMaxOutstandingR2T = 1;

+ 11 - 54
ISCSI/ISCSI.Server/SessionParameters.cs

@@ -12,61 +12,18 @@ namespace ISCSI.Server
 {
     public class SessionParameters
     {
-        public const int DefaultMaxConnections = 1;
-        public const bool DefaultInitialR2T = true;
-        public const bool DefaultImmediateData = true;
-        public const int DefaultMaxBurstLength = 262144;
-        public const int DefaultFirstBurstLength = 65536;
-        public const int DefaultDefaultTime2Wait = 2;
-        public const int DefaultDefaultTime2Retain = 20;
-        public const int DefaultMaxOutstandingR2T = 1;
-        public const bool DefaultDataPDUInOrder = true;
-        public const bool DefaultDataSequenceInOrder = true;
-        public const int DefaultErrorRecoveryLevel = 0;
-
         public static uint DefaultCommandQueueSize = 64;
-
-        /// <summary>
-        /// The maximum number of connections per session.
-        /// </summary>
-        public int MaxConnections = DefaultMaxConnections;
-
-        /// <summary>
-        /// Allow the initiator to start sending data to a target as if it has received an initial R2T
-        /// </summary>
-        public bool InitialR2T = DefaultInitialR2T;
-
-        public bool ImmediateData = DefaultImmediateData;
-
-        /// <summary>
-        /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed MaxBurstLength.
-        /// Maximum SCSI data payload in bytes in a Data-In or a solicited Data-Out iSCSI sequence (i.e. that belongs to a single command).
-        /// Irrelevant to the target in general, the initiator instructs us using ExpectedDataTransferLength.
-        /// </summary>
-        public int MaxBurstLength = DefaultMaxBurstLength;
-
-        /// <summary>
-        /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed FirstBurstLength for unsolicited data.
-        /// Maximum amount in bytes of unsolicited [SCSI] data an iSCSI initiator may send to the target during the execution of a single SCSI command.
-        /// Irrelevant to the target in general, irrelevant when (InitialR2T = Yes and) ImmediateData = No.
-        /// </summary>
-        public int FirstBurstLength = DefaultFirstBurstLength;
-        
-        /// <summary>
-        /// minimum time, in seconds, to wait before attempting an explicit/implicit logout after connection termination / reset.
-        /// </summary>
-        public int DefaultTime2Wait = DefaultDefaultTime2Wait;
-
-        /// <summary>
-        /// maximum time, in seconds after an initial wait (Time2Wait), before which an active task reassignment
-        /// is still possible after an unexpected connection termination or a connection reset.
-        /// </summary>
-        public int DefaultTime2Retain = DefaultDefaultTime2Retain;
-
-        public int MaxOutstandingR2T = DefaultMaxOutstandingR2T;
-        public bool DataPDUInOrder = DefaultDataPDUInOrder;
-        public bool DataSequenceInOrder = DefaultDataSequenceInOrder;
-        public int ErrorRecoveryLevel = DefaultErrorRecoveryLevel;
+        public int MaxConnections = DefaultParameters.Session.MaxConnections;
+        public bool InitialR2T = DefaultParameters.Session.InitialR2T;
+        public bool ImmediateData = DefaultParameters.Session.ImmediateData;
+        public int MaxBurstLength = DefaultParameters.Session.MaxBurstLength;
+        public int FirstBurstLength = DefaultParameters.Session.FirstBurstLength;
+        public int DefaultTime2Wait = DefaultParameters.Session.DefaultTime2Wait;
+        public int DefaultTime2Retain = DefaultParameters.Session.DefaultTime2Retain;
+        public int MaxOutstandingR2T = DefaultParameters.Session.MaxOutstandingR2T;
+        public bool DataPDUInOrder = DefaultParameters.Session.DataPDUInOrder;
+        public bool DataSequenceInOrder = DefaultParameters.Session.DataSequenceInOrder;
+        public int ErrorRecoveryLevel = DefaultParameters.Session.ErrorRecoveryLevel;
 
         /// <summary>
         /// - CommandQueueSize = 0 means the initiator can send one command at a time (because MaxCmdSN = ExpCmdSN + CommandQueueSize),

+ 3 - 1
ISCSI/ISCSI.csproj

@@ -36,10 +36,11 @@
     <Compile Include="ISCSI.Client\ClientHelper.cs" />
     <Compile Include="ISCSI.Client\ConnectionParameters.cs" />
     <Compile Include="ISCSI.Client\ConnectionState.cs" />
+    <Compile Include="ISCSI.Client\DefaultParameters.cs" />
+    <Compile Include="ISCSI.Client\ISCSIClient.cs" />
     <Compile Include="ISCSI.Client\ISCSIDisk.cs" />
     <Compile Include="ISCSI.Client\PDUHelper.cs" />
     <Compile Include="ISCSI.Client\SessionParameters.cs" />
-    <Compile Include="ISCSI.Client\ISCSIClient.cs" />
     <Compile Include="ISCSI.PDU\Enums\ISCSIOpCodeName.cs" />
     <Compile Include="ISCSI.PDU\Enums\ISCSIResponseName.cs" />
     <Compile Include="ISCSI.PDU\Enums\LoginResponseStatusClassName.cs" />
@@ -64,6 +65,7 @@
     <Compile Include="ISCSI.Server\ConnectionManager.cs" />
     <Compile Include="ISCSI.Server\ConnectionParameters.cs" />
     <Compile Include="ISCSI.Server\ConnectionState.cs" />
+    <Compile Include="ISCSI.Server\DefaultParameters.cs" />
     <Compile Include="ISCSI.Server\Exceptions\InvalidTargetTransferTagException.cs" />
     <Compile Include="ISCSI.Server\ISCSIServer.cs" />
     <Compile Include="ISCSI.Server\ISCSITarget.cs" />