예제 #1
0
        public static DHCPv6Packet AsError(DHCPv6Packet requestPacket, DHCPv6StatusCodes errorCode, DUID serverDuid)
        {
            DHCPv6Packet innerReceivedPacket = requestPacket.GetInnerPacket();

            List <DHCPv6PacketOption> packetOptions = new List <DHCPv6PacketOption>();

            {
                foreach (var item in innerReceivedPacket.Options)
                {
                    switch (item)
                    {
                    case DHCPv6PacketIdentityAssociationPrefixDelegationOption option:
                        if (errorCode == DHCPv6StatusCodes.NoAddrsAvail)
                        {
                            packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.NotAvailable(option));
                        }
                        else
                        {
                            packetOptions.Add(DHCPv6PacketIdentityAssociationPrefixDelegationOption.Error(option, errorCode));
                        }
                        break;

                    case DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption option:
                        packetOptions.Add(DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption.Error(option, errorCode));
                        break;

                    default:
                        break;
                    }
                }
            }

            AddOptions(packetOptions, requestPacket, serverDuid, null, null, true);

            DHCPv6Packet innerResponse = new DHCPv6Packet(DHCPv6PacketTypes.REPLY,
                                                          innerReceivedPacket.TransactionId,
                                                          packetOptions);

            DHCPv6Packet response = ConstructPacketWithHeader(requestPacket, innerResponse);

            return(response);
        }
예제 #2
0
 public static DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption Error(DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption item, DHCPv6StatusCodes statusCode) =>
 new DHCPv6PacketIdentityAssociationNonTemporaryAddressesOption(item.Id, TimeSpan.Zero, TimeSpan.Zero, new DHCPv6PacketSuboption[] { new
                                                                                                                                     DHCPv6PacketIdentityAssociationAddressSuboption(item.GetAddress(), TimeSpan.Zero, TimeSpan.Zero, new DHCPv6PacketSuboption[] {
         new DHCPv6PacketStatusCodeSuboption(statusCode)
     }
                                                                                                                                                                                     ) });
예제 #3
0
 public DHCPv6PacketStatusCodeSuboption(DHCPv6StatusCodes statusCode) : this(statusCode, String.Empty)
 {
 }
예제 #4
0
 public DHCPv6PacketStatusCodeSuboption(DHCPv6StatusCodes statusCode, String message) : this((UInt16)statusCode, message)
 {
 }
예제 #5
0
        protected static void CheckErrorPacket(DHCPv6Packet request,
                                               IPv6Address expectedAdress, UInt32 iaId, DHCPv6Packet response, DHCPv6PrefixDelegation prefixDelegation, DHCPv6StatusCodes expectedStatusCode)
        {
            Assert.NotNull(response);
            Assert.NotEqual(DHCPv6Packet.Empty, response);
            Assert.True(response.IsValid);

            Assert.Equal(DHCPv6PacketTypes.REPLY, response.GetInnerPacket().PacketType);

            CheckIfPacketIsCorrectReply(request, response);

            if (iaId != 0)
            {
                var iaOption = response.GetInnerPacket().GetNonTemporaryIdentiyAssocation(iaId);
                Assert.NotNull(iaOption);

                Assert.Equal(TimeSpan.Zero, iaOption.T1);
                Assert.Equal(TimeSpan.Zero, iaOption.T2);

                var uncastedSuboption = iaOption.Suboptions.First();
                Assert.NotNull(uncastedSuboption);
                Assert.IsAssignableFrom <DHCPv6PacketIdentityAssociationAddressSuboption>(uncastedSuboption);

                var addressSubOption = (DHCPv6PacketIdentityAssociationAddressSuboption)uncastedSuboption;

                Assert.Equal(expectedAdress, addressSubOption.Address);
                Assert.Equal(TimeSpan.Zero, addressSubOption.PreferredLifetime);
                Assert.Equal(TimeSpan.Zero, addressSubOption.ValidLifetime);

                Assert.NotEmpty(addressSubOption.Suboptions);
                Assert.Single(addressSubOption.Suboptions);

                var uncastedSubSuboption = addressSubOption.Suboptions.First();
                Assert.NotNull(uncastedSubSuboption);
                Assert.IsAssignableFrom <DHCPv6PacketStatusCodeSuboption>(uncastedSubSuboption);

                var statusSubOption = (DHCPv6PacketStatusCodeSuboption)uncastedSubSuboption;
                Assert.Equal((UInt16)expectedStatusCode, statusSubOption.StatusCode);
                //Assert.False(String.IsNullOrEmpty(statusSubOption.Message));
            }
            if (prefixDelegation != DHCPv6PrefixDelegation.None)
            {
                var iaOption = response.GetInnerPacket().GetPrefixDelegationIdentiyAssocation(prefixDelegation.IdentityAssociation);
                Assert.NotNull(iaOption);

                Assert.Equal(prefixDelegation.IdentityAssociation, iaOption.Id);

                Assert.Equal(TimeSpan.Zero, iaOption.T1);
                Assert.Equal(TimeSpan.Zero, iaOption.T2);

                Assert.NotEmpty(iaOption.Suboptions);
                Assert.Single(iaOption.Suboptions);

                var uncastedSuboption = iaOption.Suboptions.First();
                Assert.NotNull(uncastedSuboption);
                Assert.IsAssignableFrom <DHCPv6PacketIdentityAssociationPrefixDelegationSuboption>(uncastedSuboption);

                var addressSubOption = (DHCPv6PacketIdentityAssociationPrefixDelegationSuboption)uncastedSuboption;

                Assert.Equal(prefixDelegation.Mask.Identifier, addressSubOption.PrefixLength);

                Assert.NotEmpty(addressSubOption.Suboptions);
                Assert.Single(addressSubOption.Suboptions);

                Assert.Equal(TimeSpan.Zero, addressSubOption.PreferredLifetime);
                Assert.Equal(TimeSpan.Zero, addressSubOption.ValidLifetime);

                var uncastedSubSuboption = addressSubOption.Suboptions.First();
                Assert.NotNull(uncastedSubSuboption);
                Assert.IsAssignableFrom <DHCPv6PacketStatusCodeSuboption>(uncastedSubSuboption);


                var statusSubOption = (DHCPv6PacketStatusCodeSuboption)uncastedSubSuboption;
                Assert.Equal((UInt16)(expectedStatusCode == DHCPv6StatusCodes.NoAddrsAvail ? DHCPv6StatusCodes.NoPrefixAvail : expectedStatusCode), statusSubOption.StatusCode);
                //Assert.False(String.IsNullOrEmpty(statusSubOption.Message));
            }
        }
예제 #6
0
 public static DHCPv6PacketIdentityAssociationPrefixDelegationOption Error(DHCPv6PacketIdentityAssociationPrefixDelegationOption item, DHCPv6StatusCodes statusCode) =>
 new DHCPv6PacketIdentityAssociationPrefixDelegationOption(item.Id, TimeSpan.Zero, TimeSpan.Zero, new DHCPv6PacketSuboption[] { new
                                                                                                                                DHCPv6PacketIdentityAssociationPrefixDelegationSuboption(TimeSpan.Zero, TimeSpan.Zero, item.GetPrefixLength(), item.GetNetworkAddress(), new DHCPv6PacketSuboption[] {
         new DHCPv6PacketStatusCodeSuboption(statusCode)
     }
                                                                                                                                                                                         ) });