Пример #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var info = serializer.Deserialize <EeasySerialibleVersionOfDHCPv6ScopeAddressProperties>(reader);

            DHCPv4ScopeAddressProperties result = null;

            if (info.UseDynamicAddress == true)
            {
                DynamicRenewTime time = DynamicRenewTime.WithSpecificRange(
                    info.DynamicAddressHour.Value, info.DynamicAddressMinute.Value,
                    info.DynamicAddressReboundingInterval.Value, info.DynamicAddressLeaseInterval.Value);

                result = new DHCPv4ScopeAddressProperties(info.Start, info.End, info.ExcludedAddresses,
                                                          time, info.NetworkMask,
                                                          reuseAddressIfPossible: info.ReuseAddressIfPossible, addressAllocationStrategy: info.AddressAllocationStrategy,
                                                          supportDirectUnicast: info.SupportDirectUnicast, acceptDecline: info.AcceptDecline, informsAreAllowd: info.InformsAreAllowd
                                                          );
            }
            else
            {
                result = new DHCPv4ScopeAddressProperties(info.Start, info.End, info.ExcludedAddresses,
                                                          renewalTime: info.RenewalTime, preferredLifetime: info.PreferredLifetime, leaseTime: info.LeaseTime, info.NetworkMask,
                                                          reuseAddressIfPossible: info.ReuseAddressIfPossible, addressAllocationStrategy: info.AddressAllocationStrategy,
                                                          supportDirectUnicast: info.SupportDirectUnicast, acceptDecline: info.AcceptDecline, informsAreAllowd: info.InformsAreAllowd
                                                          );
            }


            return(result);
        }
Пример #2
0
        public void DynamicRenewTime_WithSpecificRange()
        {
            var time = DynamicRenewTime.WithSpecificRange(20, 45, 15, 25);

            Assert.Equal(20, time.Hour);
            Assert.Equal(45, time.Minutes);

            Assert.Equal((UInt32)15, time.MinutesToRebound);
            Assert.Equal((UInt32)25, time.MinutesToEndOfLife);
        }
Пример #3
0
        public void DynamicRenewTime_WithDefaultRange()
        {
            var time = DynamicRenewTime.WithDefaultRange(20, 45);

            Assert.Equal(20, time.Hour);
            Assert.Equal(45, time.Minutes);

            Assert.Equal((UInt32)30, time.MinutesToRebound);
            Assert.Equal((UInt32)60, time.MinutesToEndOfLife);
        }
Пример #4
0
 protected ScopeAddressProperties(
     TAddress start,
     TAddress end,
     IEnumerable <TAddress> excluded,
     Boolean?reuseAddressIfPossible = null,
     AddressAllocationStrategies?addressAllocationStrategy = null,
     Boolean?supportDirectUnicast = null,
     Boolean?acceptDecline        = null,
     Boolean?informsAreAllowd     = null,
     DynamicRenewTime renewTime   = null
     ) : this(start, end, excluded, reuseAddressIfPossible, addressAllocationStrategy, supportDirectUnicast, acceptDecline, informsAreAllowd)
 {
     UseDynamicRewnewTime = true;
     DynamicRenewTime     = renewTime;
 }
Пример #5
0
 public DHCPv4ScopeAddressProperties(
     IPv4Address start,
     IPv4Address end,
     IEnumerable <IPv4Address> excluded,
     DynamicRenewTime rewnewTime,
     Byte?maskLength = null,
     Boolean?reuseAddressIfPossible = null,
     AddressAllocationStrategies?addressAllocationStrategy = null,
     Boolean?supportDirectUnicast = null,
     Boolean?acceptDecline        = null,
     Boolean?informsAreAllowd     = null
     ) : base(start, end, excluded, reuseAddressIfPossible, addressAllocationStrategy, supportDirectUnicast, acceptDecline, informsAreAllowd, rewnewTime)
 {
     Mask = (maskLength == null || maskLength == 0) ? null : new IPv4SubnetMask(new IPv4SubnetMaskIdentifier(maskLength.Value));
 }
