public OfflineController(string networkInterfaceName, string hubHostname, NetworkProfileSetting settings) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { this.underlyingController = new WindowsFirewallOfflineController(networkInterfaceName); } else { this.underlyingController = new LinuxTrafficControlController(settings, networkInterfaceName, hubHostname); } }
private static async Task <MethodResponse> ToggleConnectivity(MethodRequest methodRequest, object userContext) { Log.LogInformation("Direct method toggleConnectivity has been invoked."); (string networkInterfaceName, CancellationToken token) = (Tuple <string, CancellationToken>)userContext; // true for network on (restriction disabled), false for network off (restriction enabled) if (!bool.TryParse(JObject.Parse(methodRequest.DataAsJson)["networkOnValue"].ToString(), out bool networkOnValue)) { throw new ArgumentException($"Unable to parse methodRequest. JsonData: {methodRequest.DataAsJson}"); } Log.LogInformation($"Toggling network {networkInterfaceName} {(networkOnValue ? "on" : "off")}"); INetworkStatusReporter reporter = new NetworkStatusReporter(Settings.Current.TestResultCoordinatorEndpoint, Settings.Current.ModuleId, Settings.Current.TrackingId); NetworkProfileSetting customNetworkProfileSetting = Settings.Current.NetworkRunProfile.ProfileSetting; customNetworkProfileSetting.PackageLoss = 100; var controller = new OfflineController(networkInterfaceName, Settings.Current.IotHubHostname, customNetworkProfileSetting); NetworkControllerStatus networkControllerStatus = networkOnValue ? NetworkControllerStatus.Disabled : NetworkControllerStatus.Enabled; await SetNetworkControllerStatus(controller, networkControllerStatus, reporter, token); return(new MethodResponse((int)HttpStatusCode.OK)); }
public LinuxTrafficControlController(NetworkProfileSetting settings, string networkInterfaceName, string iotHubHostname) { this.networkInterfaceName = networkInterfaceName; this.iotHubHostname = iotHubHostname; this.profileRuleSettings = settings; }
public SatelliteController(string networkInterfaceName, string iotHubHostname, NetworkProfileSetting settings) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { this.underlyingController = new WindowsSatelliteController(networkInterfaceName); } else { this.underlyingController = new LinuxTrafficControlController(settings, networkInterfaceName, iotHubHostname); } }
public static string GetNetworkEmulatorAddRule(string networkInterfaceName, NetworkProfileSetting settings) => $"qdisc add dev {networkInterfaceName} parent 1:2 handle 20: netem loss {settings.PackageLoss}% delay {settings.Delay}ms {settings.Jitter}ms rate {settings.Bandwidth}{settings.BandwidthUnit}";