package avnmp.java.tutorial.BuildingApplications;


import java.util.*;


// This is the class of an active packet that generates active packets. Only one instance
// of this class need exist in order to generate LoadPacketAppBasic packets.

public class LoadGenAppBasic extends LoadGenAppBasicBase
{
    long numPkts = 0;


     long PacketsPerSecond = 20;


     Date d = new Date();


    public LoadGenAppBasic()
    {
    }


    private long milliSeconds() {
        return new Date().getTime() - d.getTime();
    }


    private long Seconds()
    {
         long s = milliSeconds() / (long) 1000;

         if(s == 0)
              return 1;
         if(s < 0) {
             System.err.println("Time less than zero.");
             halt();
         }
         return s;
    }


    private double Rate() {
         return (double) numPkts / (double) Seconds();


    public void exec()
    {
           while(Rate() < PacketsPerSecond)
          {
           System.out.println("Packets/Second: "+ Rate());
           LoadPacketAppBasic lp = new LoadPacketAppBasic();
           lp.SendForProcessing("AN-5");
           numPkts++;
          }

           this.sleep(250);
     }
}