Ejemplo n.º 1
0
 protected IpV4OptionRoute(IpV4OptionType optionType, IList <IpV4Address> route, byte pointedAddressIndex)
     : base(optionType)
 {
     if ((int)pointedAddressIndex > 62)
     {
         throw new ArgumentOutOfRangeException("pointedAddressIndex", (object)pointedAddressIndex, "Maximum value is " + (object)62);
     }
     this._route = IListExtensions.AsReadOnly <IpV4Address>(route);
     this._pointedAddressIndex = pointedAddressIndex;
 }
        /// <summary>
        /// Construct a route option from the given values.
        /// </summary>
        protected IpV4OptionRoute(IpV4OptionType optionType, IList <IpV4Address> route, byte pointedAddressIndex)
            : base(optionType)
        {
            if (pointedAddressIndex > PointedAddressIndexMaxValue)
            {
                throw new ArgumentOutOfRangeException("pointedAddressIndex", pointedAddressIndex, "Maximum value is " + PointedAddressIndexMaxValue);
            }

            _route = route.AsReadOnly();
            _pointedAddressIndex = pointedAddressIndex;
        }
Ejemplo n.º 3
0
        internal override sealed Option Read(byte[] buffer, ref int offset, int length)
        {
            int num = offset + length;

            if (offset == num)
            {
                return((Option)null);
            }
            IpV4OptionType optionType = (IpV4OptionType)buffer[offset++];

            switch (optionType)
            {
            case IpV4OptionType.EndOfOptionList:
                return((Option)IpV4Option.End);

            case IpV4OptionType.NoOperation:
                return((Option)IpV4Option.Nop);

            default:
                return(OptionComplexFactory <IpV4OptionType> .Read(optionType, buffer, ref offset, num - offset));
            }
        }
