Skip to content

Commit

Permalink
Merge pull request #14 from tikitavi/master
Browse files Browse the repository at this point in the history
add DPDK vrouter options
  • Loading branch information
Andrey-mp committed Jul 9, 2018
2 parents f531e75 + 67eac87 commit 6afa22b
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 21 deletions.
16 changes: 16 additions & 0 deletions contrail-agent/config.yaml
Expand Up @@ -51,6 +51,22 @@ options:
using '-' e.g. 0-2).
It must specify only real cores cause contrail-vrouter-dpdk service will
fail if specified core number is not present in the system.
dpdk-main-mempool-size:
type: string
description: |
Main packet pool size.
dpdk-pmd-txd-size:
type: string
description: |
DPDK PMD Tx Descriptor size.
dpdk-pmd-rxd-size:
type: string
description: |
DPDK PMD Rx Descriptor size.
vhost-mtu:
type: string
description: |
MTU for vhost0 interface
log-level:
type: string
default: SYS_NOTICE
Expand Down
8 changes: 5 additions & 3 deletions contrail-agent/hooks/contrail_agent_hooks.py
Expand Up @@ -44,7 +44,7 @@
update_vrouter_provision_status,
write_configs,
update_unit_status,
set_dpdk_coremask,
set_dpdk_options,
configure_hugepages,
get_hugepages,
fix_libvirt,
Expand Down Expand Up @@ -144,7 +144,7 @@ def install_dpdk():
service_restart("libvirt-bin")

configure_vrouter_interface()
set_dpdk_coremask()
set_dpdk_options()
write_configs()

if not init_is_systemd():
Expand All @@ -170,7 +170,9 @@ def config_changed():
.format(key))

if config["dpdk"]:
set_dpdk_coremask()
if (config.changed("dpdk-main-mempool-size") or config.changed("dpdk-pmd-txd-size")
or config.changed("dpdk-pmd-rxd-size") or config.changed("dpdk-coremask")):
set_dpdk_options()
configure_hugepages()

write_configs()
Expand Down
80 changes: 67 additions & 13 deletions contrail-agent/hooks/contrail_agent_utils.py
Expand Up @@ -149,6 +149,10 @@ def configure_vrouter_interface():
addr = netifaces.ifaddresses(iface)[netifaces.AF_PACKET][0]
config["dpdk-mac"] = addr["addr"]

if config.get("vhost-mtu"):
args.append("-m")
args.append(config["vhost-mtu"])

args.append(iface)
check_call(args, cwd="scripts")

Expand Down Expand Up @@ -392,28 +396,77 @@ def _get_agent_status():
return "waiting", None


def set_dpdk_coremask():
def _get_args_from_command_string(original_args):
args_other = ''
command_args_dict = {}
args_list = original_args.split(' ')
iter_args = iter(enumerate(args_list))
# divide dpdk arguments and other
for index, arg in iter_args:
if arg in ["--vr_mempool_sz", "--dpdk_txd_sz", "--dpdk_rxd_sz"]:
command_args_dict[arg] = args_list[index+1]
next(iter_args)
else:
args_other += ' ' + arg
return command_args_dict, args_other


def _dpdk_args_from_config_to_dict():
config_args_dict = {}
dpdk_main_mempool_size = config.get("dpdk-main-mempool-size")
if dpdk_main_mempool_size:
config_args_dict["--vr_mempool_sz"] = dpdk_main_mempool_size
dpdk_pmd_txd_size = config.get("dpdk-pmd-txd-size")
if dpdk_pmd_txd_size:
config_args_dict["--dpdk_txd_sz"] = dpdk_pmd_txd_size
dpdk_pmd_rxd_size = config.get("dpdk-pmd-rxd-size")
if dpdk_pmd_rxd_size:
config_args_dict["--dpdk_rxd_sz"] = dpdk_pmd_rxd_size
return config_args_dict


def set_dpdk_options():
mask = config.get("dpdk-coremask")
service = "/usr/bin/contrail-vrouter-dpdk"
mask_arg = mask if mask.startswith("0x") else "-c " + mask
if not init_is_systemd():
check_call(["sed", "-i", "-e",
"s!^command=.*{service}!"
"command=taskset {mask} {service}!".format(service=service,
mask=mask_arg),
"/etc/contrail/supervisord_vrouter_files"
"/contrail-vrouter-dpdk.ini"])
srv = "/etc/contrail/supervisord_vrouter_files/contrail-vrouter-dpdk.ini"
with open(srv, "r") as f:
data = f.readlines()
for index, line in enumerate(data):
if not (line.startswith("command=") and service in line):
continue
original_args = line.split(service)[1].rstrip()
command_args_dict, other_args = _get_args_from_command_string(original_args)
config_args_dict = _dpdk_args_from_config_to_dict()
command_args_dict.update(config_args_dict)
dpdk_args_string = " ".join(" ".join(_) for _ in command_args_dict.items())
args = dpdk_args_string + other_args
newline = 'command=taskset ' + mask_arg + ' ' + service + ' ' + args + '\n'
data[index] = newline

