# A-level Computing 2009/AQA/Computer Components, The Stored Program Concept and the Internet/Structure of the Internet/Packet switching

Packet switching is the method by which the internet works, it features delivery of packets of data between devices over a shared network. For example the school web server sending you a webpage over the internet or you sending an email to a friend. To get from one device to another the data packets will have to travel through network adapters, switches, routers and other network nodes. The route taken by each packet might vary and at times there might be a lot of data travelling through these nodes meaning packets will be queued. This will result in varying times it takes to send data from one device to another depending on the traffic load in the network.
If you play computer games online you might have heard the term latency (or lag), this is the time taken to send data from one device to another. The higher the latency (time taken to send data), the less responsive your game will be. People with very low latency tend to do better at games as their machines will be more responsive.
* Example: The ping command
* To see the time it takes to send a message using packet switching you can use the ping command to time how long it takes to send data to another device, in this case we have used the command prompt to ping the www.example.com server:
* # ping -c 5 www.example.com
* PING www.example.com (192.0.43.10) 56(84) bytes of data.
* 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=1 ttl=250 time=80.5 ms
* 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=2 ttl=250 time=180.1 ms
* 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=3 ttl=250 time=80.3 ms
* 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=4 ttl=250 time=80.3 ms
* 64 bytes from 43-10.any.icann.org (192.0.43.10): icmp_seq=5 ttl=250 time=80.4 ms
* As you can see the same data is being sent to the same location in all 5 attempts, but the second attempt met traffic on the way and took much longer. However, at 180.1 milliseconds you probably wouldn't notice.
As packet switching doesn't define a set route for data to be sent by, any disruption in the network can be circumnavigated by re-routing:
* Example: The trace command
* The tracert command is used to map the route from one machine to another on the internet showing all the intermediate nodes, in this case, the message took ten steps to get there. The code above shows a trace from a home network to the www.google.com website. You can see that the 4th hop got lost and the data had to be re-routed.
* # tracert www.google.com
* Tracing route to www.l.google.com [209.85.147.99]
* over a maximum of 30 hops:
* 1 62 ms 99 ms 99 ms bebox.config [192.168.1.254]
* 2 53 ms 19 ms 18 ms 87-194-56-8.bethere.co.uk [87.194.56.8]
* 3 * * 83 ms 10.1.2.177
* 4 * * * Request timed out.
* 5 20 ms 17 ms 17 ms 64.233.175.25
* 6 20 ms 38 ms 19 ms 209.85.253.92
* 7 26 ms 56 ms 23 ms 66.249.95.173
* 8 45 ms 24 ms 24 ms 72.14.236.191
* 9 33 ms 35 ms 35 ms 216.239.46.221
* 10 27 ms 22 ms 22 ms bru01m01-in-f99.1e100.net [209.85.147.99]
* Trace complete.
* If you want to try this at home there are different commands used on different operating systems:
* Windows - tracert
* Linux - tracepath or traceroute
* Mac - traceroute

## Packet switching steps

* Data split into chunks (packets)
* Each packet has a from address, to address and payload (data chunk)
* If data requires multiple chunks then the order of each packet is noted
* Packets sent onto the network, moving from router to router taking different paths (set by the router). Each packet's journey time can therefore differ.
* Once packets arrive they are re-ordered
* Message sent from recipient to sender indicating that the message has been received
* If no confirmation message, sender transmits data again
* Exercise: Internet/Intranet/World Wide Web
* For the following packets (Green, Blue, Red), assuming each step from router to router takes an equal time. What order will the packets arrive at their destination? How do we make sure that the packets are read in the correct order?
* Answer:
* Green
* Red
* Blue
* Each packet has a sequence number attached to it, so that it can be ordered when it reaches its destination.
* What happens if a packet gets permanently lost on the way to a host?
* Answer:
* The packet will be resent until a confirmation message is returned from the recipient
* What happens if a router on the network fails? How will the packets get to their destination?
* Answer:
* The packets will be re-routed around the failed node