ADD

Document Sample
ADD Powered By Docstoc
					Gidon Levy       037283629
Amnon Yeshno 036204279

             1
                                             Table of Contents
1. Use cases..................................................................................................................... 7
  1.1.    Use Case no. 1: Loading a configuration script file ....................................... 8
  1.2.    Use Case no. 2: Loading a log file .................................................................... 9
  1.3.    Use Case no. 3: Running the simulator ......................................................... 10
  1.4.    Use Case no. 4: Displaying a graph ............................................................... 11
  1.5.    Use Case no. 5: Stopping the simulator execution ....................................... 12
2. Data Model .............................................................................................................. 13
  2.1.    Description of Data Objects ........................................................................... 13
     2.1.1.   DataManager ........................................................................................... 13
     2.1.2.   StatisticsHandler ..................................................................................... 14
     2.1.3.   Command................................................................................................. 14
     2.1.4.   CreateClientCommand........................................................................... 15
     2.1.5.   ConnectClientCommand ........................................................................ 15
     2.1.6.   DisconnectClientCommand ................................................................... 15
     2.1.7.   DownloadCommand ............................................................................... 16
     2.1.8.   UploadCommand .................................................................................... 16
     2.1.9.   KillClientCommand ................................................................................ 16
     2.1.10. SleepCommand ....................................................................................... 17
     2.1.11. BasicCommand ....................................................................................... 17
     2.1.12. StringCommand ...................................................................................... 17
     2.1.13. NumberCommand .................................................................................. 17
     2.1.14. BooleanCommand ................................................................................... 18
     2.1.15. MathCommand ....................................................................................... 18
     2.1.16. AssignmentCommand............................................................................. 18
     2.1.17. LookupCommand ................................................................................... 19
     2.1.18. BlockCommand ....................................................................................... 19
     2.1.19. IfCommand .............................................................................................. 19
     2.1.20. ForCommand .......................................................................................... 19
     2.1.21. Client ........................................................................................................ 20
     2.1.22. GnutellaClient ......................................................................................... 20
     2.1.23. ConnectionData ....................................................................................... 20
     2.1.24. Message .................................................................................................... 20
     2.1.25. GUID ........................................................................................................ 21
     2.1.26. PingMessage ............................................................................................ 21
     2.1.27. PongMessage ........................................................................................... 21
     2.1.28. SearchMessage ........................................................................................ 21
     2.1.29. SearchReplyMessage .............................................................................. 21
     2.1.30. DataStripe ................................................................................................ 22
  2.2.    Data Objects Relationships ............................................................................ 23
  Client/GnutellaClient/Message .................................................................................. 24
  2.3.    Databases ......................................................................................................... 25
3. Behavioral Analysis ................................................................................................ 25
  3.1.    Sequence Diagrams ......................................................................................... 25
     3.1.1.   Load Script File ....................................................................................... 25
     3.1.2.   Execute Simulator ................................................................................... 26



                                                                2
     3.1.3.     Display graph .......................................................................................... 27
     3.1.4.     Stop Execution......................................................................................... 28
  3.2.    Events ............................................................................................................... 29
  3.3.    States ................................................................................................................ 30
     3.3.1.     High Level State Chart ........................................................................... 30
     3.3.2.     Client-Server<serverIP> State Chart ................................................... 31
4. Object-Oriented Analysis ....................................................................................... 32
  4.1.    Class Diagrams ................................................................................................ 32
     4.1.1.     Class Diagram for the package: Main .................................................. 32
     4.1.2.     Class Diagram for the package: Simulator .......................................... 32
     4.1.3.     Class Diagram of the package: Statistics .............................................. 33
     4.1.4.     Class Diagram of the package: ScriptCompiler ................................... 34
     4.1.5.     Class Diagram of the package: Command ........................................... 36
  4.1.6.      Class diagram of the package: Client........................................................ 37
  4.1.7.      Class diagram of the package: GnutellaClient ......................................... 37
  4.1.8.      Class diagram of the package: Client/GnutellaClient/HTTPServer ...... 39
  4.1.9.      Class diagram of the package: Client/GnutellaClient/Message.............. 40
  4.1.11. Class diagram of the package: Client/GnutellaClient/Utilities ............... 42
  4.1.12. Class diagram of the package: GUI .......................................................... 43
  4.1.13. Class diagram of the package GUI/Graph ............................................... 44
  4.2.    Class Description ............................................................................................. 45
     4.2.1.     Classes of package: Main ....................................................................... 45
     4.2.1.1.     LCPMain ............................................................................................. 45
     4.2.2.     Classes of package: Simulator ............................................................... 45
     4.2.2.1.     DataManager ....................................................................................... 45
     4.2.2.2.     SimulatorExecuter .............................................................................. 47
     4.2.2.3.     TimeScheduler..................................................................................... 47
     4.2.3.     Classes of package: Statistics ................................................................. 49
     4.2.3.1.     StatisticsHandler ................................................................................. 49
     4.2.3.2.     StatisticsViewer ................................................................................... 52
     4.2.3.3.     Logger .................................................................................................. 53
     4.2.3.4.     DataStripe ............................................................................................ 55
     4.2.4.     Classes of package: ScriptCompiler ...................................................... 56
     4.2.4.1.     ScriptCompiler .................................................................................... 56
     4.2.4.2.     ScriptScanner ...................................................................................... 56
     4.2.4.3.     ScriptParser ......................................................................................... 57
     4.2.4.4.     CommandsGenerator ......................................................................... 57
     4.2.4.5.     TaggedToken ....................................................................................... 57
     4.2.4.6.     Utilities ................................................................................................. 57
     4.2.5.     Classes of package: Command .............................................................. 59
     4.2.5.1.     Command............................................................................................. 59
     4.2.5.2.     CreateClientCommand....................................................................... 59
     4.2.5.3.     ConnectClientCommand .................................................................... 60
     4.2.5.4.     DisconnectClientCommand ............................................................... 60
     4.2.5.5.     DownloadCommand ........................................................................... 61
     4.2.5.6.     UploadCommand ................................................................................ 61



                                                                 3
   4.2.5.7.       KillClientCommand ............................................................................ 62
   4.2.5.8.       SleepCommand ................................................................................... 62
   4.2.5.9.       BasicCommand ................................................................................... 62
   4.2.5.10.      StringCommand .................................................................................. 63
   4.2.5.11.      NumberCommand .............................................................................. 63
   4.2.5.12.      BooleanCommand ............................................................................... 63
   4.2.5.13.      MathCommand ................................................................................... 64
   4.2.5.14.      AssignmentCommand......................................................................... 64
   4.2.5.15.      LookupCommand ............................................................................... 65
   4.2.5.16.      BlockCommand ................................................................................... 65
   4.2.5.17.      IfCommand .......................................................................................... 65
   4.2.5.18.      ForCommand ...................................................................................... 66
   4.2.6.     Classes of package: Client ...................................................................... 66
   4.2.6.1.       Client .................................................................................................... 66
   4.2.6.2.       ClientFactory ....................................................................................... 68
   4.2.6.3.       ClientsHolder....................................................................................... 69
   None.......................................................................................................................... 69
   4.2.6.4.       KBytesCounter .................................................................................... 69
   4.2.6.5.       LatencyCounter................................................................................... 70
   4.2.6.6.       Session .................................................................................................. 70
   4.2.6.7.       SharedFilesManager ........................................................................... 71
4.2.7.      Classes of package: Client/GnutellaClient................................................ 72
   4.2.7.1.       GnutellaClient ..................................................................................... 72
   4.2.7.2.       GnutellaSession ................................................................................... 72
   4.2.7.3.       Connection ........................................................................................... 72
   4.2.7.4.       ConnectionData ................................................................................... 73
   4.2.7.5.       Downloader .......................................................................................... 73
   4.2.7.6.       GnutellaListener ................................................................................. 74
   4.2.7.7.       Monitor ................................................................................................ 75
   4.2.7.8.       SearchReceiver .................................................................................... 75
   4.2.7.9.       SearchRespondReceiver ..................................................................... 76
   4.2.7.10.      SocketFactory ...................................................................................... 76
4.2.8.      Classes of package: Client/GnutellaClient/HTTPServer ........................ 77
   4.2.8.1.       HTTPServer ........................................................................................ 77
   4.2.8.2.       HTTPRequestHandler ........................................................................ 77
4.2.9.      Classes of package: Client/GnutellaClient/Message ................................ 78
   4.2.9.1.       Message ................................................................................................ 78
   4.2.9.2.       GUID .................................................................................................... 78
   4.2.9.3.       MessageFactory ................................................................................... 79
   4.2.9.4.       PingMessage ........................................................................................ 79
   4.2.9.5.       PongMessage ....................................................................................... 79
   4.2.9.6.       SearchMessage .................................................................................... 79
   4.2.9.7.       SearchReplyMessage .......................................................................... 79
4.2.10. Classes of package: Client/GnutellaClient/Router .................................. 80
   4.2.10.1.      Router................................................................................................... 80
   4.2.10.2.      RouteTable........................................................................................... 80



                                                               4
     4.2.10.3.    OriginateTable .................................................................................... 81
  4.2.11. Classes of package: Client/GnutellaClient/Router .................................. 81
     4.2.11.1.    BoundedQueue .................................................................................... 81
     4.2.11.2.    Mutex ................................................................................................... 82
     4.2.11.3.    PortGenerator ..................................................................................... 82
  4.2.12. Classes of package: GUI ............................................................................. 82
     4.2.12.1.    LCP_GUI ............................................................................................. 82
     4.2.12.2.    GlobalStatisticsContents .................................................................... 82
     4.2.12.3.    ServerStatisticsContents..................................................................... 82
     4.2.12.4.    GUIEventsHandler ............................................................................. 82
     4.2.12.5.    InformationMessage ........................................................................... 83
     4.2.12.6.    PreferncesDialog ................................................................................. 83
     4.2.12.7.    AboutDialog ......................................................................................... 83
  4.2.13. Classes of package: GUI/Graph ................................................................ 84
     4.2.13.1.    DirectedGraphXYPlotter ................................................................... 84
     4.2.13.2.    Dot ........................................................................................................ 84
     4.2.13.3.    XRulerBar ........................................................................................... 84
     4.2.13.4.    YRulerBar ........................................................................................... 84
     4.2.13.5.    GraphixParameters ............................................................................ 84
     4.2.13.6.    Utilities ................................................................................................. 84
  4.3.    Packages ........................................................................................................... 85
     4.3.1.    GnutellaClient packages ......................................................................... 85
     4.3.2.    GUI Packages .......................................................................................... 87
  4.4.    Unit Testing ..................................................................................................... 88
     4.4.1.    Unit testing for DataManager class ....................................................... 88
     4.4.2.    Unit testing for SimulatorExecuter class .............................................. 88
     4.4.3.    Unit testing for StatisticsHandler class ................................................. 88
     4.4.4.    Unit testing for StatisticsViewer class ................................................... 88
     4.4.5.    Unit testing for Command class............................................................. 89
     4.4.6.    Unit testing for Client class .................................................................... 89
     4.4.7.    Unit testing for Logger class .................................................................. 89
5. System Architecture ............................................................................................... 90
  5.1.    System architecture diagram ......................................................................... 90
  5.2.    Deployment diagram ...................................................................................... 91
6. User Interface Draft................................................................................................ 91
  6.1.    The main frame during simulator execution ................................................ 91
  6.2.    The load script frame...................................................................................... 92
  6.3.    The load log file frame .................................................................................... 93
  6.4.    The preferences of the system frame ............................................................. 94
7. Testing ...................................................................................................................... 95
  7.1.    Testing the script compiler ............................................................................. 95
  7.2.    Testing the client ............................................................................................. 95
  7.3.    Testing the execution ...................................................................................... 95
  7.4.    Testing statistics viewing ................................................................................ 95
  7.5.    Testing the GUI ............................................................................................... 95
  7.6.    Testing speed constraints ............................................................................... 95



                                                                 5
  7.7. Testing platform constraints .......................................................................... 95
8. Task List .................................................................................................................. 96




                                                                6
1. Use cases




         Load configuration script file

                                                 Load log file




                                                 Run the simulator




       User




                                             Display graph




                                   Stop simulator execution




                                             7
   1.1.    Use Case no. 1: Loading a configuration script file

The story: The user chooses to load a configuration script file
Primary Actors: User
Stakeholders and Interests:
              User: wants to execute the script in the Simulator.
Pre-conditions: The system is on non-executing mode.
Post-conditions: There is a loaded script in the system memory and the system is ready to
execute it.
Main Success Scenarios:

Actor Action (or Intention)               System Responsibility

1. The user chooses to open a script
   file.
                                          2. The system displays the script file
                                             load panel.
3. The user chooses a script file to
   load.
                                          4. The system loads the script file.
                                          5. The system analyzes the script.
                                          6. The system displays success
                                             message.


Extensions (Alternative Flows) (1):

Actor Action (or Intention)               System Responsibility


                                          4. The system finds the script file
                                             syntactically wrong.
                                          5. The system doesn't load the script
                                             file.
                                          6. The system notifies the user about
                                             wrong script syntax.
                                          7. The system points to the syntax
                                             error.




                                            8
Extensions (Alternative Flows) (2):

Actor Action (or Intention)                   System Responsibility


                                              4. The system finds the script file
                                                 logically wrong.
                                              5. The system doesn't load the script
                                                 file.
                                              6. The system notifies the user about
                                                 illegal script file.
                                              7. The system points to the illegal
                                                 command.


   1.2.      Use Case no. 2: Loading a log file

   The story: The user chooses to load a log file.
   Primary Actors: User
   Stakeholders and Interests:
             User: wants to load a log file.
   Pre-conditions: The system is on non-executing mode.
   Post-conditions: There is a loaded log file in the system memory.
   Main Success Scenarios:

    Actor Action (or Intention)                    System Responsibility

          1. The user chooses to open a log
          file.
                                                      2. The system displays the log file
                                                      load panel.
          3. The user chooses a log file to
          load.
                                                      4. The system updates the logger
                                                      with the new file name.
                                                      5. The system analyzes the log file.
                                                      5. The system updates the statistics
                                                      panel and the graphs according to
                                                      the new log.




                                               9
Extensions (Alternative Flows) (1):

  Actor Action (or Intention)               System Responsibility

                                               4. The system finds the log file with
                                               wrong format.
                                               5. The system doesn't load the log
                                               file.
                                               6. The system notifies the user about
                                               illegal log file.


1.3.    Use Case no. 3: Running the simulator

The story: The user chooses to run the simulator.
Primary Actors: User
Stakeholders and Interests:
          User: wants to execute the simulator after loading a script file.
Pre-conditions: The system is on non-executing mode and there is a loaded script file
on the system memory.
Post-conditions: The system is on executing mode.
Main Success Scenarios:

 Actor Action (or Intention)                System Responsibility

 1. The user chooses to run the
    simulator.                              2. The system creates a log file with
                                               the script file name.
                                            3. The system executes the simulator
                                               with the given script file.
                                               During the execution it updates the
                                               log file and the performance
                                               statistics on the screen.




                                       10
Extensions (Alternative Flows) (2):

Actor Action (or Intention)                 System Responsibility


                                            4. The system executes the simulator
                                               with the given script file.
                                               During the execution there is not
                                               enough space on the HD to save the
                                               log file.
                                            5. The system stops the execution.
                                            6. The system notifies the user that
                                               there is no space left on the HD and
                                               that the execution is stopped.



1.4.   Use Case no. 4: Displaying a graph

The story: The user chooses to display a graph.
Primary Actors: User
Stakeholders and Interests:
          User: wants to display a graph consisting of one or more statistics
             parameters.
Pre-conditions: The system is on non-executing mode or executing mode.
Post-conditions: The graph with the selected parameters is viewed on the screen.
Main Success Scenarios:

Actor Action (or Intention)                 System Responsibility

