Exemple #1
0
        public async Task <Guid?> Handle(CreateDHCPv4InterfaceListenerCommand request, CancellationToken cancellationToken)
        {
            _logger.LogDebug("Handle started");

            var listener = DHCPv4Listener.Create(
                request.NicId,
                DHCPListenerName.FromString(request.Name),
                IPv4Address.FromString(request.IPv4Addres));

            var possibleListeners = _interfaceEngine.GetPossibleListeners();

            if (possibleListeners.Count(x => x.Address == listener.Address && x.PhysicalInterfaceId == listener.PhysicalInterfaceId) == 0)
            {
                return(null);
            }

            var activeListeners = await _interfaceEngine.GetActiveListeners();

            if (activeListeners.Count(x => x.Address == listener.Address && x.PhysicalInterfaceId == listener.PhysicalInterfaceId) > 0)
            {
                return(null);
            }

            if (await _storageEngine.Save(listener) == false)
            {
                return(null);
            }

            _interfaceEngine.OpenListener(listener);

            return(listener.Id);
        }
Exemple #2
0
        public async Task <IActionResult> GetAllInterface()
        {
            var possibleInterfaces = _interfaceEngine.GetPossibleListeners();
            var activeInterfaces   = await _interfaceEngine.GetActiveListeners();

            List <ActiveDHCPv4InterfaceEntry> activeEntries  = new List <ActiveDHCPv4InterfaceEntry>();
            List <DHCPv4InterfaceEntry>       unboundEntries = new List <DHCPv4InterfaceEntry>();

            foreach (var item in possibleInterfaces)
            {
                var activeInterface = activeInterfaces.FirstOrDefault(x => x.PhysicalInterfaceId == item.PhysicalInterfaceId && x.Address == item.Address);
                if (activeInterface != null)
                {
                    activeEntries.Add(new ActiveDHCPv4InterfaceEntry
                    {
                        SystemId              = activeInterface.Id,
                        IPv4Address           = activeInterface.Address.ToString(),
                        MACAddress            = item.PhysicalAddress,
                        Name                  = activeInterface.Name,
                        PhysicalInterfaceName = item.Interfacename,
                        PhysicalInterfaceId   = activeInterface.PhysicalInterfaceId
                    });
                }
                else
                {
                    unboundEntries.Add(new DHCPv4InterfaceEntry
                    {
                        IPv4Address         = item.Address.ToString(),
                        MACAddress          = item.PhysicalAddress,
                        InterfaceName       = item.Interfacename,
                        PhysicalInterfaceId = item.PhysicalInterfaceId,
                    });
                }
            }

            var detachedInterfaces = activeInterfaces
                                     .Where(x => possibleInterfaces.Count(y => y.PhysicalInterfaceId == x.PhysicalInterfaceId) == 0)
                                     .Select(x => new DetachedDHCPv4InterfaceEntry
            {
                SystemId    = x.Id,
                IPv4Address = x.Address.ToString(),
                Name        = x.Name
            }).ToList();


            var result = new DHCPv4InterfaceOverview
            {
                ActiveEntries   = activeEntries,
                Entries         = unboundEntries,
                DetachedEntries = detachedInterfaces
            };

            return(base.Ok(result));
        }