- command = 'connect'
- if mac is not None:
- args = 'tapname {} mac {}'.format(tap_name, mac)
- else:
- args = 'tapname {}'.format(tap_name)
- with VatTerminal(node) as vat:
- resp = vat.vat_terminal_exec_cmd_from_template('tap.vat',
- tap_command=command,
- tap_arguments=args)
- sw_if_idx = resp[0]['sw_if_index']
+ if isinstance(tap_name, unicode):
+ tap_name = str(tap_name)
+ cmd = 'tap_create_v2'
+ args = dict(
+ id=Constants.BITWISE_NON_ZERO,
+ use_random_mac=0 if mac else 1,
+ mac_address=L2Util.mac_to_bin(mac) if mac else 6 * b'\x00',
+ host_namespace=64 * b'\x00',
+ host_mac_addr=6 * b'\x00',
+ host_if_name_set=1,
+ host_if_name=tap_name + (64 - len(tap_name)) * b'\x00',
+ host_bridge=64 * b'\x00',
+ host_ip4_addr=4 * b'\x00',
+ host_ip6_addr=16 * b'\x00',
+ host_ip4_gw=4 * b'\x00',
+ host_ip6_gw=16 * b'\x00'
+ )
+ err_msg = 'Failed to create tap interface {tap} on host {host}'.format(
+ tap=tap_name, host=node['host'])
+
+ with PapiSocketExecutor(node) as papi_exec:
+ sw_if_index = papi_exec.add(cmd, **args).get_sw_if_index(err_msg)
+