Pyretic + Mininet: Switch Monitor




H1 will send 50kbps traffic to H3 and H2 will send 100 kbps to H3. We will measure the bandwidth consumption at S1, S2, S3.


[Pyretic code:]

Put this file under /home/ubuntu/pyretic/pyretic/tutorial.

from pyretic.lib.corelib import *

from pyretic.lib.std import *

from pyretic.lib.query import *

from pyretic.modules.mac_learner import *

from collections import defaultdict


from datetime import datetime

import time







def byte_count_printer(n):

  if len(n)!=0:

    print time.time()

    for i, j in n.items():

      if byte[str(i).split(" ")[2][0]]>0:

        thr[str(i).split(" ")[2][0]] = (j - byte[str(i).split(" ")[2][0]]) * 8.0 / (time.time()-clock[str(i).split(" ")[2][0]])

        print "switch ", str(i).split(" ")[2][0], " =", thr[str(i).split(" ")[2][0]], "bps"

      byte[str(i).split(" ")[2][0]]=j

      clock[str(i).split(" ")[2][0]]=time.time()

      print " ----------------------------------------------------"



def byte_counts():

  #measure the bandwidth consumption every 3 seconds

  q = count_bytes(3,['switch'])


  return q      


def main():

  return (mac_learner() + byte_counts())




1. Open one terminal to run the mininet and another to run pyretic controller


2. Open xterm windows for h1, h2, and h3.


3. Open iperf udp servers with port 5555 and 6666 at H3.


4. Use iperf udp client at H1 to send the traffic with 50kbps to the port 5555 at H3.


5. Use iperf udp client at H2 to send the traffic with 100kbps to the port 6666 at H3.


6. Check the output of pyretic controller.

From the above figure, we can see that we can get around 50kbps at switch 1 and 150 kbps at switch2 and switch 3.



Dr. Chih-Heng Ke

Department of Computer Science and Information Engineering, National Quemoy University, Kinmen, Taiwan

Email: /