Best Python code snippet using autotest_python
net_tc.py
Source:net_tc.py
...13 netem_qdisc.add_param('loss 100%')14 ack_filter = u32filter()15 ack_filter.add_rule('match ip protocol 6 0xff')16 ack_filter.add_rule('match u8 0x10 0x10 at nexthdr+13')17 ack_filter.set_dest_qdisc(netem_qdisc)18 root_qdisc = prio()19 root_qdisc.get_class(2).set_leaf_qdisc(netem_qdisc)20 root_qdisc.add_filter(ack_filter)21 lo_if = mock_netif('lo')22 root_qdisc.setup(lo_if)23 # run test here ...24 root_qdisc.restore(lo_if)25"""26import commands, os, re27import common28from autotest_lib.client.common_lib import error29from autotest_lib.client.bin.net import net_utils30# TODO (chavey) clean up those global here and new_handle()31handle_counter = 032INCR = 10033def new_handle():34 global handle_counter35 handle_counter += INCR36 return handle_counter37class tcclass(object):38 def __init__(self, handle, minor, leaf_qdisc=None):39 self._parent_class = None40 self._children = []41 self._leaf_qdisc = leaf_qdisc42 self._handle = handle43 self._minor = minor44 def get_leaf_qdisc(self):45 return self._leaf_qdisc46 def set_leaf_qdisc(self, leaf_qdisc):47 leaf_qdisc.set_parent_class(self)48 self._leaf_qdisc = leaf_qdisc49 def get_parent_class(self):50 return self._parent_class51 def set_parent_class(self, parent_class):52 self._parent_class = parent_class53 def get_minor(self):54 return self._minor55 def id(self):56 return '%s:%s' % (self._handle, self._minor)57 def add_child(self, child_class):58 child_class.set_parent_class(self)59 if child_class not in self._children:60 self._child.append(child_class)61 def setup(self, netif):62 # setup leaf qdisc63 if self._leaf_qdisc:64 self._leaf_qdisc.setup(netif)65 # setup child classes66 for child in self._children:67 child.setup()68 def restore(self, netif):69 # restore child classes70 children_copy = list(self._children)71 children_copy.reverse()72 for child in children_copy:73 child.restore()74 # restore leaf qdisc75 if self._leaf_qdisc:76 self._leaf_qdisc.restore(netif)77class tcfilter(object):78 _tc_cmd = 'tc filter %(cmd)s dev %(dev)s parent %(parent)s protocol ' \79 '%(protocol)s prio %(priority)s %(filtertype)s \\\n ' \80 '%(rules)s \\\n flowid %(flowid)s'81 conf_device = 'dev'82 conf_parent = 'parent'83 conf_type = 'filtertype'84 conf_protocol = 'protocol'85 conf_priority = 'priority'86 conf_flowid = 'flowid'87 conf_command = 'cmd'88 conf_rules = 'cmd'89 conf_qdiscid = 'qdiscid'90 conf_name = 'name'91 conf_params = 'params'92 def __init__(self):93 self._parent_qdisc = None94 self._dest_qdisc = None95 self._protocol = 'ip'96 self._priority = 197 self._handle = None98 self._tc_conf = None99 def get_parent_qdisc(self):100 return self._parent_qdisc101 def set_parent_qdisc(self, parent_qdisc):102 self._parent_qdisc = parent_qdisc103 def get_dest_qdisc(self):104 return self._dest_qdisc105 def set_dest_qdisc(self, dest_qdisc):106 self._dest_qdisc = dest_qdisc107 def get_protocol(self):108 return self._protocol109 def set_protocol(self, protocol):110 self._protocol = protocol111 def get_priority(self):112 return self._priority113 def set_priority(self, priority):114 self._priority = priority115 def get_handle(self):116 return self._handle117 def set_handle(self, handle):118 self._handle = handle119 def _get_tc_conf(self, netif):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!