Beispiel #1
0
        public void Variables_SessionFlood_Parallel_Create_Decay()
        {
            using(var gate = new NetGate(null))
              {
              gate.Configure( CONFIG_SESSION.AsLaconicConfig() );
              gate.Start();

              Rule rule;

              Assert.AreEqual(GateAction.Allow, gate.CheckTraffic( new GeneralTraffic{FromAddress="170.12.14.12"}, out rule) );
              Assert.IsNull(rule);

              gate.IncreaseVariable(TrafficDirection.Incoming, "5.5.5.5", "newSession", 8);

              Assert.AreEqual(GateAction.Deny, gate.CheckTraffic( new GeneralTraffic{FromAddress="5.5.5.5"}, out rule) );
              Assert.IsNotNull(rule);
              Assert.AreEqual("Session Flood", rule.Name);

              const int CNT = 10000;
              System.Threading.Tasks.Parallel.For(0, CNT,
                 (i)=>
                 {
                      var address = "addr-{0}".Args(i);
                      gate.IncreaseVariable(TrafficDirection.Incoming, address, "newSession", 8);

                      Rule lr;
                      Assert.AreEqual(GateAction.Deny, gate.CheckTraffic( new GeneralTraffic{FromAddress=address}, out lr) );
                      Assert.IsNotNull(lr);
                      Assert.AreEqual("Session Flood", lr.Name);
                      System.Threading.Thread.Sleep(ExternalRandomGenerator.Instance.NextScaledRandomInteger(1,5));
                 });

              Assert.AreEqual(CNT+1,  gate[TrafficDirection.Incoming].NetState.Count);
              System.Threading.Thread.Sleep(12000);
              Assert.AreEqual( 0, gate[TrafficDirection.Incoming].NetState.Count);

              Assert.AreEqual(GateAction.Allow, gate.CheckTraffic( new GeneralTraffic{FromAddress="5.5.5.5"}, out rule) );
              Assert.IsNull(rule);
              }
        }
Beispiel #2
0
        public void Variables_SessionFlood_2()
        {
            using(var gate = new NetGate(null))
              {
              gate.Configure( CONFIG_SESSION.AsLaconicConfig() );
              gate.Start();

              Rule rule;

              Assert.AreEqual(GateAction.Allow, gate.CheckTraffic( new GeneralTraffic{FromAddress="170.12.14.12"}, out rule) );
              Assert.IsNull(rule);

              gate.IncreaseVariable(TrafficDirection.Incoming, "5.5.5.5", "newSession", 5);

              Assert.AreEqual(GateAction.Allow, gate.CheckTraffic( new GeneralTraffic{FromAddress="170.12.14.12"}, out rule) );
              Assert.IsNull(rule);

              Assert.AreEqual(GateAction.Allow, gate.CheckTraffic( new GeneralTraffic{FromAddress="170.1.99.144"}, out rule) );
              Assert.IsNull(rule);

              Assert.AreEqual(GateAction.Deny, gate.CheckTraffic( new GeneralTraffic{FromAddress="5.5.5.5"}, out rule) );
              Assert.IsNotNull(rule);
              Assert.AreEqual("Session Flood", rule.Name);

              System.Threading.Thread.Sleep(5000);

              Assert.AreEqual(GateAction.Allow, gate.CheckTraffic( new GeneralTraffic{FromAddress="5.5.5.5"}, out rule) );
              Assert.IsNull(rule);

              Assert.AreEqual(GateAction.Allow, gate.CheckTraffic( new GeneralTraffic{FromAddress="170.1.99.144"}, out rule) );
              Assert.IsNull(rule);
              }
        }