Пример #6
0
 public DHCPv6ScopeAddressProperties(
     IPv6Address start,
     IPv6Address end,
     IEnumerable <IPv6Address> excluded,
     DynamicRenewTime dynamicRenewTime,
     Boolean?reuseAddressIfPossible = null,
     AddressAllocationStrategies?addressAllocationStrategy = null,
     Boolean?supportDirectUnicast = null,
     Boolean?acceptDecline        = null,
     Boolean?informsAreAllowd     = null,
     Boolean?rapitCommitEnabled   = null,
     DHCPv6PrefixDelgationInfo prefixDelgationInfo = null
     ) : base(start, end, excluded, reuseAddressIfPossible, addressAllocationStrategy, supportDirectUnicast, acceptDecline, informsAreAllowd, dynamicRenewTime)
 {
     RapitCommitEnabled  = rapitCommitEnabled;
     PrefixDelgationInfo = prefixDelgationInfo;
 }
Пример #7
0
        public void DHCPv4ScopeAddressProperties_Inheritance_DynamicAddress_OverrideByKid()
        {
            Random random = new Random();

            IPv4Address start = random.GetIPv4Address();
            IPv4Address end   = random.GetIPv4AddressGreaterThan(start);

            Guid grantParentId = random.NextGuid();
            Guid parentId      = random.NextGuid();
            Guid childId       = random.NextGuid();

            List <DomainEvent> events = new List <DomainEvent>();

            events.Add(new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
            {
                Id = grantParentId,
                AddressProperties = new DHCPv4ScopeAddressProperties(start, end, Array.Empty <IPv4Address>(), DynamicRenewTime.WithDefaultRange(11, 30), 12, true, Next, true, true, true),
            }));
            events.Add(new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
            {
                Id                = parentId,
                ParentId          = grantParentId,
                AddressProperties = new DHCPv4ScopeAddressProperties(start, end, Array.Empty <IPv4Address>(), DynamicRenewTime.WithDefaultRange(12, 30)),
            }));
            events.Add(new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
            {
                Id                = childId,
                ParentId          = parentId,
                AddressProperties = new DHCPv4ScopeAddressProperties(start, end, Array.Empty <IPv4Address>(), DynamicRenewTime.WithDefaultRange(13, 30)),
            }));

            var rootScope = GetRootScope();

            rootScope.Load(events);

            var childScope = rootScope.GetScopeById(childId);
            var properties = childScope.GetAddressProperties();

            Assert.True(properties.UseDynamicRewnewTime);
            Assert.Equal(DynamicRenewTime.WithDefaultRange(13, 30), properties.DynamicRenewTime);
        }
Пример #8
0
        public void DHCPv4ScopeAddressProperties_WithRenewTime_FailedConstructor_NullInputs()
        {
            Random      random = new Random();
            IPv4Address end    = random.GetIPv4Address();
            IPv4Address start  = random.GetIPv4AddressGreaterThan(end);

            DynamicRenewTime renewTime = DynamicRenewTime.WithDefaultRange(22, 30);

            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(start, end, null, renewTime));
            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(null, end, Array.Empty <IPv4Address>(), renewTime));
            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(start, null, Array.Empty <IPv4Address>(), renewTime));

            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(start, null, null, renewTime));
            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(null, end, null, renewTime));
            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(null, null, Array.Empty <IPv4Address>(), renewTime));

            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(null, null, null, renewTime));

            DynamicRenewTime nullRenewTime = null;

            Assert.ThrowsAny <Exception>(() => new DHCPv4ScopeAddressProperties(null, null, null, nullRenewTime));
        }
Пример #9
0
        public void DynamicRenewTime_GetLeaseTimers()
        {
            DateTime now = DateTime.Now;

            DateTime expectedLeaseTime = now.AddHours(2).AddMinutes(30);
            // add ten seconds as for the "runtime" of the test
            TimeSpan smallestExpectTimeRange = (expectedLeaseTime - now).Add(TimeSpan.FromMinutes(-10)).Add(TimeSpan.FromSeconds(-30));
            TimeSpan greatestExpectTimeRange = (expectedLeaseTime - now).Add(TimeSpan.FromMinutes(10)).Add(TimeSpan.FromSeconds(30));

            var time = DynamicRenewTime.WithSpecificRange(expectedLeaseTime.Hour, expectedLeaseTime.Minute, 30, 60);

            for (int i = 0; i < 100; i++)
            {
                var spans = time.GetLeaseTimers();

                Assert.True(spans.RenewTime >= smallestExpectTimeRange);
                Assert.True(spans.RenewTime <= greatestExpectTimeRange);

                Assert.Equal(spans.RenewTime + TimeSpan.FromMinutes(30), spans.ReboundTime);
                Assert.Equal(spans.RenewTime + TimeSpan.FromMinutes(60), spans.Lifespan);
            }
        }