Ejemplo n.º 4
0
        internal sealed override V4Option Read(byte[] buffer, ref int offset, int length)
        {
            int offsetEnd = offset + length;

            if (offset == offsetEnd)
            {
                return(null);
            }

            IpV4OptionType optionType = (IpV4OptionType)buffer[offset++];

            switch (optionType)
            {
            case IpV4OptionType.EndOfOptionList:
                return(End);

            case IpV4OptionType.NoOperation:
                return(Nop);

            default:
                return((V4Option)OptionComplexFactory <IpV4OptionType> .Read(optionType, buffer, ref offset, offsetEnd - offset));
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Constructs the option by type.
 /// </summary>
 protected IpV4Option(IpV4OptionType type)
 {
     _type = type;
 }
Ejemplo n.º 6
0
 internal IpV4OptionSimple(IpV4OptionType optionType)
     : base(optionType)
 {
 }
Ejemplo n.º 7
0
        public static IpV4Option NextIpV4Option(this Random random, int maximumOptionLength)
        {
            if (maximumOptionLength == 0)
            {
                throw new ArgumentOutOfRangeException("maximumOptionLength", maximumOptionLength, "option length must be positive");
            }

            if (maximumOptionLength >= IpV4OptionUnknown.OptionMinimumLength && random.Next(100) > 90)
            {
                return(random.NextIpV4OptionUnknown(maximumOptionLength));
            }

            // TODO: Support MTU Probe, MTU Reply and CommercialSecurity.
            List <IpV4OptionType> impossibleOptionTypes = new List <IpV4OptionType>
            {
                IpV4OptionType.MaximumTransmissionUnitProbe,
                IpV4OptionType.MaximumTransmissionUnitReply,
                IpV4OptionType.CommercialSecurity,
            };

            if (maximumOptionLength < IpV4OptionBasicSecurity.OptionMinimumLength)
            {
                impossibleOptionTypes.Add(IpV4OptionType.BasicSecurity);
            }
            if (maximumOptionLength < IpV4OptionRoute.OptionMinimumLength)
            {
                impossibleOptionTypes.Add(IpV4OptionType.LooseSourceRouting);
                impossibleOptionTypes.Add(IpV4OptionType.StrictSourceRouting);
                impossibleOptionTypes.Add(IpV4OptionType.RecordRoute);
            }
            if (maximumOptionLength < IpV4OptionStreamIdentifier.OptionLength)
            {
                impossibleOptionTypes.Add(IpV4OptionType.StreamIdentifier);
            }
            if (maximumOptionLength < IpV4OptionTimestamp.OptionMinimumLength)
            {
                impossibleOptionTypes.Add(IpV4OptionType.InternetTimestamp);
            }
            if (maximumOptionLength < IpV4OptionTraceRoute.OptionLength)
            {
                impossibleOptionTypes.Add(IpV4OptionType.TraceRoute);
            }
            if (maximumOptionLength < IpV4OptionQuickStart.OptionLength)
            {
                impossibleOptionTypes.Add(IpV4OptionType.QuickStart);
            }

            IpV4OptionType optionType = random.NextEnum <IpV4OptionType>(impossibleOptionTypes);

            switch (optionType)
            {
            case IpV4OptionType.EndOfOptionList:
                return(IpV4Option.End);

            case IpV4OptionType.NoOperation:
                return(IpV4Option.Nop);

            case IpV4OptionType.BasicSecurity:
                IpV4OptionSecurityProtectionAuthorities protectionAuthorities = IpV4OptionSecurityProtectionAuthorities.None;
                int protectionAuthorityLength = random.Next(maximumOptionLength - IpV4OptionBasicSecurity.OptionMinimumLength);
                if (protectionAuthorityLength > 0)
                {
                    protectionAuthorities = random.NextEnum <IpV4OptionSecurityProtectionAuthorities>();
                }

                return(new IpV4OptionBasicSecurity(random.NextEnum(IpV4OptionSecurityClassificationLevel.None),
                                                   protectionAuthorities,
                                                   (byte)(IpV4OptionBasicSecurity.OptionMinimumLength + protectionAuthorityLength)));

            case IpV4OptionType.LooseSourceRouting:
            case IpV4OptionType.StrictSourceRouting:
            case IpV4OptionType.RecordRoute:
                int           numAddresses = random.Next((maximumOptionLength - IpV4OptionRoute.OptionMinimumLength) / 4 + 1);
                IpV4Address[] addresses    = random.NextIpV4Addresses(numAddresses);

                byte pointedAddressIndex;
                if (random.NextBool())
                {
                    pointedAddressIndex = random.NextByte(IpV4OptionRoute.PointedAddressIndexMaxValue + 1);
                }
                else
                {
                    pointedAddressIndex = random.NextByte(10);
                }

                switch (optionType)
                {
                case IpV4OptionType.LooseSourceRouting:
                    return(new IpV4OptionLooseSourceRouting(addresses, pointedAddressIndex));

                case IpV4OptionType.StrictSourceRouting:
                    return(new IpV4OptionStrictSourceRouting(addresses, pointedAddressIndex));

                case IpV4OptionType.RecordRoute:
                    return(new IpV4OptionRecordRoute(pointedAddressIndex, addresses));

                default:
                    throw new InvalidOperationException("optionType = " + optionType);
                }

            case IpV4OptionType.StreamIdentifier:
                return(new IpV4OptionStreamIdentifier(random.NextUShort()));

            case IpV4OptionType.InternetTimestamp:
                IpV4OptionTimestampType timestampType = random.NextEnum <IpV4OptionTimestampType>();
                byte overflow = random.NextByte(IpV4OptionTimestamp.OverflowMaxValue + 1);
                byte pointedIndex;
                if (random.NextBool())
                {
                    pointedIndex = random.NextByte(IpV4OptionTimestamp.PointedIndexMaxValue + 1);
                }
                else
                {
                    pointedIndex = random.NextByte(10);
                }

                switch (timestampType)
                {
                case IpV4OptionTimestampType.TimestampOnly:
                    int             numTimestamps = random.Next((maximumOptionLength - IpV4OptionTimestamp.OptionMinimumLength) / 4 + 1);
                    IpV4TimeOfDay[] timestamps    = ((Func <IpV4TimeOfDay>)random.NextIpV4TimeOfDay).GenerateArray(numTimestamps);
                    return(new IpV4OptionTimestampOnly(overflow, pointedIndex, timestamps));

                case IpV4OptionTimestampType.AddressAndTimestamp:
                case IpV4OptionTimestampType.AddressPrespecified:
                    int numPairs = random.Next((maximumOptionLength - IpV4OptionTimestamp.OptionMinimumLength) / 8 + 1);
                    IpV4OptionTimedAddress[] pairs = new IpV4OptionTimedAddress[numPairs];
                    for (int i = 0; i != numPairs; ++i)
                    {
                        pairs[i] = new IpV4OptionTimedAddress(random.NextIpV4Address(), random.NextIpV4TimeOfDay());
                    }

                    return(new IpV4OptionTimestampAndAddress(timestampType, overflow, pointedIndex, pairs));

                default:
                    throw new InvalidOperationException("timestampType = " + timestampType);
                }

            case IpV4OptionType.TraceRoute:
                return(new IpV4OptionTraceRoute(random.NextUShort(), random.NextUShort(), random.NextUShort(), random.NextIpV4Address()));

            case IpV4OptionType.RouterAlert:
                return(new IpV4OptionRouterAlert(random.NextUShort()));

            case IpV4OptionType.QuickStart:
                return(new IpV4OptionQuickStart(random.NextEnum <IpV4OptionQuickStartFunction>(),
                                                random.NextByte(IpV4OptionQuickStart.RateMaximumValue + 1),
                                                random.NextByte(),
                                                random.NextUInt() & 0x3FFFFFFF));

            default:
                throw new InvalidOperationException("optionType = " + optionType);
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructs the option by type.
 /// </summary>
 protected IpV4OptionComplex(IpV4OptionType type)
     : base(type)
 {
 }
Ejemplo n.º 9
0
 internal IpV4OptionSimple(IpV4OptionType optionType)
     : base(optionType)
 {
 }
Ejemplo n.º 10
0
 protected IpV4Option(IpV4OptionType type)
 {
     this._type = type;
 }
Ejemplo n.º 11
0
 protected IpV4OptionComplex(IpV4OptionType type)
     : base(type)
 {
 }
 public IpV4OptionTypeRegistrationAttribute(IpV4OptionType optionType)
 {
     IpV4OptionType = optionType;
 }
 public IpV4OptionTypeRegistrationAttribute(IpV4OptionType optionType)
 {
     IpV4OptionType = optionType;
 }