Esempio n. 1
0
        /**
         * Test invoke the API to run the emulator
         */
        public void TestAPI()
        {
            try
            {
                // Creating an IConfigurator object
                NetworkEmulator.INewConfigurator configurator = new NetworkEmulator.NetworkEmulatorClass();

                // Creating a VirtualChannel object
                NetworkEmulator.VirtualChannel vc = new NetworkEmulator.VirtualChannelClass();

                LinkRule lr = new LinkRule();
                if (0 != vc.InitLinkRule(ref lr))
                {
                    throw new Exception("Failed to initialize LinkRule");
                }

                lr.BandQueueRule.dbBandwidth = 1000;

                lr.BandQueueRule.queue.QueueType          = QueueType.NORMAL_QUEUE;
                lr.BandQueueRule.queue.dropMode           = QueueDropMode.DROP_TAIL;
                lr.BandQueueRule.queue.QueueMode          = QueueMode.QUEUE_MODE_PACKET;
                lr.BandQueueRule.queue.uiQueueSize        = 100;
                lr.BandQueueRule.queue.red.QueueMin       = 50;
                lr.BandQueueRule.queue.red.QueueMax       = 100;
                lr.BandQueueRule.queue.red.MeanPacketSize = 500;


                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");
                }

                NetworkEmulator.INewController Controller = (INewController)configurator;
                Controller.Start();
                System.Threading.Thread.Sleep(30000);
                Controller.Stop(0, 1000);
            }
            catch (Exception e)
            {
                Console.WriteLine("Fail to run test API!");
                Console.WriteLine(e);
            }
        }
Esempio n. 2
0
 public void StopDriver()
 {
     NetworkEmulator.INewController Controller = (INewController)configurator;
     Controller.Stop(0, 1000);
 }