with open(srv, "w") as f:
f.writelines(data)
service_restart("contrail-vrouter-dpdk")
return

# systemd magic
srv_orig = "/lib/systemd/system/contrail-vrouter-dpdk.service"
with open(srv_orig, "r") as f:
for line in f:
if line.startswith("ExecStart="):
args = line.split(service)[1]
break
else:
args = " --no-daemon --socket-mem 1024"
data = f.readlines()
for line in data:
if not line.startswith("ExecStart="):
continue
original_args = line.split(service)[1].rstrip()
dpdk_args_dict, other_args = _get_args_from_command_string(original_args)
config_args_dict = _dpdk_args_from_config_to_dict()
dpdk_args_dict.update(config_args_dict)
break
else:
dpdk_args_dict = _dpdk_args_from_config_to_dict()
other_args = " --no-daemon --socket-mem 1024"
dpdk_args_string = " ".join(" ".join(_) for _ in dpdk_args_dict.items())
args = dpdk_args_string + other_args

srv_dir = "/etc/systemd/system/contrail-vrouter-dpdk.service.d/"
try:
Expand All @@ -425,6 +478,7 @@ def set_dpdk_coremask():
f.write("ExecStart=/usr/bin/taskset {mask} {service} {args}"
.format(service=service, mask=mask_arg, args=args))
check_call(["systemctl", "daemon-reload"])
service_restart("contrail-vrouter-dpdk")


def configure_hugepages():
Expand Down
26 changes: 21 additions & 5 deletions contrail-agent/scripts/create-vrouter.sh
Expand Up @@ -5,12 +5,14 @@
ARG_BRIDGE=b
ARG_DPDK=d
ARG_HELP=h
OPTS=:${ARG_BRIDGE}${ARG_DPDK}${ARG_HELP}
MTU=m
OPTS=:${ARG_BRIDGE}${ARG_DPDK}${ARG_HELP}${MTU}:
USAGE="\
create-vrouter [-${ARG_BRIDGE}${ARG_DPDK}${ARG_HELP}] [interface]
create-vrouter [-${ARG_BRIDGE}${ARG_DPDK}${ARG_HELP}] [-${MTU} mtu] [interface]
Options:
-$ARG_BRIDGE remove bridge from interface if exists
-$ARG_DPDK configure DPDK vRouter
-$MTU configure MTU for vhost0
-$ARG_HELP print this message"

configVRouter()
Expand All @@ -19,6 +21,7 @@ configVRouter()
# $2 - interface to setup for vhost0
# $3 - file path. bridge interface to de-configure
# $4 - file path for vhost0 interface
# $5 - mtu for vhost0
cat juju-header
if [ -s "$3" ]; then
printf "\n%s\n" "auto $2"
Expand Down Expand Up @@ -55,6 +58,11 @@ configVRouter()
post-down ip link delete vhost0
EOF
fi
if [ -n "$5" ]; then
cat <<-EOF
mtu $5
EOF
fi
}

configureInterfaces()
Expand Down Expand Up @@ -105,6 +113,7 @@ configureVRouter()
# $1 - dpdk enabled if not empty
# $2 - interface to setup for vhost0
# $3 - bridge to delete if not empty
# $4 - mtu
if [ $# = 2 ]; then
iface_down=$2
iface_delete=$2
Expand All @@ -118,10 +127,11 @@ configureVRouter()
fi
addr=`ifconfig $2 | grep -o "inet addr:[\.0-9]*" | cut -d ':' -f 2`
mask=`ifconfig $2 | grep -o "Mask:[\.0-9]*" | cut -d ':' -f 2`
mtu=$4
ifacedown $iface_down vhost0; sleep 5
configureInterfacesDir
configureInterfaces $iface_delete
configVRouter "$1" $iface_up $iface_cfg $TMP/vrouter.cfg \
configVRouter "$1" $iface_up $iface_cfg $TMP/vrouter.cfg $mtu \
> /etc/network/interfaces.d/vrouter.cfg
ifaceup $iface_up
if [ -z "$1" ]; then
Expand Down Expand Up @@ -243,9 +253,15 @@ while getopts $OPTS opt; do
usage
exit 0
;;
$MTU)
mtu=$OPTARG
;;
"?")
usageError "Unknown argument: $OPTARG"
;;
:)
usageError "Option -$OPTARG requires an argument"
;;
esac
done
shift $(($OPTIND - 1))
Expand Down Expand Up @@ -274,9 +290,9 @@ else
&& [ -z "$(find /sys/class/net/$gateway/brif -maxdepth 0 -empty)" ] \
&& [ -n "$remove_bridge" ]; then
interface=$(find /sys/class/net/$gateway/brif | sed -n -e '2p' | xargs basename)
configureVRouter "$dpdk" $interface $gateway
configureVRouter "$dpdk" $interface $gateway $mtu
else
configureVRouter "$dpdk" $gateway
configureVRouter "$dpdk" $gateway $mtu
fi
fi

Expand Down

0 comments on commit 6afa22b

Please sign in to comment.