Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 protected static DynamicRenewTime GetDynamicRenewTime(DHCPv6DynamicRenewTimeRequest request) =>
 DynamicRenewTime.WithSpecificRange(request.Hours, request.Minutes, request.MinutesToRebound, request.MinutesToEndOfLife);
Exemplo n.º 6
0
 public void DynamicRenewTime_Failed_ReboundGreaterThanLifeTime(Int32 reboundValue, Int32 lifetime)
 {
     Assert.ThrowsAny <ArgumentException>(() => DynamicRenewTime.WithSpecificRange(13, 10, reboundValue, lifetime));
 }
Exemplo n.º 7
0
 public void DynamicRenewTime_Failed_EndOfLifeNotInRange(Int32 lifetime)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(13, 10, 45, lifetime));
 }
Exemplo n.º 8
0
 public void DynamicRenewTime_Failed_ReboundNotInRange(Int32 reboundValue)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(13, 10, reboundValue, 30));
 }
Exemplo n.º 9
0
 public void DynamicRenewTime_Failed_MinutesNotInRange(Int32 minuteValue)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(13, minuteValue, 20, 30));
 }
Exemplo n.º 10
0
 public void DynamicRenewTime_Failed_HoursNotInRange(Int32 hourValue)
 {
     Assert.ThrowsAny <ArgumentOutOfRangeException>(() => DynamicRenewTime.WithSpecificRange(hourValue, 10, 20, 30));
 }