Пример #10
0
        public void SerializeAndDeserialize_WithDynamicRenew()
        {
            Random random = new Random();

            DynamicRenewTime time = DynamicRenewTime.WithSpecificRange(random.Next(1, 20), random.Next(10, 60), random.Next(20, 40), random.Next(50, 60));

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Converters.Add(new IPv4AddressJsonConverter());
            settings.Converters.Add(new DHCPv4ScopeAddressPropertiesConverter());

            var input = new DHCPv4ScopeAddressProperties(
                IPv4Address.FromString("192.168.10.20"), IPv4Address.FromString("192.168.10.50"),
                new List <IPv4Address> {
                IPv4Address.FromString("192.168.10.30"), IPv4Address.FromString("192.168.10.34")
            },
                time,
                (Byte)random.Next(10, 30), random.NextBoolean(), DaAPI.Core.Scopes.ScopeAddressProperties <DHCPv4ScopeAddressProperties, IPv4Address> .AddressAllocationStrategies.Next, random.NextBoolean(), random.NextBoolean(), random.NextBoolean());

            String serialized = JsonConvert.SerializeObject(input, settings);
            var    actual     = JsonConvert.DeserializeObject <DHCPv4ScopeAddressProperties>(serialized, settings);

            Assert.Equal(input, actual);
        }
Пример #11
0
        public void DHCPv4ScopeAddressProperties_ValueAreValidForRoot_WithDynamicRenew()
        {
            Random random = new Random();

            IPv4Address start = random.GetIPv4Address();
            IPv4Address end   = random.GetIPv4AddressGreaterThan(start);

            DynamicRenewTime time = DynamicRenewTime.WithDefaultRange(23, 10);

            DHCPv4ScopeAddressProperties validProperties = new DHCPv4ScopeAddressProperties(
                start, end, Array.Empty <IPv4Address>(),
                time,
                24,
                random.NextBoolean(),
                DHCPv4ScopeAddressProperties.AddressAllocationStrategies.Next,
                random.NextBoolean(), random.NextBoolean(), random.NextBoolean()
                );

            Boolean shouldBeValid = validProperties.ValueAreValidForRoot();

            Assert.True(shouldBeValid);
            Assert.True(validProperties.UseDynamicRewnewTime);
            Assert.Equal(time, validProperties.DynamicRenewTime);

            List <DHCPv4ScopeAddressProperties> invalidProperties = new List <DHCPv4ScopeAddressProperties>
            {
                new DHCPv4ScopeAddressProperties(
                    start, end, Array.Empty <IPv4Address>(),
                    time,
                    0,
                    random.NextBoolean(),
                    DHCPv4ScopeAddressProperties.AddressAllocationStrategies.Next,
                    random.NextBoolean(), random.NextBoolean(), random.NextBoolean()
                    ),
                new DHCPv4ScopeAddressProperties(
                    start, end, Array.Empty <IPv4Address>(),
                    time,
                    24,
                    null,
                    DHCPv4ScopeAddressProperties.AddressAllocationStrategies.Next,
                    random.NextBoolean(), random.NextBoolean(), random.NextBoolean()
                    ),
                new DHCPv4ScopeAddressProperties(
                    start, end, Array.Empty <IPv4Address>(),
                    time,
                    24,
                    random.NextBoolean(),
                    null,
                    random.NextBoolean(), random.NextBoolean(), random.NextBoolean()
                    ),
                new DHCPv4ScopeAddressProperties(
                    start, end, Array.Empty <IPv4Address>(),
                    time,
                    24,
                    random.NextBoolean(),
                    DHCPv4ScopeAddressProperties.AddressAllocationStrategies.Next,
                    null, random.NextBoolean(), random.NextBoolean()
                    ),
                new DHCPv4ScopeAddressProperties(
                    start, end, Array.Empty <IPv4Address>(),
                    time,
                    24,
                    random.NextBoolean(),
                    DHCPv4ScopeAddressProperties.AddressAllocationStrategies.Next,
                    random.NextBoolean(), null, random.NextBoolean()
                    ),
                new DHCPv4ScopeAddressProperties(
                    start, end, Array.Empty <IPv4Address>(),
                    time,
                    24,
                    random.NextBoolean(),
                    DHCPv4ScopeAddressProperties.AddressAllocationStrategies.Next,
                    random.NextBoolean(), random.NextBoolean(), null
                    ),
            };

            foreach (var item in invalidProperties)
            {
                Boolean shouldBeInvalid = item.ValueAreValidForRoot();
                Assert.False(shouldBeInvalid);
                Assert.True(item.UseDynamicRewnewTime);
            }
        }
