public void HandleRequest_ScopeNotFound(Boolean withPrefixDelegation) { Random random = new Random(); UInt32 prefixId = random.NextUInt32(); Byte prefixLength = (Byte)random.Next(20, 60); IPv6Address prefixNetworkAddress = IPv6Address.FromString("fd01::0"); DHCPv6PacketOption[] options = Array.Empty <DHCPv6PacketOption>(); if (withPrefixDelegation == true) { options = new DHCPv6PacketOption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationOption(prefixId, TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), new DHCPv6PacketSuboption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationSuboption(TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), prefixLength, prefixNetworkAddress, Array.Empty <DHCPv6PacketSuboption>()) }) }; } var packet = GetRequestPacket(random, out _, out DUID _, out UInt32 _, true, options); GetMockupResolver(DHCPv6Packet.Empty, out Mock <IScopeResolverManager <DHCPv6Packet, IPv6Address> > scopeResolverMock); DHCPv6RootScope rootScope = GetRootScope(scopeResolverMock); DHCPv6Packet result = rootScope.HandleRequest(packet, GetServerPropertiesResolver()); Assert.Equal(DHCPv6Packet.Empty, result); CheckEventAmount(1, rootScope); CheckHandeledEvent(0, packet, result, rootScope, null, DHCPv6RequestHandledEvent.RequestErrors.ScopeNotFound); }
public void HandleRenew_OnlyPrefix(Boolean isUnicast) { Random random = new Random(); UInt32 prefixId = random.NextUInt32(); Byte prefixLength = (Byte)random.Next(34, 64); IPv6Address prefixNetworkAddress = IPv6Address.FromString("fd01::0"); DHCPv6PacketOption[] options = new DHCPv6PacketOption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationOption(prefixId, TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), new DHCPv6PacketSuboption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationSuboption(TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), prefixLength, prefixNetworkAddress, Array.Empty <DHCPv6PacketSuboption>()) }) }; var packet = isUnicast == true? GetRenewPacket(random, out IPv6Address _, out DUID _, out UInt32 _, false, options) : GetRelayedRenewPacket(random, out IPv6Address _, out DUID _, out UInt32 _, false, options); var resolverInformations = GetMockupResolver(packet, out Mock <IScopeResolverManager <DHCPv6Packet, IPv6Address> > scopeResolverMock); Guid scopeId = random.NextGuid(); DHCPv6RootScope rootScope = GetRootScope(scopeResolverMock); rootScope.Load(new List <DomainEvent> { new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent( new DHCPv6ScopeCreateInstruction { AddressProperties = new DHCPv6ScopeAddressProperties( IPv6Address.FromString("fe80::01"), IPv6Address.FromString("fe80::ff"), new List <IPv6Address> { IPv6Address.FromString("fe80::02") }, preferredLifeTime: TimeSpan.FromDays(0.5), validLifeTime: TimeSpan.FromDays(1), reuseAddressIfPossible: false, prefixDelgationInfo: DHCPv6PrefixDelgationInfo.FromValues(IPv6Address.FromString("2140:1::0"), new IPv6SubnetMaskIdentifier(32), new IPv6SubnetMaskIdentifier(prefixLength)), addressAllocationStrategy: DHCPv6ScopeAddressProperties.AddressAllocationStrategies.Next), ResolverInformation = resolverInformations, Name = "Testscope", Id = scopeId, }), }); DHCPv6Packet result = rootScope.HandleRenew(packet, GetServerPropertiesResolver()); CheckErrorPacket(packet, IPv6Address.Empty, 0, result, DHCPv6PrefixDelegation.FromValues(prefixNetworkAddress, new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), prefixId), DHCPv6StatusCodes.NoBinding); CheckEventAmount(1, rootScope); CheckHandeledEvent(0, packet, result, rootScope, scopeId, DHCPv6RenewHandledEvent.RenewErrors.OnlyPrefixIsNotAllowed); }
public void HandleRelease_NoLeaseFound(Boolean withPrefixDelegation, Boolean isUnicast) { Random random = new Random(); UInt32 prefixId = random.NextUInt32(); Byte prefixLength = (Byte)random.Next(34, 64); IPv6Address prefixNetworkAddress = IPv6Address.FromString("fd01::0"); DHCPv6PacketOption[] options = Array.Empty <DHCPv6PacketOption>(); if (withPrefixDelegation == true) { options = new DHCPv6PacketOption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationOption(prefixId, TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), new DHCPv6PacketSuboption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationSuboption(TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), prefixLength, prefixNetworkAddress, Array.Empty <DHCPv6PacketSuboption>()) }) }; } var packet = isUnicast == true? GetReleasePacket(random, out IPv6Address leasedAddress, out _, out UInt32 iaId, true, options) : GetRelayedReleasePacket(random, out leasedAddress, out _, out iaId, true, options); var resolverInformations = GetMockupResolver(packet, out Mock <IScopeResolverManager <DHCPv6Packet, IPv6Address> > scopeResolverMock); Guid scopeId = random.NextGuid(); Guid leaseId = random.NextGuid(); DateTime leaseCreatedAt = DateTime.UtcNow; DHCPv6RootScope rootScope = GetRootScope(scopeResolverMock); rootScope.Load(new List <DomainEvent> { new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent( new DHCPv6ScopeCreateInstruction { AddressProperties = new DHCPv6ScopeAddressProperties( IPv6Address.FromString("fe80::01"), IPv6Address.FromString("fe80::ff"), new List <IPv6Address> { IPv6Address.FromString("fe80::02") }, preferredLifeTime: TimeSpan.FromDays(0.5), validLifeTime: TimeSpan.FromDays(1), reuseAddressIfPossible: false, prefixDelgationInfo: DHCPv6PrefixDelgationInfo.FromValues(IPv6Address.FromString("2140:1::0"), new IPv6SubnetMaskIdentifier(32), new IPv6SubnetMaskIdentifier(prefixLength)), addressAllocationStrategy: DHCPv6ScopeAddressProperties.AddressAllocationStrategies.Next), ResolverInformation = resolverInformations, Name = "Testscope", Id = scopeId, }), new DHCPv6LeaseCreatedEvent { EntityId = leaseId, Address = leasedAddress, ClientIdentifier = new UUIDDUID(random.NextGuid()), IdentityAssocationId = iaId, ScopeId = scopeId, StartedAt = leaseCreatedAt, ValidUntil = DateTime.UtcNow.AddDays(1), HasPrefixDelegation = withPrefixDelegation, PrefixLength = prefixLength, IdentityAssocationIdForPrefix = prefixId, DelegatedNetworkAddress = prefixNetworkAddress, }, new DHCPv6LeaseActivatedEvent { EntityId = leaseId, ScopeId = scopeId, } }); DHCPv6Packet result = rootScope.HandleRelease(packet, GetServerPropertiesResolver()); CheckErrorPacket(packet, leasedAddress, iaId, result, withPrefixDelegation == false ? DHCPv6PrefixDelegation.None : DHCPv6PrefixDelegation.FromValues(prefixNetworkAddress, new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), prefixId), DHCPv6StatusCodes.NoBinding); DHCPv6Lease lease = rootScope.GetScopeById(scopeId).Leases.GetLeaseById(leaseId); Assert.Equal(LeaseStates.Active, lease.State); CheckEventAmount(1, rootScope); CheckHandeledEvent(0, packet, result, rootScope, scopeId, DHCPv6ReleaseHandledEvent.ReleaseError.NoLeaseFound); }
public void HandleRequest_LeaseFound_LeaseIsPending(Boolean withPrefixDelegation) { Random random = new Random(); UInt32 prefixId = random.NextUInt32(); Byte prefixLength = (Byte)random.Next(20, 60); IPv6Address prefixNetworkAddress = IPv6Address.FromString("fd01::0"); DHCPv6PacketOption[] options = Array.Empty <DHCPv6PacketOption>(); if (withPrefixDelegation == true) { options = new DHCPv6PacketOption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationOption(prefixId, TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), Array.Empty <DHCPv6PacketSuboption>()) }; } var packet = GetRequestPacket(random, out IPv6Address _, out DUID clientDuid, out UInt32 iaId, true, options); var resolverInformations = GetMockupResolver(packet, out Mock <IScopeResolverManager <DHCPv6Packet, IPv6Address> > scopeResolverMock); Guid scopeId = random.NextGuid(); Guid leaseId = random.NextGuid(); IPv6Address leasedAddress = IPv6Address.FromString("fe80::2"); DHCPv6RootScope rootScope = GetRootScope(scopeResolverMock); rootScope.Load(new List <DomainEvent> { new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent( new DHCPv6ScopeCreateInstruction { AddressProperties = new DHCPv6ScopeAddressProperties( IPv6Address.FromString("fe80::0"), IPv6Address.FromString("fe80::ff"), new List <IPv6Address> { IPv6Address.FromString("fe80::1") }, t1: DHCPv6TimeScale.FromDouble(0.5), t2: DHCPv6TimeScale.FromDouble(0.75), preferredLifeTime: TimeSpan.FromDays(0.5), validLifeTime: TimeSpan.FromDays(1), addressAllocationStrategy: DHCPv6ScopeAddressProperties.AddressAllocationStrategies.Next), ResolverInformation = resolverInformations, Name = "Testscope", Id = scopeId, }), new DHCPv6LeaseCreatedEvent { EntityId = leaseId, Address = leasedAddress, ClientIdentifier = clientDuid, IdentityAssocationId = iaId, ScopeId = scopeId, StartedAt = DateTime.UtcNow, ValidUntil = DateTime.UtcNow.AddDays(1), HasPrefixDelegation = withPrefixDelegation, PrefixLength = prefixLength, IdentityAssocationIdForPrefix = prefixId, DelegatedNetworkAddress = prefixNetworkAddress, } }); DHCPv6Packet result = rootScope.HandleRequest(packet, GetServerPropertiesResolver()); CheckPacket(packet, leasedAddress, iaId, result, DHCPv6PacketTypes.REPLY, withPrefixDelegation == false ? DHCPv6PrefixDelegation.None : DHCPv6PrefixDelegation.FromValues(prefixNetworkAddress, new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), prefixId)); CheckEventAmount(2, rootScope); CheckLeaseActivatedEvent(0, scopeId, leaseId, rootScope); CheckHandeledEvent(1, packet, result, rootScope, scopeId, DHCPv6RequestHandledEvent.RequestErrors.NoError); }
public async Task HandleRebind_LeaseFound_ReuseIsNotAllowed_TwoPackets(Boolean withPrefixDelegation) { Random random = new Random(); UInt32 prefixId = random.NextBoolean() == false?random.NextUInt32() : 0; Byte prefixLength = (Byte)random.Next(34, 64); IPv6Address prefixNetworkAddress = IPv6Address.FromString("fd01::0"); DHCPv6PacketOption[] options = Array.Empty <DHCPv6PacketOption>(); if (withPrefixDelegation == true) { options = new DHCPv6PacketOption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationOption(prefixId, TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), Array.Empty <DHCPv6PacketSuboption>()) }; } var packet = GetRelayedRebindPacket(random, out IPv6Address _, out DUID clientDuid, out UInt32 iaId, true, options); var resolverInformations = GetMockupResolver(packet, out Mock <IScopeResolverManager <DHCPv6Packet, IPv6Address> > scopeResolverMock); Guid scopeId = random.NextGuid(); Guid leaseId = random.NextGuid(); IPv6Address leasedAddress = IPv6Address.FromString("fe80::01"); IPv6Address expectedAddress = IPv6Address.FromString("fe80::03"); DateTime leaseCreatedAt = DateTime.UtcNow.AddHours(-2); DHCPv6RootScope rootScope = GetRootScope(scopeResolverMock); rootScope.Load(new List <DomainEvent> { new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent( new DHCPv6ScopeCreateInstruction { AddressProperties = new DHCPv6ScopeAddressProperties( IPv6Address.FromString("fe80::01"), IPv6Address.FromString("fe80::ff"), new List <IPv6Address> { IPv6Address.FromString("fe80::02") }, t1: DHCPv6TimeScale.FromDouble(0.5), t2: DHCPv6TimeScale.FromDouble(0.75), preferredLifeTime: TimeSpan.FromDays(0.5), validLifeTime: TimeSpan.FromDays(1), reuseAddressIfPossible: false, prefixDelgationInfo: DHCPv6PrefixDelgationInfo.FromValues(IPv6Address.FromString("2140:1::0"), new IPv6SubnetMaskIdentifier(32), new IPv6SubnetMaskIdentifier(prefixLength)), addressAllocationStrategy: DHCPv6ScopeAddressProperties.AddressAllocationStrategies.Next), ResolverInformation = resolverInformations, Name = "Testscope", Id = scopeId, }), new DHCPv6LeaseCreatedEvent { EntityId = leaseId, Address = leasedAddress, ClientIdentifier = clientDuid, IdentityAssocationId = iaId, ScopeId = scopeId, StartedAt = leaseCreatedAt, ValidUntil = DateTime.UtcNow.AddDays(1), HasPrefixDelegation = withPrefixDelegation, PrefixLength = prefixLength, IdentityAssocationIdForPrefix = prefixId, DelegatedNetworkAddress = prefixNetworkAddress, }, new DHCPv6LeaseActivatedEvent { EntityId = leaseId, ScopeId = scopeId, } }); Guid serverId = random.NextGuid(); var revokedLease = rootScope.GetScopeById(scopeId).Leases.GetLeaseById(leaseId); DHCPv6Packet result = rootScope.HandleRebind(packet, GetServerPropertiesResolver(serverId)); await Task.Delay(3000); DHCPv6Packet secondResult = rootScope.HandleRebind(packet, GetServerPropertiesResolver(serverId)); Assert.Equal(result, secondResult); DHCPv6Lease lease = CheckLease(0, 1, expectedAddress, scopeId, rootScope, DateTime.UtcNow, clientDuid, iaId, false, withPrefixDelegation); CheckPacket(packet, expectedAddress, iaId, result, DHCPv6PacketTypes.REPLY, withPrefixDelegation == false ? DHCPv6PrefixDelegation.None : DHCPv6PrefixDelegation.FromValues(lease.PrefixDelegation.NetworkAddress, new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), prefixId)); Assert.False(revokedLease.IsActive()); Assert.Equal(LeaseStates.Revoked, revokedLease.State); CheckEventAmount(5, rootScope); CheckRevokedEvent(0, scopeId, leaseId, rootScope); CheckLeaseCreatedEvent(1, clientDuid, iaId, scopeId, rootScope, expectedAddress, lease); CheckLeaseActivatedEvent(2, scopeId, lease.Id, rootScope); CheckHandeledEvent(3, packet, result, rootScope, scopeId, DHCPv6RebindHandledEvent.RebindErrors.NoError); CheckHandeledEvent(4, packet, result, rootScope, scopeId, DHCPv6RebindHandledEvent.RebindErrors.NoError); }
public async Task HandleRenew_OnlyPrefix_LeaseFound_NotReuseAddress(Boolean isUnicast, Boolean sendSecondPacket) { Random random = new Random(); UInt32 prefixId = random.NextUInt32(); Byte prefixLength = 36; IPv6Address prefixNetworkAddress = IPv6Address.FromString("2140:1::0"); IPv6Address leasedAddress = IPv6Address.FromString("fe80::4"); DHCPv6PacketOption[] options = new DHCPv6PacketOption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationOption(prefixId, TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), new DHCPv6PacketSuboption[] { new DHCPv6PacketIdentityAssociationPrefixDelegationSuboption(TimeSpan.FromSeconds(random.Next()), TimeSpan.FromSeconds(random.Next()), prefixLength, prefixNetworkAddress, Array.Empty <DHCPv6PacketSuboption>()) }) }; var packet = isUnicast == true? GetRenewPacket(random, out IPv6Address _, out DUID clientDuid, out UInt32 _, false, options) : GetRelayedRenewPacket(random, out IPv6Address _, out clientDuid, out UInt32 _, false, options); var resolverInformations = GetMockupResolver(packet, out Mock <IScopeResolverManager <DHCPv6Packet, IPv6Address> > scopeResolverMock); Guid scopeId = random.NextGuid(); Guid leaseId = random.NextGuid(); UInt32 iaId = random.NextUInt32(); DateTime leaseCreatedAt = DateTime.UtcNow.AddHours(-random.Next(4, 10)); DHCPv6RootScope rootScope = GetRootScope(scopeResolverMock); rootScope.Load(new List <DomainEvent> { new DHCPv6ScopeEvents.DHCPv6ScopeAddedEvent( new DHCPv6ScopeCreateInstruction { AddressProperties = new DHCPv6ScopeAddressProperties( IPv6Address.FromString("fe80::01"), IPv6Address.FromString("fe80::ff"), new List <IPv6Address> { IPv6Address.FromString("fe80::02") }, preferredLifeTime: TimeSpan.FromDays(0.5), validLifeTime: TimeSpan.FromDays(1), t1: DHCPv6TimeScale.FromDouble(0.5), t2: DHCPv6TimeScale.FromDouble(0.75), reuseAddressIfPossible: false, prefixDelgationInfo: DHCPv6PrefixDelgationInfo.FromValues(IPv6Address.FromString("2140:1::0"), new IPv6SubnetMaskIdentifier(32), new IPv6SubnetMaskIdentifier(prefixLength)), addressAllocationStrategy: DHCPv6ScopeAddressProperties.AddressAllocationStrategies.Random), ResolverInformation = resolverInformations, Name = "Testscope", Id = scopeId, }), new DHCPv6LeaseCreatedEvent { EntityId = leaseId, Address = leasedAddress, ClientIdentifier = clientDuid, IdentityAssocationId = iaId, ScopeId = scopeId, StartedAt = leaseCreatedAt, ValidUntil = DateTime.UtcNow.AddDays(1), HasPrefixDelegation = true, PrefixLength = prefixLength, IdentityAssocationIdForPrefix = prefixId, DelegatedNetworkAddress = prefixNetworkAddress, }, new DHCPv6LeaseActivatedEvent { EntityId = leaseId, ScopeId = scopeId, }, new DHCPv6LeaseRenewedEvent { EntityId = leaseId, ScopeId = scopeId, ResetPrefix = true, End = DateTime.UtcNow.AddDays(1) } }); DHCPv6Packet result = rootScope.HandleRenew(packet, GetServerPropertiesResolver()); DHCPv6Lease lease = CheckLease(0, 1, leasedAddress, scopeId, rootScope, leaseCreatedAt, clientDuid, iaId, false, true); CheckPacket(packet, leasedAddress, 0, result, DHCPv6PacketTypes.REPLY, DHCPv6PrefixDelegation.FromValues(lease.PrefixDelegation.NetworkAddress, new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), prefixId)); DHCPv6Packet secondResponse = null; if (sendSecondPacket == true) { await Task.Delay(1000); secondResponse = rootScope.HandleRenew(packet, GetServerPropertiesResolver()); CheckPacket(packet, leasedAddress, 0, secondResponse, DHCPv6PacketTypes.REPLY, DHCPv6PrefixDelegation.FromValues(lease.PrefixDelegation.NetworkAddress, new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), prefixId)); } CheckPacket(packet, leasedAddress, 0, result, DHCPv6PacketTypes.REPLY, DHCPv6PrefixDelegation.FromValues(lease.PrefixDelegation.NetworkAddress, new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), prefixId)); CheckEventAmount(sendSecondPacket == false ? 2 : 3, rootScope); CheckDHCPv6LeasePrefixAddedEvent(0, prefixId, scopeId, rootScope, lease); CheckHandeledEvent(1, packet, result, rootScope, scopeId, DHCPv6RenewHandledEvent.RenewErrors.NoError); if (sendSecondPacket == true) { CheckHandeledEvent(2, packet, secondResponse, rootScope, scopeId, DHCPv6RenewHandledEvent.RenewErrors.NoError); } var trigger = CheckTrigger <PrefixEdgeRouterBindingUpdatedTrigger>(rootScope); Assert.Null(trigger.OldBinding); Assert.NotNull(trigger.NewBinding); Assert.Equal(leasedAddress, trigger.NewBinding.Host); Assert.Equal(lease.PrefixDelegation.NetworkAddress, trigger.NewBinding.Prefix); Assert.Equal(new IPv6SubnetMask(new IPv6SubnetMaskIdentifier(prefixLength)), trigger.NewBinding.Mask); }