Welcome back.
This is part two of this lesson.
We're gonna continue immediately from the end of part one,
so let's get started.
Right at the offset,
It's critical to understand
that layer two at the networking stack, it uses layer one.
So in order to have an active layer two network,
you need the layer one or physical layer
in place and working.
Meaning two network interfaces and a shared medium
between those as a minimum.
But now on top of this each networking stack.
So remember, this is all the networking software layers
each stack,
so the left and the right now have both layer one
and layer two.
So conceptually, layer two sits
on top of layer one, like this.
And our games, these are now communicating using layer two.
Each device because it's layer two, now has a Mac aaddress,
a hardware address
which is owned by the network interface card
on each device.
So let's step through what happens now
when the game on the left wants to send something
to the game running on the right.
Well, the left game knows the Mac address
of the game on the right.
Let's assume that is a starting point.
So it communicates with the layer two software.
Let's assume this is Ethernet on the left.
It indicates that it wants to send data
to the Mac address on the right.
And the layer two software
based on this creates an Ethernet frame
containing the data that the game wants to send
in the payload part of the frame.
So the frame(F1) has a destination
of the Mac address ending 5b:76
which is the Mac address on the laptop on the right,
and it contains within the payload part of that frame,
the data that the game wants to send.
At this point, this is where the benefits
of layer two begin.
Layer two can communicate
with the layer one part of the networking stack.
And it can look for any signs of a carrier signal.
If any other device on the network,
were transmitting at this point,
you would see the signal on the layer one network.
So it's looking to sense a carrier,
and this is the job of CSMA,
which stands for carrier sense, multiple access.
In this case, it doesn't detect a carrier,
and so it passes the frame to layer one.
Layer one doesn't care what the frame is,
it doesn't understand the frame
as anything beyond a block of data.
And so it transmits this block of data
onto the shared medium.
On the right side,
the layer one software receives the raw bitstream
and it passes it up to its layer two.
Layer two reviews the destination Mac address of the frame,
it sees that the frame is destined for itself,
and so it can pass that payload, that data,
back to the game.
And so that's how these games can communicate,
using layer two.
So layer two is using layer one to transmit
and receive the raw data.
But it's standing on top of this Mac addresses
which allow for machine to machine communication.
In an addition, it's adding this media access control.
So let's look at an example of how this works.
If we assume that at the same time,
that the left machine was transmitting,
the machine on the right attempted to do the same.
So layer two works with layer one
and it checks for a carrier on the shared physical medium.
If the left machine is transmitting, which we know it is,
the carrier is detected,
and layer two on the right simply waits
until the carrier is not detected.
So it's layer two which is adding this control.
Layer one on its own would simply transmit
and cause a collision,
but layer two checks for any carrier,
before it instructs layer one to transmit.
When the carrier isn't detected anymore,
then layer two sends the frame
down to layer one for transmission,
layer one just sees it as data to send
and it transmits it across the physical medium.
It's received at the left side device.
Layer one sends this raw data to layer two.
It can see that it's the intended destination
and so it sends the data contained in the frame payload
back to the game.
Now I want to reiterate a term again
which you need to remember,
and that term is Encapsulation.
This is the process of taking some data
in this case, game data,
and wrapping it in something else.
So in this case, the game data
is encapsulated inside a frame.
At each side before giving the game back it's intended data,
the data is DEM encapsulated.
The payload is extracted from the frame.
So this is a concept that you need to remember
because as data passes down the OSI model,
it's encapsulated in more and more different components.
So the transport layer does some encapsulation.
The network layer does some encapsulation
and the data link layer does some encapsulation.
This is a process which you need to be comfortable with.
Now, two more things which I want to cover on this screen.
And the first of this is conceptually,
for anything using layer two to communicate,
they see it as layer two on the left,
is directly communicating to layer two on the right.
Even though layer two is using layer one
to perform the physical communication,
anything which is using these layer two services,
has no visibility of that.
That's something that's common in the OSI model.
Anything below the point that you're communicating with,
is abstracted away.
If you're using a web browser
which functions at layer seven,
you don't have to worry
about how your data gets to the web server.
It just works.
So your web browser which is running at layer seven,
is communicating with a web server,
which is also running at layer seven.
You don't have to worry
about how this communication happens.
The other thing which I want to cover
is if in this scenario,
what if both machines, check for a carrier
which doesn't exist?
And then both layer twos instruct their layer one
to both transmit at the same time.
This causes a collision.
Now layer two contains, collision detection.
And that's what the CD part of CSMA/CD is for.
If a collision is detected,
then a jam signal is sent by all of the devices,
which detect it,
and then alarm them backoff occurs.
The backoff is a period of time
during which no device will attempt a transmission.
So after this backoff period occurs,
the transmission is retried.
Now because this backoff is random,
hopefully it means that only one device
will attempt to transmit it first,
and all the devices will see the carrier on the network
and wait before transmitting.
But if we still have a collision,
then this backoff is attempted again
only now with a greater period.
So over time, there's less and less likelihood
that you're going to have multiple devices transmitting
at the same time.
So this collision detection and avoidance
is essential for layer two.
It's the thing that allows multiple devices
to coexist on the same layer two network.
Okay, so let's move on.
So now you have an idea about layer two networking.
Let's revisit how our laptops are connected.
In the previous example, where I showed Hubs,
we had four devices connected to the same four port hub.
Now hubs are layer one devices.
This means they don't understand frames in any way.
They just see physical data.
Essentially, they're a multiport repeater.
They just repeat any physical activity
on one port to all the ports.
So the top laptop sends a frame
destined for the bottom laptop,
the hub just sees this as raw data.
It repeats this on all of the other ports,
and this means all of the other laptops
will receive this data,
which the layer to software will interpret as a frame.
They'll all receive this data,
so this frame they'll see
that they're not the intended destination
and they'll discard it.
The bottom laptop will see
that it is the intended destination,
and it's layer two software,
will pass on the data to the game.
Now, hubs aren't smart
and this means that if the laptop on the right
want to start transmitting at exactly the same time
then it would cause a collision,
and this collision would be repeated
on all of the other ports that the hub has connected.
Using a layer one device, a hub,
doesn't prevent you running a layer two network
over the top of it.
But it means that the hub doesn't understand layer two,
and so it behaves in a layer one way.
You still have each device doing carrier sense,
multiple access,
and so collisions should be reduced,
but if multiple devices try and transmit
at exactly the same time,
then this will still cause collisions.
What will improve this is using a switch,
and switch is a layer two device.
It works in the same way physically as a hub,
but it understands layer two,
and so provides significant advantages.
Let's review how this changes things.
To keep things simple, let's keep the same design.
Only now we have a switch in the middle.
It still has four ports,
and it's still connected to the same four laptops.
Because they're layer two,
they now have their own hardware addresses,
their Mac addresses.
Now because this switch is a layer two device,
it means that it has layer two software running inside it,
which means that it understands layer two.
And because of that it maintains what's called
a Mac address table.
Switches over time run what's connected to each port.
So the device Mac addresses
which are connected to each port.
When a switch sees frames, it can interpret them
and see the source and destination Mac addresses.
So over time, with this network,
the Mac address table will get populated
with each of our devices.
So the switch will store the Mac addresses it sees on a port
and the port itself.
This is generally going to happen the first time
each of the laptops sends a frame,
which the switch receives.
It will see the source Mac address on the frame
and it will update the Mac address table which it maintains.
Now let's say the Mac address table is populated,
and the top laptop sends a frame
which is intended for the left laptop.
Well, the switch will see the frame arrive at the port
that the top laptop is connected to,
at which point one of two things will happen.
If the switch didn't know which port
the destination Mac address was on,
well, it would forward this frame to all of the other ports.
If it does know
which port the specific Mac address is attached to,
then it will use that one port to forward the frame to.
Switches are intelligent.
They aren't just repeating the physical level,
they interpret the frames
and make decisions based on the source
and destination Mac addresses of those frames.
So switches store and forward frames.
They receive the frame, they store it,
and then they forward it based on the Mac address table,
and then they discard it.
Now this has another benefit.
Because it's not just repeating
like a dumb layer one device,
it means that it won't forward collisions.
In fact, each port on the switch
is a separate collision domain.
Because each port is a separate collision domain,
the only two things which can transmit at the same time,
are the device and the port it's connected to.
So if there is a collision,
it will be limited to that one port only.
The switch will not forward that corrupted data
through to any of its other ports,
because it's only forwards valid frames.
The switch isn't forwarding the physical layer,
it's dealing with frames only.
It receives a frame if it's valid, it stores it,
it reviews it,
and then it forwards.
Now layer two is the foundation for all networks
which you use day to day.
It's how your wired networks work.
It's how WiFi networks work.
It's how the internet works
which is basically a huge collection
of interconnected layer two networks.
The name itself, so the internet,
stands for an inter network of networks.
So these networks, a layer two networks
which are all connected to together, to form the internet.
So in summary,
what position are we in by adding layer two
where we have identifiable devices?
For the first time, we can uniquely address frames
to a particular device using Mac addresses.
It allows for device to device communication
rather than the shared media which layer one offers.
We also have media access controls
so devices can share access to physical media
in a nice way avoiding crosstalk and collisions.
But we also have the ability to detect collisions,
and so if they do occur,
we have a way correct or work around them.
So with all of that, we can do Unicast communications
which are one-to-one communications
and we can do broadcast communications
which are one-to-all communications.
And as long as we replace
layer one hubs with layer two switches
which are like hubs with superpowers,
then we gain the ability to scale to a much better degree,
and we avoid a lot of the collisions
because switches store and forward
rather than just repeating everything.
Now layer two really does provide crucial functionality.
Everything from this point onwards builds on layer two.
So it's critical that you understand that.
So if necessary, then re-watch this video
because from now on,
you need to understand the layer two,
at real fundamental level.
Now, this seems like a great point to take a break.
So go ahead and complete this video,
and when you're ready,
join me in the next part of this series,
where we'll be looking at layer three,
which is the network layer.