Пример #12
0
 protected static DynamicRenewTime GetDynamicRenewTime(DHCPv6DynamicRenewTimeRequest request) =>
 DynamicRenewTime.WithSpecificRange(request.Hours, request.Minutes, request.MinutesToRebound, request.MinutesToEndOfLife);
Пример #13
0
 public void DynamicRenewTime_Failed_HoursNotInRange(Int32 hourValue)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(hourValue, 10, 20, 30));
 }
Пример #14
0
        public void DHCPv4ScopeAddressProperties_Inheritance_DynamicAddress_OverrideByParentWithStatic2()
        {
            Random random = new Random();

            IPv4Address start = random.GetIPv4Address();
            IPv4Address end   = random.GetIPv4AddressGreaterThan(start);

            Guid grantParentId = random.NextGuid();
            Guid parentId      = random.NextGuid();
            Guid childId       = random.NextGuid();

            List <DomainEvent> events = new List <DomainEvent>();

            events.Add(new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
            {
                Id = grantParentId,
                AddressProperties = new DHCPv4ScopeAddressProperties(start, end, Array.Empty <IPv4Address>(), TimeSpan.FromHours(2), TimeSpan.FromHours(4), TimeSpan.FromHours(6), 12, true, Next, true, true, true),
            }));
            events.Add(new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
            {
                Id                = parentId,
                ParentId          = grantParentId,
                AddressProperties = new DHCPv4ScopeAddressProperties(start, end, Array.Empty <IPv4Address>(), DynamicRenewTime.WithDefaultRange(11, 30)),
            }));
            events.Add(new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
            {
                Id                = childId,
                ParentId          = parentId,
                AddressProperties = new DHCPv4ScopeAddressProperties(start, end, Array.Empty <IPv4Address>(), preferredLifetime: TimeSpan.FromHours(3)),
            }));

            var rootScope = GetRootScope();

            rootScope.Load(events);

            var childScope = rootScope.GetScopeById(childId);
            var properties = childScope.GetAddressProperties();

            Assert.False(properties.UseDynamicRewnewTime);
            Assert.Null(properties.DynamicRenewTime);
            Assert.Equal(TimeSpan.FromHours(2), properties.RenewalTime);
            Assert.Equal(TimeSpan.FromHours(3), properties.PreferredLifetime);
            Assert.Equal(TimeSpan.FromHours(6), properties.LeaseTime);
        }
Пример #15
0
 public void DynamicRenewTime_Failed_MinutesNotInRange(Int32 minuteValue)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(13, minuteValue, 20, 30));
 }
Пример #16
0
 public void DynamicRenewTime_Failed_ReboundGreaterThanLifeTime(Int32 reboundValue, Int32 lifetime)
 {
     Assert.ThrowsAny <ArgumentException>(() => DynamicRenewTime.WithSpecificRange(13, 10, reboundValue, lifetime));
 }
Пример #17
0
 public void DynamicRenewTime_Failed_EndOfLifeNotInRange(Int32 lifetime)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(13, 10, 45, lifetime));
 }
Пример #18
0
 public void DynamicRenewTime_Failed_ReboundNotInRange(Int32 reboundValue)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(13, 10, reboundValue, 30));
 }