Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5618 in orxonox.OLD for branches/network


Ignore:
Timestamp:
Nov 16, 2005, 7:07:56 PM (19 years ago)
Author:
snellen
Message:

connection_monitor.cc and connection_monitor.h updated

Location:
branches/network/src/lib/network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/connection_monitor.cc

    r5581 r5618  
    1515
    1616#include "connection_monitor.h"
     17#include <debug.h>
     18#include <SDL/SDL.h>
     19#include <string.h>
    1720
    1821/* using namespace std is default, this needs to be here */
     
    2023
    2124ConnectionMonitor::ConnectionMonitor()
    22  {
     25{
    2326
    24          totalReceivedPackets=0;
    25          totalLostPackets=0;
    26          //packetSize=?;
     27  /* set the class id for the base object and add ist to class list*/
     28  this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor");
    2729
    28          currentPacketID=0;
    29          currentDatarate=0;
    30          timeForLastFewPackets=0;
     30  /*initialize variables*/
    3131
    32  }
     32  /*Data of the lifetime of the ConnectionMonitor Object*/
     33  packetToAverage = 5;
     34
     35  startTime= SDL_GetTicks();
     36  totalReceivedPackets=0;
     37  averageDatarate=0;
     38  totalLostPackets=0;
     39  totalPacketloss=0;
     40
     41  /*Data of the current packet*/
     42  currentPacketID=0;
     43  currentPacketTick=0;
     44  lastPacketID=0;
     45  lastPacketTick=0;
     46  currentDelay=0;
     47
     48  /*Data of the last n packets (n is specified by paxketsToAverage)*/
     49  sizeOfLastFewPackets=0;
     50  currentDatarate=0;
     51  lastFewDelays = new unsigned int [packetToAverage];
     52  lastFewPackets = new byte* [packetToAverage];
     53  packetCounter=0;
     54
     55
     56}
    3357
    3458
    3559ConnectionMonitor::~ConnectionMonitor()
    36  {
     60{
     61
     62
     63}
    3764
    3865
    3966
     67void ConnectionMonitor::processPacket(byte* currentPacket, unsigned int packetLength)
     68{
     69  /*Process the current Package*/
     70  currentPacketTick = SDL_GetTicks();
     71  currentDelay = currentPacketTick - lastPacketTick;
    4072
    41  }
     73  /*  Only for Udp
     74      if(currentPacketID - lastPacketID > 1)
     75      {
     76              totalLostPackets += currentPacketID - lastPacketID;
     77      }
     78
     79     totalPacketloss = (totalLostPackets/totalReceivedPackets)*100 ;
     80  */
     81
     82  /*Do whats needed for Averaging*/
     83
     84  if(packetCounter = packetToAverage)
     85    {
     86      computeAverageStatistic();
     87      displayStatistic();
     88      packetCounter = 0;
     89    }
     90
     91  lastFewDelays[packetCounter] = currentDelay;
     92  lastFewPackets[packetCounter] = currentPacket;
     93  sizeOfLastFewPackets += packetLength;
    4294
    4395
     96  /*Update the lifetime Variables*/
     97  totalReceivedPackets ++;
     98  averageDatarate = totalReceivedPackets/(currentPacketTick - startTime);
    4499
    45  void ConnectionMonitor::processPacket(byte* packet)
    46  {
     100  /*Preparefor the next Packet*/
     101  lastPacketTick = currentPacketTick;
     102  packetCounter++;
     103}
    47104
    48105
     106/* Compute the value of current Datarate*/
     107void ConnectionMonitor::computeAverageStatistic()
     108{
     109  int timeForLastFewPackets;
     110  for(int i=0;i <= packetToAverage-1;i++)
     111    timeForLastFewPackets += lastFewDelays[i];
    49112
    50  }
     113  currentDatarate = packetToAverage/timeForLastFewPackets;
     114}
    51115
    52116
    53  void ConnectionMonitor::displayStatistic()
    54  {
     117void ConnectionMonitor::displayStatistic()
     118{
     119  PRINT(0)("============================================\n");
     120  PRINT(0)("Connection Monitor Network Statistics:\n");
     121  PRINT(0)("Total received packets:",totalReceivedPackets);
     122  PRINT(0)("Average datarate :\n",averageDatarate);
     123  PRINT(0)("Total lost packets:",totalLostPackets);
     124  PRINT(0)("Packetloss [%] :\n",totalPacketloss);
    55125
     126  PRINT(0)("Current datarate :\n",currentDatarate);
     127  PRINT(0)("Delays of the last few packets :\n",currentDelay);
     128  for(int i=1 ;i <= packetToAverage-1;i++)
     129    PRINT(0)("%i ",lastFewDelays[i]);
    56130
     131  PRINT(0)("============================================\n");
    57132
     133}
    58134
    59 
    60  }
    61 
  • branches/network/src/lib/network/connection_monitor.h

    r5581 r5618  
    1111
    1212class ConnectionMonitor : virtual public BaseObject
    13 {
    14         public:
    15                         ConnectionMonitor();
    16                         ~ConnectionMonitor();
     13  {
     14  public:
     15    ConnectionMonitor();
     16    ~ConnectionMonitor();
    1717
    18     void                processPacket(byte* packet);
     18    void                processPacket(byte* packet, unsigned int packetLength);
    1919
    2020
    21         private:
     21  private:
    2222
    2323
    2424    void                displayStatistic();
     25    void                computeAverageStatistic();
     26
     27    /*Data of the lifetime of the ConnectionMonitor Object*/
     28    unsigned int        packetToAverage;
    2529
    2630    unsigned int        totalReceivedPackets;
     31    float               averageDatarate;
    2732    unsigned int        totalLostPackets;
    28     unsigned int        packetSize;
     33    float               totalPacketloss;
     34    unsigned int        startTime;
    2935
     36    /*Data of the current packet*/
    3037    unsigned int        currentPacketID;
     38    unsigned int        currentPacketTick;
     39    unsigned int        lastPacketID;
     40    unsigned int        lastPacketTick;
     41    unsigned int        currentDelay;
     42
     43    /*Data of the last n packets (n is specified by paxketsToAverage)*/
     44    unsigned int        sizeOfLastFewPackets;
    3145    unsigned int        currentDatarate;
    32     unsigned int        timeForLastFewPackets;
     46    byte**              lastFewPackets;
     47    unsigned int*       lastFewDelays;
     48    unsigned int        packetCounter;
    3349
    34 };
     50  };
    3551
    3652#endif
    37 
Note: See TracChangeset for help on using the changeset viewer.