Пример #1
0
        public void TestInform_RootScopeAcceptInforms()
        {
            Random random = new Random();

            IPv4Address start         = random.GetIPv4Address();
            IPv4Address end           = random.GetIPv4AddressGreaterThan(start);
            IPv4Address sourceAddress = random.GetIPv4AddressBetween(start, end);

            DHCPv4Packet input = GetInformPacket(random, sourceAddress);

            DHCPv4RootScope rootScope = GetRootScope();

            Guid scopeId = Guid.NewGuid();

            rootScope.Load(new List <DomainEvent> {
                new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
                {
                    AddressProperties = new DHCPv4ScopeAddressProperties(start, end, new List <IPv4Address>(), informsAreAllowd: true),
                    Id = scopeId,
                })
            });

            DHCPv4Packet result = rootScope.HandleInform(input);

            DHCPv4InformHandledEvent domainEvent = TestResult <DHCPv4InformHandledEvent>(
                input, result, false, true, scopeId, rootScope);

            Assert.Equal(InformErros.NoError, domainEvent.Error);
        }
Пример #2
0
        public void TestInform_RandomScopeAcceptInforms()
        {
            Random random = new Random();

            IPv4Address start         = random.GetIPv4Address();
            IPv4Address end           = random.GetIPv4AddressGreaterThan(start);
            IPv4Address sourceAddress = random.GetIPv4AddressBetween(start, end);

            List <Tuple <IPv4Address, IPv4Address> > existingRanges = new List <Tuple <IPv4Address, IPv4Address> >
            {
                new Tuple <IPv4Address, IPv4Address>(start, end),
            };

            DHCPv4Packet input = GetInformPacket(random, sourceAddress);

            Int32 rootScopeAmount     = random.Next(3, 10);
            List <DomainEvent> events = new List <DomainEvent>();

            for (int i = 0; i < rootScopeAmount; i++)
            {
                Guid rootScopeId = Guid.NewGuid();
                Tuple <IPv4Address, IPv4Address> addressRange = random.GenerateUniqueAddressRange(existingRanges);

                events.Add(new DHCPv4ScopeAddedEvent(new DHCPv4ScopeCreateInstruction
                {
                    Id = rootScopeId,
                    AddressProperties = new DHCPv4ScopeAddressProperties
                                            (addressRange.Item1, addressRange.Item2, Array.Empty <IPv4Address>(), informsAreAllowd: true)
                }));

                GenerateScopeTree(
                    random.NextDouble(), random,
                    rootScopeId, existingRanges, events);
            }

            Int32 randomScopeIndex = random.Next(0, events.Count);
            DHCPv4ScopeAddedEvent corelatedScopeEvent = (DHCPv4ScopeAddedEvent)events[randomScopeIndex];

            corelatedScopeEvent.Instructions.AddressProperties = new DHCPv4ScopeAddressProperties
                                                                     (start, end, Array.Empty <IPv4Address>(), informsAreAllowd: true);

            Guid scopeId = corelatedScopeEvent.Instructions.Id;

            DHCPv4RootScope rootScope = GetRootScope();

            rootScope.Load(events);

            DHCPv4Packet result = rootScope.HandleInform(input);

            DHCPv4InformHandledEvent domainEvent = TestResult <DHCPv4InformHandledEvent>(
                input, result, false, true, scopeId, rootScope);

            Assert.Equal(InformErros.NoError, domainEvent.Error);
        }
Пример #3
0
        public void TestInform_ScopeNotFound()
        {
            Random random = new Random();

            IPv4Address  sourceAddress = random.GetIPv4Address();
            DHCPv4Packet input         = GetInformPacket(random, sourceAddress);

            DHCPv4RootScope rootScope = GetRootScope();
            DHCPv4Packet    result    = rootScope.HandleInform(input);

            DHCPv4InformHandledEvent domainEvent = TestResult <DHCPv4InformHandledEvent>(
                input, result, true, false, new Guid?(), rootScope);

            Assert.Equal(InformErros.ScopeNotFound, domainEvent.Error);
        }
Пример #4
0
        private void CheckHandeledEvent(
            Int32 index, InformErros error,
            DHCPv4Packet requestPacket,
            DHCPv4Packet result,
            DHCPv4RootScope rootScope)
        {
            IEnumerable <DomainEvent> changes = rootScope.GetChanges();

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

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

            Assert.Equal(requestPacket, handeledEvent.Request);
            Assert.Equal(result, handeledEvent.Response);
            Assert.Equal(error, handeledEvent.Error);
            if (error == InformErros.NoError)
            {
                Assert.True(handeledEvent.WasSuccessfullHandled);
            }
            else
            {
                Assert.False(handeledEvent.WasSuccessfullHandled);
            }
        }
Пример #5
0
 public DHCPv4PacketHandledEntry(DHCPv4InformHandledEvent entry) : this(entry, DHCPv4MessagesTypes.Inform)
 {
 }