{
 "metadata": {
  "name": "",
  "signature": "sha256:3bb6fed41815ab02f5db449f0fb6dc3bca89d7411c6822dfe382fccc1777b7c3"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 14: Mobile Network and Transport Layer"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14.1, Page 452"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "O=800*1000; #Object size(Bytes)\n",
      "S=536.*8;  #max Segment Size(in bits)\n",
      "RTT=0.1; #Round trip-time in sec\n",
      "R=1.*10**6; #Transmission rate of the link from the server to the client in bps\n",
      "\n",
      "#Calculations\n",
      "Lmin=2*RTT+(O/R); #latency(msec)\n",
      "# For minimum latency (S/R) +RTT -(W*S/R) = 0;Therefore\n",
      "W=1+(RTT)/(S/R);\n",
      "\n",
      "#Results\n",
      "print 'The minimum possible latency is %d sec'%Lmin;\n",
      "print 'The minimum window size is %.1f segments'%W;"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The minimum possible latency is 1 sec\n",
        "The minimum window size is 24.3 segments\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14.2, Page 452"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "RTT=0.1; #Round trip-time in sec\n",
      "MSS=536.*8; #Maximum segment size in bits\n",
      "p=0.01;# packet loss probability for the path\n",
      "RTO=5*RTT; #Retransmission time out(from eqn 14.2 on page 450)\n",
      "\n",
      "#Calculations\n",
      "R=0.93*MSS/(RTT*math.sqrt(p));\n",
      "RR=MSS/(RTT*math.sqrt(1.33*p)+RTO*p*(1+32*p**2)*min(1,3*math.sqrt(0.75*p)));\n",
      "\n",
      "#Results\n",
      "print 'The upper bound of the throughput is %.4f Mbps'%(R*10**-6);\n",
      "print 'The throughput with retransmission due to errors is %.4f Mbps'%(RR*10**-6);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The upper bound of the throughput is 0.3988 Mbps\n",
        "The throughput with retransmission due to errors is 0.3341 Mbps\n"
       ]
      }
     ],
     "prompt_number": 2
    }
   ],
   "metadata": {}
  }
 ]
}