ConnectionParameters.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. using Utilities;
  11. namespace ISCSI.Server
  12. {
  13. public class TransferEntry
  14. {
  15. public SCSICommandPDU Command;
  16. public uint NextR2NSN;
  17. public TransferEntry(SCSICommandPDU command, uint nextR2NSN)
  18. {
  19. Command = command;
  20. NextR2NSN = nextR2NSN;
  21. }
  22. }
  23. public class ConnectionParameters
  24. {
  25. /// <summary>
  26. /// The default MaxRecvDataSegmentLength is used during Login
  27. /// </summary>
  28. public const int DefaultMaxRecvDataSegmentLength = 8192;
  29. public static int DeclaredMaxRecvDataSegmentLength = 262144;
  30. public ushort CID; // connection ID, generated by the initiator
  31. /// <summary>
  32. /// per direction parameter that the target or initator declares.
  33. /// maximum data segment length that the target (or initator) can receive in a single iSCSI PDU.
  34. /// </summary>
  35. public int InitiatorMaxRecvDataSegmentLength = DefaultMaxRecvDataSegmentLength;
  36. public int TargetMaxRecvDataSegmentLength = DeclaredMaxRecvDataSegmentLength;
  37. public uint StatSN = 0; // Initial StatSN, any number will do
  38. // Dictionary of current transfers: <transfer-tag, TransferEntry>
  39. private Dictionary<uint, TransferEntry> n_transfers = new Dictionary<uint, TransferEntry>();
  40. public TransferEntry AddTransfer(uint transferTag, SCSICommandPDU command, uint nextR2NSN)
  41. {
  42. TransferEntry entry = new TransferEntry(command, nextR2NSN);
  43. n_transfers.Add(transferTag, entry);
  44. return entry;
  45. }
  46. public TransferEntry GetTransferEntry(uint transferTag)
  47. {
  48. TransferEntry result;
  49. n_transfers.TryGetValue(transferTag, out result);
  50. return result;
  51. }
  52. public void RemoveTransfer(uint transferTag)
  53. {
  54. n_transfers.Remove(transferTag);
  55. }
  56. }
  57. }