private void bt_start_Click(object sender, EventArgs e) { NetworkEmulatorConfiguration networkEmulatorConfiguration = new NetworkEmulatorConfiguration(); networkEmulatorConfiguration.dbBandwidth = double.Parse(tb_set_Bandwidth.Text); myNetworkEmulatorDriver.SetDriver(networkEmulatorConfiguration); myNetworkEmulatorDriver.StartDriver(); }
public void SetDriver(NetworkEmulatorConfiguration yourConfiguration) { try { vc = new NetworkEmulator.VirtualChannelClass(); lr = new LinkRule(); fr = new PacketFilterRule(); //带宽 lr.BandQueueRule.dbBandwidth = yourConfiguration.dbBandwidth; lr.BandQueueRule.queue.QueueType = QueueType.NO_QUEUE; //lr.BandQueueRule.queue.dropMode = QueueDropMode.DROP_TAIL; //lr.BandQueueRule.queue.QueueMode = QueueMode.QUEUE_MODE_PACKET; //lr.BandQueueRule.queue.uiQueueSize = 100; //延时 lr.LatencyRule.LatencyType = LatencyType.FIXED_LATENCY; lr.LatencyRule.uLatencyType.FixedLatency.ulLatency = 0; if (0 != vc.SetLinkRule(ref lr, ref lr, 1)) { throw new Exception("Failed to Set LinkRule"); } //NetworkEmulator.PacketFilterRule fr = new PacketFilterRule(); if (0 != vc.InitFilterRule(ref fr)) { throw new Exception("Failed initializing FilterRule"); } fr.ipVersion = NetworkType.ALL_NETWORK; // Adding FilterRule to the VirtualChannel if (0 != vc.AddFilterRule(ref fr)) { throw new Exception("Failed to add FilterRule"); } // Adding VirtualChannel to the emulation if (0 != configurator.SubmitVirtualChannel(vc)) { throw new Exception("Failed to add VirtualChannel to the emulation"); } } catch (Exception e) { PutErrorMessages("Fail to run test API!"); Console.WriteLine("Fail to run test API!"); Console.WriteLine(e); } }