How to monitor the switch queue length in the mininet ?

 

[topology]

 

H1------(s1-eth1) S1 (s1-eth2)-------H2

 

[mininet script]

#!/usr/bin/env python

from mininet.cli import CLI

from mininet.net import Mininet

from mininet.link import Link,TCLink,Intf

from mininet.node import RemoteController

 

if '__main__' == __name__:

  net = Mininet(link=TCLink)

  h1 = net.addHost('h1')

  h2 = net.addHost('h2')

  s1 = net.addSwitch('s1')

  c0 = net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6633)

  linkopts0=dict(bw=20, delay='1ms', loss=0, max_queue_size=20, use_tbf=True)

  linkopts1=dict(bw=5, delay='1ms', loss=0, max_queue_size=10, use_tbf=True)

  net.addLink(h1, s1, cls=TCLink, **linkopts0)

  net.addLink(s1, h2, cls=TCLink, **linkopts1)

  net.build()

  c0.start()

  s1.start([c0])

 

  CLI(net)

  net.stop()

 

[monitor_qlen.py]

from time import sleep, time

from subprocess import *

import re

 

default_dir = '.'

 

def monitor_qlen(interval_sec=0.01):

  pat_queued =re.compile(r'backlog\s[^\s]+\s([\d]+)p')

  cmd = "tc -s qdisc show dev s1-eth2"

  ret = []

  open("qlen.txt","w").write('')

  t0 = "%f" % time()

  while 1: 

    p = Popen(cmd, shell=True, stdout=PIPE)

    output = p.stdout.read()

    matches = pat_queued.findall(output)

    if matches and len(matches) > 1:

      ret.append(matches[1])

      t1 = "%f" % time()

      #print str(float(t1)-float(t0)), matches[1]

      open("qlen.txt","a").write(str(float(t1)-float(t0))+' '+matches[1]+'\n')

    sleep(interval_sec)

 

monitor_qlen()

 

[execution]

Start iperf server at h2 and iperf client at h1

 

At the time, open another terminal to run queue length monitor program.

You can find the qlen.txt

 

We can also use gnuplot to draw the figure.

 

Reference

https://github.com/mininet/mininet-util

 

Dr. Chih-Heng Ke (smallko@gmail.com)

Department of Computer Science and Information Engineering,

National Quemoy University, Kinmen, Taiwan.