internal static IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceBased CreateSpecificInstance(DataSegment data)
        {
            IpV6TaggerIdType taggerIdType = (IpV6TaggerIdType)((data[Offset.TaggerIdType] & Mask.TaggerIdType) >> Shift.TaggerIdType);
            int taggerIdLength            = (taggerIdType == IpV6TaggerIdType.Null ? 0 : (data[Offset.TaggerIdLength] & Mask.TaggerIdLength) + 1);

            if (data.Length < Offset.TaggerId + taggerIdLength)
            {
                return(null);
            }
            DataSegment identifier = data.Subsegment(Offset.TaggerId + taggerIdLength, data.Length - Offset.TaggerId - taggerIdLength);

            switch (taggerIdType)
            {
            case IpV6TaggerIdType.Null:
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionNull(identifier));

            case IpV6TaggerIdType.Default:
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionDefault(data.Subsegment(Offset.TaggerId, taggerIdLength), identifier));

            case IpV6TaggerIdType.IpV4:
                if (taggerIdLength != IpV4Address.SizeOf)
                {
                    return(null);
                }
                IpV4Address ipV4Address = data.ReadIpV4Address(Offset.TaggerId, Endianity.Big);
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV4(ipV4Address, identifier));

            case IpV6TaggerIdType.IpV6:
                if (taggerIdLength != IpV6Address.SizeOf)
                {
                    return(null);
                }
                IpV6Address ipV6Address = data.ReadIpV6Address(Offset.TaggerId, Endianity.Big);
                return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV6(ipV6Address, identifier));

            default:
                return(null);
            }
        }
Ejemplo n.º 2
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));
            }
        }