1. The user chooses the statistics
   parameters for graph y-axis.
                                            2. The system displays the graph with
                                               the selected axis.




                                       11
1.5.     Use Case no. 5: Stopping the simulator execution

The story: The user chooses to stop the simulator execution.
Primary Actors: User
Stakeholders and Interests:
          User: wants to stop the simulator execution.
Pre-conditions: The system is on executing mode.
Post-conditions: The system is on non-executing mode.
Main Success Scenarios:

Actor Action (or Intention)                   System Responsibility

       1. The user chooses to stop the
          simulator execution.
                                                 2. The system stops the execution.
                                                    It updates the log file and the
                                                    performance statistics on the
                                                    screen.




                                         12
2. Data Model
  2.1.    Description of Data Objects
      2.1.1. DataManager
             Responsible for parsing the configuration script file and creating
             collection of commands that describe the event flow of the simulator. The
             DataManager also creates a clients hash table which will be used by the
             command when dealing with client operations.
             It also responsible for creating and managing the following configuration
             parameters: The P2P protocol, the frequency of sampling, the frequency of
             logging and the frequency of viewing.

           Attributes:
            commands : Hashtable<double, Command> - A command represents one
               operation that parsed from a script. The commands hash table represents
               the events occurring during script execution. The hash table key will be
               the time when a certain command occurs and the value is the related
               command.
            clients : Hashtable<Integer, Client> - Clients hash table will be used by
               the command when dealing with client operations. The hash table key
               will be the client's ID as defined by the user and the value is a pointer to
               the related client.
            symbolTable : Hashtable<String, Object> – A table of the variables
               defined in the script. The hash table key will be the variable's name as
               defined by the script and the value is a pointer to the related object.
               There will be a reference to the symbolTable in every command.
            servers : Vector<String> - A vector of all server names at one simulaor
               running period. the server name String is at the form:
               "<server_ip:server_port>".
            randCommandGenerated : Boolean - Indicates whether a random
               command generated for the sake of generating an alternate script with
               the permanent random values.
            scriptFileName : String - Holds the current script file name for loading
               the current script file and for generating a log file with the same name.
               May be used also for generating an alternate file with permanent random
               values in a case of existing random values in the current script file.
            protocolType : String – The name of the P2P protocol that will be used
               by the simulator.
            loggingFreq : Double – The frequency of logging the DataStripes.
            samplingFreq : Double – The frequency of DataStripes creation
               according to the statistics arrived from clients.
            displayingFreq : Double – The frequency of displaying the statistics
               described in the DataStripes.
            initialClientPort : int – The number of the initial client port that will be
               used by all clients of the simulator.
            sharedDir : String - The name of the shared files directory which will be
               used by all clients of the simulator.


                                           13
        downloadDir : String - The name of the download directory which will
         be used by all clients of the simulator.
        time : int - current running time of the running simulator.

2.1.2. StatisticsHandler
       Responsibles for receiving the statistics arrived from clients during
       system's execution and creating an updated DataStripe every
       <samplingFreq> (as described in 2.1.3) seconds according to the statistics
       collected.
       It also creates the Logger and the StatisticsViewer and provides them with
       statistics information.

     Attributes:
      statistics : Vector<DataStripe> – Holds the DataStripes of the system
         which responsible to describe the system. The DataStripes are arranged
         chronologically.
      StatisticsViewer : StatisticsViewer – The Statistics handler is responsible
         to update the StatisticsViewer with the running Statistics.
      logger : Logger – The Statistics handler is responsible to update the
         Logger with the running Statistics.
      dataStripe : DataStripe – Represents the current data Stripe that is
         switched every <samplingFreq> (as described in 2.1.3), and represent the
         statistics of the current time period it belongs. Every time there is a
         communication event the clients update dataStripe with the statistics.
      dataForGraph : ArrayList – Represents the chosen statistics that are
         going to be viewed in the graph.
      graphViewingIsReady : boolean – Indicate whether there is a need for
         viewing the graph.

2.1.3. Command
     The command is an abstract class which will be implemented by commands
     classes with a certain type like: IfCommand, CreateClientCommand,
     ConnectClientCommand, MathCommand, DownloadCommand,
     UploadCommand, ForCommand, etc.

     Attributes:
      None




                                   14
2.1.4. CreateClientCommand
     Create client command extends the Command abstract class.

    Attributes:
     argsVector : Vector<Command> –
      {clientID : NumberCommand,
       simulatedSpeed : NumberCommand,
       simulatedLatency : NumberCommand}
    Will notate the client's ID to create, his simulated latency, and his simulated
    speed.
     clients : Hashtable<Integer, Client> – Clients hash table will be used by
        the CreateClientCommand when dealing with client creation. The hash
        table key will be the client's ID as defined by the user and the value is a
        pointer to the related client.

2.1.5. ConnectClientCommand
     Connect client command extends the Command abstract class.

    Attributes:
     argsVector : Vector< Command > –
      {clientID : NumberCommand,
       serverIPAddress : StringCommand}
    Will notate the client's ID and the server's IP address that the client will
    connect to.
     clients : Hashtable<Integer, Client> – Clients hash table will be used by
        the ConnectClientCommand when dealing with client connection. The
        hash table key will be the client's ID as defined by the user and the value
        is a pointer to the related client.

2.1.6. DisconnectClientCommand
     Disconnect client command extends the Command abstract class.

    Attributes:
     argsVector : Vector< Command > –
      {clientID : NumberCommand,
       serverIPAddress : StringCommand}
    Will notate the client's ID and the server's IP address that the client will
    disconnect from.
     clients : Hashtable<Integer, Client> – Clients hash table will be used by
        the DisconnectClientCommand when dealing with client disconnection.
        The hash table key will be the client's ID as defined by the user and the
        value is a pointer to the related client.




                                    15
2.1.7. DownloadCommand
     Download command extends the Command abstract class.

    Attributes:
     argsVector : Vector< Command > –
      {clientID : NumberCommand,
       serverIPAddress : StringCommand,
       filename : StringCommand }
    Will notate the client's ID and the server's IP address that the client will
    download from and the filename will notate the file name to download.
     clients : Hashtable<Integer, Client> – Clients hash table will be used by
        the DownloadCommand when dealing with client downloads. The hash
        table key will be the client's ID as defined by the user and the value is a
        pointer to the related client.

2.1.8. UploadCommand
     Upload command extends the Command abstract class.

    Attributes:
     argsVector : Vector< Command > –
      {clientID : NumberCommand,
       serverIPAddress : StringCommand,
       filename : StringCommand}
    Will notate the client's ID and the server's IP address that the client will
    upload to and the filename will notate the file name to upload.
     clients : Hashtable<Integer, Client> – Clients hash table will be used by
        the UploadCommand when dealing with client uploads. The hash table
        key will be the client's ID as defined by the user and the value is a
        pointer to the related client.

2.1.9. KillClientCommand
     Kill client command extends the Command abstract class.

    Attributes:
     argsVector : Vector< Command > –
       {clientID : NumberCommand}
    Will notate the client's ID to kill.
     clients : Hashtable<Integer, Client> – Clients hash table will be used by
        the KillClientCommand when dealing with client killing. The hash table
        key will be the client's ID as defined by the user and the value is a
        pointer to the related client.




                                    16
2.1.10. SleepCommand
     Sleep command extends the Command abstract class.

     Attributes:
      argsVector : Vector< Command > –
        {milliseconds: NumberCommand}
     Will notate the sleeping time of the system by milliseconds.

2.1.11. BasicCommand
     Basic command extends the Command abstract class.
     A command that includes basic information as a String form for the use of
     StringCommand, BooleanCommand, NumberCommand and
     AssignmentCommand.

     Attributes:
      basicArg : String
     Will notate the information as a String form.

2.1.12. StringCommand
     String command extends the Command abstract class.
     A command that includes String.

     Attributes:
      argsVector : Vector< Command > –
        {string : BasicCommand}
     Will notate the value of the string.

2.1.13. NumberCommand
     Number command extends the Command abstract class.
     A command that includes number: (integer or double).

     Attributes:
      argsVector : Vector< Command > –
        {number : BasicCommand}
     Will notate the value of the number.




                                    17
2.1.14. BooleanCommand
     Boolean command extends the Command abstract class.
     A command that includes boolean check and return true or false.
     The boolean operators will include: <, >, ==, >=, <=, !=, &&, ||.

     Attributes:
      argsVector : Vector< Command > –
        {booleanOperator : BasicCommand,
        leftOperand : Command,
        rightOperand : Command}
     Will notate the Boolean operator and the operands.

2.1.15. MathCommand
     Math command extends the Command abstract class.
     A command that includes mathematic calculation and return result number.
     The mathematic operators will include: +, -, *, /.

     Attributes:
      argsVector : Vector<Command> –
        {mathOperator : BasicCommand,
         leftOperand : NumberCommand,
         rightOperand : NumberCommand}
     Will notate the math operator and the operands.

2.1.16. AssignmentCommand
     Assignment command extends the Command abstract class.
     A command for a variable assignment.

     Attributes:
      argsVector : Vector< Command > –
        {variableName : BasicCommand
         variableValue : Command}
     Will notate the variable name and its value.
      symbolTable : Hashtable<String, Command > – A table of the variables
         defined in the script. The hash table key will be the variable's name as
         defined by the script and the value is a pointer to the related object.




                                    18
2.1.17. LookupCommand
     Variable command extends the Command abstract class.
     A command for a variable lookup.

     Attributes:
      argsVector : Vector< Command > –
        {variableName : BasicCommand}
     Will notate the variable name to lookup.
      symbolTable : Hashtable<String, Command > – A table of the variables
         defined in the script. The hash table key will be the variable's name as
         defined by the script and the value is a pointer to the related object.

2.1.18. BlockCommand
     Block command extends the Command abstract class.
     A command that includes a sequence of commands inside.

     Attributes:
      argsVector : Vector<Command > –
     Will notate the commands sequence to execute.

2.1.19. IfCommand
     If command extends the Command abstract class.
     A command that includes If-2 condition or If-3 condition.

     Attributes:
      argsVector : Vector< Command > –
        {booleanCheck : BooleanCommand
         thenClause : Command
         elseClause : Command} (for if-3) or
        {booleanCheck : BooleanCommand
         thenClause : Command} (for if-2)
     Will notate the boolean check, the then clause and the else clause in a case of
     if-3.
2.1.20. ForCommand
     For command extends the Command abstract class.
     A command that includes for loop

     Attributes:
      argsVector : Vector< Command > –
        {forInitAssiggnment : AssignmentCommand
         forBooleanCheck : BooleanCommand
         forIncAssiggnment : AssignmentCommand
         forClause : Command}
     Will notate the for initial assignment, the for Boolean check, the for
     increment assignment and the for clause.



                                     19
2.1.21. Client
     A Client is a simulated client that will connect to P2P servers and
     download/upload files from/to them, and will transfer appropriate statistics
     about them.
     The Client is an abstract Class which will be implemented by several plug-
     ins of client implementations that using different protocols.

     Attributes:
      clientID : double – Will notate the client's ID.
      simLatency : double – Will notate the simulated latency of the client.
      simSpeedLimit : double – Will notate the simulated download/upload
         speed of the client.
      ttl : double – Will notate client time to live.

2.1.22. GnutellaClient
     A client that implements the GenericClient using Gnutella protocol.


2.1.23. ConnectionData
        Provides a linkage between the Servant and JTella.
        ConnectionInformation is used by GNUTellaConnectionand and others in
        determining current parameters settable by the Servant application.

     Attributes:
      listeningGnutellaPort : int - The Gnutella port the client listens.
      listeningHttpPort : int - Is the http port the client listens.

2.1.24. Message
        Abstract base class for GNUTella messages.

     Attributes:
      originatingConnection : Connection - The messages original connection.
      guid : GUID - The messages - Globally Unique Identifier.
      type : short - The messages type.
      ttl : byte - The messages ttl which indicate the message time to live. The
         ttl is decremented in 1 when passing from one host to another in order to
         drop it when it pass through over too many hosts usually around 7.
      hops : byte - The messages hops which indicate the message time to live.
         The hops is incremented in 1 when passing from one host to another in
         order to drop it when it pass through over too many hosts usually around
         7
      payload : short array - The data, such as a data field, block, or stream,
         being processed or transported — the part that represents user
         information and user overhead information.
      payloadSize : short array - The messages payload size.



                                    20
2.1.25. GUID
        Globally Unique Identifier Represents a unique ID for a message.

     Attributes:
      clientID : short array - represents the ID of client that takes a part of the
         GUID data.
      Rand : Random - represents a random number that takes a part of the
         GUID data.
      data : short array - Represents the GUID data.

2.1.26. PingMessage
     A subclass of Message represents GNUTella Ping message.

2.1.27. PongMessage
     A subclass of Message represents a pong GNUTella message. A Pong
     message is sent in reply to a Ping and provides host information.
     Attributes:
      port : short - The listening port of the GNUTella client to sent the
         message.
      ipAddress : String The IP of the GNUTella client to sent the message.

2.1.28. SearchMessage
     A subclass of Message represents GNUTella search message
     The message for queries in order to search files at the other GNUTella
     clients.

     Attributes:
      query : String - The name of file that LCP client is looking for.

2.1.29. SearchReplyMessage
     A subclass of Message represents GNUTella QUERY HIT responses to a
     search request.

     Attributes:
      fileRecords : Vector<FileRecord> - The filerecors vector in order to
         check whether a file exists in our shared directory.
      port : short - The port of the LCP clients HTTP Server to give the
         connected GNUTella client who wishes to download a file.
      ipAddress : String - The IP of the LCP clients HTTP Server to give the
         connected GNUTella client who wishes to download a file.
      speed : String - The speed of the LCP clients HTTP Server to give the
         connected GNUTella client who wishes to download a file.
      vendorCode : String - The vendorCode of the LCP clients HTTP Server
         to give the connected GNUTella client who wishes to download a file.




                                     21
2.1.30. DataStripe
     Describes the statistics at a certain time for a given servers list.

     Attributes:
      serversStatistics : Hashtable<String, double[] > -
     serversStatisticsMap hash table will notate the statistical data per server. The
     hash table key will be a string of the server's IP address and the value will be
     statistics array.
     Description of the statistics array:
     StatisticsArray[0] – numConnectionTrials : double
     StatisticsArray[1] – numConnectionSuccesses : double
     StatisticsArray[2] – connectionSuccessPercentage : double
     StatisticsArray[3] – bytesReceived : double
     StatisticsArray[4] – bytesSent : double
     StatisticsArray[5] – downloadRate : double
     StatisticsArray[6] – uploadRate : double
     StatisticsArray[7] – maxDownloadRate : double
     StatisticsArray[8] – maxUploadRate : double

        globalStatistics : double[] – Global statistics for all servers.




                                      22
2.2.   Data Objects Relationships




                                    23
Client/GnutellaClient/Message




                                24
  2.3.   Databases

  Not Applicable

3. Behavioral Analysis
  3.1.    Sequence Diagrams
      3.1.1. Load Script File




                                25
3.1.2. Execute Simulator




                           26
3.1.3. Display graph




                       27
3.1.4. Stop Execution




                        28
3.2.    Events
    In our system there are several a-synchronic events:

    3.2.1. Upon Client connecting trial, the Client should update the
         StatisticsHandler using the operation: updateNumConnectionTrials
         (<[serverIP] : [serverPort]> : String), notating the StatisticsHandler with a
         connection trial to the server <[serverIP] : [serverPort ]>.

    3.2.2. Upon Client connecting to a server, the Client should update the
         StatisticsHandler using the operation: updateNumConnectionSuccess
         (<[serverIP] : [serverPort]> : String), notating the StatisticsHandler with
         successful connection to the server: <[serverIP] : [serverPort]>.

    3.2.3. During Client downloading, when receiving a packet of information, the
         Client should update the StatisticsHandler using the operation:
         updateReceivedBytes(<[serverIP] : [serverPort]> : String, value : double ),
         notating the StatisticsHandler with the number of bytes received from the
         server <[serverIP] : [serverPort]>.

    3.2.4. During Client uploading, when sending a packet of information, the Client
         should update the StatisticsHandler using the operation:
         updateSentBytes(<[serverIP] : [serverPort]> : String, value : double),
         notating the StatisticsHandler with the number of bytes sent to the server
         <[serverIP] : [serverPort]>.




                                         29
