示例#1
0
        private void CheckHandeledEvent(Int32 index, DHCPv6Packet requestPacket, DHCPv6Packet result, DHCPv6RootScope rootScope, Guid?scopeId, DHCPv6RequestHandledEvent.RequestErrors error)
        {
            IEnumerable <DomainEvent> changes = rootScope.GetChanges();

            Assert.IsAssignableFrom <DHCPv6RequestHandledEvent>(changes.ElementAt(index));

            DHCPv6RequestHandledEvent handeledEvent = (DHCPv6RequestHandledEvent)changes.ElementAt(index);

            Assert.Equal(requestPacket, handeledEvent.Request);
            Assert.Equal(result, handeledEvent.Response);
            Assert.Equal(scopeId, handeledEvent.ScopeId);
            Assert.Equal(error == DHCPv6RequestHandledEvent.RequestErrors.NoError, handeledEvent.WasSuccessfullHandled);
            Assert.Equal(error, handeledEvent.Error);
        }
示例#2
0
        internal DHCPv6Packet HandleRequestInternal(
            DHCPv6Packet packet,
            IDHCPv6ServerPropertiesResolver properyResolver,
            Boolean isRapitCommit,
            out DHCPv6RequestHandledEvent.RequestErrors requestError,
            Boolean onlyGenerateResponse)
        {
            var addressProperties = GetAddressProperties();
            var innerPacket       = packet.GetInnerPacket();

            DUID   clientIdentifier      = innerPacket.GetClientIdentifer();
            UInt32?identityAssociationId = innerPacket.GetNonTemporaryIdentityAssocationId();

            DHCPv6Lease lease;

            if (identityAssociationId.HasValue == true)
            {
                lease = Leases.GetLeaseAssociationIdAndDuid(identityAssociationId.Value, clientIdentifier);
            }
            else
            {
                lease = Leases.GetLeaseByClientDuid(clientIdentifier);
            }

            requestError = DHCPv6RequestHandledEvent.RequestErrors.NoError;
            DHCPv6Packet response;

            if (lease == DHCPv6Lease.Empty)
            {
                response     = DHCPv6Packet.AsError(packet, DHCPv6StatusCodes.NoAddrsAvail, properyResolver.GetServerDuid());
                requestError = DHCPv6RequestHandledEvent.RequestErrors.LeaseNotFound;
            }
            else
            {
                if (onlyGenerateResponse == true)
                {
                    return(DHCPv6Packet.AsReply(packet, addressProperties, GetScopeProperties(), lease, true, properyResolver.GetServerDuid(), isRapitCommit));
                }

                var ancsestorLease = lease.HasAncestor() == true?Leases.GetAncestor(lease) : null;

                if (lease.IsPending() == true)
                {
                    if (identityAssociationId.HasValue == true)
                    {
                        lease.RemovePendingState();
                        if (ancsestorLease != null)
                        {
                            Leases.Revoke(ancsestorLease);
                        }

                        response = DHCPv6Packet.AsReply(packet, addressProperties, GetScopeProperties(), lease, false, properyResolver.GetServerDuid(), isRapitCommit);
                    }
                    else
                    {
                        response     = DHCPv6Packet.AsError(packet, DHCPv6StatusCodes.NoAddrsAvail, properyResolver.GetServerDuid());
                        requestError = DHCPv6RequestHandledEvent.RequestErrors.LeasePendingButOnlyPrefixRequested;
                    }
                }
                else if (lease.IsActive() == true)
                {
                    if (identityAssociationId.HasValue == false)
                    {
                        lease.ActivateAddressPrefix();
                    }

                    response = DHCPv6Packet.AsReply(packet, addressProperties, GetScopeProperties(), lease, true, properyResolver.GetServerDuid(), isRapitCommit);
                }
                else
                {
                    response     = DHCPv6Packet.AsError(packet, DHCPv6StatusCodes.NoAddrsAvail, properyResolver.GetServerDuid());
                    requestError = DHCPv6RequestHandledEvent.RequestErrors.LeaseNotInCorrectState;
                }

                if (requestError == DHCPv6RequestHandledEvent.RequestErrors.NoError)
                {
                    PrefixBinding oldBinding = null;
                    PrefixBinding newBinding = null;

                    if ((ancsestorLease?.PrefixDelegation ?? DHCPv6PrefixDelegation.None) != DHCPv6PrefixDelegation.None)
                    {
                        oldBinding = PrefixBinding.FromLease(ancsestorLease, false);
                    }

                    if (lease.PrefixDelegation != DHCPv6PrefixDelegation.None)
                    {
                        newBinding = PrefixBinding.FromLease(lease, false);
                    }

                    if ((oldBinding != newBinding) && (oldBinding != null || newBinding != null))
                    {
                        base.AddNotificationTrigger(new PrefixEdgeRouterBindingUpdatedTrigger(oldBinding, newBinding, Id));
                    }
                }
            }

            return(response);
        }