예제 #1
0
        public void ApplyValues(IDictionary <String, String> valueMapper, ISerializer serializer)
        {
            String rawByteValue = serializer.Deserialze <String>(valueMapper[nameof(ClientDuid)]);

            Byte[] parsedBytes = ByteHelper.GetBytesFromHexString(rawByteValue);
            ClientDuid = DUIDFactory.GetDUID(parsedBytes);
        }
예제 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            String rawValue = (String)reader.Value;

            Byte[] value = Convert.FromBase64String(rawValue);

            DUID address = DUIDFactory.GetDUID(value);

            return(address);
        }
예제 #3
0
        public static DHCPv6PacketIdentifierOption FromByteArray(Byte[] data, Int32 offset)
        {
            UInt16 code = ByteHelper.ConvertToUInt16FromByte(data, offset);

            DUID duid = DUIDFactory.GetDUID(data, offset + 4);

            if (duid == DUID.Empty)
            {
                throw new ArgumentException("duid");
            }

            return(new DHCPv6PacketIdentifierOption(code, duid));
        }
예제 #4
0
        public void GetDUID_Unknown()
        {
            Random random = new Random();

            Byte[] value = random.NextBytes(20);
            Byte[] input = new byte[2 + value.Length];
            input[0] = 0;
            input[1] = 17;
            value.CopyTo(input, 2);

            var duid = DUIDFactory.GetDUID(input, 0);

            Assert.NotNull(duid);
            Assert.IsAssignableFrom <UnknownDUID>(duid);

            Assert.Equal(value, duid.Value);
        }
예제 #5
0
        public void Add_WithReplace()
        {
            Byte newCode = 2;

            Random random = new Random();

            Byte[] value = random.NextBytes(20);
            Byte[] input = new byte[2 + value.Length];
            input[0] = 0;
            input[1] = newCode;
            value.CopyTo(input, 2);

            DUIDFactory.AddDUIDType(newCode, (input) => new FakeDUID(), true);

            var duid = DUIDFactory.GetDUID(input);

            Assert.NotNull(duid);
            Assert.IsAssignableFrom <FakeDUID>(duid);
        }
예제 #6
0
        public Boolean ArePropertiesAndValuesValid(IDictionary <String, String> valueMapper, ISerializer serializer)
        {
            if (valueMapper.ContainsKey(nameof(ClientDuid)) == false)
            {
                return(false);
            }

            try
            {
                String rawByteValue = serializer.Deserialze <String>(valueMapper[nameof(ClientDuid)]);
                Byte[] parsedBytes  = ByteHelper.GetBytesFromHexString(rawByteValue);

                var duid = DUIDFactory.GetDUID(parsedBytes);
                return(duid.Type != DUID.DUIDTypes.Unknown);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #7
0
        public void GetDUID_LinkLayerAddressAndTimeDUID()
        {
            String rawInput = "00:01:00:01:23:c4:e7:39:00:15:5d:07:e1:12";

            Byte[]   input      = ByteConverter.FromString(rawInput, ':');
            Byte[]   macAddress = ByteConverter.FromString("00:15:5d:07:e1:12", ':');
            DateTime time       = new DateTime(2019, 1, 6, 16, 20, 09);

            var duid = DUIDFactory.GetDUID(input, 0);

            Assert.NotNull(duid);
            Assert.IsAssignableFrom <LinkLayerAddressAndTimeDUID>(duid);

            LinkLayerAddressAndTimeDUID castedDuid = (LinkLayerAddressAndTimeDUID)duid;

            Assert.Equal(macAddress, castedDuid.LinkLayerAddress);
            Assert.Equal(LinkLayerAddressDUID.DUIDLinkLayerTypes.Ethernet, castedDuid.LinkType);
            Assert.Equal(Beer.DaAPI.Core.Common.DUID.DUIDTypes.LinkLayerAndTime, duid.Type);
            Assert.Equal(time, castedDuid.Time);
        }
예제 #8
0
 public void Add_AlreadyExists()
 {
     Assert.ThrowsAny <Exception>(() =>
                                  DUIDFactory.AddDUIDType(1, (input) => new FakeDUID(), false));
 }