def run_cli(): interactive = sys.stdin.isatty() and sys.stdout.isatty() # Colorize output to standard error if interactive and sys.stderr.isatty(): stderr = ColorizedOutput(sys.stderr, '\033[31m') # red (not bright) else: stderr = sys.stderr try: hist_file = os.path.expanduser('~/.trafficgen_history') open(hist_file, 'a+').close() except: print >> stderr, 'Error: Cannot open ~/.trafficgen_history' hist_file = None raise try: s = bess.BESS() s.connect() except bess.BESS.APIError as e: print >> stderr, e.message, '(bessd daemon is not running?)' cli = TGENCLI(s, generator_commands, ferr=stderr, interactive=interactive, history_file=hist_file) print('Starting BESS...') bess_commands._do_start(cli, '-k') cli.loop()
def test_create_port(self): client = bess.BESS() client.connect() response = client.create_port('PCAPPort', 'p0', {'dev': 'rnd'}) self.assertEqual(0, response.error.code) self.assertEqual('p0', response.name) response = client.create_port('PMDPort', 'p0', { 'loopback': True, 'port_id': 14325, 'pci': 'akshdkashf'}) self.assertEqual(0, response.error.code) self.assertEqual('p0', response.name) response = client.create_port('UnixSocketPort', 'p0', {'path': '/ajksd/dd'}) self.assertEqual(0, response.error.code) self.assertEqual('p0', response.name) response = client.create_port('VPort', 'p0', { 'ifname': 'veth0', 'container_pid': 23124, 'rxq_cpus': [1, 2, 3], 'tx_tci': 123, 'tx_outer_tci': 123, 'loopback': False, 'ip_addrs': ['1.2.3.4', '255.254.253.252'] }) self.assertEqual(0, response.error.code) self.assertEqual('p0', response.name)
def test_connect(self): client = bess.BESS() client.connect() time.sleep(1) self.assertEqual(True, client.is_connected()) client.disconnect() time.sleep(1) self.assertEqual(False, client.is_connected())
def test_run_module_command(self): client = bess.BESS() client.connect() response = client.run_module_command('m1', 'add', 'ExactMatchCommandAddArg', {'gate': 0, 'fields': ['\x11', '\x22']}) self.assertEqual(0, response.error.code)
def run_cmds(instream): try: s = bess.BESS() s.connect() except bess.BESS.APIError: # show no error msg, since user might be about to launch the daemon pass cli = TGENCLI(s, generator_commands, fin=instream, ferr=sys.stderr, interactive=False) print('Starting BESS...') bess_commands._do_start(cli, '-k') cli.loop() # end of loop due to error? if cli.stop_loop: if cli.last_cmd: cli.ferr.write(' Command failed: %s\n' % cli.last_cmd) sys.exit(1)
def test_list_modules(self): client = bess.BESS() client.connect() response = client.list_modules() self.assertEqual(0, response.error.code)
def test_kill(self): client = bess.BESS() client.connect() response = client.kill(block=False) self.assertEqual(0, response.error.code)