3.3.     States

    3.3.1. High Level State Chart


                                                             loadScriptFile( fileName:String )


                                        StartPoint                                                        PreExecution

                                                                  ended by user operation




                                                                                                              executeSimulator()

        generateScript()                                          loadLogFile(fileName : String)



                       ended by user operation                                                                     OnExecution


                                                     ended by user operation



                                                                                                 stopExecution()



       ScriptEditing



                                                                      PostExecution


          saveScriptFile(fileName : String)




                                                            30
                            3.3.2. Client-Server<serverIP> State Chart
                                 A state chart that describes the states and the events as a consequence of
                                 interaction between a client and one specific server (a client can connect to
                                 more than one server but this State Chart describes a connection with one of
                                 the servers).


                             create client                                                                                                                      disconnect(server : String)
                                                               NotConnectedTo
                                                                   Server
                                 kill()


                                                                                                     connect( server : String )
 kill()


                                          [ numberOfAttempts==5 ]

                              kill()
                                                                                              [ connection failed && numberOfAttempts<5 ]



                                                                        AttemptToConnect

                                             entry/ statisticsHandler.updateNumConnectionTrials(<[serverIP]:[serverPort]> :1)
                                             entry/^ ^statisticsHandler.update(<serverIP>, "ConnectionTrial", String)




                    disconnect(server : String)                                           [ connection successed ]

                                                                                     kill()
                                                                                                                                                   ConnectedToServer

                                                                                                                     entry/^ ^statisticsHandler.update(<serverIP>, "connection", 1)
                                                                                                                     entry/ statisticsHandler.updateNumConnectionSuccess(<[serverIP]:[serverPort]> : String)

download( server : String, filename: String )
                                                                download( server : String, filename: String )


                                                                                                                     finish all download / upload

                                                   DataTransferWithServer

                     do/ ^statisticsHandler.update(<serverIP>, "download", : String, value : double )
                     do/ ^statisticsHandler. updateReceivedBytes(<[serverIP]:[serverPort]><packetsRecieved>)
                     do/ ^statisticsHandler.update(<serverIP>, "upload", : String, value : double)
                     do/ ^statisticsHandler. updateSentBytes(<[serverIP]:[serverPort]> <packetsSent>)




                                                                                                                 upload( server : String, filename: String )


               download( server : String, filename: String )




                                                                                                         31
4. Object-Oriented Analysis
   4.1.     Class Diagrams
        4.1.1. Class Diagram for the package: Main



      4.1.2. Class Diagram for the package: Simulator




                                       32
4.1.3. Class Diagram of the package: Statistics




                                 33
4.1.4. Class Diagram of the package: ScriptCompiler
     Since the whole diagram is too big to fit inside this document, the classes are
     represented without their detail inside the class diagram.
     The classes ScriptScanner, ScriptParser. CommandsGenerator, and Utilities
     are specified below separately.




                                    34
The detailed classes:




                        35
4.1.5. Class Diagram of the package: Command




                              36
4.1.6. Class diagram of the package: Client




4.1.7. Class diagram of the package: GnutellaClient
     Since the whole diagram is too big to fit inside this document, the classes are
     represented without their detail inside the class diagram.
     The classes Downloader, GnutellaClient, Connection, GnutellaSession,
     GnutellaListener,ConnectionData, and SearchReceiver are specified below
     separately.




                                    37
The detailed classes:




                        38
4.1.8. Class diagram of the package: Client/GnutellaClient/HTTPServer




                                39
4.1.9. Class diagram of the package: Client/GnutellaClient/Message




                                40
4.1.10.   Class diagram of the package: Client/GnutellaClient/Router




                                    41
4.1.11. Class diagram of the package: Client/GnutellaClient/Utilities




                                  42
4.1.12. Class diagram of the package: GUI




                                43
4.1.13. Class diagram of the package GUI/Graph




                                44
4.2.   Class Description

    4.2.1. Classes of package: Main
        4.2.1.1.    LCPMain
            Responsibles for initializing the system and the GUI, and operating the
            main classes in the system: SimulatorExecuter, DataManager,
            StisticsHandler and ScriptGenerator.

    4.2.2. Classes of package: Simulator
        4.2.2.1.     DataManager
            Responsible for parsing the configuration script file and creating
            collection of commands that describe the event flow of the simulator. The
            DataManager also creates a clients hash table which will be used by the
            command when dealing with client operations.
            It also responsible for creating and managing the following configuration
            parameters: The P2P protocol, the frequency of sampling, the frequency of
            logging and the frequency of viewing.

         Attributes:
          commands : Hashtable<double, Command> - A command represents one
             operation that parsed from a script. The commands hash table represents
             the events occurring during script execution. The hash table key will be
             the time when a certain command occurs and the value is the related
             command.
          clients : Hashtable<Integer, Client> - Clients hash table will be used by
             the command when dealing with client operations. The hash table key
             will be the client's ID as defined by the user and the value is a pointer to
             the related client.
          symbolTable : Hashtable<String, Object> – A table of the variables
             defined in the script. The hash table key will be the variable's name as
             defined by the script and the value is a pointer to the related object.
             There will be a reference to the symbolTable in every command.
          servers : Vector<String> - A vector of all server names at one simulaor
             running period. the server name String is at the form:
             "<server_ip:server_port>".
          randCommandGenerated : Boolean - Indicates whether a random
             command generated for the sake of generating an alternate script with
             the permanent random values.
          scriptFileName : String - Holds the current script file name for loading
             the current script file and for generating a log file with the same name.
             May be used also for generating an alternate file with permanent random
             values in a case of existing random values in the current script file.
          protocolType : String – The name of the P2P protocol that will be used
             by the simulator.
          loggingFreq : Double – The frequency of logging the DataStripes.



                                         45
   samplingFreq : Double – The frequency of DataStripes creation
    according to the statistics arrived from clients.
   displayingFreq : Double – The frequency of displaying the statistics
    described in the DataStripes.
   initialClientPort : int – The number of the initial client port that will be
    used by all clients of the simulator.
   sharedDir : String - The name of the shared files directory which will be
    used by all clients of the simulator.
   downloadDir : String - The name of the download directory which will
    be used by all clients of the simulator.
   time : int - current running time of the running simulator.

Operations:
 initialize() : void - Initializes the data for the simulator when system
   starts.
   If there is no preferences file it generates default parameters, create file
   and saves them on the file.
   Otherwise it loads the parameters from the existed file.
   o Pre-condition: The system is at start position without any preferences
        in memory as described in ADD, 3.3.1.
   o Post-condition: The system is at start position with preferences in
        memory as described in ADD, 3.3.1.
 initializeBeforeExecution() : void - Initialize the data for the simulator
   before execution.
   Creates new clients hash table and new SymbolTable for the use of the
   LookUp And Assignment of variable on a real execution.
   o Pre-condition: The system is in PreExecution state as described in
        ADD 3.3.1.
   o Post-condition: The system is still in PreExecution state as described
        in ADD 3.3.1.
 loadScriptFile() : void – Load script file with the file name in memory:
   (scriptFileName : String). It will call the compile method in
   ScriptCompiler class which parses the script and creates the commands.
   It returns an error description if there is an error by reading the script.
   o Pre-condition: The system is in StartPoint state as described in 3.3.1.
   o Post-condition: The system is in PreExecution state as described in
        3.3.1.
 savePreferences() : void - Saves the preferences in memory on the
   preferences file.
   o Pre-condition: The system is at preferences wizard and the user
        pressed OK.
   o Post-condition: The system is at any state as described in 3.3.1.




                                46
4.2.2.2.   SimulatorExecuter
    Responsible for running the simulator due to the Commands hash table
    and the clients hash table as generated by the DataManager. It executes
    each command according to it's time as appears in the hash table.

 Operations:
  run() : void – Will execute the simulator by executing the commands.
    o Pre-condition: The system is in PreExecution state as described in
         3.3.1.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1.
  stop() : void – Will stop the simulator execution.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1.
    o Post-condition: The system is in PostExecution state as described in
         3.3.1.
  preProcessing() : String - Will do some preprocessing operations to
    assemble the list of servers from the script and to build a new script with
    permanent random values if the original script includes random values.
    It returns an error description if there is an error by reading the
    commands.
    o Pre-condition: The system is in StartPoint state as described in 3.3.1.
    o Post-condition: The system is in PreExecution state as described in
         3.3.1.

4.2.2.3.    TimeScheduler
    Responsible for updating all of the events during simulator's running due
    to the progress of time, according to user's preferences.
    Also takes a part with simulating the client's speed and latency by
    notifying the ClientsHolder from the Client Package which holds the
    clients for every second.
    Responsibles for killing the clients which its time has come and for
    updating the console.

 Attributes:
  Time : int - The current running time by second to update the simulator
     executer when running the simulator.
  shutdownFlag : boolean - A flag notating if there was a shut down event
     from the GUI for stopping the simulator.
  currentConsoleBuffer : String - The current buffer to update the console
     which updated during every second and flushed every second.




                                47
Operations:

   initialize() : void - Initializes the TimeScheduler when loading a new
    script/log file.
    o Pre-condition: The system is in StartPoint/PreExecution/
         OnExecution/PostExecution state as described in 3.3.1.
    o Post-condition: The system is in PreExecution state as described in
         3.3.1.
   shutdown() : void - Turns on the shutdownFlag which notifies the
    TimeScheduler to stop running.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1.
    o Post-condition: The system is in PostExecution state as described in
         3.3.1.
   run() : void - Responsibles for updating the sampling, logging and
    displaying frequency at the preferred frequency. Also Update the running
    time, wakes up speed limited clients (for simulating speed and latency),
    and kill client whith its time to live < currnt running time - the time of its
    creation.
    o Pre-condition: The system is in PreExecution state as described in
         3.3.1.
    o Post-condition: The system is in PostExecution state as described in
         3.3.1.
   showStatistics() : void - Responsibles to view and update the textual
    statistics: the global statistics table and the Statistics per server tree.
    Also responsibles to view the last statistics correctly when loading a log
    file.
    o Pre-condition: In a case of updating during system running a
         simulator the system is in OnExecution state as described in 3.3.1.
         In a case of loading a log file the system either could be in
         StartPoint/PreExecution/OnExecution/PostExecution state.
    o Post-condition: In a case of updating during system running a
         simulator the system is in OnExecution state as described in 3.3.1.
         In a case of loading a log file the system is in PostExecution state.

   updateGraph() : void - Responsibles to update and view the chosen data
    on the graph every second.
    o Pre-condition: The system is in OnExecution state as described in
        3.3.1.
    o Post-condition: The system is in OnExecution state as described in
        3.3.1.




                                48
        updateGraphImmediately() : void - Responsibles to update and view the
         chosen data on the graph whenever there was a chanege in the chosen
         items on the global statistics table or in the servers statistics tree.
         Will update the data to view in the graph according to the chosen items
         in the table and the tree described above.
         o Pre-condition: The system is in OnExecution state as described in
             3.3.1.
         o Post-condition: The system is in OnExecution state as described in
             3.3.1.
        setTimeForLoadingLogFile(time : int) : void - Responsibles for setting
         the time to the last second when loading a log file in order to reach per-
         execution state. The parameter time will be the last time represented in
         the log file.
         o Pre-condition: The system is in StartPoint/PreExecution/
             OnExecution/PostExecution state as described in 3.3.1.
         o Post-condition: The system is in PostExecution state as described in
             3.3.1.
        addTextForConsole (textToAdd : String) : void - Responsibles for
         collecting text from the clients every time there is a comunication event.
         The parameter textToAdd will be string that describes the
         communication event.
             Pre-condition: The system is in OnExecution state as described in
             ADD 3.3.1.
         o Post-condition: The system is in OnExecution state as described in
             ADD 3.3.1.

4.2.3. Classes of package: Statistics
    4.2.3.1.     StatisticsHandler
        Responsibles for receiving the statistics arrived from clients during
        system's execution and creating an updated DataStripe every
        <samplingFreq> (as described in 2.1.3) seconds according to the statistics
        collected.
        It also creates the Logger and the StatisticsViewer and provides them with
        statistics information.

     Attributes:
      statistics : Vector<DataStripe> – Holds the DataStripes of the system
         which responsible to describe the system. The DataStripes are arranged
         chronologically.
      StatisticsViewer : StatisticsViewer – The Statistics handler is responsible
         to update the StatisticsViewer with the running Statistics.
      logger : Logger – The Statistics handler is responsible to update the
         Logger with the running Statistics.




                                    49
   dataStripe : DataStripe – Represents the current data Stripe that is
    switched every <samplingFreq> (as described in 2.1.3), and represent the
    statistics of the current time period it belongs. Every time there is a
    communication event the clients update dataStripe with the statistics.
   dataForGraph : ArrayList – Represents the chosen statistics that are
    going to be viewed in the graph.
   graphViewingIsReady : boolean – Indicate whether there is a need for
    viewing the graph.

Operations:
 initialize() : void – Initializes the StatisticsHandler when loading a new
   script/log file
   o Pre-condition: The system is in StartPoint/PreExecution/
       OnExecution/PostExecution state as described in 3.3.1.
   o Post-condition: Post-condition: The system is in PreExecution state
       as described in 3.3.1.
 arrangeRateStatistics() – void - Responsibles to update the download and
   upload rates by comparing the bytes recieved/sent in the current time
   DataStripe dataStripe to the previous DataStripe from statistics vector.
   o Pre-condition: The system is in OnExecution state as described in
       3.3.1.
   o Post-condition: Post-condition: The system is in OnExecution state
       as described in 3.3.1.
 updateNumConnectionTrials(server : String) : void - Responseibles to
   updating the number of connection trials for a server, and the global
   statistics accordingly. The parameter server is the string represents the
   server name to update <[ip]:[port]>.
   o Pre-condition: The system is in OnExecution state as described in
       3.3.1 and there is a client that its state is AttemptToConnect as
       described in 3.3.2 and the event as described in 3.2.1 occurred.
   o Post-condition: The system is in OnExecution state as described in
       3.3.1 and the DataStripe dataStripe is updated with the new statistics.
 updateNumConnectionSuccess(server : String) : void - Responseibles to
   updating the number of connection success for a server, and the global
   statistics accordingly. The parameter server is the string represents the
   server name to update <[ip]:[port]>.
   o Pre-condition: The system is in OnExecution state as described in
       3.3.1 and there is a client that its state is ConnectedToServer as
       described in 3.3.2 and the event as described in 3.2.2 occurred.
   o Post-condition: The system is in OnExecution state as described in
       3.3.1 and the DataStripe dataStripe is updated with the new statistics.




                               50
   updateReceivedBytes(server : String, value : double) : void -
    Responseibles to update the number of received bytes to a server, the
    download rate and the global statistics accordingly. The parameter
    server is the string represents the server name to update <[ip]:[port]>.
    The parameter value is the statistics data to increase.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1 and there is a client that its state is DataTransferWithServer as
         described in 3.3.2 and the event as described in 3.2.3 occurred.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1 and the DataStripe dataStripe is updated with the new statistics.
   updateSentBytes(server : String, value : double) : void - Responseibles
    to update the number of sent bytes to a server, the upload rate and the
    and the global statistics accordingly. The parameter server is the string
    represents the server name to update <[ip]:[port]>. The parameter value
    is the statistics data to increase.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1 and there is a client that its state is DataTransferWithServer as
         described in 3.3.2 and the event as described in 3.2.4 occurred.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1 and the DataStripe dataStripe is updated with the new statistics.
   nextDataStripe() : void - Responsibles for adding dataStripe to the
    statistcs and creating new DataStripe representing the current dataStripe.
    It switches it every [samplingFreq] (as described in 2.1.3).
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1.
   showStatisticsPerServer : void - Notifies the Statistics Viewer to view
    the current statistics at the statistics per server tree.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1 or in PostExecution.
   showGlobalStatistics : void - Notifies the Statistics Viewer to view the
    current statistics at the global statistics table.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1 or in PostExecution.
   prepareDataForGraph : void - Preparing the specific data to be
    represented in the graph as the user the user chooses to represent it.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1 or in PostExecution.



                                51
    viewGraph : void - Notifies the Statistics Viewer to view the current
     statistics at the graph.
     o Pre-condition: The system is in OnExecution state as described in
          3.3.1 or in PostExecution.
     o Post-condition: The system is in OnExecution state as described in
          3.3.1 or in PostExecution.
    prepareGraphViewing : void - If the user change the data to represent on
     Graph it notifies the Statistics Viewer to view the current statistics at the
     graph.
     o Pre-condition: The system is in OnExecution state as described in
          3.3.1 or in PostExecution.
     o Post-condition: The system is in OnExecution state as described in
          3.3.1 or in PostExecution.
    initializeLogger : void - Initializes the logger's log file when the system
     starts running a simulator.
     o Pre-condition The system is in PreExecution state as described in
          ADD 3.3.1.
     o Post-condition: The system is in OnExecution state as described in
          ADD 3.3.1.
    Log(time : int) : void - logger to log the current statistics. The parameter
     time represents the current time to log.
     o Pre-condition The system is in OnExecution state as described in
          ADD 3.3.1.
     o Post-condition: The system is in OnExecution state as described in
          ADD 3.3.1.
    closeLogger() : void - logger to log the current statistics.
     o Pre-condition The system is in OnExecution state as described in
          ADD 3.3.1.
     o Post-condition: The system is in PostExecution state as described in
          ADD 3.3.1.

