internal IpV6ExtensionHeaderOptions(IpV4Protocol? nextHeader, IpV6Options options)
     : base(nextHeader)
 {
     if (options.BytesLength % 8 != 6)
         options = options.Pad((14 - options.BytesLength % 8) % 8);
     Options = options;
 }
        public static IpV6ExtensionHeader NextIpV6ExtensionHeader(this Random random, IpV4Protocol?nextHeader, bool isEncapsulatingSecurityPayloadPossible)
        {
            IpV4Protocol extensionHeaderType =
                random.NextValue(
                    IpV6ExtensionHeader.ExtensionHeaders.Where(extensionHeader => isEncapsulatingSecurityPayloadPossible ||
                                                               extensionHeader != IpV4Protocol.EncapsulatingSecurityPayload).ToList());

            switch (extensionHeaderType)
            {
            case IpV4Protocol.IpV6HopByHopOption:     // 0
                return(new IpV6ExtensionHeaderHopByHopOptions(nextHeader, random.NextIpV6Options()));

            case IpV4Protocol.IpV6Route:     // 43
                IpV6RoutingType routingType = random.NextEnum(IpV6RoutingType.Nimrod);
                switch (routingType)
                {
                case IpV6RoutingType.SourceRoute:
                    return(new IpV6ExtensionHeaderRoutingSourceRoute(nextHeader, random.NextByte(), random.NextIpV6AddressArray(random.NextInt(0, 10))));

                case IpV6RoutingType.Type2RoutingHeader:
                    return(new IpV6ExtensionHeaderRoutingHomeAddress(nextHeader, random.NextByte(), random.NextIpV6Address()));

                case IpV6RoutingType.RoutingProtocolLowPowerAndLossyNetworksSourceRouteHeader:
                    byte          commonPrefixLengthForNonLastAddresses = random.NextByte(IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.MaxCommonPrefixLength + 1);
                    byte          commonPrefixLengthForLastAddress      = random.NextByte(IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.MaxCommonPrefixLength + 1);
                    IpV6Address[] addresses = random.NextIpV6AddressWithLeadingZeroBytesArray(commonPrefixLengthForNonLastAddresses,
                                                                                              random.NextInt(0, 10));
                    if (addresses.Any() || random.NextBool())
                    {
                        addresses = addresses.Concat(random.NextIpV6AddressWithLeadingZeroBytes(commonPrefixLengthForLastAddress)).ToArray();
                    }
                    return(new IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks(nextHeader, random.NextByte(), commonPrefixLengthForNonLastAddresses,
                                                                                          commonPrefixLengthForLastAddress, addresses));

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

            case IpV4Protocol.FragmentHeaderForIpV6:     // 44
                return(new IpV6ExtensionHeaderFragmentData(nextHeader, random.NextUShort(IpV6ExtensionHeaderFragmentData.MaxFragmentOffset + 1),
                                                           random.NextBool(), random.NextUInt()));

            case IpV4Protocol.IpV6Opts:     // 60
                IpV6Options options = random.NextIpV6Options();
                return(new IpV6ExtensionHeaderDestinationOptions(nextHeader, options));

            case IpV4Protocol.MobilityHeader:     // 135
                return(random.NextIpV6ExtensionHeaderMobility(nextHeader));

            case IpV4Protocol.EncapsulatingSecurityPayload:     // 50
                return(new IpV6ExtensionHeaderEncapsulatingSecurityPayload(random.NextUInt(), random.NextUInt(), random.NextDataSegment(random.Next(100))));

            case IpV4Protocol.AuthenticationHeader:     // 51
                return(new IpV6ExtensionHeaderAuthentication(nextHeader, random.NextUInt(), random.NextUInt(), random.NextDataSegment(random.Next(25) * 4)));

            default:
                throw new InvalidOperationException(string.Format("Invalid extensionHeaderType value {0}", extensionHeaderType));
            }
        }
Beispiel #3
0
 internal IpV6ExtensionHeaderOptions(IpV4Protocol?nextHeader, IpV6Options options)
     : base(nextHeader)
 {
     if (options.BytesLength % 8 != 6)
     {
         options = options.Pad((14 - options.BytesLength % 8) % 8);
     }
     Options = options;
 }
 internal static IpV6ExtensionHeaderHopByHopOptions ParseData(IpV4Protocol nextHeader, DataSegment data)
 {
     IpV6Options options = new IpV6Options(data);
     return new IpV6ExtensionHeaderHopByHopOptions(nextHeader, options);
 }
 private IpV6ExtensionHeaderHopByHopOptions(IpV4Protocol nextHeader, IpV6Options options)
     : base(nextHeader, options)
 {
 }
 public IpV6ExtensionHeaderDestinationOptions(IpV4Protocol nextHeader, IpV6Options options)
     : base(nextHeader, options)
 {
 }
Beispiel #7
0
 public void IpV6OptionsEnumerableConstructor()
 {
     IpV6Options options = new IpV6Options(new IpV6Option[] { new IpV6OptionPad1() }.Concat(new IpV6OptionPad1()));
     Assert.AreEqual(2, options.Count);
     Assert.AreEqual(new IpV6OptionPad1(), options[0]);
     Assert.AreEqual(new IpV6OptionPad1(), options[1]);
 }
 /// <summary>
 /// Creates an instance from next header and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="options">Options for the extension header.</param>
 public IpV6ExtensionHeaderHopByHopOptions(IpV4Protocol? nextHeader, IpV6Options options)
     : base(nextHeader, options)
 {
 }
 internal IpV6ExtensionHeaderOptions(IpV4Protocol nextHeader, IpV6Options options)
     : base(nextHeader)
 {
     Options = options;
 }
Beispiel #10
0
        internal static IpV6ExtensionHeaderDestinationOptions ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            IpV6Options options = new IpV6Options(data);

            return(new IpV6ExtensionHeaderDestinationOptions(nextHeader, options));
        }
Beispiel #11
0
 /// <summary>
 /// Creates an instance from next header and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="options">Extension header options.</param>
 public IpV6ExtensionHeaderDestinationOptions(IpV4Protocol?nextHeader, IpV6Options options)
     : base(nextHeader, options)
 {
 }
Beispiel #12
0
 /// <summary>
 /// Creates an instance from next header and options.
 /// </summary>
 /// <param name="nextHeader">Identifies the type of header immediately following this extension header.</param>
 /// <param name="options">Options for the extension header.</param>
 public IpV6ExtensionHeaderHopByHopOptions(IpV4Protocol?nextHeader, IpV6Options options)
     : base(nextHeader, options)
 {
 }