import os import signal from string import Template import subprocess import time from multiprocessing import Pool from functools import cached_property from TdcPlugin import TdcPlugin
with IPRoute() as ip:
ticks = 20 whileTrue: if ticks == 0: raise TimeoutError try:
dev0_idx = ip.link_lookup(ifname=dev0)[0]
ip.link('set', index=dev0_idx, state='up') break except:
time.sleep(0.1)
ticks -= 1 continue
def _ipr2_ns_create_cmds(self):
cmds = []
ns = self.args.NAMES['NS']
cmds.append(self._replace_keywords('netns add {}'.format(ns)))
cmds.append(self._replace_keywords('link add $DEV1 type veth peer name $DEV0'))
cmds.append(self._replace_keywords('link set $DEV1 netns {}'.format(ns)))
cmds.append(self._replace_keywords('link add $DUMMY type dummy'.format(ns)))
cmds.append(self._replace_keywords('link set $DUMMY netns {}'.format(ns)))
cmds.append(self._replace_keywords('netns exec {} $IP link set $DEV1 up'.format(ns)))
cmds.append(self._replace_keywords('netns exec {} $IP link set $DUMMY up'.format(ns)))
cmds.append(self._replace_keywords('link set $DEV0 up'.format(ns)))
if self.args.device:
cmds.append(self._replace_keywords('link set $DEV2 netns {}'.format(ns)))
cmds.append(self._replace_keywords('netns exec {} $IP link set $DEV2 up'.format(ns)))
return cmds
def _ipr2_ns_create(self): '''
Create the network namespace in which the tests will be run and set up
the required network devices for it. '''
self._exec_cmd_batched('pre', self._ipr2_ns_create_cmds())
def _ipr2_ns_destroy(self): '''
Destroy the network namespace for testing (and any associated network
devices as well) '''
self._exec_cmd('post', self._ipr2_ns_destroy_cmd())
if proc.returncode isnotNoneand proc.returncode != 0: raise RuntimeError("iproute2 exited with an error code")
def _exec_cmd(self, stage, command): '''
Perform any required modifications on an executable command, then run
it in a subprocess andreturn the results. '''
if self.args.verbose > 3:
print('_exec_cmd: command "{}"'.format(command))
if self.args.verbose > 3:
print('_exec_cmd proc: {}'.format(proc))
self._proc_check()
def _exec_cmd_batched(self, stage, commands): for cmd in commands:
self._exec_cmd(stage, cmd)
def _replace_keywords(self, cmd): """ For a given executable command, substitute any known
variables contained within NAMES with the correct values """
tcmd = Template(cmd)
subcmd = tcmd.safe_substitute(self.args.NAMES) return subcmd
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.