[MUSIC] In the last video we learned how to start our mini data center. And we saw how our video streaming application was affected by congestion from other tenants. In this assignment, we'll act as a network operator and quantify the problem by implementing a traffic monitor. We'll write a small amount of code in this assignment to piece together a traffic monitor. In doing so, we'll be able to collect statistics about the amount of traffic each host sends and receives. We use the same topology in host applications as the previous assignment. We'll do this using the open flow protocol which gives our STN controller the ability to program switches. A lot of this code is provided for you but understanding how it works at a high level may be helpful. A controller will send an open flow message to each edge switch asking for ports statistics. Each switch collects information about the number of packets or bytes sent and received from each port, the number of dropped packets, and several other statistics. After receiving a statistics request, each switch sends a reply to the controller with the stats for each port. It's important to remember each statistic applies to only one port on a switch and each port connects to another switch or host. So let's see this in action. First, I'll demonstrate the system as you'll see it before you implement your solution. Then I'll show you how to verify your code is working as expected. Just like the first assignment, we'll start two terminals or two tabs. In the first terminal move to the directory cloud net mooc. And we'll start our network emulator using the command sudo mdc and passive parameter vid. You'll be prompted for the sudo password which is mooc lower case mooc. So this starts the mini-network emulator into topologies and applications I described in the previous video. In the second terminal or tab, move to the directory cloudnetmooc/minidc/controller. And they you want to start our SDN controller reu with the command ryu-manager and pass controller.py. Now go back to the first terminal and press enter. So Chrome browser should pop up, and a video should start playing. Like we saw in the first assignment the video quality is poor. We can downsize the browser since we don't need it right now. Now open a new Chrome instance from the desktop. Not from the one playing the video stream since this is in a sandboxed environment in our emulator. And bring up our cloud dashboard by going to localhost or 127.0.0.1. In the top section, these two tablets describe the types of tenants in our data center and the applications running on each host. Video streaming, as you can see on the left, is a tenant with two hosts. And these two hosts are running a PHP server and a Chrome instance. Now if we scroll down a bit more, we can see there are several empty charts. These will display data collected from our traffic monitor. If coded correctly, you should see a line chart on the left two and a pie chart on the right. Now we'll shut down our emulator and examine the code you'll need to add. So type in exit into our emulator and stop our controller by pressing controlling C. Now let's look at the code you'll need to add. Open a terminal and cd to the directory cloudnetmooc/minidc/controller/. You can either do this in the terminal or in the file manager. And you'll want to open the file bwmon.py. I'm going to use emacs to do this. But to keep the VM side small we've only installed the graphical editor mouse pad. So you can install your prefered editor using the command pseudo apt get install e-max vim or nano. So if you scroll to the end of the file. You'll see this function's status reply handler. This is a function that is called each time the controller receives the statistics reply from a switch. The first thing to note is the variable name, which takes the responding switch's ID. Called the data path ID, or dpid, and converts it to the representation we saw on our topology diagram. So the variable name will be something like s101 or s102. This next section of code is extracting the number of dropped packets from the statsReply. So the reply consists of a list of statistics grouped by port, as I described earlier. So this block of code enumerates each item in body with the current item name stat. This code then sums all the dropped packets from each port and then passes the result to our bandwidth statistics module. Now, this will provide a helpful template for the code you need to add. So, your code should pass through the BW stats module the number of transmitted and received bytes for each host. So in the comments I provided a description of this function. You'll also need to determine what host is associated with the port for that statistic. So, you can use the object self.topo.ports to determine which host is associated with that port. So, this is a two-level dictionary that takes the responding switch's name and a port number and returns. Either a host name, such as H1 or H2, or a switch name, such as S101 or S102, depending on which node is associated with that port. You can also reference the documentation at the top of this file for useful properties and functions in the topology class. One helpful hint is that there are virtual ports built into each switch for actions like sending a packet to a controller or flooding, which sends a packet out all ports. We only care about statistics from ports that are connected to a host. Your code shouldn't be very long. My solution is only five lines. Now you can check if your code is working properly by starting up the system again. In the first terminal, cd ~/cloudnetmooc/ and start our emulator with the command sudo ./mdc --vid, and it prompted for the sudo password, remember it's mooc, m o o c all lower case. And then we'll start our ryu controller, by going into the, directory cloud network minidc controller. And starting the controller with the command ryu manager, and controller.py. Now we'll start our emulator. And our Chrome browser will pop up. So we'll bring up our dashboard now to see the statistics that should be reported. So open a new Chrome instance from the desktop. Remember not from the one running the Video streaming success in the sandbox and go to local host or 127.0.0.1, and we should see now that our graphs actually had data. So, let's look at the two pie graphs on the right. At the top, we can see the number of bites sent by each host. On the bottom we can see the percentage of total traffic sent by each tenant. So if we look at the bottom one, we can see that the traffic on the network is dominated by VLAN1. And if we look at our chart on the top we can see that VLAN1 Is our Iperf tenants. This means that our video application is using only a very small share of the available network bandwidth. And since our video streaming application is adaptive, and playing in poor quality. We can conclude that there's a lot of congestion on the network, or very small amount of bandwidth available to the video stream length tenant. So, now let's close our emulator by typing exit. And stopping our controller by issuing a command control C. This concludes the walk through for assignment two. In the next video we'll learn how to improve our routing policy to achieve higher quality video streaming. [MUSIC]