SessionParameters.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. namespace ISCSI.Server
  11. {
  12. public class SessionParameters
  13. {
  14. public const int DefaultMaxConnections = 1;
  15. public const bool DefaultInitialR2T = true;
  16. public const bool DefaultImmediateData = true;
  17. public const int DefaultMaxBurstLength = 262144;
  18. public const int DefaultFirstBurstLength = 65536;
  19. public const int DefaultDefaultTime2Wait = 2;
  20. public const int DefaultDefaultTime2Retain = 20;
  21. public const int DefaultMaxOutstandingR2T = 1;
  22. public const bool DefaultDataPDUInOrder = true;
  23. public const bool DefaultDataSequenceInOrder = true;
  24. public const int DefaultErrorRecoveryLevel = 0;
  25. public static uint DefaultCommandQueueSize = 64;
  26. /// <summary>
  27. /// The maximum number of connections per session.
  28. /// </summary>
  29. public int MaxConnections = DefaultMaxConnections;
  30. /// <summary>
  31. /// Allow the initiator to start sending data to a target as if it has received an initial R2T
  32. /// </summary>
  33. public bool InitialR2T = DefaultInitialR2T;
  34. public bool ImmediateData = DefaultImmediateData;
  35. /// <summary>
  36. /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed MaxBurstLength.
  37. /// 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).
  38. /// Irrelevant to the target in general, the initiator instructs us using ExpectedDataTransferLength.
  39. /// </summary>
  40. public int MaxBurstLength = DefaultMaxBurstLength;
  41. /// <summary>
  42. /// The total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed FirstBurstLength for unsolicited data.
  43. /// Maximum amount in bytes of unsolicited [SCSI] data an iSCSI initiator may send to the target during the execution of a single SCSI command.
  44. /// Irrelevant to the target in general, irrelevant when (InitialR2T = Yes and) ImmediateData = No.
  45. /// </summary>
  46. public int FirstBurstLength = DefaultFirstBurstLength;
  47. /// <summary>
  48. /// minimum time, in seconds, to wait before attempting an explicit/implicit logout after connection termination / reset.
  49. /// </summary>
  50. public int DefaultTime2Wait = DefaultDefaultTime2Wait;
  51. /// <summary>
  52. /// maximum time, in seconds after an initial wait (Time2Wait), before which an active task reassignment
  53. /// is still possible after an unexpected connection termination or a connection reset.
  54. /// </summary>
  55. public int DefaultTime2Retain = DefaultDefaultTime2Retain;
  56. public int MaxOutstandingR2T = DefaultMaxOutstandingR2T;
  57. public bool DataPDUInOrder = DefaultDataPDUInOrder;
  58. public bool DataSequenceInOrder = DefaultDataSequenceInOrder;
  59. public int ErrorRecoveryLevel = DefaultErrorRecoveryLevel;
  60. /// <summary>
  61. /// - CommandQueueSize = 0 means the initiator can send one command at a time (because MaxCmdSN = ExpCmdSN + CommandQueueSize),
  62. /// (in this case there won't be any queue following the currently processed command).
  63. /// - Over a low-latency connection, most of the gain comes from increasing the queue size from 0 to 1
  64. /// - CmdSN is session wide, so CommandQueueSize is a session parameter.
  65. /// </summary>
  66. public uint CommandQueueSize = DefaultCommandQueueSize;
  67. public ulong ISID; // Initiator Session ID
  68. public ushort TSIH; // Target Session Identifying Handle
  69. public bool IsDiscovery; // Indicate whether this is a discovery session
  70. public bool CommandNumberingStarted;
  71. public uint ExpCmdSN;
  72. // Target Transfer Tag:
  73. // There are no protocol specific requirements with regard to the value of these tags,
  74. // but it is assumed that together with the LUN, they will enable the target to associate data with an R2T
  75. public static uint m_nextTransferTag; // TargetTransferTag
  76. // R2Ts are sequenced per command and must start with 0 for each new command.
  77. // We use a dictionary to store which R2TSN should be used next.
  78. // We use the transfer-tag that belongs to the command (SCSI Data-Out requests
  79. // will specify the TargetTransferTag, not the CmdSN)
  80. // (p.s. assuming the initator always sends the maximum amount of immediate data,
  81. // it's possible to calculate the next R2TSN from the BufferOffset)
  82. // Dictionary of next R2TSN to use: <transfer-tag, NextR2TSN>
  83. public Dictionary<uint, uint> NextR2TSN = new Dictionary<uint, uint>();
  84. public uint GetNextTransferTag()
  85. {
  86. uint transferTag = m_nextTransferTag;
  87. m_nextTransferTag++;
  88. return transferTag;
  89. }
  90. public uint GetNextR2TSN(uint transferTag)
  91. {
  92. uint nextR2TSN = NextR2TSN[transferTag];
  93. NextR2TSN[transferTag]++;
  94. return nextR2TSN;
  95. }
  96. }
  97. }