Beispiel #1
0
 private DHCPv4ScopePropertyResponse GetScopePropertyResponse(DHCPv4ScopeProperty property)
 {
     return(property switch
     {
         DHCPv4AddressListScopeProperty item => new DHCPv4AddressListScopePropertyResponse
         {
             Addresses = item.Addresses.Select(x => x.ToString()).ToList(),
             OptionCode = item.OptionIdentifier,
             Type = item.ValueType,
         },
         DHCPv4AddressScopeProperty item => new DHCPv4AddressScopePropertyResponse
         {
             Value = item.Address.ToString(),
             OptionCode = item.OptionIdentifier,
             Type = item.ValueType,
         },
         DHCPv4BooleanScopeProperty item => new DHCPv4BooleanScopePropertyResponse
         {
             Value = item.Value,
             OptionCode = item.OptionIdentifier,
             Type = item.ValueType,
         },
         DHCPv4NumericValueScopeProperty item => new DHCPv4NumericScopePropertyResponse
         {
             Value = item.Value,
             NumericType = item.NumericType,
             Type = item.ValueType,
             OptionCode = item.OptionIdentifier,
         },
         DHCPv4TextScopeProperty item => new DHCPv4TextScopePropertyResponse
         {
             Value = item.Value,
             OptionCode = item.OptionIdentifier,
             Type = item.ValueType,
         },
         DHCPv4TimeScopeProperty item => new DHCPv4TimeScopePropertyResponse
         {
             Value = item.Value,
             OptionCode = item.OptionIdentifier,
             Type = item.ValueType,
         },
         _ => throw new NotImplementedException(),
     });
Beispiel #2
0
        public static List <DHCPv4ScopeProperty> GenerateProperties(this Random random, ICollection <DHCPv4OptionTypes> excludedOptions)
        {
            HashSet <Byte>             usedOptionIdentifier = new HashSet <byte>(excludedOptions.Select(x => (Byte)x));
            List <DHCPv4ScopeProperty> result = new List <DHCPv4ScopeProperty>();

            Int32 addressListPropertieAmount = random.Next(3, 10);

            for (int i = 0; i < addressListPropertieAmount; i++)
            {
                byte identiifer = GetRandomIdentifier(random, usedOptionIdentifier);

                result.Add(new DHCPv4AddressListScopeProperty(
                               identiifer, random.GetIPv4Addresses()));
            }

            Int32 addressPropertieAmount = random.Next(3, 10);

            for (int i = 0; i < addressPropertieAmount; i++)
            {
                byte identiifer = GetRandomIdentifier(random, usedOptionIdentifier);

                result.Add(new DHCPv4AddressScopeProperty(
                               identiifer, random.GetIPv4Address()));
            }

            Int32 booleanPropertieAmount = random.Next(3, 10);

            for (int i = 0; i < booleanPropertieAmount; i++)
            {
                byte identiifer = GetRandomIdentifier(random, usedOptionIdentifier);

                result.Add(new DHCPv4BooleanScopeProperty(
                               identiifer, random.NextBoolean()));
            }

            Int32 textPropertieAmount = random.Next(3, 10);

            for (int i = 0; i < textPropertieAmount; i++)
            {
                byte identiifer = GetRandomIdentifier(random, usedOptionIdentifier);

                result.Add(new DHCPv4TextScopeProperty(
                               identiifer, random.GetAlphanumericString(random.Next(30, 100))));
            }

            Int32 numericPropertieAmount = random.Next(10, 20);

            for (int i = 0; i < textPropertieAmount; i++)
            {
                byte  identiifer = GetRandomIdentifier(random, usedOptionIdentifier);
                Int64 value;
                DHCPv4NumericValueTypes numericType;
                Double randomValue = random.NextDouble();
                if (randomValue < 0.33)
                {
                    value       = (UInt32)Int32.MaxValue + (UInt32)random.Next();
                    numericType = DHCPv4NumericValueTypes.UInt32;
                }
                else if (randomValue < 0.66)
                {
                    value       = random.Next(0, UInt16.MaxValue);
                    numericType = DHCPv4NumericValueTypes.UInt16;
                }
                else
                {
                    value       = random.Next(0, Byte.MaxValue);
                    numericType = DHCPv4NumericValueTypes.Byte;
                }

                result.Add(
                    DHCPv4NumericValueScopeProperty.FromRawValue(identiifer, value.ToString(), numericType));
            }

            Int32 timePropertieAmount = random.Next(3, 10);

            for (int i = 0; i < timePropertieAmount; i++)
            {
                byte identiifer = GetRandomIdentifier(random, usedOptionIdentifier);

                result.Add(new DHCPv4TimeScopeProperty(
                               identiifer, random.NextBoolean(), TimeSpan.FromMinutes(random.Next(3, 10000))));
            }

            return(result);
        }