'Test TCLink bw and delay'

def testLinkChange(self):

    p = pexpect.spawn('mn    --link    tc,bw=10,delay=10ms')
    p.expect(self.prompt)
    p.sendline('iperf')
    p.expect("Results:    \\['([\\d\\.]+)    Mbits/sec',")
    bw = float(p.match.group(1))
    self.assertTrue((bw < 10.1), ('Bandwidth    %.2f    >=    10.1    Mb/s' % bw))
    self.assertTrue((bw > 9.0), ('Bandwidth    %.2f    <=    9    Mb/s' % bw))
    p.expect(self.prompt)
    p.sendline('h1    ping    -c    4    h2')
    p.expect('rtt    min/avg/max/mdev    =    ([\\d\\.]+)/([\\d\\.]+)/([\\d\\.]+)/([\\d\\.]+)    ms')
    delay = float(p.match.group(2))
    self.assertTrue((delay > 40), 'Delay    <    40ms')
    self.assertTrue((delay < 45), 'Delay    >    40ms')
    p.expect(self.prompt)
    p.sendline('exit')
    p.wait()