4.2.3.2.    StatisticsViewer
    Responsibles for representing the server's performance statistics handled
    by the StatisticsHandler. It is operated by the StatisticsHandler.
    The StatisticsHandler uses DataManager for setting the viewing
    frequency.

 Attributes:
  colors : array<Color> – Represents the colors that are going to be
     represented at the graph. Each color represents a statistics type.
  dataForGraph : array<Color> – Represents the statistical data that is
     going to be represented at the graph.
  follow : Boolean – Indicate whether the graph will follow the data that
     being updated when viewed to the user.




                                 52
 Operations:
  showStatisticsPerServer(dataStripe : DataStripe) : void - Updating the
    current statistics per server in order to view it to the user. The parameter
    dataStripe is the current DataStripe to show to the user.
    o Pre-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
  showStatisticsPerServer(dataStripe : DataStripe) : void - Updating the
    current global statistics in order to view it to the user. The parameter
    dataStripe is the current DataStripe to show to the user.
    o Pre-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
  prepareColorsForGraph() : void - Responsibles to prepare the colors that
    are going to be represented at the graph.
    o Pre-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
  prepareLegendForGraph() : void - Responsibles to prepare the legend
    that is going to indicate for the data represented at the graph.
    o Pre-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
  viewGraph() : void - Responsible to order the DirectedGraphXYPlotter
    from the package GUI/Graph to plot the graph to the screen.
    o Pre-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.
    o Post-condition: The system is in OnExecution state as described in
        3.3.1 or in PostExecution.

4.2.3.3.     Logger
    Responsibles for logging the statistics of the current running simulator to a
    log file and for loading the statistics from a given log file name.

 Attributes:
  logFile : File – The current log file to log(during simulator's
     run)/represent(when loading a log file).
  writer : BufferedWriter – The BufferedWriter that writing to the current
     log file in order to update the statistics.
  reader : BufferedReader - The BufferedReader that reading from a
     loaded log file.



                                 53
   error : boolean – Indicates whether there was an error reading the log
    file.

Operations:
 createLogFile(scriptFileName : String) : void - Responsibles for the
   creation of a new log file. The parameter scriptFileName will be the log
   file name as well with the postfix .log instead of the postfix .txt.
   o Pre-condition: The system is in PreExecution state as described in
        3.3.1.
   o Post-condition: The system is in OnExecution state as described in
        3.3.1.

   closeLogFile() : void - Closing a log file at the end of a simulator run.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1.
    o Post-condition: The system is in PostExeution state as described in
         3.3.1.
   writeInitialText (scriptFileName : String) : void - Initialize the log file
    initials at the start of a simulator run. The parameter scriptFileName will
    be the log file name as well with the postfix .log instead of the postfix
    .txt.
    o Pre-condition: The system is in PreExecution state as described in
         3.3.1.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1.
   log(dataStripe : DataStripe, time : int) : void - Responsibles for logging
    the current dataStripe to the log file at the current time. The parameter
    time is for the current logging time. The parameter dataStripe will be
    the current DataStripe to log and the current logging time.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1.
   loadLogFile(filename : String) : Vector<DataStripe> - Responsibles for
    loading a log file to represent it to the user. The parameter fileName will
    be the file log file name to load.
    o Pre-condition: The system is in StartPoint/PreExecution/
         OnExecution/PostExecution state as described in 3.3.1.
    o Post-condition: The system is in PreExecution state as described in
         3.3.1.




                                54
4.2.3.4.   DataStripe
    Describes the statistics at a certain time for a given servers list.

 Attributes:
  serversStatistics : Hashtable<String, double[] > -
     serversStatisticsMap hash table will notate the statistical data per server.
     The hash table key will be a string of the server's IP address and the
     value will be statistics array.
     Description of the statistics array:
     StatisticsArray[0] – numConnectionTrials : double
     StatisticsArray[1] – numConnectionSuccesses : double
     StatisticsArray[2] – connectionSuccessPercentage : double
     StatisticsArray[3] – bytesReceived : double
     StatisticsArray[4] – bytesSent : double
     StatisticsArray[5] – downloadRate : double
     StatisticsArray[6] – uploadRate : double
     StatisticsArray[7] – maxDownloadRate : double
     StatisticsArray[8] – maxUploadRate : double

    globalStatistics : double[] – The global statistics for all servers.

 Operations:
  initialize() : void - Crating a new data stripe at the beginning of running
    or every <SamplingFreq> seconds.
    o Pre-condition: The system is in OnExecution state as described in
        3.3.1 in a case of the system is in middle of running a simulator.
        The system is in PreExecution state in a case of the system starts
        running a simulator.
    o Post-condition: The system is in OnExecution state as described in
        3.3.1.




                                   55
4.2.4. Classes of package: ScriptCompiler
    4.2.4.1.    ScriptCompiler
        This class implements the script compiler which invokes the scanner,
        parser and commands generator.

     Attributes:
      errorDescription : String – description of compilation error if occured.
      randCommandGenerated : boolean – Indicates whether there was a
         generation of random command.

     Operations:
      compile (script : String) : Hashtable<Integer, Command> - Compile the
        script into commands that will be runned by the Simulator Executer. The
        parameter script script will be the String of LCP script that has been
        loaded by the system. Returns a hashtable of time and command to
        operate.
        o Pre-condition: There is loaded text of LCP script in memory
        o Post-condition: There is an Hash table of Command in returns to the
            DataManager.

   4.2.4.2.  ScriptScanner
       Responsibles for scanning the script as a whole String.

     Attributes:
      Script : String – Loaded LCP script as a string.
      index : int – Loaded LCP script as a string.
      errorDescription : String – Represents the error description if scanning
         error occurs.

     Operations:
      scan (script : String) : LinkedList<TagedToken> - Scans the script and
        converts it into ataged token list. The parameter script will be a loaded
        LCP script as a string. Returns a linked list of tagged tokens.
        o Pre-condition: There is loaded text of LCP script in memory
        o Post-condition: There is linked list of TagedToken in memory.




                                    56
4.2.4.3.  ScriptParser
    Responsibles for parsing the taged token list.

 Attributes:
  errorDescription : String – the errorDescription if parsing error has
     occured.

 Operations:
  parseALL (tagedTokenList : LinkedList<TaggedToken>) :
    LinkedList<LinkedList> - Parses the taged token list, and converts it into
    parsed lists. The parameter tagedTokenList will be a linked list of
    tagged tokens. Returns linked list of linked lists represents parsed lists.
    o Pre-condition: There is linked list of tagged tokens in memory.
    o Post-condition: There is linked list of linked lists represents parsed
        lists in memory.

4.2.4.4.  CommandsGenerator
    Responsibles for generating the LCP commands from the parsed lists.

 Attributes:
  randCommandGenerated : boolean – Indicates whether there was a
     generation of random command.

 Operations:
  generateCommands(parsedLists : LinkedList<LinkedList>) :
    LinkedList<LinkedList> - Generates commands, and returns commands
    hash table. The parameter parsedLists will a linked list of linked lists
    represents the parsed lists. Returns Hashtable of commands for the
    Simulator executer to run.
    o Pre-condition: There is linked list of linked lists represents parsed
        lists in memory.
    o Post-condition: There is an Hash table of Command in returns to the
        DataManager.

4.2.4.5.   TaggedToken
    Represents a pair: (tag, token).
 Attributes:
  tag : String – the tag (first) string of the pair.
  token : String – the token (second) string of the pair.
4.2.4.6.   Utilities
    Includes static service methods for the compiler components.

 Operations:
  isSpecialChar (ch : char) : boolean - Checks if 'ch' is a special char. The
    parameter ch is the char to check. Returns true if 'ch' is a special char.



                                 57
   isNumber(token : string) : boolean - Checks if 'token' represents
    number. The parameter token is the string to check. Returns true if
    'token' represents number.
   isScriptIdentifier(token : string) : boolean - Checks if 'token' is a legal
    identifier in the script. The parameter token is the string to check.
    Returns true if 'token' is a legal identifier in the script.
   isSpecialFunction(token : string) : boolean - Checks if 'token' is a
    special function. The parameter token is the string to check. Returns true
    if 'token' is a special function.
   isCompoundFunction(token : string) : boolean - Checks if 'token' is a
    compound function:if, for. The parameter token is the string to check.
    Returns true if 'token' is a compound function:if, for.
   isOtherFunction(token : string) : boolean - Checks if 'token' is an
    "other" function as rand. The parameter token is the string to check.
    Returns true if 'token' is an "other" function as rand.
   isIgnoredTag(token : string) : boolean - Checks if 'tag' is a ignored tag
    (used by the ScriptScanner). The parameter token is the string to check.
    Returns true if 'tag' is a ignored tag (used by the ScriptScanner).
   getType(specialFunctionName: string, argIndex : int) : String -
    Extracts the type of a special function's argument. The parameter
    specialFunctionName is the string to check. The parameter argIndex is
    the argument number supposed to be in the command to create. Returns
    the type of a special function's argument.
   getNumberOfArgs(specialFunctionName: string) : int - Checks what is
    the number of arguments in a special function. The parameter
    specialFunctionName is the string to check. Returns the number of
    arguments in a special function.
   getAppearanceIndexes(tagedTokenList : LinkedList<TaggedToken>,
    tag : String) : LinkedList<Integer> - Finds indications for the appearance
    indexes of 'tag' in 'taggedTokenList'. The parameter taggedTokenList is
    the tagged token list to check. The parameter tag is the tag to check.
    Returns list of integers indicate the appearance indexes of 'tag' in
    'taggedTokenList'.
   getTagList(tagedTokenList : LinkedList<TaggedToken>, tag : String) :
    LinkedList<String> - Derives a list of tags from 'tagedTokenList'. The
    parameter taggedTokenList is a list to extract the tags from. Returns a
    list of tags derived from 'tagedTokenList'.
   tagEqual(taggedTokenList : LinkedList<TaggedToken>, index : int,
    tags : String) : boolean - Checks if 'tags' contains the tag in
    'taggedTokenList' on 'index' place. The parameter taggedTokenList is
    the tagged to token list to check if 'tags' includes it. The parameter index
    is the index of the place in the list to check. The parameter tags is the
    tags to check. Returns true if 'tags' contains the tag in 'taggedTokenList'
    on 'index' place.




                                58
       subList(startIndex : int, endIndex : int, tagedTokenList :
        LinkedList<TaggedToken>) : LinkedList<TaggedToken> - Extract
        sublist from a lTagged token list. The parameter startIndex indicates the
        desire start of the sub list. The parameter endIndex indicates the desire
        end of the sub list. The parameter tagedTokenList is the original
        tagedList to convert. Returns a sub list of 'tagedTokenList'.
       tagedTokenListToString(tagedTokenList: LinkedList<TaggedToken>) :
        String - Converts taged token list into string. The parameter
        tagedTokenList is the list to convert. Returns a string extracted from the
        tagged token list.

4.2.5. Classes of package: Command
    4.2.5.1.   Command
        The command is an abstract class which will be implemented by
        commands classes with a certain type like: IfCommand,
        CreateClientCommand, ConnectClientCommand, MathCommand,
        DownloadCommand, UploadCommand, ForCommand, etc.

    Attributes:
     None

    Operations:
     toScript() : String – Will convert a command to a script text.
       o Pre-condition: The system is in ScriptEditing state as described in
           3.3.1 and the user chooses to save a script file.
       o Post-condition: The system is in ScriptEditing state.
     execute() : Object – Will execute the command.
       o Pre-condition: The system is in OnExecution state as described in
           3.3.1.
       o Post-condition: The system is in OnExecution state as described in
           3.3.1.


   4.2.5.2.   CreateClientCommand
       Create client command extends the Command abstract class.

    Attributes:
     argsVector : Vector<Command> –
      {clientID : NumberCommand,
       simulatedSpeed : NumberCommand,
       simulatedLatency : NumberCommand}
    Will notate the client's ID to create, his simulated speed and his simulated
    latency.




                                   59
    clients : Hashtable<Integer, Client> – Clients hash table will be used by
     the CreateClientCommand when dealing with client creation. The hash
     table key will be the client's ID as defined by the user and the value is a
     pointer to the related client.

 Operations:
  toScript() : String – Will convert a CreateClientCommand to a script
    text.
  execute() : Object – Will execute the command.

4.2.5.3.  ConnectClientCommand
    Connect client command extends the Command abstract class.

 Attributes:
  argsVector : Vector< Command > –
   {clientID : NumberCommand,
    serverIPAddress : StringCommand}
 Will notate the client's ID and the server's IP address that the client will
 connect to.
  clients : Hashtable<Integer, Client> – Clients hash table will be used by
     the ConnectClientCommand when dealing with client connection. The
     hash table key will be the client's ID as defined by the user and the value
     is a pointer to the related client.

 Operations:
  toScript() : String – Will convert a ConnectClientCommand to a script
    text.
  execute() : Object – Will execute the command.


4.2.5.4.  DisconnectClientCommand
    Disconnect client command extends the Command abstract class.

 Attributes:
  argsVector : Vector< Command > –
   {clientID : NumberCommand,
    serverIPAddress : StringCommand}
 Will notate the client's ID and the server's IP address that the client will
 disconnect from.
  clients : Hashtable<Integer, Client> – Clients hash table will be used by
     the DisconnectClientCommand when dealing with client disconnection.
     The hash table key will be the client's ID as defined by the user and the
     value is a pointer to the related client.




                                 60
 Operations:
  toScript() : String – Will convert a DisconnectClientCommand to a script
    text.
  execute() : Object – Will execute the command.

