Changeset 5618 in orxonox.OLD for branches/network/src/lib
- Timestamp:
- Nov 16, 2005, 7:07:56 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/connection_monitor.cc
r5581 r5618 15 15 16 16 #include "connection_monitor.h" 17 #include <debug.h> 18 #include <SDL/SDL.h> 19 #include <string.h> 17 20 18 21 /* using namespace std is default, this needs to be here */ … … 20 23 21 24 ConnectionMonitor::ConnectionMonitor() 22 25 { 23 26 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"); 27 29 28 currentPacketID=0; 29 currentDatarate=0; 30 timeForLastFewPackets=0; 30 /*initialize variables*/ 31 31 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 } 33 57 34 58 35 59 ConnectionMonitor::~ConnectionMonitor() 36 { 60 { 61 62 63 } 37 64 38 65 39 66 67 void ConnectionMonitor::processPacket(byte* currentPacket, unsigned int packetLength) 68 { 69 /*Process the current Package*/ 70 currentPacketTick = SDL_GetTicks(); 71 currentDelay = currentPacketTick - lastPacketTick; 40 72 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; 42 94 43 95 96 /*Update the lifetime Variables*/ 97 totalReceivedPackets ++; 98 averageDatarate = totalReceivedPackets/(currentPacketTick - startTime); 44 99 45 void ConnectionMonitor::processPacket(byte* packet) 46 { 100 /*Preparefor the next Packet*/ 101 lastPacketTick = currentPacketTick; 102 packetCounter++; 103 } 47 104 48 105 106 /* Compute the value of current Datarate*/ 107 void ConnectionMonitor::computeAverageStatistic() 108 { 109 int timeForLastFewPackets; 110 for(int i=0;i <= packetToAverage-1;i++) 111 timeForLastFewPackets += lastFewDelays[i]; 49 112 50 } 113 currentDatarate = packetToAverage/timeForLastFewPackets; 114 } 51 115 52 116 53 void ConnectionMonitor::displayStatistic() 54 { 117 void 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); 55 125 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]); 56 130 131 PRINT(0)("============================================\n"); 57 132 133 } 58 134 59 60 }61 -
branches/network/src/lib/network/connection_monitor.h
r5581 r5618 11 11 12 12 class ConnectionMonitor : virtual public BaseObject 13 {14 15 16 13 { 14 public: 15 ConnectionMonitor(); 16 ~ConnectionMonitor(); 17 17 18 void processPacket(byte* packet );18 void processPacket(byte* packet, unsigned int packetLength); 19 19 20 20 21 21 private: 22 22 23 23 24 24 void displayStatistic(); 25 void computeAverageStatistic(); 26 27 /*Data of the lifetime of the ConnectionMonitor Object*/ 28 unsigned int packetToAverage; 25 29 26 30 unsigned int totalReceivedPackets; 31 float averageDatarate; 27 32 unsigned int totalLostPackets; 28 unsigned int packetSize; 33 float totalPacketloss; 34 unsigned int startTime; 29 35 36 /*Data of the current packet*/ 30 37 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; 31 45 unsigned int currentDatarate; 32 unsigned int timeForLastFewPackets; 46 byte** lastFewPackets; 47 unsigned int* lastFewDelays; 48 unsigned int packetCounter; 33 49 34 };50 }; 35 51 36 52 #endif 37
Note: See TracChangeset
for help on using the changeset viewer.