Ejemplo n.º 1
0
 internal static void WriteData(byte[] buffer, ref int offset, IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
 {
     buffer[offset + Offset.Function] = (byte)((((byte)function << Shift.Function) & Mask.Function) | (rate & Mask.Rate));
     buffer[offset + Offset.Ttl]      = ttl;
     buffer.Write(offset + Offset.Nonce, nonce << Shift.Nonce, Endianity.Big);
     offset += DataLength;
 }
 public static void ReadData(DataSegment data, out IpV4OptionQuickStartFunction function, out byte rate, out byte ttl, out uint nonce)
 {
     function = (IpV4OptionQuickStartFunction)(data[Offset.Function] & Mask.Function);
     rate = (byte)(data[Offset.Rate] & Mask.Rate);
     ttl = data[Offset.Ttl];
     nonce = data.ReadUInt(Offset.Nonce, Endianity.Big);
 }
Ejemplo n.º 3
0
 internal static void ReadData(DataSegment data, out IpV4OptionQuickStartFunction function, out byte rate, out byte ttl, out uint nonce)
 {
     function = (IpV4OptionQuickStartFunction)((data[Offset.Function] & Mask.Function) >> Shift.Function);
     rate     = (byte)(data[Offset.Rate] & Mask.Rate);
     ttl      = data[Offset.Ttl];
     nonce    = data.ReadUInt(Offset.Nonce, Endianity.Big) >> Shift.Nonce;
 }
 public static void WriteData(byte[] buffer, ref int offset, IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
 {
     buffer[offset + Offset.Function] = (byte)(((byte)function & Mask.Function) | (rate & Mask.Rate));
     buffer[offset + Offset.Ttl] = ttl;
     buffer.Write(offset + Offset.Nonce, nonce, Endianity.Big);
     offset += DataLength;
 }
Ejemplo n.º 5
0
        public IpV6OptionQuickStart(IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
            : base(IpV6OptionType.QuickStart)
        {
            IpOptionQuickStartCommon.AssertValidParameters(function, rate, ttl, nonce);

            Function = function;
            Rate     = rate;
            Ttl      = ttl;
            Nonce    = nonce;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates an instance from the given function, rate, TTL and nonce.
        /// </summary>
        /// <param name="function">Function field.</param>
        /// <param name="rate">
        /// For rate request, this is the Rate Request field.
        /// For Report of Approved Rate, this is the Rate Report field.
        /// </param>
        /// <param name="ttl">
        /// For a Rate Request, contains the Quick-Start TTL (QS TTL) field.
        /// The sender must set the QS TTL field to a random value.
        /// Routers that approve the Quick-Start Request decrement the QS TTL (mod 256) by the same amount that they decrement the IP TTL.
        /// The QS TTL is used by the sender to detect if all the routers along the path understood and approved the Quick-Start option.
        /// The transport sender must calculate and store the TTL Diff, the difference between the IP TTL value, and the QS TTL value in the Quick-Start Request packet, as follows:
        /// TTL Diff = ( IP TTL - QS TTL ) mod 256.
        /// For a Report of Approved Rate, this is not used.
        /// </param>
        /// <param name="nonce">
        /// For a Rate Request and Report of Approved Rate, contain a 30-bit QS Nonce.
        /// The sender should set the QS Nonce to a random value.
        /// </param>
        public IpV6OptionQuickStart(IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
            : base(IpV6OptionType.QuickStart)
        {
            IpOptionQuickStartCommon.AssertValidParameters(function, rate, nonce);

            QuickStartFunction = function;
            Rate = rate;
            Ttl = ttl;
            Nonce = nonce;
        }
        public static void AssertValidParameters(IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
        {
            if (function != IpV4OptionQuickStartFunction.RateRequest &&
                function != IpV4OptionQuickStartFunction.RateReport)
            {
                throw new ArgumentException("Illegal function " + function, "function");
            }

            if (rate > RateMaximumValue)
                throw new ArgumentOutOfRangeException("rate", rate, "Rate maximum value is " + RateMaximumValue);

            if ((nonce & 0x00000003) != 0)
                throw new ArgumentException("nonce last two bits are reserved and must be zero", "nonce");
        }
        internal static void AssertValidParameters(IpV4OptionQuickStartFunction function, byte rate, uint nonce)
        {
            if (function != IpV4OptionQuickStartFunction.RateRequest &&
                function != IpV4OptionQuickStartFunction.RateReport)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Illegal function {0}", function), "function");
            }

            if (rate > RateMaximumValue)
                throw new ArgumentOutOfRangeException("rate", rate, string.Format(CultureInfo.InvariantCulture, "Rate maximum value is {0}", RateMaximumValue));

            if (nonce > NonceMaximumValue)
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "nonce cannot be bigger than {0}", NonceMaximumValue), "nonce");
        }
Ejemplo n.º 9
0
        internal static void AssertValidParameters(IpV4OptionQuickStartFunction function, byte rate, uint nonce)
        {
            if (function != IpV4OptionQuickStartFunction.RateRequest &&
                function != IpV4OptionQuickStartFunction.RateReport)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Illegal function {0}", function), "function");
            }

            if (rate > RateMaximumValue)
            {
                throw new ArgumentOutOfRangeException("rate", rate, string.Format(CultureInfo.InvariantCulture, "Rate maximum value is {0}", RateMaximumValue));
            }

            if (nonce > NonceMaximumValue)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "nonce cannot be bigger than {0}", NonceMaximumValue), "nonce");
            }
        }
Ejemplo n.º 10
0
        public static void AssertValidParameters(IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
        {
            if (function != IpV4OptionQuickStartFunction.RateRequest &&
                function != IpV4OptionQuickStartFunction.RateReport)
            {
                throw new ArgumentException("Illegal function " + function, "function");
            }

            if (rate > RateMaximumValue)
            {
                throw new ArgumentOutOfRangeException("rate", rate, "Rate maximum value is " + RateMaximumValue);
            }

            if ((nonce & 0x00000003) != 0)
            {
                throw new ArgumentException("nonce last two bits are reserved and must be zero", "nonce");
            }
        }
 public IpV4OptionQuickStart(IpV4OptionQuickStartFunction function, byte rate, byte ttl, uint nonce)
     : base(IpV4OptionType.QuickStart)
 {
     if (function != IpV4OptionQuickStartFunction.RateRequest && function != IpV4OptionQuickStartFunction.RateReport)
     {
         throw new ArgumentException("Illegal function " + (object)function, "function");
     }
     if ((int)rate > 15)
     {
         throw new ArgumentOutOfRangeException("rate", (object)rate, "Rate maximum value is " + (object)15);
     }
     if (((int)nonce & 3) != 0)
     {
         throw new ArgumentException("nonce last two bits are reserved and must be zero", "nonce");
     }
     this._function = function;
     this._rate     = rate;
     this._ttl      = ttl;
     this._nonce    = nonce;
 }