4.2.5.5.  DownloadCommand
    Download command extends the Command abstract class.

 Attributes:
  argsVector : Vector< Command > –
   {clientID : NumberCommand,
    serverIPAddress : StringCommand,
    filename : StringCommand }
 Will notate the client's ID and the server's IP address that the client will
 download from and the filename will notate the file name to download.
  clients : Hashtable<Integer, Client> – Clients hash table will be used by
     the DownloadCommand when dealing with client downloads. The hash
     table key will be the client's ID as defined by the user and the value is a
     pointer to the related client.

 Operations:
  toScript() : String – Will convert a DownloadCommand to a script text.
  execute() : Object – Will execute the command.

4.2.5.6.  UploadCommand
    Upload command extends the Command abstract class.

 Attributes:
  argsVector : Vector< Command > –
   {clientID : NumberCommand,
    serverIPAddress : StringCommand,
    filename : StringCommand}
 Will notate the client's ID and the server's IP address that the client will
 upload to. The filename will notate the file name to upload.
  clients : Hashtable<Integer, Client> – Clients hash table will be used by
     the UploadCommand when dealing with client uploads. The hash table
     key will be the client's ID as defined by the user and the value is a
     pointer to the related client.

 Operations:
  toScript() : String – Will convert a UploadCommand to a script text.
  execute() : Object – Will execute the command.




                                 61
4.2.5.7.    KillClientCommand
    Kill client command extends the Command abstract class.

 Attributes:
  argsVector : Vector< Command > –
    {clientID : NumberCommand}
 Will notate the client's ID to kill.
  clients : Hashtable<Integer, Client> – Clients hash table will be used by
     the KillClientCommand when dealing with client killing. The hash table
     key will be the client's ID as defined by the user and the value is a
     pointer to the related client.

 Operations:
  toScript() : String – Will convert a KillClientCommand to a script text.
  execute() : Object – Will execute the command.


4.2.5.8.   SleepCommand
    Sleep command extends the Command abstract class.

 Attributes:
  argsVector : Vector< Command > –
    {milliseconds: NumberCommand}
 Will notate the sleeping time of the system by milliseconds.

 Operations:
  toScript() : String – Will convert a SleepCommand to a script text.
  execute() : Object – Will execute the command.


4.2.5.9.    BasicCommand
    Basic command extends the Command abstract class.
    A command that includes basic information as a form of java.lang.String
    for the use of StringCommand, BooleanCommand, NumberCommand and
    AssignmentCommand.

 Attributes:
  basicArg : String
 Will notate the information as a String form.

 Operations:
  toScript() : String – Will convert a BasicCommand to a script text.
  execute() : Object – Will execute the command.




                                62
4.2.5.10. StringCommand
    String command extends the Command abstract class.
    A command that includes String

 Attributes:
  argsVector : Vector< Command > –
    {string : BasicCommand}
 Will notate the value of the string.

 Operations:
  toScript() : String – Will convert a StringCommand to a script text.
  execute() : Object – Will execute the command.


4.2.5.11. NumberCommand
    Number command extends the Command abstract class.
    A command that includes number: (integer or double).

 Attributes:
  argsVector : Vector< Command > –
    {number : BasicCommand}
 Will notate the value of the number.

 Operations:
  toScript() : String – Will convert a NumberCommand to a script text.
  execute() : Object – Will execute the command.


4.2.5.12. BooleanCommand
    Boolean command extends the Command abstract class.
    A command that includes boolean check and return true or false.
    The boolean operators will include: <, >, ==, >=, <=, !=, &&, ||.

 Attributes:
  argsVector : Vector< Command > –
    {booleanOperator : BasicCommand,
    leftOperand : Command,
    rightOperand : Command}
 Will notate the boolean operator and the operands.

 Operations:
  toScript() : String – Will convert a BooleanCommand to a script text.
  execute() : Object – Will execute the command.




                                63
4.2.5.13. MathCommand
    Math command extends the Command abstract class.
    A command that includes mathematic calculation and returns number
    result.
    The mathematic operators will include: +, -, *, /.

 Attributes:
  argsVector : Vector<Command> –
    {mathOperator : BasicCommand,
     leftOperand : NumberCommand,
     rightOperand : NumberCommand}
 Will notate the math operator and the operands.

 Operations:
  toScript() : String – Will convert a MathCommand to a script text.
  execute() : Object – Will execute the command.


4.2.5.14. AssignmentCommand
    Assignment command extends the Command abstract class.
    A command for a variable assignment.

 Attributes:
  argsVector : Vector< Command > –
    {variableName : BasicCommand
     variableValue : Command}
 Will notate the variable name and the variable value.
  symbolTable : Hashtable<String, Command > – A table of the variables
     defined in the script. The hash table key will be the variable's name as
     defined by the script and the value is a pointer to the related object.

 Operations:
  toScript() : String – Will convert an AssignmentClientCommand to a
    script text.
  execute() : Object – Will execute the command.




                                64
4.2.5.15. LookupCommand
    Variable command extends the Command abstract class.
    A command for a variable lookup.

 Attributes:
  argsVector : Vector< Command > –
    {variableName : BasicCommand}
 Will notate the variable name to lookup.
  symbolTable : Hashtable<String, Command > – A table of the variables
     defined in the script. The hash table key will be the variable's name as
     defined by the script and the value is a pointer to the related object.
 Operations:
  toScript() : String – Will convert a LookupCommand to a script text.
  execute() : Object – Will execute the command.


4.2.5.16. BlockCommand
    Block command extends the Command abstract class.
    A command that includes a sequence of commands inside.

 Attributes:
  argsVector : Vector<Command > –
 Will notate the commands sequence to execute.

 Operations:
  toScript() : String – Will convert a BlockCommand to a script text.
  execute() : Object – Will execute the command.


4.2.5.17. IfCommand
    If command extends the Command abstract class.
    A command that includes If-2 condition or If-3 condition.

 Attributes:
  argsVector : Vector< Command > –
    {booleanCheck : BooleanCommand
     thenClause : Command
     elseClause : Command} (for if-3) or
    {booleanCheck : BooleanCommand
     thenClause : Command} (for if-2)
 Will notate the boolean check, the then clause and the else clause in a case of
 if-3.




                                65
    Operations:
     toScript() : String – Will convert a IfCommand to a script text.
     execute() : Object – Will execute the command.
   4.2.5.18. ForCommand
       For command extends the Command abstract class.
       A command that includes for loop

     Attributes:
      argsVector : Vector< Command > –
        {forInitAssiggnment : AssignmentCommand
         forBooleanCheck : BooleanCommand
         forIncAssiggnment : AssignmentCommand
         forClause : Command}
     Will notate the for assignment, the for Boolean check, the for increment
     assignment and the for clause.
     Operations:
      toScript() : String – Will convert a ForCommand to a script text.
      execute() : Object – Will execute the command.

4.2.6. Classes of package: Client
    4.2.6.1.    Client
     A Client is a simulated client that will connect to P2P servers and
     download/upload files from/to them, and will transfer appropriate statistics
     about them.
     The Client is an abstract Class which will be implemented by several plug-
     ins of client implementations that using different protocols.

     Attributes:
      clientID : double – Will notate the client's ID.
      simLatency : double – Will notate the simulated latency of the client.
      simSpeedLimit : double – Will notate the simulated download/upload
         speed of the client.
      ttl : double – Will notate the time to live for the client.
      bornTime : double – Will notate the client born time for the calculation
         when the time to live excided the time limit.
      sessions : Hashtable<String, Session> – Will notate the sessions that the
         client will open with the servers. The hash table key will be the server
         name and the value will be the Session that has opened with it.




                                    66
Operations:
 initialize(realExecution : boolean) : void – will initialize the client with
   it's listening ports, shared file count in his sharing folder and initialize it's
   listeners. The parameter realExecution notates whether this is a real
   execution, and whether the client needs to initialize the above data for
   real.
   o Pre-condition: The system is in OnExecution state as described in
        3.3.1.
   o Post-condition: The Post-condition: The system is in OnExecution
        state as described in 3.3.1.

   listen(realExecution : boolean) : void – Will connect the client to the net
    when it created. The parameter realExecution notates whether this is a
    real execution, and whether the client needs to connect the net for real.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1.
    o Post-condition: The Post-condition: The system is in OnExecution
         state as described in 3.3.1.
   connect(serverAddress: String, realExecution : boolean) : void – Will
    connect the client to the server serverAddress. The parameter
    serverAddress is a string notates the servers ip address and port to
    connect. The parameter realExecution notates whether this is a real
    execution, and whether the client needs to connect the net for real.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1 and the client is in NotConnectedToServer state as described in
         3.3.2 related to the server: serverAddress.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1 and the client is in AttemptToConnect state as described in
         3.3.2 related to the server: serverAddress.
   disconnect(serverAddress: String, realExecution : boolean) : void –
    Will disconnect the client from the server serverAddress. The parameter
    serverAddress is a string notates the server ip address and port to
    disconnect. The parameter realExecution notates whether this is a real
    execution, and whether the client needs to disconnect from the net for
    real.
    o Pre-condition: The system is in OnExecution state as described in
         3.3.1 and the client is in one of the following states described in
         3.3.2: AttemptToConnect, ConnectedToServer,
         DataTransferWithServer related to the server: serverAddress.
    o Post-condition: The system is in OnExecution state as described in
         3.3.1 and the client is in NotConnectedToServer state as described in
         3.3.2 related to the server: serverAddress.




                                 67
    download(serverAddress : String, filename : String, realExecution :
     boolean) : void – Will search and download a file named filename from
     the server serverAddress. The parameter serverAddress is a string
     notates the servers ip address and port to download from. The parameter
     filename is a string notates the fileName the client supposed to search
     and download. The parameter realExecution notates whether this is a
     real execution, and whether the client needs to perform download from
     the net for real.
     o Pre-condition: The system is in OnExecution state as described in
         3.3.1 and the client is in one of the following states described in
         3.3.2: ConnectedToServer, DataTransferWithServer related to the
         server: serverAddress.
     o Post-condition: The system is in OnExecution state as described in
         3.3.1 and the client is in DataTransferWithServer state as described
         in 3.3.2 related to the server: serverAddress.
    kill(realExecution : boolean) : void – Will kill the client and all his net
     sessions. The parameter realExecution notates whether this is a real
     execution, and whether the client needs to kill all it's net sessions.
     o Pre-condition: The system is in OnExecution state as described in
         3.3.1 and for each server the client is in one of the following states
         described in 3.3.2: NotConnectedToServer, AttemptToConnect,
         ConnectedToServer, DataTransferWithServer.
     o Post-condition: The system is in OnExecution state as described in
         3.3.1 and the client is dead.

4.2.6.2.   ClientFactory
    The ClientFactory responsibles to generate client according to the
    prefernces of the user. For now it will create Gnutella client only.
 Attributes:
    None.
 Operations:
  generateClient(clientID : double, simulatedSpeed : double,
     simulatedLatency : double, ttl: double) : Client - Creates Client
     according to the P2P protocol notated in the preferences. The parameter
     clientID will be the ID of client. simulatedSpeed will be the simulated
     speed of client. The parameter simulatedLatency will be the simulated
     latency of client. The parameter ttl will be the time to live of client.
     Retruns the client that was created.
     o Pre-condition: The system is at OnExecution state as described in
         3.3.1.
     o Post-condition: The system is at OnExecution state as described in
         3.3.1.




                                 68
4.2.6.3.   ClientsHolder

    This class is designed for holding clients with a monitor, for acheiving
    simulated speed and latency.
    It holds a client until the TimeSchduler free it.
    It occurs every second.

 Attributes:
   None.
 Operations:
  holdMeForASec() : boolean - Holds a client for the rest of the second,
     with the help of the TimeScheduler.
     o Pre-condition: The system is at OnExecution state as described in
        3.3.1 and a client finishes his limited kb/sec to download according
        to his simulated speed or the client has not finished waiting by his
        simulated latency.
     o Post-condition: The system is still in OnExecution state as described
        in 3.3.1 and the client is waiting on the monitor.
  freeAllClients () : boolean - Free all clients on this classes monitor.
     Occurs for every second.
     o Pre-condition: The system is still in OnExecution state as described
        in 3.3.1 and the client is waiting on the monitor.
     o Post-condition: The system is still in OnExecution state as described
        in 3.3.1 and all clients are is notified and release from the monitor.

4.2.6.4.    KBytesCounter
    This class is responsible to answer the client if it excided its speed limit by
    its simulated speed.
 Attributes:
  Time : int – The amount of time that the client has already been in a
      simulated latency.
  Limit : int – The limit of how many KB the client should be able to
      download/upload.

 Operations:
  incNumKbytesAndAskIfWait(toInc, int) : boolean - The client
    increment The counter of how many bytes it was downloaded/uploaded
    and get a boolean answer weather to continiue download/upload or go to
    sleep. The parameter toInc is the number of bytes that the client was
    downloaded/uploaded since its previous update. Returns true if the client
    excided its speed limit.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1 and a client may excided its speed limit.
    o Post-condition: The system is still in OnExecution state as described
        in 3.3.1 and the client is either wait for the next second or contimiue
        to download/upload.


                                  69
4.2.6.5.    LatencyCounter
    This class is responsible to answer the client if it has reached to the latency
    time limit by its simulated latency.
 Attributes:
  numKbytes : int – The number of KB that the client has already
      downloaded/uploaded.
  Limit : int – The limit of how many time the client should be wait for his
      simulate latency.

 Operations:
  incTimeAndAskIfWait () : boolean Increments the time the client was
    wait until now (in seconds) and returns an answer weather the client
    should finish its simulated latency time. Returns a boolean answer
    weather the client should finish its simulated latency time.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1 and a client is notifies by the TimeScheduler in order to get an
        answer if he excided its latency time limit.
    o Post-condition: The system is still in OnExecution state as described
        in 3.3.1 and the client is either wait for the next second or continues
        to download/upload.

4.2.6.6.   Session
    Represents a communication session between the client and the Server he
    connects with.
 Attributes:
  client : Client – Represents the client initiated this session.
  remoteIPAddress : String – Represents the servers IP address that
     participate in this session.
  remotePort : int – Represents the servers port that participate in this
     session.
  remoteServerAddress : String – Represents the servers IP addres and
     servers port in one String.
  shutdownFlag : boolean – Represents whether the session should be shut
     down.
  fileNamesToDownload : BlockingQueue<String> – A thread safe queue
     represents the files to download according to the script order.

 Operations:
  None.




                                  70
4.2.6.7.   SharedFilesManager
    Responsibles for managing the shared files directory which stores the files
    which the clients share in order to reply for search queries and download
    requsets.

 Attributes:
  indexToFile : Hashtable<Integer, File> - The indexToFile hash table
     represents the mapping of files by file index.
     The hash table key will be the file index and the value is the related file
     name.

    fileToIndexes : Hashtable<String, Vector<Integer>> - The indexToFile
     hash table represents the mapping of file index by files. There is a chance
     of existance of some files with the same name, so in that case the file
     name has a vector of file indexes. The hash table key will be the file
     name and the value is the related vector of file indexes.
    sharedFilesCount : int – Represents the number of the total shared files
     inside the sahred directory.
    sharedFilesSize : int - Represents the of the total shared files size inside
     the sahred directory.

 Operations:
  isFileInSharedDirectory(fileName : String) : Boolean - Checks if the file
    with the name fileName is in the shared directory. It returns a boolean
    response that indicates the existance of the file in the shared directory.
    o Pre-condition: The system is at OnExecution state as described in
         ADD, 3.3.1 and a client received search query.
    o Post-condition: The system is still in OnExecution state as described
         in ADD 3.3.1 and the client is ready to build an answer for the search
         query that it received.
  getFilesData(String fileName) : Vector<Vector> - Gets the files data for
    the requested file namas: fileName.
    It returns a vector include Vectors represnts the data of the requsted files
    with the same file name.
    o Pre-condition: The system is in OnExecution state as described in
         ADD 3.3.1 and the client is ready to build an answer for the search
         query that it received.
    o Post-condition: The system is in OnExecution state as described in
         ADD 3.3.1 and the client can build an answer for the search query
         with the file data.




                                 71
