#NEWLINE# def netem( self , loss_ratio = 0 , loss_corr = 0 , dup_ratio = 0 , delay = 0 , jitter = 0 , delay_jitter_corr = 0 , reorder_ratio = 0 , reorder_corr = 0 , toggle = [ 1000000 ] ) : #NEWLINE# #INDENT# assert ( subprocess . call ( shlex . split ( 'tc qdisc add dev {0} parent 1:3 handle 30: netem' . format ( self . nic ) ) ) == 0 ) #NEWLINE# while ( len ( toggle ) != 0 ) : #NEWLINE# #INDENT# impair_cmd = 'tc qdisc change dev {0} parent 1:3 handle 30: netem loss {1}% {2}% duplicate {3}% delay {4}ms {5}ms {6}% reorder {7}% {8}%' . format ( self . nic , loss_ratio , loss_corr , dup_ratio , delay , jitter , delay_jitter_corr , reorder_ratio , reorder_corr ) #NEWLINE# print ( 'Setting network impairment:' ) #NEWLINE# print ( impair_cmd ) #NEWLINE# assert ( subprocess . call ( shlex . split ( impair_cmd ) ) == 0 ) #NEWLINE# print ( 'Impairment timestamp: {0}' . format ( datetime . datetime . today ( ) ) ) #NEWLINE# time . sleep ( toggle . pop ( 0 ) ) #NEWLINE# if ( len ( toggle ) == 0 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# assert ( subprocess . call ( shlex . split ( 'tc qdisc change dev {0} parent 1:3 handle 30: netem' . format ( self . nic ) ) ) == 0 ) #NEWLINE# print ( 'Impairment stopped timestamp: {0}' . format ( datetime . datetime . today ( ) ) ) #NEWLINE# time . sleep ( toggle . pop ( 0 ) )