Exemplo n.º 1
0
        private void CheckByteRepresentation(DHCPv6Packet input, IPv6HeaderInformation header)
        {
            Byte[] rawStream    = new Byte[1800];
            Int32  writtenBytes = input.GetAsStream(rawStream);

            Byte[] stream = ByteHelper.CopyData(rawStream, 0, writtenBytes);

            DHCPv6Packet secondPacket = DHCPv6Packet.FromByteArray(stream, header);

            Assert.Equal(input, secondPacket);
        }
Exemplo n.º 2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            DHCPv6Packet packet = (DHCPv6Packet)value;

            Byte[] bytes = packet.GetAsStream();

            serializer.Serialize(writer, new DHCPv6PacketSerializerInfo
            {
                Header = (IPv6HeaderInformation)packet.Header,
                Stream = bytes,
            });
        }
Exemplo n.º 3
0
        public async Task OpenListener_SendPacket_CloseListener()
        {
            await Task.Delay(2000);

            var          comparer    = new ByteArrayComparer();
            DHCPv6Packet dummyPacket = new DHCPv6Packet(null, 4, DHCPv6PacketTypes.Solicit, new List <DHCPv6PacketOption>
            {
                new DHCPv6PacketTrueOption(DHCPv6PacketOptionTypes.RapitCommit),
                new DHCPv6PacketByteOption(DHCPv6PacketOptionTypes.Preference, 14),
            });

            Int32 packetsReceived = 0;

            Byte[] packetAsByte = dummyPacket.GetAsStream();

            var serviceBusMock = new Mock <IServiceBus>(MockBehavior.Strict);

            serviceBusMock.Setup(x => x.Publish(
                                     It.Is <DHCPv6PacketArrivedMessage>(y => comparer.Equals(y.Packet.GetAsStream(), packetAsByte) == true))).Callback(() => packetsReceived++).Returns(Task.CompletedTask).Verifiable();

            Mock <ILoggerFactory> factoryMock = new Mock <ILoggerFactory>(MockBehavior.Strict);

            factoryMock.Setup(x => x.CreateLogger(It.IsAny <String>())).Returns(Mock.Of <ILogger <DHCPv6Server> >());

            IDHCPv6InterfaceEngine engine = new DHCPv6InterfaceEngine(
                serviceBusMock.Object,
                Mock.Of <IDHCPv6StorageEngine>(MockBehavior.Strict),
                factoryMock.Object
                );

            var possibleListener = engine.GetPossibleListeners();
            var listener         = possibleListener.First();

            engine.OpenListener(listener);


            IPAddress  address        = new IPAddress(listener.Address.GetBytes());
            IPEndPoint ownEndPoint    = new IPEndPoint(address, 546);
            IPEndPoint serverEndPoint = new IPEndPoint(address, 547);

            UdpClient client = new UdpClient(ownEndPoint);

            client.Send(packetAsByte, packetAsByte.Length, serverEndPoint);

            Int32 trysLeft = 100;

            while (trysLeft-- > 0 && packetsReceived == 0)
            {
                await Task.Delay(1000);
            }

            engine.CloseListener(listener);
            engine.Dispose();

            client.Send(packetAsByte, packetAsByte.Length, serverEndPoint);
            await Task.Delay(3000);

            Assert.Equal(1, packetsReceived);
            client.Dispose();

            serviceBusMock.Verify(x => x.Publish(
                                      It.Is <DHCPv6PacketArrivedMessage>(y => comparer.Equals(y.Packet.GetAsStream(), packetAsByte) == true)), Times.Once);
        }
Exemplo n.º 4
0
 public DHCPv6PacketInformation(DHCPv6Packet packet)
 {
     Content = packet.GetAsStream();
     Header  = new SimplifiedIPv6HeaderInformation(packet.Header);
 }