4.2.7. Classes of package: Client/GnutellaClient

   4.2.7.1.   GnutellaClient
    A client that implements the Client using Gnutella protocol.
   4.2.7.2.   GnutellaSession
    A session that implements the Session using Gnutella protocol.

   4.2.7.3.   Connection
       A class represents a connection to gnutella network.

    Attributes:
     client : GnutellaClient - The Gnutella client that operate this connection.
     socket : Socket - The socket used to operate this connection.
     host : String - The IP of the server that the connection will connect.
     port : String - The port of the server that the connection will connect.
     serverAddress : String - A string represent the servers IP and port
        together .

    Operations:

       startOutgoingConnection () : void - Initializes an Outgoing Gnutella
        Connection with a server. Returns true if connection succeed.
        o Pre-condition: The system is at OnExecution state as described in
            3.3.1 and a client is in state NotConnectedToServer as described in
            3.3.2.
        o Post-condition: The system is at OnExecution state as described in
            ADD, 3.3.1 and a client is in state AttemptToConnect as described in
            3.3.2.
       startOutgoingConnection () : void - Initializes an Incoming Gnutella
        Connection with a server. Returns true if connection succeed.
        o Pre-condition: The system is at OnExecution state as described in
            3.3.1 and a client is in state NotConnectedToServer as described in
            3.3.2.
        o Post-condition: The system is at OnExecution state as described in
            ADD, 3.3.1 and a client is in state AttemptToConnect as described in
            3.3.2.

       shutdown() : void - Shuts Down the Gnutella connection.
        o Pre-condition: The system is at OnExecution state as described in
           3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.
        o Post-condition: The system is at OnExecution state as described in
           3.3.1 and a client is in state NotConnectedToServer as described in
           3.3.2.




                                   72
    prioritySend (m : Message) : void - Push a message to send to a queue
     with high priority, which means that the message will not being dropped.
     The parameter m is the message to push.
     o Pre-condition: The system is at OnExecution state as described in
         3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.
     o Post-condition: The system is at OnExecution state as described in
         3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.

    send (m : Message) : void - Push a message to send to a queue with low
     priority, which means that the message will not being dropped. The
     parameter m is the message to push.
     o Pre-condition: The system is at OnExecution state as described in
         3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.
     o Post-condition: The system is at OnExecution state as described in
         3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.

    sendAndReceive (m : Message, receiver : SearchRespondReceiver) :
     void - Responsibles for managing search query message to server and to
     receive a search response from the server. which means that the message
     will not being dropped. The parameter m is the message to send. The
     parameter receiver the SearchRespondReceiver that supposed to catch
     the search reply message.
     o Pre-condition: The system is at OnExecution state as described in
         3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.
     o Post-condition: The system is at OnExecution state as described in
         3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.

4.2.7.4.   ConnectionData
    Provides a linkage between the Servant and JTella.
    ConnectionInformation is used by GNUTellaConnectionand and others in
    determining current parameters settable by the Servant application.

 Attributes:
  listeningGnutellaPort : int - The Gnutella port the client listens.
  listeningHttpPort : int - Is the http port the client listens.

4.2.7.5.   Downloader
    Downloads a specified section of a file from a specified host, and saves
    the downloaded data to a specified file name on disk.

 Attributes:
  socket : Socket - The socket used to operate this connection.
  port : String - The port of the server that the connection will connect.
  serverAddress : String - A string represent the servers IP and port
     together .



                                73
 Operations:
  run () : void - The main method for the Downloader. Requests the file
    from the remote host, retrieves any data sent by the remote host.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1 and a client is in state ConnectedToServer as described in 3.3.2.
    o Post-condition: The system is at OnExecution state as described in
        3.3.1 and a client is in state DataTransferWithServer as described in
        3.3.2.
  shutdown () : void - Shuts down the Downloader.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1 and a client is in state DataTransferWithServer as described in
        3.3.2.
    o Post-condition: The system is at OnExecution state as described in
        ADD, 3.3.1 and a client is in state NotConnectedToServer or
        ConnectedToServer as described in 3.3.2.

4.2.7.6.  GnutellaListener
    Manager for incoming Gnutella connections.

 Attributes:
  Client : GnutellaClient - The GnutellaClient that uses the
     GnutellaListener.
  serverSocket : ServerSocket - The ServerSocket that the
     GnutellaListener uses for listening for incoming messages.

 Operations:
  run () : void - Start listening for incoming messages.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1, and a client is creating.
    o Post-condition: The system is at OnExecution state as described in
        3.3.1 , and a client was created.
  shutdown () : void - Shuts down the GnutellaListenre.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1 and for each server the client is in one of the following states
        described in 3.3.2: NotConnectedToServer, AttemptToConnect,
        ConnectedToServer, DataTransferWithServer.
    o Post-condition: The system is at OnExecution state as described in
        ADD, 3.3.1 and a client killed.




                                 74
4.2.7.7.    Monitor
    Responsibles for catching the messages arrives from the Connection
    connection. When it catches a message it route it to the router for routing
    it according to the Gnutella Protocol. If the next arriving message is a ping
    message he sends back a pong message.
 Attributes:
  Connection : Connection - The connection the monitor works on.
  serverSocket : ServerSocket - The ServerSocket that the
      GnutellaListener uses for listening for incoming messages.

 Operations:
  run () : void - Makes the Monitor start running.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1, and a client is in NotConnectedToServer state as described in
        3.3.2.
    o Post-condition: The system is at OnExecution state as described in
        3.3.1 , and a client is in ConnectedToServer state as described in
        3.3.2.
  shutdown () : void - Shuts down the Monitor.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1, and a client is in ConnectedToServer state as described in
        3.3.2.
    o Post-condition: The system is at OnExecution state as described in
        3.3.1 , and a client is in NotConnectedToServer state as described in
        3.3.2.

4.2.7.8.   SearchReceiver
    Responsibles for receiving search messages from any host in the Gnutella
    network and preparing SearchReplyMessage with all the details needed to
    connect to the HTTP server and downloading the file.

 Attributes:
  listeningHttpPort : int - The port where the http server listens.
 Operations:
  receiveSearch (searchMessage : SearchMessage, connection :
     Connection) : void - Responsibles to get the search message from any
     host connected to the connection and reply a search reply message to that
     host. The parameter searchMessage is the search message as was
     extracted from the connected host. The parameter connection is the
     connection that the host described above is connected to
     o Pre-condition: The system is at OnExecution state as described in
         3.3.1, and a client is in ConnectedToServer state as described in
         3.3.2.
     o Post-condition: The system is at OnExecution state as described in
         3.3.1 , and a client is in ConnectedToServer state as described in
         3.3.2.


                                 75
4.2.7.9.    SearchRespondReceiver
    Responsibles for receiving a search respond from a host which we have
    sent search message to it. It gathers the information needed for
    downloading a file from that host.
    Responsibles for putting all this information in a hash table.

 Attributes:
  searchResponses : Hashtable<String, SearchReplyMessage.FileRecord>
     - The whole FileRecords arranged by the String of the query.
  query : String - The current query the SearchRespondReceiver handles.

 Operations:
  receiveSearchReply (searchReply: SearchReplyMessage) : void - Gets
    the SearchReplyMessage and analyzes it in order to locate the specific
    file to download and to collect all the details like its size and directory it
    located in the host If there exists more than one file with the same name
    it chooses the biggest file by LCPs definition It put the information as a
    FileRecord in the Hashtable searchResponses. The parameter
    searchReply is the SearchReplyMessage it gets to analyze.
    o Pre-condition: The system is at OnExecution state as described in
         3.3.1, and a client is in ConnectedToServer state as described in
         3.3.2.
    o Post-condition: The system is at OnExecution state as described in
         3.3.1 , and a client is in ConnectedToServer state as described in
         3.3.2.

4.2.7.10. SocketFactory
    Responsibles for a unified sockets creations.

 Operations:
  getSocket (host : String, port : int, maxWait : int) : void - Creates a
    socket with a maxiumum wait value on the initial connection. The
    parameter host is the remote host IP. The parameter port is the remote
    port. The parameter maxWait is the maximum wait time for connection
    in milliseconds. Returns the socket was created.
    o Pre-condition: The system is at OnExecution state as described in
        3.3.1, and a client is either in ConnectedToServer state if it wishes to
        start a new download, or in NotConnectedToServer state if he
        whishes to open a new outgoing connection as described in 3.3.2.
    o Post-condition: The system is at OnExecution state as described in
        3.3.1, and a client is either in DataTransferWithServer state if it
        wished to start a new download, or in ConnectedToServer state if he
        whished to open a new outgoing connection as described in 3.3.2.




                                  76
4.2.8. Classes of package: Client/GnutellaClient/HTTPServer
    4.2.8.1.   HTTPServer
        A class being an HTTP server for performing upload operations.

     Attributes:
      Port : int - The listening HTTP port.
      Serverocket : ServerSocket - The ServerSocket which listen to incoming
         messages asynchronically.

     Operations:

        run () : void - Running a socket which wait for acceptions of incoming
         Gnutella client who wish to upload files in HTTP protocol.
         o Pre-condition: The system is at OnExecution state as described in
             3.3.1, and a client is created now and tries to operate its HTTP
             server.
         o Post-condition: The system is at OnExecution state as described in
             3.3.1 , and a client operate its HTTP server.
        shutdown () : void - Shuts down the ServerSocket.
         o Pre-condition: The system is at OnExecution state as described in
             3.3.1, and a client is time to live is arrived or there was a
             KillClientCommand operate on client.
         o Post-condition: The system is at OnExecution state as described in
             3.3.1 , and a client is dead and not listening to the http port.
             In a case of Stopping the simulator, The system will be in
             PostExecution state.

   4.2.8.2.   HTTPRequestHandler
       A class responsibles for managing the message transmissions with
       connected clients for an HTTPServer in order to upload shared files.

     Attributes:
      Socket : Socket - The socket used to communicate with the clients and
         upload the shared files to them.
      serverAddress : String - The address <ip>:<port> of the connected
         Gnutella client who wish to upload a shared file from this client.

     Operations:
      run () : void - Activates the HTTPRequestHandler.
        o Pre-condition: The system is at OnExecution state as described in
            3.3.1, and a client is created now and tries to operate its HTTP
            server.
        o Post-condition: The system is at OnExecution state as described in
            3.3.1 , and a client operate its HTTP server.




                                    77
4.2.9. Classes of package: Client/GnutellaClient/Message
    4.2.9.1.   Message
        Abstract base class for GNUTella messages.

    Attributes:
     originatingConnection : Connection - The messages original connection.
     guid : GUID - The messages - Globally Unique Identifier.
     type : short - The messages type.
     ttl : byte - The messages ttl which indicate the message time to live. The
        ttl is decremented in 1 when passing from one host to another in order to
        drop it when it pass through over too many hosts usually around 7.
     hops : byte - The messages hops which indicate the message time to live.
        The hops is incremented in 1 when passing from one host to another in
        order to drop it when it pass through over too many hosts usually around
        7
     payload : short array - The data, such as a data field, block, or stream,
        being processed or transported — the part that represents user
        information and user overhead information.
     payloadSize : short array - The messages payload size.

   4.2.9.2.   GUID
        Globally Unique Identifier Represents a unique ID for a message.

    Attributes:
     clientID : short array - represents the ID of client that takes a part of the
        GUID data.
     Rand : Random - represents a random number that takes a part of the
        GUID data.
     data : short array - Represents the GUID data.

    Operations:
     hashCode () : int – Produce a hashcode for this GUID.
     generateGUID () : short array– Generate something remotely
       resembling a windows guid The short this returns is cast to a GUID byte
       when it is actually used. Return the GUID data.
     getClientIdentifier () : short array– Generate something resembling a
       guid for this host.




                                    78
4.2.9.3.    MessageFactory
 Constructs the appropriate Message subclass.
 Operations:
  createMessage (rawMessage : short array, originatingConnection :
     Connection) : int – Factory method providing messages. The parameter
     rawMessage is the meaage data. The parameter originatingConnection
     is the connection which carried the message. Returns a Message subclass
     according to the message type.
4.2.9.4.    PingMessage
 A subclass of Message represents GNUTella Ping message.

4.2.9.5.   PongMessage
 A subclass of Message represents a pong GNUTella message. A Pong
 message is sent in reply to a Ping and provides host information.
 Attributes:
  port : short - The listening port of the GNUTella client to sent the
     message.
  ipAddress : String The IP of the GNUTella client to sent the message.

4.2.9.6.  SearchMessage
 A subclass of Message represents GNUTella search message
 The message for queries in order to search files at the other GNUTella
 clients.

 Attributes:
  query : String - The name of file that LCP client is looking for.

4.2.9.7.   SearchReplyMessage
 A subclass of Message represents GNUTella QUERY HIT responses to a
 search request.

 Attributes:
  fileRecords : Vector<FileRecord> - The filerecors vector in order to
     check whether a file exists in our shared directory.
  port : short - The port of the LCP clients HTTP Server to give the
     connected GNUTella client who wishes to download a file.
  ipAddress : String - The IP of the LCP clients HTTP Server to give the
     connected GNUTella client who wishes to download a file.
  speed : String - The speed of the LCP clients HTTP Server to give the
     connected GNUTella client who wishes to download a file.
  vendorCode : String - The vendorCode of the LCP clients HTTP Server
     to give the connected GNUTella client who wishes to download a file.




                                79
4.2.10. Classes of package: Client/GnutellaClient/Router

   4.2.10.1. Router
       Routes messages read from the network to appropriate Connections.

    Attributes:
     Sessions : Hashtable<String, Session> - Includes the whole sessions
        connect to an LCP clients.
     pingRouteTable : RouteTable - The routing table for ping messages in
        order to participate in the GNUTella network nodes assembly.
     originateTable : OriginateTable - A table the manages the messages that
        LCP will route back according to the GNUTella network nodes
        assembly.

    Operations:
     run () : void – Runs along routing messages.
     shutdown () : void Stops the operation of the router.

   4.2.10.2. RouteTable
       Contains history information on Messages used for routing Maps GUIDs
       to the connection they arrived on.

     Attributes:
     primaryHashMap : HashMap<GUID, Connection> - The hashtable
      represents the routing table. The hash table key will be the GUID of the
      GNUTella client connected to LCP client and the hash table value will
      be the connection with that GNUTella client.
     secondaryHashMap : HashMap<GUID, Connection> - A secondary
      routing table that reserved for a case the size of the primaryHashMap
      approaches its maxSize limit.
     maxSize : int - The max size of the primary routing table.

    Operations:
     put(guid : GUID, connection : Connection) : void – Puts a GUID to
       Connection mapping in the table. The parameter guid is the GUID to
       insert as a key. The parameter connection is the Connection to insert as a
       value.
     get (guid : GUID) : Connection Retrieves a Connection for a GUID. The
       parameter guid The GUID of the Connection to retrive. Returns the
       retrived conneciont.




                                  80
   4.2.10.3. OriginateTable
       Contains information for routing originated messages.

        Attributes:

        hashMap : HashMap<GUID, SearchRespondReceiver> - The hashMap
         containing the information for routing originated messages the hashMap
         key will be the GUID of the message and the hashMap value will be the
         corresponding SearchRespondReceiver.

    Operations:
     put(guid : GUID, receiver: SearchRespondReceiver) : void – Puts a
       GUID to MessageReceiver mapping in the table. The parameter guid is
       the GUID to insert as a key. The parameter receiver is the
       SearchRespondReceiver to insert as a value.
     get (guid : GUID) : SearchRespondReceiver - Gets a message receiver
       for a GUID. The parameter guid is the SearchRespondReceiver with the
       right GUID to get.


        remove(guid : GUID) : void - Removes the guide/receiver mapping. The
         parameter guid is the SearchRespondReceiver with the right GUID to
         remove.
        containsGUID (guid : GUID) : void - Check if MessageReceiver exists
         for guid This is equivalent to checking if we sent a message. The
         parameter guid is the GUID to check. The parameter and answer whether
         the MessageReceiver exists.

