Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PACKET TCP/PACKET LEVEL TEST
- for (int i = 0; i < packetCount; i++) { //1 LOOP = 1 PACKET
- //packet transmitted cost = transmit cost and error check cost
- a2.pTotalCost += a2.pTransCost + a2.pCheckCost;
- float r;
- //using frame error probability and frame count to find errors
- for (int i = 0; i < a2.packetSize; i++) {
- //probability failure check
- r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
- //if a single frame has an error, we need to re-transmit entire packet
- //so the loop going through all frames in a packet will end
- if (r <= a2.errRate) {
- a2.errorCount++;
- //ending loop through 1 packet if an error is found
- i = a2.packetSize;
- }
- }
- //if single packet had an error, while-loop activates and tries to re-transmit and error check
- while (r <= a2.errRate) {
- //transmit packet again if it fails, and error check again
- a2.pTotalCost += a2.pTransCost + a2.pCheckCost;
- //using probability for error in frames of failed packet
- for (int i = 0; i < a2.packetSize; i++) {
- r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
- if (r <= a2.errRate) {
- a2.errorCount++;
- //ending loop through 1 packet if an error is found
- //while-loop will activate again and try to re-transmit and error check
- i = a2.packetSize;
- }
- }
- }
- }
- cout << "Number of Packets with Errors: " << a2.errorCount << endl;
- cout << "Total Cost of transmitting and error checking " << packetCount << " packets: " << a2.pTotalCost << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement