SHARE
TWEET

Untitled

a guest Nov 14th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     //PACKET TCP/PACKET LEVEL TEST
  3.     for (int i = 0; i < packetCount; i++) { //1 LOOP = 1 PACKET
  4.         //packet transmitted cost = transmit cost and error check cost
  5.         a2.pTotalCost += a2.pTransCost + a2.pCheckCost;
  6.         float r;
  7.  
  8.         //using frame error probability and frame count to find errors
  9.         for (int i = 0; i < a2.packetSize; i++) {
  10.             //probability failure check
  11.             r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
  12.            
  13.             //if a single frame has an error, we need to re-transmit entire packet
  14.             //so the loop going through all frames in a packet will end
  15.             if (r <= a2.errRate) {
  16.                 a2.errorCount++;
  17.                 //ending loop through 1 packet if an error is found
  18.                 i = a2.packetSize;
  19.             }
  20.  
  21.         }
  22.  
  23.         //if single packet had an error, while-loop activates and tries to re-transmit and error check
  24.         while (r <= a2.errRate) {
  25.             //transmit packet again if it fails, and error check again
  26.             a2.pTotalCost += a2.pTransCost + a2.pCheckCost;
  27.  
  28.             //using probability for error in frames of failed packet
  29.             for (int i = 0; i < a2.packetSize; i++) {
  30.                 r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
  31.                
  32.                 if (r <= a2.errRate) {
  33.                     a2.errorCount++;
  34.                     //ending loop through 1 packet if an error is found
  35.                     //while-loop will activate again and try to re-transmit and error check
  36.                     i = a2.packetSize;
  37.                 }
  38.  
  39.             }
  40.         }
  41.        
  42.     }
  43.    
  44.     cout << "Number of Packets with Errors: " << a2.errorCount << endl;
  45.     cout << "Total Cost of transmitting and error checking " << packetCount << " packets: " << a2.pTotalCost << endl;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top