4.2.11. Classes of package: Client/GnutellaClient/Router
    4.2.11.1. BoundedQueue
        A Queue supporting standard enqueue/dequeue fileNamesToDownload
        with a maximum permitted size. Having a maximum size guards against
        unrestricted memory usage.

        Attributes:
        queue: LinkedList - The bounded queue represented by a LinkedList.

    Operations:
     enqueue (o: Object) : boolean – Enqueues an object from the queue. The
       parameter o is the object to insert to the queue. Return true if enqueue
       worked, false if queue is full.
     dequeue () : Object Removes an object from the queue. Returns the next
       object from the queue.
     empty () : boolean - Check if the queue is empty. Returns true if empty,
       false otherwise.



                                   81
   4.2.11.2. Mutex
       A simple mutex.

    Operations:
     down () : void – Freezes the Thread that operate this function.
     up () : void Releazes all Threads on this Mutex.

   4.2.11.3. PortGenerator
       A class responsibles to generate a port to each LCP client starting from the
       user.

    Operations:
     generateListeningPort (port : int) : void – Generates the port. The
       parameter port is the initial port asked to generate. Returns the first
       occupied port.

4.2.12. Classes of package: GUI
    4.2.12.1. LCP_GUI
        Represents the main window of LCP with all the GUI components.

    Operations:
     clearAll () : void – Clears the statistics table and tree and the graph
       canvas.
     displaySuccessMessage (successDescription : String) : void – Displays
       an informative Success message. The parameter successDescription will
       be a string describes the success.


   4.2.12.2. GlobalStatisticsContents
       A class represents the global statistics table contents.
   4.2.12.3. ServerStatisticsContents
       A class represents the servers statistics tree contents.

   4.2.12.4. GUIEventsHandler
       A class that responsible for all events in the gui that occurs in the main
       window.

    Attributes:
     run : boolean - Indicates if the system running a simulator.
     firstTimeSinceScriptLoaded : boolean - Indicates wheater the the graph
        was represented for the first time since the script was loaded.
     numberOfChosenGlobalListItems : int - Indicates the number of Items
        represented in the global statistics table.
     lastSelectionNoOnGlobalTable : int - Indicates what was the last chosen
        number on the global table.



                                     82
 Operations:
  arrangeSelectionListeners () : void – Will attach SelectionAdapter for
     every GUI component from LCP_GUI represents the main window of
     LCP.
  openScriptEvent () : void – Opens a new dialog for loading a script file
     and loads the chosen file.
  openLogEvent () : void – Opens a new dialog for loading a log file and
     loads the chosen file.
  runOrStopEvent () : void – Runs/Stops the simulator.
  exitEvent () : void – Exits LCP with a standard exit dialog.
  aboutEvent () : void – Dispatches the "about" window.
  preferencesEvent () : void – Dispatches the user preferences window.
4.2.12.5. InformationMessage
    Responsibles to display an informative Error/Success message for the
    script compiler and logger.

 Operations:
  displayErrorMessage (errorDescription : String) : void – Displays an
    informative Error message. The parameter errorDescription will be a
    string describes the error.
  displaySuccessMessage (successDescription : String) : void – Displays
    an informative Success message. The parameter successDescription will
    be a string describes the success.

4.2.12.6. PreferncesDialog
    A dialog for representing the user preferences wizard.

 Operations:
  open() : void – Opens the user preferences dialog.

4.2.12.7. AboutDialog
    A dialog for representing our names and some standart details about our
    project.

 Operations:
  open() : void – Opens the ―About‖ dialog.




                                83
4.2.13. Classes of package: GUI/Graph
    4.2.13.1. DirectedGraphXYPlotter
        A class represents the plotter for the statistics graph.
     Attributes:
      _seriesData : ArrayList - The data to represent in the graph.
      _seriesScaledValues : ArrayList - The data to represnt in the graph
         according to the graph pixels.
      _nodeLists : ArrayList - The list of nodes to plot in the graph.
      _edgeLists : ArrayList - The list of edges to plot in the graph.
      _colors : Color array - The colors to represent in the graph.

     Operations:
      plot (w : int, h : int, follow : boolean) : void – plotting the data of the
        graph. The parameter w is the desired graph width. The parameter h is
        the desired graph height. The parameter follow indicates weather the
        graph plotter should follow the graph progress.
      displaySuccessMessage (successDescription : String) : void – Displays
        an informative Success message. The parameter successDescription will
        be a string describes the success.

   4.2.13.2. Dot
       A Figure for representing Node(s) in a graph (extents
       org.eclipse.draw2d.Ellipse).

   4.2.13.3. XRulerBar
       A Figure that can render itself as the x-Axis for a given set of series data
       (extends org.eclipse.draw2d.Polyline).

   4.2.13.4. YRulerBar
       A Figure that can render itself as the y-Axis for a given set of series data.
       (extends org.eclipse.draw2d.Polyline).

   4.2.13.5. GraphixParameters
       The parameters that helps designing the graph and representing it well.

   4.2.13.6. Utilities
       Utilities class for graph.
    Operations:
     getMaximum (values : object array) : void – Returns the LARGEST
        value in the array. The parameter values is the array to check.
     getMinimum (values : object array) : void – Returns the SMALLEST
        value in the array. The parameter values is the array to check.
     getLongestSeries (seriesData : ArrayList) : void – Returns the longest
        series in the ArrayList. The parameter seriesData is the ArrayList to
        check.



                                     84
4.3.    Packages
    4.3.1. GnutellaClient packages




                                     85
86
4.3.2. GUI Packages




                      87
4.4.   Unit Testing

    4.4.1. Unit testing for DataManager class
        4.4.1.1.  loadScriptFile(fileName : String) : void
                  We will check that this method practically loads the selected file.
                  It should parses the script and creates the commands so we will
                  open the selected file in a text editor and check if the script
                  matches the created commands.
                  We will also check what happens when the filename is illegal or
                  non exist.

    4.4.2. Unit testing for SimulatorExecuter class
        4.4.2.1.  executeSimulator() : void
                  We will check that this method goes over all the commands and
                  operates the execute method in Command.
        4.4.2.2.  stopExecution : void
                  We will check that this method stops the simulator execution.

    4.4.3. Unit testing for StatisticsHandler class
        4.4.3.1.  loadLogFile(fileName : String) : void
                  We will open the selected file in a text editor and check if the
                  statistics in the file matches the row statistics in the GUI.
                  We will also check what happens when the filename is illegal or
                  non exist.
        4.4.3.2.  update(server : String, dataType : String, value : double) : void
                  We will check that this method is called on every event.
                  We will check that the server matches the related server, the
                  dataType matches the occurred event and the value matches the
                  related value.
                  We will check that this method updates the DataStripe's statistics
                  in the StatisticsHandler.
        4.4.3.3.  setGraphAxis(y : String, x : String) : void
                  We will check that this method shows the graph y(x).
                  We can open the log file in a text editor and checks if the statistics
                  in the file matches the graph.

    4.4.4. Unit testing for StatisticsViewer class
        4.4.4.1.  view(dataStripe : DataStripe) : void
                  We will check that this method views the dataStripe as a textual
                  row.
        4.4.4.2.  showGraph(y : String, yValues : Vector, x : String, xValues :
                  Vector) : void
                  We will check that this method shows the graph y(x) with xValues
                  in x-axis and yValues in y-axis.




                                         88
4.4.5. Unit testing for Command class
    4.4.5.1.  toScript() : String
              We will check that this method result is a String text which is a
              translation of the Command in the script language.
    4.4.5.2.  execute() : Object
              We will check that this method executes the Command depends on
              the Command type.
4.4.6. Unit testing for Client class
    4.4.6.1.  connect(server : String) : void
              We will check that this method tries to make a connection with the
              server. We will check that all the connection steps are
              implemented well.
              We will check this method with legal and illegal server.
    4.4.6.2.  disconnect(server : String) : void
              We will check that this method disconnects from the server.
              We will check this method with legal and illegal server.
    4.4.6.3.  download(server : String, filename : String) : void
              We will check that this method tries to download the filename
              from the server.
              We will check that all the download steps are implemented well.
              We will check this method with legal and illegal server.
    4.4.6.4.  upload(server : String, filename : String) : void
              We will check that this method tries to upload the filename to the
              server.
              We will check that all the upload steps are implemented well.
              We will check this method with legal and illegal server.
    4.4.6.5.  kill() : void
              We will check that this method kills the client.

4.4.7. Unit testing for Logger class
    4.4.7.1.  log(dataStripe : DataStripe) : void
              We will check that this method logs the dataStripe statistics in the
              log file.




                                    89
5. System Architecture
The LCP System is a stand-alone program which operates on one computer.
All the simulated clients are in the same machine as the entirety system.
The tested servers are outside the system scope.
Therefore, there is only one software component in the system.

   5.1.   System architecture diagram




                                         90
   5.2.   Deployment diagram




6. User Interface Draft

   6.1.   The main frame during simulator execution




                                      91
6.2.   The load script frame




                               92
6.3.   The load log file frame




                                 93
6.4.   The preferences of the system frame




                                    94
7. Testing
   7.1.   Testing the script compiler
          We will write many kinds of different scripts which include simple
          expressions, compound expressions and illegal expressions. We will operate
          the script compiler on these scripts and check the results.
          First, we will test each component of the compiler separately, and than test the
          whole compiler.

   7.2.    Testing the client
           We will test the client operations which include connection, disconnection
           and file transfer. We will check that these operations are implemented well
           and the client is a suitable p2p client which can communicate with p2p server
           by the defined p2p protocol.

   7.3.    Testing the execution
           We will test the commands execution. We will check that each command is
           executed well and the clients update the statistics on every event.

   7.4.    Testing statistics viewing
           We will check that the textual statistics are updated in the right frequency.
           We will check that the graph generation engine is performing well on any two
           variables.

   7.5.    Testing the GUI
           We will test all the GUI features: buttons, menus, sliders, panels etc.

   7.6.    Testing speed constraints
           We will check that the script file loading and the log file loading is not taking
           more than 2 seconds.

   7.7.    Testing platform constraints
           We will test the whole application on Linux operating system.




                                            95
8. Task List

Task ID                       1
Title                         Design of Script Compiler
Est Starting Date                22.2.06      Actual Starting Date           22.2.06
Est Finish Date                   1.4.06      Actual Finish Date             10.4.06
Description
The task will include implementation of the following classes:
ScriptScanner, ScriptParser and commandsGenerator in order to be able to convert script
text file into LCP commands.
 See sub-tasks                             1.1 Design of Script scanner
                                            1.2 Design of Script Parser
                                            1.3 Design of Commands Generator
 Superceded by tasks



Task ID                        1.1
Title                           Design of Script scanner
Est Starting Date                   22.2.06      Actual Starting Date           22.2.06
Est Finish Date                      5.3.06      Actual Finish Date             15.3.06
Description
The task will include implementation of the ScriptScanner class responsible for getting a
string from a file and switching it into tokens.
 See sub-tasks
 Superceded by tasks



Task ID                        1.2
Title                          Design of Script parser
Est Starting Date                   5.3.06     Actual Starting Date              15.3.06
Est Finish Date                    26.3.06     Actual Finish Date                30.3.06
Description
The task will include implementation of the ScriptParser class responsible for getting a
list of tokens from the ScriptScanner and switching it into parsed list.
 See sub-tasks                              1.2.1 Parsing of simple expressions
                                             1.2.2 Parsing of complex expressions
 Superceded by tasks




                                           96
Task ID                      1.2.1
Title                        Parsing of simple expressions
Est Starting Date                 5.3.06      Actual Starting Date               15.3.06
Est Finish Date                  12.3.06      Actual Finish Date                 20.3.06
Description
The task will include implementation of a basic ScriptParser responsible for a
noncomplex kind of expressions.
 See sub-tasks
 Superceded by tasks



Task ID                       1.2.2
Title                         Parsing of complex expressions
Est Starting Date                 31.3.06      Actual Starting Date              13.3.06
Est Finish Date                   66.3.06      Actual Finish Date                27.3.06
Description
The task will include extension of the basic ScriptParser in order to support complex
expressions.
 See sub-tasks
 Superceded by tasks



Task ID                        1.3
Title                          Design of Commands Generator
Est Starting Date                  26.2.06      Actual Starting Date            25.2.06
Est Finish Date                     1.4.06      Actual Finish Date              25.3.06
Description
The task will include implementation of the CommandsGenerator class responsible for
getting parsed list from the ScriptParser and generating Commands from the list.
 See sub-tasks
 Superceded by tasks




                                           97
Task ID                      6
Title                        Design of Commands
Est Starting Date               20.3.06        Actual Starting Date           20.3.06
Est Finish Date                 31.3.06        Actual Finish Date              4.4.06
Description
The task will include implementation of all types of the LCP commands.
 See sub-tasks                              2.1 Implementing basic commands
                                             2.2 Implementing client commands
                                             2.3 Implementing compound commands
 Superceded by tasks



Task ID                      2.1
Title                        Implementing basic commands
Est Starting Date                20.3.06       Actual Starting Date          20.3.06
Est Finish Date                  25.3.06       Actual Finish Date            21.3.06
Description
The task will include implementation of all LCP commands of a basic type.
 See sub-tasks                              2.1.1 Implementing atomic commands.
                                             2.1.2 Implementing global commands.
 Superceded by tasks



Task ID                      2.1.1
Title                        Implementing atomic commands
Est Starting Date                20.3.06       Actual Starting Date          20.3.06
Est Finish Date                  22.3.06       Actual Finish Date            21.3.06
Description
The task will include implementation of all atomic LCP commands of a basic type:
BasicCommand, StringCommand, NumberCommand and BooleanCommand.
 See sub-tasks

 Superceded by tasks




                                          98
Task ID                      2.1.2
Title                        Implementing global commands
Est Starting Date                23.3.06       Actual Starting Date           23.3.06
Est Finish Date                  25.3.06       Actual Finish Date             25.3.06
Description
The task will include implementation of all global LCP commands of a basic type:
SleepCommand, MathCommand, AssignmentCommand, and LookupCommand.
 See sub-tasks

 Superceded by tasks



Task ID                      2.2
Title                        Implementing client commands
Est Starting Date                25.3.06      Actual Starting Date            25.3.06
Est Finish Date                  27.3.06      Actual Finish Date              27.3.06
Description
The task will include implementation of all LCP commands of a client operation type:
CreateClientCommand, ConnectClientCommand, DisconnectClientCommand,
DownloadCommand, UploadCommand and KillClientCommand.
 See sub-tasks
 Superceded by tasks



Task ID                      2.3
Title                        Implementing compound commands
Est Starting Date                28.3.06      Actual Starting Date         29.3.06
Est Finish Date                  31.3.06      Actual Finish Date             1.4.06
Description
The task will include implementation of all LCP commands of a compound type:
BlockCommand, IfCommand and ForCommand.
 See sub-tasks
 Superceded by tasks




                                          99
Task ID                      1
Title                        Design of LCP client
Est Starting Date                2.4.06       Actual Starting Date             20.4.06
Est Finish Date                 10.5.06       Actual Finish Date                8.7.06
Description
The task will include implementation of the LCP p2p client.
 See sub-tasks                             3.1 Implementing generic client
                                            3.2 Implementing gnutella client
                                            3.3 Implementing client events
 Superceded by tasks



Task ID                      3.1
Title                        Implementing generic client
Est Starting Date                2.4.06      Actual Starting Date              20.4.06
Est Finish Date                  4.4.06      Actual Finish Date                21.4.06
Description
The task will include implementation of the LCP p2p generic client which will be the
abstract class: Client.
 See sub-tasks
 Superceded by tasks



