Пример #1
0
        private static IpV6Option CreateOption(IpV6OptionType optionType, DataSegment data)
        {
            IpV6Option prototype;

            if (!_prototypes.TryGetValue(optionType, out prototype))
            {
                return(new IpV6OptionUnknown(optionType, data));
            }
            return(prototype.CreateInstance(data));
        }
Пример #2
0
        private static IpV6Option CreateOption(IpV6OptionType optionType, DataSegment data)
        {
            IIpV6OptionComplexFactory factory;

            if (!_factories.TryGetValue(optionType, out factory))
            {
                return(new IpV6OptionUnknown(optionType, data));
            }
            return(factory.CreateInstance(data));
        }
Пример #3
0
        public static Tuple <IList <IpV6Option>, bool> Read(DataSegment data)
        {
            int offset = 0;
            List <IpV6Option> options = new List <IpV6Option>();
            bool isValid = true;

            while (offset < data.Length)
            {
                IpV6OptionType optionType = (IpV6OptionType)data[offset++];
                if (optionType == IpV6OptionType.Pad1)
                {
                    options.Add(new IpV6OptionPad1());
                    continue;
                }

                if (offset >= data.Length)
                {
                    isValid = false;
                    break;
                }

                byte optionDataLength = data[offset++];
                if (offset + optionDataLength > data.Length)
                {
                    isValid = false;
                    break;
                }

                IpV6Option option = CreateOption(optionType, data.Subsegment(ref offset, optionDataLength));
                if (option == null)
                {
                    isValid = false;
                    break;
                }

                options.Add(option);
            }

            return(new Tuple <IList <IpV6Option>, bool>(options, isValid));
        }
 /// <summary>
 /// Creates an unknown option according to the given type and data.
 /// </summary>
 /// <param name="type">The type of the IP option.</param>
 /// <param name="data">The data of the IP option.</param>
 public IpV6OptionUnknown(IpV6OptionType type, DataSegment data)
     : base(type)
 {
     Data = data;
 }
Пример #5
0
 internal IpV6OptionComplex(IpV6OptionType type)
     : base(type)
 {
 }
Пример #6
0
 protected IpV6OptionSimple(IpV6OptionType type) : base(type)
 {
 }
Пример #7
0
 internal IpV6OptionSimple(IpV6OptionType type)
     : base(type)
 {
 }
Пример #8
0
 protected IpV6Option(IpV6OptionType type)
 {
     OptionType = type;
 }
Пример #9
0
 protected IpV6OptionComplex(IpV6OptionType type)
     : base(type)
 {
 }
Пример #10
0
 protected IpV6OptionSimple(IpV6OptionType type) : base(type)
 {
 }
Пример #11
0
 internal IpV6OptionComplex(IpV6OptionType type)
     : base(type)
 {
 }
Пример #12
0
 protected IpV6Option(IpV6OptionType type)
 {
     OptionType = type;
 }
Пример #13
0
 internal IpV6Option(IpV6OptionType type)
 {
     OptionType = type;
 }
 public IpV6OptionTypeRegistrationAttribute(IpV6OptionType optionType)
 {
     OptionType = optionType;
 }
Пример #15
0
        public static IpV6Option NextIpV6Option(this Random random)
        {
            IpV6OptionType optionType = random.NextEnum <IpV6OptionType>();

            switch (optionType)
            {
            case IpV6OptionType.Pad1:
                return(new IpV6OptionPad1());

            case IpV6OptionType.PadN:
                return(new IpV6OptionPadN(random.Next(10)));

            case IpV6OptionType.JumboPayload:
                return(new IpV6OptionJumboPayload(random.NextUInt()));

            case IpV6OptionType.TunnelEncapsulationLimit:
                return(new IpV6OptionTunnelEncapsulationLimit(random.NextByte()));

            case IpV6OptionType.RouterAlert:
                return(new IpV6OptionRouterAlert(random.NextEnum <IpV6RouterAlertType>()));

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

            case IpV6OptionType.Calipso:
                return(new IpV6OptionCalipso(random.NextEnum <IpV6CalipsoDomainOfInterpretation>(), random.NextByte(), random.NextUShort(),
                                             random.NextDataSegment(random.NextInt(0, IpV6OptionCalipso.CompartmentBitmapMaxLength + 1) / 4 * sizeof(int))));

            case IpV6OptionType.SimplifiedMulticastForwardingDuplicatePacketDetection:
                if (random.NextBool())
                {
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceHashAssistValue(random.NextDataSegment(random.NextInt(1, 100))));
                }
                IpV6TaggerIdType taggerIdType = random.NextEnum <IpV6TaggerIdType>();
                DataSegment      identifier   = random.NextDataSegment(random.NextInt(0, 100));
                switch (taggerIdType)
                {
                case IpV6TaggerIdType.Null:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionNull(identifier));

                case IpV6TaggerIdType.Default:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionDefault(random.NextDataSegment(random.NextInt(1, 17)), identifier));

                case IpV6TaggerIdType.IpV4:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV4(random.NextIpV4Address(), identifier));

                case IpV6TaggerIdType.IpV6:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV6(random.NextIpV6Address(), identifier));

                default:
                    throw new InvalidOperationException(string.Format("Invalid taggerIdType value {0}", taggerIdType));
                }

            case IpV6OptionType.HomeAddress:
                return(new IpV6OptionHomeAddress(random.NextIpV6Address()));

            case IpV6OptionType.EndpointIdentification:
                return(new IpV6OptionEndpointIdentification(random.NextDataSegment(random.Next(10)), random.NextDataSegment(random.Next(10))));

            case IpV6OptionType.RoutingProtocolLowPowerAndLossyNetworksOption:
                return(new IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(random.NextBool(), random.NextBool(), random.NextBool(), random.NextByte(),
                                                                             random.NextUShort(), random.NextDataSegment(random.Next(10))));

            case IpV6OptionType.IdentifierLocatorNetworkProtocolNonce:
                return(new IpV6OptionIdentifierLocatorNetworkProtocolNonce(random.NextDataSegment(random.Next(10))));

            case IpV6OptionType.LineIdentification:
                return(new IpV6OptionLineIdentificationDestination(random.NextDataSegment(random.Next(10))));

            default:
                throw new InvalidOperationException(string.Format("Invalid optionType value {0}", optionType));
            }
        }
 public IpV6OptionTypeRegistrationAttribute(IpV6OptionType optionType)
 {
     OptionType = optionType;
 }
Пример #17
0
 /// <summary>
 /// Creates an unknown option according to the given type and data.
 /// </summary>
 /// <param name="type">The type of the IP option.</param>
 /// <param name="data">The data of the IP option.</param>
 public IpV6OptionUnknown(IpV6OptionType type, DataSegment data)
     : base(type)
 {
     Data = data;
 }
Пример #18
0
 protected IpV6OptionComplex(IpV6OptionType type) 
     : base(type)
 {
 }
Пример #19
0
 internal IpV6OptionSimple(IpV6OptionType type)
     : base(type)
 {
 }