So next, let's get inside a router and understand the pieces of it a little bit more. So there's all these pieces that we've been talking about; input interfaces, output queues, and all these different things. But what do they actually do? What are their functions? Let's start talking about input interfaces first of all. So the input interfaces are the routers first line of defense. It's the first time that sees a packet, and these are physical interfaces. So most of their operations are at layer one and layer two. They taken signals from the line and extract bit patterns out of them, and they uses bit pattern to construct higher layer representations of packets. So one thing they do is they perform lookup. They create the packet and they figured out which outbound interface to send it out. Then what they will do is they will actually tag the packet with a little bit of control information which is used inside the router. That control information is then used to determine the output port and route it through the mesh inside the backplane. Input interfaces may optionally enqueue packets if they have queues, and they may optionally perform scheduling as well. Scheduling is this idea about deciding when to send packets and which packets to send. You might think, well, for router has packets, it should service them in order. Packets are in a line. They're in a queue. So we should serve ahead of the queue first. That's a good strategy that's called FIFO queuing. But there's different ways to do it. We may have higher priority packets. Like the router might determine, "Oh, there's some voice-over IP packets in here, we should probably send those first." So scheduling is a really important parameter because that allows you to service different packets in different orders, provide quality of service, things like that. This is all done at the input interface. Next, there's the backplane. The job of the backplane is to get packets from input interfaces to output interfaces. The backplane uses information that the input interface determined to figure out which outbound interface has sent it out. So it's not the backplanes job to figure out which outbound interface has sent it out, that's the job of the input interface. Finally, there's the output interface. The job of the output interface is to optionally enqueue packets and optionally perform scheduling. Then it takes the packets in the internal representation used inside the router, and then clocks at the bit. So it'll produce a physical encoding that goes at the output interface. If it's optical, if it's ethernet, it'll produce that encoding. So there's different pieces of a router. But how do you actually construct a router? Well, with many things in computer science, there are certain principles we have about how to design things. It's not like math. With calculus, we have rigorous proofs about how we build things. A lot of things in computer science are more like we have rules, and design decisions, and things like that. It's like that for routers too. So with routers, there's certain common architectures that you see over and over which are good designs for routers. Knowing these architectures can help you decide which routers that you'd buy for your own networks. So there's a few key kinds of router architectures out there. One key question centers around where to put queues inside the routers. On one hand, these queues are fast memory. They have to process packets at high speed, so they're very expensive. So you don't just want to put queues everywhere in your router. Another issue is that they need to perform complicated forwarding functions. You're going to have these queues, but oftentimes you won't process first-in, first-out. You're going to make complicated decisions about which packets to drop. So when you think about these things, queuing is actually really important, and they have a lot of influence on router design. So there's three key architectures that are used to design routers. There's input-queued routers, output-queued routers, and combined input-output queued routers. So these architectures differ in several key ways. Input-queued routers queue packets only at the inputs. They don't have queues at the outputs. So the advantage of these designs are, first of all, this saves us memory. We don't have to have expensive memory in two places. We just have to have it in one place so that reduces our costs. It also makes things easy to design because there's only one point in the router where we have to worry about queuing. We don't have to have some crazy distributed system inside the router that coordinates queuing and decides where to queue things. If we only have one point where we queue, then router designs get easier. So you can queue packets if the backplane gets overloaded and the outputs get overloaded. So this is a pretty smart place to queue because it protects the internals of the router as well. A downside that comes up here something called head-of-line blocking, where packets can actually get stuck. We'll talk about head-of-line blocking a little bit later. But the basic idea is packets come in, and you might have a packet at the head of that queue which prevents other packets behind it from getting sent out. So an alternative is called output-queued. Output-queued architectures only have queues at the outputs of the router. So there's a lot of advantages of output-queued routers. They're also easy to design. There's only one point where you queue. It also reduces your memory requirements. You don't have to have expensive memory at the inputs. You only needed at the outputs. But a problem that comes up here is dealing with collisions. What if multiple inputs sent to the same output at the same time? Well, then you have a bottleneck at the hardware that's used to load packets into the output queue. That could get overloaded, and if that's overloaded, where do you queue? There's no queuing at the inputs. So if there's another input riding to that buffer at the output, you can have another input riding into that same buffer. So you get a collision, and you're forced to drop. So this is a problem. Now to get around this, you can make the hardware faster. You can make the hardware of the output queue fast enough so that it can handle all the inputs riding at the same time, but that's pretty expensive. Because if you have a one gig interface, suddenly you have to have a 48 gig cross-connect to get the packets in there. It's not a very feasible design. So typically, we don't use output-queued designs when we design routers. Another type of router design is called combined input-output queued. Here, what we do is we enqueue packets at both the inputs and the outputs. So there's a lot of advantage here. We can achieve higher utilization because no matter where the bottleneck is you can queue, and you can smooth outburst so you get less loss. You can get a higher utilization of the routers' resources. The problem here is, it's harder to design forwarding algorithms for these routers. Because if you think about it, things get challenging. If a packet comes in and the router gets overloaded, maybe there's not enough capacity in its backplane or inside of its internal queues. You can queue up packets, but where do you queue? So what these routers do is they'll design more advanced distributed algorithms to deal with these challenges. There's one called distributed backpressure. The way it works is you'll queue packets at the output queue, output queue. Then when that gets full, you'll send the backpressure message telling the input queue to slow down and stop sending packets, then you'll start queuing at the input queue. When the output queue trickles out, then it can send another message to the input queue saying, "Okay, you can send packets now." So if you think about it, you need some more advanced distributed algorithms inside the router to coordinate queuing, and you can implement those and router vendors have gotten very good at that. But it makes routers more complicated, and you need more advanced hardware for this. So typically, you see input-queue designs in a lower end routers, and you see combined input-output queue designs in higher end routers.