Task ID                        3.2
Title                          Implementing gnutella client
Est Starting Date                   5.4.06      Actual Starting Date            25.4.06
Est Finish Date                     6.5.06      Actual Finish Date               1.7.06
Description
The task will include implementation of the LCP p2p Gnutella client which will extend
the abstract Client with a gnutella protocol.
 See sub-tasks                               3.2.1 Connection and disconnection
                                              3.2.2 File transfer
 Superceded by tasks




                                          100
Task ID                      3.2.1
Title                        Connection and disconnection
Est Starting Date                 5.4.06       Actual Starting Date              25.4.06
Est Finish Date                  35.4.06       Actual Finish Date                10.5.06
Description
The task will include implementation of all gnutella client operations dealing with
connection and disconnection to a server.
 See sub-tasks                              3.2.1.1 Handshaking
                                             3.2.1.2 Standard message
 Superceded by tasks



Task ID                      3.2.1.1
Title                        Handshaking
Est Starting Date                 5.4.06      Actual Starting Date              25.4.06
Est Finish Date                  30.4.06      Actual Finish Date                 1.5.06
Description
The task will include implementation of the gnutella client handshaking.
 See sub-tasks
 Superceded by tasks



Task ID                      3.2.1.6
Title                        Standard message
Est Starting Date                10.4.06      Actual Starting Date               1.5.06
Est Finish Date                  35.4.06      Actual Finish Date                10.5.06
Description
The task will include implementation of the gnutella client Standard message.
 See sub-tasks
 Superceded by tasks




                                           101
Task ID                      3.2.2
Title                        File transfer
Est Starting Date                16.4.06       Actual Starting Date            10.6.06
Est Finish Date                   6.5.06       Actual Finish Date               1.7.06
Description
The task will include implementation of file transfer between LCP p2p Gnutella client
and a server.
 See sub-tasks
 Superceded by tasks



Task ID                      3.3
Title                        Implementing client events
Est Starting Date                 1.5.06      Actual Starting Date               2.7.06
Est Finish Date                  10.5.06      Actual Finish Date                10.7.06
Description
The task will include implementation of the LCP p2p client events.
 See sub-tasks                             3.3.1 Implementing client connection trial
                                            event
                                            3.3.2 Implementing client successful
                                            connection event
                                            3.3.3 Implementing client failure connection
                                            event
                                            3.3.4 Implementing download event
                                            3.3.5 Implementing upload event
 Superceded by tasks



Task ID                      3.3.1
Title                        Implementing client connection trial event
Est Starting Date                 1.5.06      Actual Starting Date              2.7.06
Est Finish Date                   5.5.06      Actual Finish Date                4.7.06
Description
The task will include implementation of client connection trial event.
 See sub-tasks
 Superceded by tasks




                                          102
Task ID                      3.3.2
Title                        Implementing client successful connection event
Est Starting Date                 5.5.06      Actual Starting Date           4.7.06
Est Finish Date                   6.5.06      Actual Finish Date             5.7.06
Description
The task will include implementation of client successful connection event.
 See sub-tasks
 Superceded by tasks



Task ID                      3.3.3
Title                        Implementing client failure connection event
Est Starting Date                 6.5.06      Actual Starting Date           6.7.06
Est Finish Date                   7.5.06      Actual Finish Date             7.7.06
Description
The task will include implementation of client failure connection event.
 See sub-tasks
 Superceded by tasks



Task ID                      3.3.4
Title                        Implementing download event
Est Starting Date                 7.5.06    Actual Starting Date             8.7.06
Est Finish Date                   8.5.06    Actual Finish Date               8.7.06
Description
The task will include implementation of download event.
 See sub-tasks
 Superceded by tasks



Task ID                      3.3.5
Title                        Implementing upload event
Est Starting Date                 8.5.06     Actual Starting Date            9.7.06
Est Finish Date                  10.5.06     Actual Finish Date             10.7.06
Description
The task will include implementation of upload event.
 See sub-tasks
 Superceded by tasks



                                         103
Task ID                        4
Title                           Design of Statistics collecting and representing
Est Starting Date                  15.4.06       Actual Starting Date            15.4.06
Est Finish Date                    15.5.06       Actual Finish Date              15.5.06
Description
The task will include implementation of the classes responsible for processing, saving
and viewing the statistics of a simulator execution.
 See sub-tasks                               4.1 Implementing DataStripe
                                              4.2 Implementing StatisticsHandler
                                              4.3 Implementing StatisticsViewer
                                              4.4 Implementing Logger
 Superceded by tasks



Task ID                      4.1
Title                        Implementing DataStripe
Est Starting Date                15.4.06     Actual Starting Date               15.4.06
Est Finish Date                  18.4.06     Actual Finish Date                 18.4.06
Description
The task will include implementation of the DataStripe class responsible for keeping a
row of data.
 See sub-tasks
 Superceded by tasks



Task ID                         4.2
Title                            Implementing StatisticsHandler
Est Starting Date                   19.4.06     Actual Starting Date             19.4.06
Est Finish Date                     24.4.06     Actual Finish Date               24.4.06
Description
The task will include implementation of the StatisticsHandler class responsible for
processing the statistics of a simulator execution.
 See sub-tasks
 Superceded by tasks




                                           104
Task ID                        4.3
Title                          Implementing StatisticsViewer
Est Starting Date                  24.4.06       Actual Starting Date            24.4.06
Est Finish Date                     1.5.06       Actual Finish Date               1.5.06
Description
The task will include implementation of the StatisticsViewer class responsible for
viewing the statistics of a simulator execution.
 See sub-tasks                               4.3.1 Implementing textual data viewer
                                              4.3.2 Implementing graphical data viewer
 Superceded by tasks



Task ID                       4.3.1
Title                         Implementing textual data viewer

Est Starting Date               24.4.06       Actual Starting Date                24.4.06
Est Finish Date                 27.4.06       Actual Finish Date                  27.4.06
Description
The task will include implementation of the textual viewing part for the StatisticsViewer
class.
 See sub-tasks
 Superceded by tasks



Task ID                       4.3.2
Title                         Implementing graphical data viewer

Est Starting Date               28.4.06       Actual Starting Date              28.4.06
Est Finish Date                  5.5.06       Actual Finish Date                 5.5.06
Description
The task will include implementation of the graphical viewing part for the
StatisticsViewer class.
 See sub-tasks
 Superceded by tasks




                                           105
Task ID                         4.4
Title                           Implementing Logger
Est Starting Date                    6.5.06      Actual Starting Date               6.5.06
Est Finish Date                     15.5.06      Actual Finish Date                15.5.06
Description
The task will include implementation of the Logger class responsible for saving (logging)
and also loading the statistics of a simulator execution.
 See sub-tasks                                4.4.1 Implementing logging statistics
                                               4.4.2 Implementing loading a log file
 Superceded by tasks



Task ID                       4.4.1
Title                         Implementing logging statistics
Est Starting Date                  6.5.06     Actual Starting Date               6.5.06
Est Finish Date                   10.5.06     Actual Finish Date                10.5.06
Description
The task will include implementation of the saving (logging) part of the Logger class
during a simulator execution.
 See sub-tasks
 Superceded by tasks



Task ID                          4.4.2
Title                            Implementing loading a log file
Est Starting Date                    11.5.06      Actual Starting Date           11.5.06
Est Finish Date                      15.5.06      Actual Finish Date             15.5.06
Description
The task will include implementation of a part of the Logger class responsible for loading
the statistics of a simulator after a simulator execution.
 See sub-tasks
 Superceded by tasks




                                           106
Task ID                      5
Title                        Design of simulator executing
Est Starting Date               15.4.06       Actual Starting Date            15.4.06
Est Finish Date                 30.4.06       Actual Finish Date              30.4.06
Description
The task will include implementation of the components responsible for simulator
execution.
 See sub-tasks                             5.1 Implementing simulatorExecuter
                                            5.2 Implementing DataManager
 Superceded by tasks

Task ID                      5.1
Title                        Implementing simulatorExecuter
Est Starting Date                15.4.06      Actual Starting Date           15.4.06
Est Finish Date                  17.4.06      Actual Finish Date             17.4.06
Description
The task will include implementation of the simulatorExecuter class.
 See sub-tasks
 Superceded by tasks



Task ID                       5.6
Title                         Implementing DataManager
Est Starting Date                 18.4.06    Actual Starting Date             18.4.06
Est Finish Date                   30.4.06    Actual Finish Date               30.4.06
Description
The task will include implementation of the DataManager class which holds the running
information of the simulator.
 See sub-tasks
 Superceded by tasks




                                          107
Appendixes

Script Syntax
The script syntax consists of the following components:
       • Numbers: Integers or floats
       • Strings: Sequence of chars between quotes
       • Math operators: +, -, *, /
       • Boolean operators: ==, <, <=, >, >=, !=
       • Assignments: Assign number or string to a variable
       • Special functions:
            o createClient(<client ID>, <speed>, <latency>, <ttl>)
                    <client ID>: Number, client identifier
                    <speed>: Number, client's simulated speed
                    <latency>: Number, client's simulated latency
                    <ttl>: Number, time to live (living time of a client)
                   This function creates a client with the above features.

           o connectClient(<client ID>, <server>)
                 <client ID>: Number, client identifier
                 <server>: String, server's address with the format: "IP:Port"
                This function connects a client to the specified server.

           o disconnectClient(<client ID>, <server>)
                  <client ID>: Number, client identifier
                  <server>: String, server's address with the format: "IP:Port"
                 This function disconnects a client from the specified server.

           o download(<client ID>, <server>, <file name>)
                 <client ID>: Number, client identifier
                 <server>: String, server's address with the format: "IP:Port"
                 <file name>: String, the name of the file to download
                This function downloads the specified file from the specified server.

           o killClient(<client ID>)
                  <client ID>: Number, client identifier
                 This function kills the specified client.

           o sleep(<time>)
                  <time>: Number, time to sleep in milliseconds
                 This function performs a delay of <time> milliseconds.

           o rand(<number>)
                 <number>: Number, upper limit of random number
                This function generates a random number between 0 and <number>
                exclusive.


                                           108
        •   Condition: If-statement
            o if (<arg1> <boolean operator> <arg2>)
                    <arg1>: Number or string
                    <boolean operator>: Boolean operator
                    <arg2>: Number or string
                   Remarks:
                   (<arg1> <boolean operator> <arg2>) – can be called Condition.
                   We can only compare between numbers or strings and not between
                   number and string.

        •   Loop: for-statement
            o for (<init assignment>, <condition>, <iteration assignment>)
                    <init assignment>: Assignment, Initial assignment
                    <condition>: Condition, Loop condition
                    <iteration assignment>: Assignment, Loop assignment

        •   Block: Sequence of commands
            o { <command>, <command>, … }
                    <command>: Command, Any legal command
                   Remark: Can be after if-statement or for-statement.

        •   Comments: User comments after //.

        •   Semicolon: Every command ends with semicolon (;)

Remarks:
     • All the above functions must written in case sensitive mode
         (e.g. createClient and not createclient).
     • Server's address must written in the format "IP:Port" with no spaces
         (e.g. "123.54.67.43:6069" and not "123.54.67.43 : 6069").


Script Example:

// example of a simple script

server = "122.34.45.78:3030";
for (x = 0, x < 10, x=x+1) {
        createClient(x, 10.67, 0, 20);
        connectClient(x, server);
        sleep(1000);
}
download (4, server, "madonna");

// end of script



                                          109
This script creates 10 clients and connects them to a specified server.
There is a delay of 1 second between each client creation.
The client with id 4 downloads the file "madonna" from the specified server.

P2P Protocol
Peer to Peer (P2P) networks are prevalent in today's Internet connected world.
They all, to some greater or lesser extent, allow people to download files from
other machines connected to the P2P network in question. Many different
P2P network specifications exist, and the open source specifications may have
many different servents (a system which can act as both SERVer and cliENT)
available for use. Probably the first well known P2P network was Napster,
which had a servent of the same name. However, Napster failed due to its reliance on a
central server of servents and the files they were sharing. Should this central server be
taken down, the entire network became unusable.

Gnutella Protocol
Probably the most well know modern P2P network is Gnutella, an open source system
with a myriad of clients, some of the more well known of which can be found at the
Gnutelliums website (http://www.gnutelliums.com).
Gnutella has a decentralized net or web-like structure, with servents connecting to each
other at random. Servents still, however, need some way of knowing where the remote
hosts to which they need to connect were located. Gnutella still need some central point
from which this information could be gained, from which the servents could bootstrap.
Several well known points quickly sprung up, mostly run by the developers of the more
well known servents. These points became known as hostcaches. A hostcache is just a
modified servent that return the location of ‗normal‘ servents. Once a list of hosts has
been obtained, connection attempts can be made.
After a connection attempt was succeeded, search requests are sent in to the network, and
responses sent back along the same route.
File download can then be requested directly from the remote host sharing
the required file, rather than going via the Gnutella network as searches do.
How the Gnutella file sharing network works:




                                            110
Gnutella 0.6 specifies two different types of servent that can connect to the Gnutella
network: ultrapeers and leaf nodes.
Ultrapeers are servents that allow incoming connections, while leaf nodes do not.
A leaf node can only make outgoing connections to ultrapeers, and an ultrapeer can
connect to anything using the network.

A representation of the layout of the Gnutella 0.6 network, showing how the
ultrapeers and leaf nodes link together:




Gnutella 0.6 handshaking consists of a 3 way handshake. At its simplest level,
the local servent sends
GNUTELLA CONNECT/0.6<CR><LF>
Like HTTP, each line of the request is separated by a <CR><LF>, and the
end of the request is denoted by a double <CR><LF>.
So the connection attempt would in fact be
GNUTELLA CONNECT/0.6<CR><LF>
Other headers, each ended with a <CR><LF>
<CR><LF>
The ‗Other headers‘ shown above are a mixture of mandatory and optional headers that
are sent when handshaking.
The 2 most common response types are shown below:
        • 200 – A host sending back a type 200 response is indicating its availability for
            connecting to.
            The full response should be:
            GNUTELLA/0.6 200 OK<CR><LF>




                                            111
       •   503 – A 503 response from a host indicates that the connection request was
           denied for some reason.
           The full response should be:
           GNUTELLA/0.6 503 Busy<CR><LF>

If anything other than a 200 response is gained the servent should drop the connection.
If a 200 response is received the servent must send:
GNUTELLA/0.6 200 OK
This informs the remote host that the connection is set up.
From this point the messages between the two hosts can be queries, responses to queries
or ping-pong messages.
The file download protocol is HTTP. File data is never transferred over the Gnutella
network.


JTella 0.7
JTella is a system created by Ken McCrary. First released in October 2000,
JTella is supposed to provide an easy to use API for writing a Gnutella
servent. It is a set of Java classes that provided the ability to connect to
the Gnutella network and make searches for files, while not dictating how
downloads should be handled or the layout of any kind of UI.
JTella is also designed to be easy to understand, consisting (at version 0.7) of only 37
classes, most of which are fairly small and all of which are well commented.
JTella can essentially be divided into three sections:
        • Classes dealing with a connection and staying connected to the Gnutella
             network.
        • Classes dealing with searching for files on the network, and dealing with the
             results to some extent.
        • Supporting classes that contain functions used by the above mentioned
             sections.
JTella as it stands in version 0.7 will not make a connection to the Gnutella 0.6
Network because it supports only the old version – Gnutella 0.4.
The network has simply changed too much from version 0.4 to version 0.6, and not
enough servents currently being used still support version 0.4 of the protocol.
Therefore, we have to change this package to support the following:
        • Gnutella 0.6 protocol
        • Download component
        • LCP requirements: specified search, unlimited connections etc.




                                           112

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:41
posted:8/17/2011
language:English
pages:112