private void FillTeamingInfo(IReadOnlyDictionary <string, NetworkUsage> usages, TeamingNetworkUsage teamingUsage)
        {
            using (var collector = teamingConnector.Connect(teamingUsage.InterfaceName))
            {
                var teamingMode = collector.GetTeamingMode();
                teamingUsage.ChildInterfaces = new HashSet <string>(collector.GetChildPorts());

                // We don't handle nested teaming interfaces.
                if (!teamingUsage.ChildInterfaces.All(x => !IsTeamingInterface(x)))
                {
                    throw new NotSupportedException("Nested teaming interfaces are not supported.");
                }

                // We ignore disabled interfaces.
                var childSpeeds = teamingUsage.ChildInterfaces
                                  .Select(x => usages[x].NetworkMaxMBitsPerSecond)
                                  .Where(x => x > 0);

                // NOTE: Teaming modes description can be seen here: https://github.com/jpirko/libteam/wiki/Infrastructure-Specification
                switch (teamingMode)
                {
                case "activebackup":
                    var activePort = collector.GetActivebackupRunnerPort();
                    teamingUsage.NetworkMaxMBitsPerSecond = usages[activePort].NetworkMaxMBitsPerSecond;
                    return;

                case "roundrobin":
                case "random":
                case "broadcast":
                    teamingUsage.NetworkMaxMBitsPerSecond = childSpeeds.Min();
                    return;

                case "loadbalance":
                case "lacp":
                    teamingUsage.NetworkMaxMBitsPerSecond = childSpeeds.Sum();
                    return;

                default:
                    throw new ArgumentException($"Unknown teaming mode {teamingMode}.");
                }
            }
        }
        private bool TryFillTeamingInfo(IReadOnlyDictionary <string, NetworkUsage> usages, TeamingNetworkUsage teamingUsage, out Exception exception)
        {
            try
            {
                FillTeamingInfo(usages, teamingUsage);
            }
            catch (Exception error)
            {
                exception = error;
                return(false);
            }

            exception = null;
            return(true);
        }