-: Layer 4, the transport layer. 2 2
Now, the transport layer is our dividing line 3 3
between what we call the upper layers of the OSI model 4 4
and the lower layers of that OSI model. 5 5
Now, we've already covered the lower layers 6 6
when we talked about the physical, 7 7
the data link, and the network layers. 8 8
And so now, we're going to move into the upper layers, 9 9
starting with this layer, the transport layer, 10 10
the session layer, the presentation layer, 11 11
and the application layer. 12 12
Now, in the next couple of lessons, 13 13
we're going to cover each of these as we go forward. 14 14
Now, segment is our datatype here 15 15
when we're dealing with the transport layer. 16 16
When we deal with segments and datagrams, 17 17
we're talking about the transport layer. 18 18
Now, as we talk about datagrams, 19 19
we're going to go into those a little bit more later in depth. 20 20
But for now, let's focus on the two protocols 21 21
that we have inside layer 4, 22 22
which are the TCP and the UDP protocols. 23 23
And we're also going to introduce 24 24
a couple of extra reliability features here 25 25
known as windowing and buffering. 26 26
Now, what is TCP? 27 27
TCP is a transmission control protocol. 28 28
It is a connection-oriented protocol, 29 29
which means it's a reliable way to transport segments 30 30
across our network. 31 31
Now, if a segment has dropped, 32 32
the protocol will actually ask for acknowledgment 33 33
each and every time. 34 34
If it doesn't get that acknowledgement, 35 35
it's going to resend that piece of information. 36 36
That's why we call this connection full protocol 37 37
because it has this two-way type of information 38 38
where I'm sending you information 39 39
and I'm verifying you actually got it 40 40
by listening that you got it and you give me a response. 41 41
Now, let's look at this little diagram here 42 42
on the screen for a second. 43 43
You're going to see that I have a client on the left 44 44
and a server on the right. 45 45
Now, the client is going to send what's called a SYN packet 46 46
or a synchronization packet over to the server. 47 47
Now, when the server gets that, 48 48
it's going to send back a synchronization acknowledgment 49 49
to the client known as a SYN-ACK. 50 50
Now, when the client gets that acknowledgement, 51 51
it's going to send back its own acknowledgement to the server. 52 52
This is known as the ACK. 53 53
Now, when we do this SYN, SYN-ACK, ACK, 54 54
this is what we refer to as a three-way handshake. 55 55
Essentially, it's the client going, hey server, 56 56
are you ready to get some information? 57 57
And then the server says, sure, why not? 58 58
Send me some information. 59 59
And the client says, okay, here it comes. 60 60
And then, the transmission is going to begin 61 61
because we've established that three-way handshake 62 62
and we know that both sides are ready to communicate. 63 63
Now, are you ready? 64 64
Yes, I am, here it comes. 65 65
Now, every time this data, which we call a segment, 66 66
is sent across the network, 67 67
there is going to be an acknowledgment that it was received 68 68
and that tells us there was successful 69 69
two-way communication occurring. 70 70
Now, if the server is expecting to get 100 pieces 71 71
of information, but it only got 98 of those, 72 72
it's going to say to the client, 73 73
hey, you told me you're going to send me 100 things 74 74
but you only sent me 98. 75 75
Send me over those two things that I'm missing. 76 76
And then a retransmission occurs. 77 77
This way, the communication can go forth 78 78
and we can always make sure we're getting 79 79
what we're supposed to because we have this resending 80 80
of the packets across the network. 81 81
Now, this is used for all network data 82 82
that needs to be assured to get to its final destination. 83 83
I like to think about this like certified mail. 84 84
If I want to send a message to the IRS, for example, 85 85
I want to make sure that they get it 86 86
and that doesn't get lost in the mail. 87 87
So, I might pay a little extra money 88 88
to get a certified receipt that when it gets there, 89 89
they have to sign it and that gets mailed back to me. 90 90
This way, when I get that receipt back, 91 91
I know that the IRS got my mail package. 92 92
That's the way TCP works. 93 93
Now, on the other hand, we have another protocol 94 94
known as UDP. 95 95
UDP is what we call a connectionless protocol, 96 96
meaning, it doesn't have to wait for connections. 97 97
UDP stands for User Datagram Protocol 98 98
and the reason why we call it a datagram 99 99
is because if you're using UDP, 100 100
you're using this type of data, 101 101
it's called a datagram. 102 102
And so, for the exam, I want you to remember 103 103
that layer 4 is for segments almost exclusively 104 104
because we use it with TCP. 105 105
But if you're using UDP, this is now called a datagram. 106 106
So, if you have a datagram or a segment, 107 107
you're in layer 4. 108 108
Now, when we talk about UDP, UDP is unreliable 109 109
and it transmits segments called datagrams 110 110
and if they're dropped, 111 111
the sender will never even know that it happened. 112 112
Now, why would I want to send stuff 113 113
where the sender isn't aware of it 114 114
and I don't get any kind of receipt? 115 115
Well, UDP is really good for audio and visual streaming 116 116
because you send a lot of data 117 117
and there's a lot less overhead when you use UDP 118 118
because we don't have that constant three-way handshake 119 119
to establish it and we don't have 120 120
all the checks and balances that are associated 121 121
by using TCP. 122 122
So, by using UDP, you can really increase the performance 123 123
of your network because you're going to have 124 124
zero retransmissions, 125 125
you're just going to end up dropping information. 126 126
Now, isn't that a bad thing? 127 127
Why would we want to drop information? 128 128
Well, for certain applications, it really doesn't matter. 129 129
For example, you're streaming this video right now 130 130
and if I dropped out for one hundredth of a second, 131 131
would you even notice? 132 132
Well, you probably wouldn't. 133 133
And that's why UDP is so good 134 134
because we can drop one 100th of the time here 135 135
and you're really never even going to notice it 136 136
and there won't be a retransmission. 137 137
But with TCP, it's going to lead to a lot more buffering 138 138
because you have to wait and then get resent to you 139 139
and then put it in the right place and then play it back. 140 140
And so, because of that acknowledgement and that overhead 141 141
for every single second of this video, 142 142
it's going to end up making a lot larger 143 143
and use a lot more bandwidth. 144 144
And that's one of the big reasons why we use UDP 145 145
for video streaming and audio streaming. 146 146
Now, let's do a quick little summary here of TCP versus UDP 147 147
because this is a really, really important concept. 148 148
In fact, if you have your notes out right now, 149 149
I would write down this chart 150 150
that I'm going to tell you right now 151 151
as we talk about TCP versus UDP 152 152
because it really is that important. 153 153
Now first, TCP is reliable. 154 154
It has a three-way handshake where UDP is not very reliable, 155 155
it's an unreliable protocol 156 156
because there is no three-way handshake. 157 157
TCP is what we call connection-oriented 158 158
or a connectionfull protocol 159 159
because we have that three-way handshake 160 160
in the acknowledgements but UDP is connectionless. 161 161
It's a fire and forget method. 162 162
I just start sending out information 163 163
and hopefully you're going to get it. 164 164
TCP uses segment retransmission and flow control 165 165
that's being handled through windowing, 166 166
which we're going to talk about more in just a second. 167 167
UDP, on the other hand, there is no retransmission 168 168
and no windowing. 169 169
With TCP, we have segmentation of our sequencing 170 170
of all of our different segments. 171 171
With UDP, there is no sequencing. 172 172
Now, what this means is, as I send everything out, 173 173
I'm going to send it out in the proper order from one to 100. 174 174
I'll do this for both TCP and UDP. 175 175
Now, if you miss some of those pieces, 176 176
or they arrive in a different order 177 177
because they take different paths over the network, 178 178
with TCP, they're sequencing 179 179
so it knows that you have one to 1,000 180 180
and it puts them back in the right sequence. 181 181
With UDP, whatever they come in as, 182 182
that's how it's going to broadcast it. 183 183
And so, it can be coming in 1, 50, 2, 500, 184 184
3, 4, 5, 6, 20, 185 185
in any random order like that 186 186
and that's how you're going to hear it. 187 187
So, if video, you may hear a little bit of jumpiness, 188 188
or a little bit of high-pitch squeaks 189 189
or something like that 190 190
because one of those frames may have come out of order. 191 191
Now, when we go back to TCP, it is going to acknowledge 192 192
each of those segments. 193 193
And so, we have acknowledgment. 194 194
If I don't get it, I know that I didn't get it 195 195
and I can get it retransmitted to me and then get it again. 196 196
With UDP, there is no acknowledgement. 197 197
So, again, UDP has a lot less overhead 198 198
because there's no connection, 199 199
no windowing, no retransmission, no sequencing, 200 200
and no acknowledgement. 201 201
Now, if you have to get something there 202 202
and you want to make sure the person got it, 203 203
you really have to use TCP as your protocol of choice. 204 204
And that's why we really are going to use TCP 205 205
for things like banking and websites and ecommerce 206 206
and things like that. 207 207
But if we have something that has a lot of data 208 208
like audio or video streaming, 209 209
UDP really does well with that 210 210
because we don't need to get 211 211
every single piece of that file. 212 212
We can skip a little bit here and there and that's okay. 213 213
Now, earlier in the lesson, 214 214
I mentioned a concept known as windowing 215 215
and I said, we'd get to it later. 216 216
Well, here we are. 217 217
We're going to talk about windowing. 218 218
Now, what is windowing? 219 219
Windowing is going to allow the clients 220 220
to adjust the amount of data in each segment 221 221
as it goes through the transmission. 222 222
This way, we can continually adjust 223 223
to either send more or fewer pieces of data 224 224
for each segment that's being transmitted. 225 225
So, the whole idea here with windowing 226 226
is that if you're sending data 227 227
and you're getting a lot of retransmissions, 228 228
well, you might be sending too much information. 229 229
So, you need to back that down 230 230
and close the window a little bit. 231 231
So, you'll send less each time. 232 232
Now, if you're not getting any retransmissions, 233 233
it means you're probably not going fast enough. 234 234
So, instead, we can open up that window 235 235
and send more data with each of those segments. 236 236
And then, if we start getting 237 237
a lot more of those retransmissions happening again, 238 238
well, we start closing that window down. 239 239
And so, always we're opening and closing the window 240 240
to maximize our throughput and our bandwidth here. 241 241
So, if you ever copied a file over a network 242 242
on a Windows machine, you've probably seen 243 243
where it starts that movie file and it starts saying, 244 244
hey, you have 20 minutes remaining 245 245
and then it drops down to five minutes remaining, 246 246
then it jumps up to 50 minutes remaining, 247 247
and then 30 minutes remaining, and then an hour, 248 248
and then it goes down to three minutes. 249 249
And it has a really hard time estimating 250 250
how long it's going to take to move that really large file 251 251
off of your shared drive and onto your Windows computer. 252 252
Now, why is that? 253 253
Well, that's windowing at work. 254 254
What's happening here is that as there's issues 255 255
on the network, and there's a lot more retransmissions, 256 256
the window decreases become smaller 257 257
and that means, we have to send more segments 258 258
to get all that data across, which takes more time. 259 259
Now, as things go better, 260 260
and the network starts flowing again, 261 261
that window opens up and we can send less segments 262 262
with more data each time and that's going to end up 263 263
decreasing the time or making it go down. 264 264
So, what happens here is as you can see on the screen, 265 265
let's say that little green thing is what I'm sending 266 266
and I start sending the information over 267 267
but that red starts creeping up 268 268
to where we start to not being able to keep up with it. 269 269
So, we'll come back down and then the red can creep up again 270 270
and then, we'll come back down and we'll keep doing that. 271 271
Hopefully, the red and the green here 272 272
will eventually match at a higher level 273 273
than it was starting with. 274 274
As soon as we open up that window and close that window, 275 275
we can start out slow and then we can go faster 276 276
by opening up that window and faster and faster 277 277
until we have problems and then we'll start 278 278
closing it down again. 279 279
And we'll keep doing that over and over and over again, 280 280
until we get the best bandwidth we can 281 281
as we try to push as much as we can. 282 282
So, for example, if I started counting numbers to you, 283 283
I'm going to start going slow. 284 284
One, two, three, that's pretty slow, right? 285 285
You'll say okay, okay, I got it, Jason. 286 286
You can go faster. 287 287
So, I start talking faster. 288 288
One, two, three, four, five, okay? 289 289
That's still good, let's try again. 290 290
One, two, three, four, five, 291 291
oh, wait, wait, wait, wait, that's too fast, Jason. 292 292
Okay, let me slow down. 293 293
One, two, three, four, five, you got it? 294 294
Okay, and we keep doing that. 295 295
That's the idea of windowing. 296 296
I'll speed up and I'll slow down 297 297
until you don't have any errors copying down 298 298
what I'm saying. 299 299
That's the whole idea here. 300 300
And we want to be able to send as much information to you 301 301
as quickly as possible 302 302
with the least amount of retransmissions 303 303
but still getting the maximum throughput. 304 304
Now, the next concept we want to talk about is buffering. 305 305
If you've ever watched online video, 306 306
you've probably dealt with buffering before. 307 307
Now, devices such as routers have a special memory in them 308 308
that will store segments if the bandwidth 309 309
isn't readily available. 310 310
Now, this is called the buffer. 311 311
So, when it becomes available, 312 312
it'll go ahead and start transmitting out the contents 313 313
of that buffer and clear itself out. 314 314
The same thing happens when you try to load a video. 315 315
If the network is congested, 316 316
it will take in a lot of information at first 317 317
in anticipation of the fact 318 318
that you're going to watch it faster, 319 319
then, you're going to be able to download the rest of the video. 320 320
And so, this is the idea with our buffering 321 321
our routers, as well. 322 322
So, if the buffer is going to overflow, though, 323 323
and on a router you only have so much space 324 324
and you start putting too much information there 325 325
cause you can't send it out, 326 326
then what's going to end up happening? 327 327
You run out of memory. 328 328
And when you run out of memory, the segment's will drop. 329 329
So, let's look at an example of how buffering 330 330
is going to work. 331 331
Let's take a look at the buffer on the router 332 332
and here we have router four in our diagram. 333 333
Notice how it's kind of the central point of this diagram. 334 334
Now, I have stuff coming into it from router number six, 335 335
and router number one and router number three. 336 336
So, if I look at all of those, there's 100 megabits, 337 337
100 megabits, and 10 megabits. 338 338
That's a possibility of 210 megabits per second 339 339
of information going into router four. 340 340
Now, if it needs to send that information out 341 341
to router five, and there's only a 50 megabit connection, 342 342
you can see pretty quickly 343 343
that there's going to be a bottleneck here. 344 344
Now, what's going to end up happening for us 345 345
is that router four is going to have to catch 346 346
all that extra information in its buffer. 347 347
And when it has more availability, 348 348
it'll send that information out to router five 349 349
and clear its buffer. 350 350
You may ask, why would we design a network this way? 351 351
Well, often what's happening here 352 352
is there isn't necessarily going to be 100% utilization 353 353
from router four to router five. 354 354
Maybe that's our exterior one connection 355 355
going out to the Internet. 356 356
In fact, router one may only be sending you 357 357
10 or 15 megabits per second right now. 358 358
And router three might be sending you 30. 359 359
And router six might be sending you one 360 360
which is all added together less than 50. 361 361
So, no buffering would occur. 362 362
Now, there's also the possibility that router one 363 363
and router three sends us more information. 364 364
And that can cause buffering to occur 365 365
because router four can't send enough data out 366 366
to router five over that 50 megabit per second connection. 367 367
So, this is the idea, we want to buffer things and hold it 368 368
and then as we have room, we can send that information out, 369 369
clear the buffer, and keep on moving. 370 370
Because when we look at your networks, 371 371
the chances are not every device is communicating 372 372
to 100% of its capability all of the time. 373 373
And so, by doing this, we can pay for a smaller connection 374 374
to the outside world that 50 megabit connection, 375 375
as opposed to paying for a large 376 376
and expensive fiber connection of one gigabit per second. 377 377
So, we can keep our costs down 378 378
by knowing what our utilization is over our network 379 379
for the long period of time. 380 380
Now, that gets into some more advanced concepts 381 381
that as you work as a network engineer, 382 382
you'll start working on those designs 383 383
and as bandwidth keeps getting cheaper, 384 384
it becomes less and less important for us, 385 385
at least in the small office, home office environment. 386 386
But in large corporations, this is a big deal. 387 387
Now, what are some examples of layer 4 devices? 388 388
Well, we have TCP and UDP as our protocols for layer 4. 389 389
So, if you see TCP and UDP, 390 390
you know you're dealing with layer 4. 391 391
We also have things like WAN accelerators, 392 392
where we try to add compression to our IP packets, 393 393
and then we send those segments over 394 394
through those WAN accelerators 395 395
to get them through our network faster. 396 396
We also have load balancers and firewalls 397 397
that can operate at layer 4 398 398
by blocking and allowing different ports and protocols 399 399
to go through them. 400 400
For example, if you've ever gone in your firewall 401 401
and blocked a port like Port 80 over TCP, 402 402
well, that is a layer 4 block 403 403
because you're blocking the port, Port 80, 404 404
which is web traffic and the protocol TCP, 405 405
which is our protocol at layer 4.