So next we're going to get into a pretty exciting part of IoT, which is how these devices can actually work together to achieve various objectives. We're going to get into the wireless MAC. We just kind of focused on one aspect of that, which is allowing them to deal with kind of collectively sharing a channel for communication. And there's a few kind of sub challenges here, in terms of how do we deal with collisions and avoid collisions. We'll talk about power-saving algorithms later, how they can kind of go to sleep and transmit to each other, even when they're sleeping. And then we'll talk about association and neighbor discovery and service discovery, how nodes can kind of discover a network. But first we're going to talk about collisions and how nodes can kind of collectively share a channel and transmit on that channel. So let's kind of start with this fundamental challenge of how can wireless hosts share a spectrum. I don't know if you've ever been at a party or talking with somebody and two people kind of talk at the same time. It can be hard to understand when two people are talking to you at the same time. And computers have the same problem because they're receiving. And then if two transmitters are talking at the same time, they only have one ear, they only have one antenna to hear. So the signals get combined and get corrupted and all messed up. So there's this issue of what happens when two hosts transmit at the same time. We call this a collision. Their data collides, it gets corrupted, data becomes garbage. So what should we do about collisions? Well, there's a few options. One option is to just give up and let the transmissions collide. Okay, that doesn't seem like a very good solution because then your data gets corrupted sometimes. Another approach is what's called collision detection. If we can at least figure out when collisions happened, then at least we can kind of rely on higher layer protocols or whatever to retransmit if there's a collision. So collision detection is you go ahead and let transmissions collide, but you detect when that happens. And when the sender figures out that their packets collided, they retransmit. A third approach, which is even more powerful, is called collision avoidance. And what collision avoidance is, is you try and prevent collisions from happening in the first place. And this is kind of hard to do. This relies on distributed algorithms operating across your different nodes and coordinating them, computing schedules of when they transmit. But you can do this and some protocols do this. So we're going to talk about these different mechanisms next. We're going to talk about collision detection and collision avoidance. Both these schemes are used in protocols, they're used in different environments. We'll talk about some of their trade-offs. And we're going to start with collision detection. And as motivation, we're going to talk about it in the context of wired networks to first build an understanding of how it works. So here's the scenario. Suppose we have a wired ethernet. We have three computers that are connected together and suppose at time zero this host, this computer starts transmitting data. So electrical signals propagate through wires at the speed of light, actually a little bit less than the speed of light. So I'm going to kind of slow down time so we have time to see the signal propagate through the wire. So we can see that signal's kind of propagating through the wire, it hasn't reached the other computers yet. And suppose right at that time, another computer starts transmitting. It could happen. I mean, we don't know when computers are going to get data on when they want to transmit. So suppose that purple host starts transmitting at time eight microseconds. So the purple host is going to start transmitting. It doesn't know about the yellow signal yet. It hasn't reached it yet. So it's going to happily start transmitting. The signals are going to propagate out and then, uh-oh, the signals collide. We have two kind of bit patterns going together in the wires and they overlap and they turn into garbage. But they only turn into garbage at that point right there. The other hosts are not aware of this yet because the collided signal has not reached them yet. But it will. Let's let time keep going forward. The collided signal goes out and it reaches these hosts. And those hosts see that signal. And they say okay, well, I was receiving a packet. And now, I see a collided signal and so I know it's garbage. So I can throw it away. So this relies on the assumption that these hosts have some hardware where they can distinguish between a collided signal and an uncollided signal. And that's a true assumption for most networks. What we can do is we can kind of watch voltages. And if we see a collided signal, the voltages are going to shoot up to be a higher value than normal. because there will be peaks where they add up. So network interface cards are designed to detect collisions. So these hosts know that and they know they should start discarding any other data in that packet. That packet got collided, got corrupted, should ignore the rest of it. The yellow host doesn't know about this yet, though. So the signal that's collided is going to continue propagating along until the yellow host receives it. And then, what should the yellow host do? Well, the yellow host knows it was trying to transmit a packet and the packet was going out and then a collision happened. So the yellow host knows something and knows that it tried to send a packet and that packet probably didn't reach its destination. That package got corrupted before it reached its destination. So the yellow host knows that. And so what it could do is it could say, well, I'll wait till the collision finishes so the line becomes clear, and then I'll transmit again. I'll transmit my signal again and get the packet through the second time. So we can do that. So that, actually, is the main idea behind collision detection. You kind of transmit your packet, you sense collisions, and then you retransmit if there is a collision. Now, I want to show you another scenario about why this can be a little bit tricky. So we're going to do the same scenario, but we're going to use a smaller packet. And there's a problem that's going to come up when we do this. But let's run through the same scenario where the yellow host starts transmitting. And this time, it's going to transmit a smaller packet. So same thing is going to happen, the signal is going to propagate out over the wire. It's going to kind of go out, the other host is going to start transmitting. And the signals are going to go out. They're going to kind of meet in the middle, just like before. There's a collision. And then the collided signal is going to go out. That's fine. So everything is just as it was before. But now suppose the yellow host, right at this time, is done transmitting its packet. Suppose it just finished transmitting its yellow packet at this point in time. It could happen. Maybe that packet wasn't very long. So that host, maybe he has another packet to start sending, so it's going to start sending a blue packet. It's going to start sending that blue packet. Signal's still going to start going out. And then the collided signal finally reaches back to that original host. So things get a little confusing now. If you're that first host there, what do you think happened? It received a collided signal. That first host might say, okay, well, my blue packet collided, so I should retransmit my blue packet. But in fact, the yellow packet didn't get through either. Both packets collided. And so this shows why collision detection can be a little bit complicated. There's a question of when you transmit and when you receive a collision which packets got collided. Really this host should transmit both the yellow packet and the blue packet. So that's a problem. So there's different solutions to this. And the way this is solved in wired ethernet is we just do something really simple. We say, okay, all packets have to be larger than a certain amount. There's a minimum packet size. And that packet size is chosen based on an assumption about what the maximum length of a link is and the propagation delays of electrical signals through copper. So if we make the packet length to always be larger than a certain amount, this can never happen. And that's just what we do in wired networks. So that's wired networks. But what about wireless networks? So wireless networks are different in several ways. And one way they're different is that there's a lot more attenuation in wireless networks. If I send the signal down a copper line using electricity, that signal will go a really long distance with not that much attenuation. But in wireless, there tends to be a really huge drop-off in my signal strength as I go out. because it's increasing with that sphere, four pi r squared is what happens. And when we talk about signal degradation, it's useful to keep some numbers in mind. So in general, if I have a transmitter and I'm transmitting data, if I'm standing really close to that transmitter, I'm actually going to get a lot of loss, even if I'm really close to it. So I tend to, for example, get on the order of 30 decibels loss. It's kind of one heuristic to keep in mind. When you're standing really close to an access point or really close to a transmitter, about a 30 decibel loss of your signal strength is kind of the maximum of what is practically achievable by just any propagation through the air. Further out, there's another region which kind of matters a lot, and that's about 65 decibels of loss. This is kind of the minimum signal strength you need for kind of good communication in wireless. So if you kind of got your laptop and you're looking at the little bars on it, if those bars say you're at 65 decibels loss, that's okay. You're still going to get a pretty decent signal. But once you kind of get out to 70 decibels, that's kind of the minimum signal strength you need for reliable delivery. So this is different than wired. In wired, you kind of have this really good transmission. In wireless, you kind of have these regions where there's kind of these big drop-offs. After 70 decibels, which isn't that far out from your transmitter, you're going to get a huge drop-off in your signal strength. And this tends to affect collision detection. It introduces a problem for collision detection. Let's run through that same scenario with wireless transmitters. So suppose I have this host. And same sort of deal, it's going to start transmitting a packet. And this is wireless we're talking about, so it's kind of going to go out in all directions like a sphere. It's going to propagate out. And just like before, there's going to be another host and what the other host is going to do is it's going to start transmitting a packet around this time. And so time continues forward and these signals are going to go out. And they're going to collide. And so that access point is sitting there and it's receiving both these signals, but it's receiving garbage. It's receiving data from both of these signals. But one interesting thing that happens here, which doesn't happen in the wired scenario, is that these two nodes don't hear each other. The node sending the blue packet and the node sending the purple packet don't hear each other because they're outside of that 70 decibel loss range. And so they don't know there's a collision. That yellow host is sitting there, it's sending to the access point, it's sending data. It collided with the purple host, its data did not get through, but it has no idea. Collision detection doesn't work in wireless networks because there's no guarantee that you can see the collision, which is very different than wired networks. So this problem that I showed to you here has a name, it's called the hidden node problem. And the hidden node problem is this problem that you may collide with another host that you can't see. So a device may be visible to an access point or receiver, but not to other nodes that are also communicating with that access point. So this is a problem. Another problem that makes it even worse is we're using wireless here. And so you can collide with yourself. Have you ever tried to talk and also listen at the same time? Imagine you're at a party and you're yelling and at the same time you're trying to hear and listen to something. You can't do it. In wired, you can do that. because in wired ethernet, you have several wires. And so you can actually transmit on some wires and receive on another pair of wires at the same time, that's okay. But in wireless, you can't because you're transmitting antenna is sitting right next to your receiver and your receiver goes deaf because it hears that huge transmission. So most radios in wireless networks are functionally half-duplex. They can only send or only receive at a time. They can't do both. And so because your transmitted signal is much louder than your receive signal, you can't hear collisions because of that either. So to deal with this, we don't use collision detection so much in wireless networks. Instead we use another scheme called collision avoidance. And what collision avoidance is, is it is a more advanced scheme where we're going to run a distributed protocol, similar to two-phase commit, where we're going to collectively agree on who can transmit and when they can transmit. And it works like this. When a node wants to transmit a packet, when it has data it wants to transmit, it doesn't just start transmitting it. Instead what it does is it broadcasts a request to send packet. It first broadcasts a message saying, hey, I have a packet. Is it okay if I send this packet? And that message has its own identifier in there. If we're talking about EO 2.11, it's the sending those MAC address. So an access point is sitting there and it receives this message. And then what the access point will do is it will send a clear to send message. And the clear to send message gives authorization for the sending node to send. So the sending node said, hey, you know, can I send this message? And the access point is going to say, yes MAC address, you can send that message. So it'll respond back specifically to that host and tell it it can send using a clear to send message. So the protocol is a request to send and a clear to some message. So what other hosts do while this process is taking place is they sit there and they listen. So that other computer sitting over there is sitting there and it didn't hear the request to send because it's outside of the broadcaster's radio range. But here's the clear to send. And so it can say, hey, I just received a clear to send, so that means somebody else was allocated the channel. So I should not transmit anything because I might collide with them. And so the clear to send also goes back to the broadcasting host who receives it and they can transmit their data packet. And the access point receives the data packet. The access point will then send back an acknowledgement which informs the sending host that they received the packet successfully. But it also informs other hosts that the channel is now clear. So the other hosts over there can say, okay, I saw a clear to send, I stopped transmitting because someone else was transmitting. And then I received an ACK and so now I know they're done transmitting and so therefore I can start transmitting, if I want. If I want to send a packet, I can send a request to send this in the packet myself. So this process is known as collision avoidance and it relies on kind of this distributed set of messages to allocate the channel. So what I've done here is I've told you about this problem with collisions and how they can affect transmissions. And I've given you two schemes to deal with them. We've talked about collision detection, which works well in point-to-point links, including point-to-point wireless links and wired networks. And we also talked about collision avoidance and there's a bunch of varieties of collision avoidance that are used in practice in wireless networks.