summaryrefslogtreecommitdiffstats
path: root/vnfs
diff options
context:
space:
mode:
authorDino Simeon Madarang <dino.simeonx.madarang@intel.com>2015-07-15 09:22:07 +0100
committerMaryam Tahhan <maryam.tahhan@intel.com>2015-08-25 09:05:55 +0000
commitfcdbebe21c7ce590bb6e321506dcd722ad9f9863 (patch)
tree0f71099ddcbe7ce276fdfc2ab3bf1d7cf819535e /vnfs
parent65fe266e99de3746372e633794c07ad95c1e383e (diff)
vnfs: Enable PVP using vhost-cuse
Enable PVP testing using vhost-cuse as guest access method Recent changes: * Move NEWS.md changes to NEWS.rst * Update comment to vhost-cuse * Restore config back to checkout state after make * Merge OPNFV 1092 updates * Add PVP-vhost-cuse to NEWS.md * Add comment/example to GUEST_CORE_BINDING * Move hardcoded values to conf/04_vnfs.conf * Set default VNF to QemuDpdkVhostCuse * Compile eventfd_link if VHOST_USER=n * Use MAC and PCI address from conf * Use vhost method in conf to properly set interface type JIRA: VSPERF-59 Change-Id: Ib1159e216f3e25b9971c0935969680582683916b Signed-off-by: Madarang, Dino Simeon <dino.simeonx.madarang@intel.com> Reviewed-by: Maryam Tahhan <maryam.tahhan@intel.com>
Diffstat (limited to 'vnfs')
-rw-r--r--vnfs/qemu/qemu_dpdk_vhost_cuse.py388
1 files changed, 388 insertions, 0 deletions
diff --git a/vnfs/qemu/qemu_dpdk_vhost_cuse.py b/vnfs/qemu/qemu_dpdk_vhost_cuse.py
new file mode 100644
index 00000000..43b732fc
--- /dev/null
+++ b/vnfs/qemu/qemu_dpdk_vhost_cuse.py
@@ -0,0 +1,388 @@
+# Copyright 2015 Intel Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Automation of QEMU hypervisor for launching vhost-cuse enabled guests.
+"""
+
+import os
+import time
+import logging
+import locale
+import re
+import subprocess
+
+from tools import tasks
+from conf import settings
+from vnfs.vnf.vnf import IVnf
+
+_QEMU_BIN = settings.getValue('QEMU_BIN')
+_RTE_TARGET = settings.getValue('RTE_TARGET')
+
+_GUEST_MEMORY = settings.getValue('GUEST_MEMORY')
+_GUEST_SMP = settings.getValue('GUEST_SMP')
+_GUEST_CORE_BINDING = settings.getValue('GUEST_CORE_BINDING')
+_QEMU_CORE = settings.getValue('QEMU_CORE')
+
+_GUEST_IMAGE = settings.getValue('GUEST_IMAGE')
+_GUEST_SHARE_DIR = settings.getValue('GUEST_SHARE_DIR')
+
+_GUEST_USERNAME = settings.getValue('GUEST_USERNAME')
+_GUEST_PASSWORD = settings.getValue('GUEST_PASSWORD')
+
+_GUEST_PROMPT_LOGIN = settings.getValue('GUEST_PROMPT_LOGIN')
+_GUEST_PROMPT_PASSWORD = settings.getValue('GUEST_PROMPT_PASSWORD')
+_GUEST_PROMPT = settings.getValue('GUEST_PROMPT')
+
+_QEMU_GUEST_DPDK_PROMPT = settings.getValue('QEMU_GUEST_DPDK_PROMPT')
+_QEMU_GUEST_TEST_PMD_PROMPT = settings.getValue('QEMU_GUEST_TEST_PMD_PROMPT')
+_HUGEPAGE_DIR = settings.getValue('HUGEPAGE_DIR')
+
+_GUEST_OVS_DPDK_DIR = settings.getValue('GUEST_OVS_DPDK_DIR')
+_OVS_DPDK_SHARE = settings.getValue('OVS_DPDK_SHARE')
+
+_LOG_FILE_QEMU = os.path.join(
+ settings.getValue('LOG_DIR'), settings.getValue('LOG_FILE_QEMU'))
+_LOG_FILE_GUEST_CMDS = os.path.join(
+ settings.getValue('LOG_DIR'), settings.getValue('LOG_FILE_GUEST_CMDS'))
+
+_OVS_VAR_DIR = settings.getValue('OVS_VAR_DIR')
+_GUEST_NET1_MAC = settings.getValue('GUEST_NET1_MAC')
+_GUEST_NET2_MAC = settings.getValue('GUEST_NET2_MAC')
+_GUEST_NET1_PCI_ADDRESS = settings.getValue('GUEST_NET1_PCI_ADDRESS')
+_GUEST_NET2_PCI_ADDRESS = settings.getValue('GUEST_NET2_PCI_ADDRESS')
+
+class QemuDpdkVhostCuse(tasks.Process, IVnf):
+ """
+ Control an instance of QEMU with vHost user guest communication.
+ """
+ _bin = _QEMU_BIN
+ _logfile = _LOG_FILE_QEMU
+ _cmd = None
+ _expect = _GUEST_PROMPT_LOGIN
+ _proc_name = 'qemu'
+ _number_vnfs = 0
+
+ class GuestCommandFilter(logging.Filter):
+ """
+ Filter out strings beginning with 'guestcmd :'.
+ """
+ def filter(self, record):
+ return record.getMessage().startswith(self.prefix)
+
+ def __init__(self, memory=_GUEST_MEMORY, cpus=_GUEST_SMP,
+ monitor_path='/tmp', shared_path_host=_GUEST_SHARE_DIR,
+ args='', timeout=120, deployment="PVP"):
+ """
+ Initialisation function.
+
+ :param timeout: Time to wait for login prompt. If set to
+ 0 do not wait.
+ :param number: Number of QEMU instance, used when multiple QEMU
+ instances are started at once.
+ :param args: Arguments to pass to QEMU.
+
+ :returns: None
+ """
+ self._logger = logging.getLogger(__name__)
+ self._number = self._number_vnfs
+ self._number_vnfs = self._number_vnfs + 1
+ self._logfile = self._logfile + str(self._number)
+ self._log_prefix = 'guest_%d_cmd : ' % self._number
+ self._timeout = timeout
+ self._monitor = '%s/vm%dmonitor' % (monitor_path, self._number)
+
+ name = 'Client%d' % self._number
+ vnc = ':%d' % self._number
+ self._cmd = ['sudo', '-E', 'taskset ' + str(_QEMU_CORE), self._bin,
+ '-m', str(memory), '-smp', str(cpus), '-cpu', 'host',
+ '-drive', 'if=scsi,file='+_GUEST_IMAGE,
+ '-drive',
+ 'if=scsi,file=fat:rw:%s,snapshot=off' % shared_path_host,
+ '-boot', 'c', '--enable-kvm',
+ '-monitor', 'unix:%s,server,nowait' % self._monitor,
+ '-object',
+ 'memory-backend-file,id=mem,size=' + str(memory) + 'M,' +
+ 'mem-path=' + _HUGEPAGE_DIR + ',share=on',
+ '-numa', 'node,memdev=mem -mem-prealloc',
+ '-net', 'none', '-no-reboot',
+ '-netdev',
+ 'type=tap,id=net1,script=no,downscript=no,' +
+ 'ifname=dpdkvhostcuse0,vhost=on',
+ '-device',
+ 'virtio-net-pci,netdev=net1,mac=' + _GUEST_NET1_MAC,
+ '-netdev',
+ 'type=tap,id=net2,script=no,downscript=no,' +
+ 'ifname=dpdkvhostcuse1,vhost=on',
+ '-device',
+ 'virtio-net-pci,netdev=net2,mac=' + _GUEST_NET2_MAC,
+ '-nographic', '-vnc', str(vnc), '-name', name,
+ '-snapshot',
+ ]
+ self._cmd.extend(args)
+ self._configure_logging()
+
+ def _configure_logging(self):
+ """
+ Configure logging.
+ """
+ self.GuestCommandFilter.prefix = self._log_prefix
+
+ logger = logging.getLogger()
+ cmd_logger = logging.FileHandler(
+ filename=_LOG_FILE_GUEST_CMDS + str(self._number))
+ cmd_logger.setLevel(logging.DEBUG)
+ cmd_logger.addFilter(self.GuestCommandFilter())
+ logger.addHandler(cmd_logger)
+
+ # startup/Shutdown
+
+ def start(self):
+ """
+ Start QEMU instance, login and prepare for commands.
+ """
+ super(QemuDpdkVhostCuse, self).start()
+ self._affinitize()
+
+ if self._timeout:
+ self._login()
+ self._config_guest_loopback()
+
+ def stop(self):
+ """
+ Kill QEMU instance if it is alive.
+ """
+ self._logger.info('Killing QEMU...')
+
+ super(QemuDpdkVhostCuse, self).kill()
+
+ # helper functions
+
+ def _login(self, timeout=120):
+ """
+ Login to QEMU instance.
+
+ This can be used immediately after booting the machine, provided a
+ sufficiently long ``timeout`` is given.
+
+ :param timeout: Timeout to wait for login to complete.
+
+ :returns: None
+ """
+ # if no timeout was set, we likely started QEMU without waiting for it
+ # to boot. This being the case, we best check that it has finished
+ # first.
+ if not self._timeout:
+ self._expect_process(timeout=timeout)
+
+ self._child.sendline(_GUEST_USERNAME)
+ self._child.expect(_GUEST_PROMPT_PASSWORD, timeout=5)
+ self._child.sendline(_GUEST_PASSWORD)
+
+ self._expect_process(_GUEST_PROMPT, timeout=5)
+
+ def execute(self, cmd, delay=0):
+ """
+ Send ``cmd`` with no wait.
+
+ Useful for asynchronous commands.
+
+ :param cmd: Command to send to guest.
+ :param timeout: Delay to wait after sending command before returning.
+
+ :returns: None
+ """
+ self._logger.debug('%s%s', self._log_prefix, cmd)
+ self._child.sendline(cmd)
+ time.sleep(delay)
+
+ def wait(self, msg=_GUEST_PROMPT, timeout=30):
+ """
+ Wait for ``msg``.
+
+ :param msg: Message to wait for from guest.
+ :param timeout: Time to wait for message.
+
+ :returns: None
+ """
+ self._child.expect(msg, timeout=timeout)
+
+ def execute_and_wait(self, cmd, timeout=30, prompt=_GUEST_PROMPT):
+ """
+ Send ``cmd`` and wait ``timeout`` seconds for prompt.
+
+ :param cmd: Command to send to guest.
+ :param timeout: Time to wait for prompt.
+
+ :returns: None
+ """
+ self.execute(cmd)
+ self.wait(prompt, timeout=timeout)
+
+ def send_and_pass(self, cmd, timeout=30):
+ """
+ Send ``cmd`` and wait ``timeout`` seconds for it to pass.
+
+ :param cmd: Command to send to guest.
+ :param timeout: Time to wait for prompt before checking return code.
+
+ :returns: None
+ """
+ self.execute(cmd)
+ self.wait(_GUEST_PROMPT, timeout=timeout)
+ self.execute('echo $?')
+ self._child.expect('^0$', timeout=1) # expect a 0
+ self.wait(_GUEST_PROMPT, timeout=timeout)
+
+ def _affinitize(self):
+ """
+ Affinitize the SMP cores of a QEMU instance.
+
+ This is a bit of a hack. The 'socat' utility is used to
+ interact with the QEMU HMP. This is necessary due to the lack
+ of QMP in older versions of QEMU, like v1.6.2. In future
+ releases, this should be replaced with calls to libvirt or
+ another Python-QEMU wrapper library.
+
+ :returns: None
+ """
+ thread_id = (r'.* CPU #%d: .* thread_id=(\d+)')
+
+ self._logger.info('Affinitizing guest...')
+
+ cur_locale = locale.getlocale()[1]
+ proc = subprocess.Popen(
+ ('echo', 'info cpus'), stdout=subprocess.PIPE)
+ output = subprocess.check_output(
+ ('sudo', 'socat', '-', 'UNIX-CONNECT:%s' % self._monitor),
+ stdin=proc.stdout)
+ proc.wait()
+
+ for cpu in range(0, int(_GUEST_SMP)):
+ match = None
+ for line in output.decode(cur_locale).split('\n'):
+ match = re.search(thread_id % cpu, line)
+ if match:
+ self._affinitize_pid(
+ _GUEST_CORE_BINDING[self._number - 1][cpu],
+ match.group(1))
+ break
+
+ if not match:
+ self._logger.error('Failed to affinitize guest core #%d. Could'
+ ' not parse tid.', cpu)
+
+ def _config_guest_loopback(self):
+ """
+ Configure VM to run testpmd
+
+ Configure performs the following:
+ * Mount hugepages
+ * mount shared directory for copying DPDK
+ * Disable firewall
+ * Compile DPDK
+ * DPDK NIC bind
+ * Run testpmd
+ """
+
+ # Guest images _should_ have 1024 hugepages by default,
+ # but just in case:'''
+ self.execute_and_wait('sysctl vm.nr_hugepages=1024')
+
+ # Mount hugepages
+ self.execute_and_wait('mkdir -p /dev/hugepages')
+ self.execute_and_wait(
+ 'mount -t hugetlbfs hugetlbfs /dev/hugepages')
+
+ # mount shared directory
+ self.execute_and_wait('umount ' + _OVS_DPDK_SHARE)
+ self.execute_and_wait('rm -rf ' + _GUEST_OVS_DPDK_DIR)
+ self.execute_and_wait('mkdir -p ' + _OVS_DPDK_SHARE)
+ self.execute_and_wait('mount -o iocharset=utf8 /dev/sdb1 ' +
+ _OVS_DPDK_SHARE)
+ self.execute_and_wait('mkdir -p ' + _GUEST_OVS_DPDK_DIR)
+ self.execute_and_wait('cp -a ' + _OVS_DPDK_SHARE + '/* ' + _GUEST_OVS_DPDK_DIR)
+
+ # Disable services (F16)
+ self.execute_and_wait('systemctl status iptables.service')
+ self.execute_and_wait('systemctl stop iptables.service')
+
+ # build and configure system for dpdk
+ self.execute_and_wait('cd ' + _GUEST_OVS_DPDK_DIR + '/DPDK',
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+
+ self.execute_and_wait('export CC=gcc', prompt=_QEMU_GUEST_DPDK_PROMPT)
+ self.execute_and_wait('export RTE_SDK=' + _GUEST_OVS_DPDK_DIR + '/DPDK',
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+ self.execute_and_wait('export RTE_TARGET=%s' % _RTE_TARGET,
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+
+ self.execute_and_wait("sed -i -e 's/CONFIG_RTE_LIBRTE_VHOST_USER=n/" +
+ "CONFIG_RTE_LIBRTE_VHOST_USER=y/g' config/common_linuxapp",
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+
+ self.execute_and_wait('make uninstall', prompt=_QEMU_GUEST_DPDK_PROMPT)
+ self.execute_and_wait('make install T=%s -j 2' % _RTE_TARGET,
+ timeout=300, prompt=_QEMU_GUEST_DPDK_PROMPT)
+
+ self.execute_and_wait('modprobe uio', prompt=_QEMU_GUEST_DPDK_PROMPT)
+ self.execute_and_wait('insmod %s/kmod/igb_uio.ko' % _RTE_TARGET,
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+ self.execute_and_wait('./tools/dpdk_nic_bind.py --status',
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+ self.execute_and_wait('./tools/dpdk_nic_bind.py -b igb_uio'
+ ' ' + _GUEST_NET1_PCI_ADDRESS + ' '
+ + _GUEST_NET2_PCI_ADDRESS,
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+
+ self.execute_and_wait('./tools/dpdk_nic_bind.py --status',
+ prompt=_QEMU_GUEST_DPDK_PROMPT)
+
+ self.execute_and_wait('cd ' + _RTE_TARGET + '/build/app/test-pmd',
+ prompt=_QEMU_GUEST_TEST_PMD_PROMPT)
+
+ self.execute_and_wait('./testpmd -c 0x3 -n 4 --socket-mem 512 --'
+ ' --burst=64 -i --txqflags=0xf00 ' +
+ '--disable-hw-vlan', 20, "Done")
+ self.execute('set fwd mac_retry', 1)
+ self.execute_and_wait('start', 20,
+ 'TX RS bit threshold=0 - TXQ flags=0xf00')
+
+
+if __name__ == '__main__':
+ import sys
+
+ with QemuDpdkVhostCuse() as vm1:
+ print(
+ '\n\n************************\n'
+ 'Basic command line suitable for ls, cd, grep and cat.\n If you'
+ ' try to run Vim from here you\'re going to have a bad time.\n'
+ 'For more complex tasks please use \'vncviewer :1\' to connect to'
+ ' this VM\nUsername: %s Password: %s\nPress ctrl-C to quit\n'
+ '************************\n' % (_GUEST_USERNAME, _GUEST_PASSWORD))
+
+ if sys.argv[1]:
+ with open(sys.argv[1], 'r') as file_:
+ for logline in file_:
+ # lines are of format:
+ # guest_N_cmd : <command>
+ # and we only want the <command> piece
+ cmdline = logline.split(':')[1].strip()
+
+ # use a no timeout since we don't know how long we
+ # should wait
+ vm1.send_and_wait(cmdline, timeout=-1)
+
+ while True:
+ USER_INPUT = input()
+ vm1.send_and_wait(USER_INPUT, timeout=5)
63'>863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
# Copyright 2017-2018 Intel Corporation., Tieto
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file introduces a set of regression tests, which verify several DPDK features
# used internally by Open vSwitch. Tests can be used for verification of performance
# and correct functionality of upcoming DPDK and OVS releases and release candidates.

############################################################
#
#  Generic configuration used by OVSDPDK testcases
#
############################################################
_OVSDPDK_1st_PMD_CORE = 4
_OVSDPDK_2nd_PMD_CORE = 5
# calculate PMD mask from core IDs configured above
_OVSDPDK_PMD_MASK_1_CORE = str(hex(1<<_OVSDPDK_1st_PMD_CORE))[2:]
_OVSDPDK_PMD_MASK_2_CORE = str(hex((1<<_OVSDPDK_1st_PMD_CORE) + (1<<_OVSDPDK_2nd_PMD_CORE))[2:])

_OVSDPDK_GUEST_5_CORES = [('7', '8', '9', '10', '11')]

# number of queues configured in OVS and GUEST
_OVSDPDK_MQ = '2'

# Path to the log file
_OVSDPDK_VSWITCH_LOG = os.path.join(LOG_DIR, LOG_FILE_VSWITCHD)

_OVSDPDK_HEADER_LEN = 18                # length of frame headers in bytes, it's used for calculation
                                        # of payload size, i.e. payload = frame_size - header_len

_OVSDPDK_PKT_SIZES = (64,128,256,512,1024,1500)

INTEGRATION_TESTS = INTEGRATION_TESTS + [
    ############################################################
    #
    #  DPDK NIC Support
    #
    ############################################################
    {
        "Name": "ovsdpdk_nic_p2p_single_pmd_unidir_cont",
        "Deployment": "p2p",
        "Description": "P2P with single PMD in OVS and unidirectional traffic.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
            },
            "TRAFFICGEN_PKT_SIZES" : _OVSDPDK_PKT_SIZES,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_1_CORE,
        },
    },
    {
        "Name": "ovsdpdk_nic_p2p_single_pmd_bidir_cont",
        "Deployment": "p2p",
        "Description": "P2P with single PMD in OVS and bidirectional traffic.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "TRAFFICGEN_PKT_SIZES" : _OVSDPDK_PKT_SIZES,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_1_CORE,
        },
    },
    {
        "Name": "ovsdpdk_nic_p2p_two_pmd_bidir_cont",
        "Deployment": "p2p",
        "Description": "P2P with two PMDs in OVS and bidirectional traffic.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "TRAFFICGEN_PKT_SIZES" : _OVSDPDK_PKT_SIZES,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_2_CORE,
        },
    },
    {
        "Name": "ovsdpdk_nic_p2p_single_pmd_unidir_tput",
        "Deployment": "p2p",
        "Description": "P2P with single PMD in OVS and unidirectional traffic.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_throughput",
                'bidir' : 'False',
            },
            "TRAFFICGEN_PKT_SIZES" : _OVSDPDK_PKT_SIZES,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_1_CORE,
        },
    },
    {
        "Name": "ovsdpdk_nic_p2p_single_pmd_bidir_tput",
        "Deployment": "p2p",
        "Description": "P2P with single PMD in OVS and bidirectional traffic.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_throughput",
                'bidir' : 'True',
            },
            "TRAFFICGEN_PKT_SIZES" : _OVSDPDK_PKT_SIZES,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_1_CORE,
        },
    },
    {
        "Name": "ovsdpdk_nic_p2p_two_pmd_bidir_tput",
        "Deployment": "p2p",
        "Description": "P2P with two PMDs in OVS and bidirectional traffic.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_throughput",
                'bidir' : 'True',
            },
            "TRAFFICGEN_PKT_SIZES" : _OVSDPDK_PKT_SIZES,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_2_CORE,
        },
    },
    ############################################################
    #
    #  DPDK Hotplug Support
    #
    ############################################################
    {
        "Name": "ovsdpdk_hotplug_attach",
        "Deployment": "clean",
        "Description": "Ensure successful port-add after binding a device to igb_uio after ovs-vswitchd is launched.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            # suppress DPDK configuration, so physical interfaces are not bound to DPDK driver
            'WHITELIST_NICS' : [],
            'NICS' : [],
        },
        "TestSteps": [
                        # restore original NICS configuration, so we can use add/del_phy_port
                        ['settings', 'setValue', 'TEST_PARAMS', ''],
                        # add DPDK port, but it should fail
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['#port', 'vswitch', 'add_phy_port', 'int_br0'],
                        # check, that DPDK port is not available and remove it
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                                                '|Error attaching device.*$NICS[0]["pci"]'],
                        # NOTE: it fails in case that NIC was already bound to DPDK driver
                        ['tools', 'assert', 'len(#STEP[-1])'],
                        ['vswitch', 'del_port', 'int_br0', '#STEP[port][0]'],
                        # find out which DPDK driver is being used; it should be the last configured
                        # DPDK module; optional path and .ko suffix must be removed
                        ['tools', 'eval', '\'$TOOLS["dpdk_modules"][-1]\'.split("/")[-1].split(".")[0]'],
                        # bind NIC to DPDK driver
                        ['tools', 'exec_shell', 'sudo $TOOLS["bind-tool"] --bind #STEP[-1] $NICS[0]["pci"]'],
                        # and check that DPDK port can be created without errors
                        ['#port2', 'vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                                                '|Error attaching device.*$NICS[0]["pci"]'],
                        ['tools', 'assert', 'not len(#STEP[-1])'],
                     ]
    },
    {
        # Support of netdev-dpdk/detach has been removed from OVS, so testcase will fail with recent
        # OVS/DPDK versions. There is an ongoing discussion about possible support of netdev-dpdk/detach
        # in the future OVS versions.
        # Test has been tested with:
        #   OVS_TAG = 03d6399e618e4136c5da0be2b6f18f0b7d75b2bb
        #   DPDK_TAG = v16.11
        "Name": "ovsdpdk_hotplug_detach",
        "Deployment": "clean",
        "Description": "Same as ovsdpdk_hotplug_attach, but delete and detach the device after the hotplug. "
                       "Note: Support of netdev-dpdk/detach has been removed from OVS, so testcase will fail "
                       "with recent OVS/DPDK versions.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            # suppress DPDK configuration, so physical interfaces are not bound to DPDK driver
            'WHITELIST_NICS' : [],
            'NICS' : [],
        },
        "TestSteps": [
                        # check if OVS supports netdev-dpdk/detach, fail otherwise
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] list-commands', '|netdev-dpdk\/detach'],
                        ['tools', 'assert', 'len(#STEP[-1])'],
                        # restore original NICS configuration, so we can use add/del_phy_port
                        ['settings', 'setValue', 'TEST_PARAMS', ''],
                        # find out which DPDK driver is being used; it should be the last configured
                        # DPDK module; optional path and .ko suffix must be removed
                        ['tools', 'eval', '\'$TOOLS["dpdk_modules"][-1]\'.split("/")[-1].split(".")[0]'],
                        # bind NIC to DPDK driver
                        ['tools', 'exec_shell', 'sudo $TOOLS["bind-tool"] --bind #STEP[-1] $NICS[0]["pci"]'],
                        # and check that DPDK port can be created without errors
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['#port', 'vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                                                '|Error attaching device.*$NICS[0]["pci"]'],
                        ['tools', 'assert', 'not len(#STEP[-1])'],
                        # try to unbind port - should fail beause it is being used
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] netdev-dpdk/detach $NICS[0]["pci"] 2>&1; exit 0',
                                                '|Device.*$NICS[0]["pci"].*is being used by interface'],
                        ['tools', 'assert', 'len(#STEP[-1])'],
                        # delete port and unbind it - should succeed
                        ['vswitch', 'del_port', 'int_br0', '#STEP[port][0]'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] netdev-dpdk/detach $NICS[0]["pci"]',
                                                '|Device.*$NICS[0]["pci"].*has been detached'],
                        ['tools', 'assert', 'len(#STEP[-1])'],
                        # try to add port again
                        ['vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                                                '|Error attaching device.*$NICS[0]["pci"]'],
                        # it will work because auto attach was implemented into OVS
                        ['tools', 'assert', 'not len(#STEP[-1])'],
                        ['vswitch', 'del_switch', 'int_br0'],
                     ]
    },
]

############################################################
#
#  RX Checksum Support
#
############################################################
# TCL script used for simulation of traffic with wrong CRC
_OVSDPDK_CRC_CRC_TCL = ''
_OVSDPDK_CRC_FRAME_LOSS = ''

_OVSDPDK_CRC_VERIFY_CRC = [
    # use TCL script with tunneling protocols encap/decap support;
    # it must be configured dynamically, otherwise it won't
    # be possible to change it again below.
    ['settings', 'setValue', 'TRAFFICGEN_IXNET_TCL_SCRIPT',
     'ixnetrfc2544v2.tcl'],
    # send traffic before IP or UDP header checksum is randomized
    ['trafficgen', 'send_traffic', {}],
    ['trafficgen', 'get_results'],
    # packets should flow through OVS without frameloss (frame_rate is low)
    ['tools', 'assert', 'float(#STEP[-1][0]["frame_loss_percent"]) == 0'],
    # for 2nd run use TCL file with randomized checksum values
    ['settings', 'setValue', 'TRAFFICGEN_IXNET_TCL_SCRIPT',
     '$_OVSDPDK_CRC_CRC_TCL'],
    ['trafficgen', 'send_traffic', {}],
    ['trafficgen', 'get_results'],
    # and verify that majority of frames but not all of them were lost
    ['tools', 'assert', 'round(float(#STEP[-1][0]["frame_loss_percent"]),3) == $_OVSDPDK_CRC_FRAME_LOSS'],
]

INTEGRATION_TESTS = INTEGRATION_TESTS + [
    {
        "Name": "ovsdpdk_checksum_l3",
        "Deployment": "op2p",
        "Description": "Test verifies RX IP header checksum (offloading) validation for tunneling protocols.",
        "Tunnel Type": "vxlan",
        "Tunnel Operation": "decapsulation",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFICGEN" : "IxNet",
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 20,
                'bidir' : 'False',
            },
            "TRAFFICGEN_DURATION" : 10,
            "TRAFFICGEN_PKT_SIZES" : (64,)
        },
        "TestSteps": [
                        # TCL file with randomized IP header checksum values
                        ['settings', 'setValue', '_OVSDPDK_CRC_CRC_TCL',
                         'ixnetrfc2544v2_random_ip_crc.tcl'],
                        # IP checksum is a value between 0 and 65536, so only 1 of 65536
                        # frames has correct CRC and all other frames will be dropped
                        ['settings', 'setValue', '_OVSDPDK_CRC_FRAME_LOSS',
                         round(100 - 1 / 65536 * 100, 3)],
                    ] + _OVSDPDK_CRC_VERIFY_CRC
    },
    {
        "Name": "ovsdpdk_checksum_l4",
        "Deployment": "op2p",
        "Description": "Test verifies RX UDP header checksum (offloading) validation for tunneling protocols.",
        "Tunnel Type": "vxlan",
        "Tunnel Operation": "decapsulation",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFICGEN" : "IxNet",
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 20,
                'bidir' : 'False',
            },
            "TRAFFICGEN_DURATION" : 10,
            "TRAFFICGEN_PKT_SIZES" : (64,)
        },
        "TestSteps": [
                        # TCL file with randomized UDP header checksum values
                        ['settings', 'setValue', '_OVSDPDK_CRC_CRC_TCL',
                         'ixnetrfc2544v2_random_udp_crc.tcl'],
                        # UDP checksum can be disabled by value 0; so valid checksum
                        # values are from 1 to 65535; It means that only one of 65535 frames
                        # has correct checksum and all other frames will be dropped
                        ['settings', 'setValue', '_OVSDPDK_CRC_FRAME_LOSS',
                         round(100 - 1 / 65535 * 100, 3)],
                    ] + _OVSDPDK_CRC_VERIFY_CRC
    },
    ############################################################
    #
    #  Flow Control Support
    #
    ############################################################
    {
        "Name": "ovsdpdk_flow_ctrl_rx",
        "Deployment": "p2p",
        "Description": "Test the rx flow control functionality of DPDK PHY ports.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFICGEN" : "IxNet",
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                "flow_control" : True,
                'bidir' : 'True',
            },
            "TRAFFICGEN_DURATION" : 10,
            "TRAFFICGEN_PKT_SIZES" : (64,)
        },
        "TestSteps": [
                        # send traffic before flow control is applied
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show'],
                        ['trafficgen', 'send_traffic', {}],
                        ['trafficgen', 'get_results'],
                        # frame loss with small packets should be detected
                        ['tools', 'assert', '#STEP[-1][0]["frame_loss_percent"] > 10'],
                        # delete phy ports so they can be created with flow control
                        ['vswitch', 'del_flow', '$VSWITCH_BRIDGE_NAME', {}],
                        ['vswitch', 'del_port', '$VSWITCH_BRIDGE_NAME', 'dpdk0'],
                        ['vswitch', 'del_port', '$VSWITCH_BRIDGE_NAME', 'dpdk1'],
                        # turn on flow control
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] add-port $VSWITCH_BRIDGE_NAME dpdk0 -- set Interface dpdk0 type=dpdk options:dpdk-devargs=$NICS[0]["pci"] options:rx-flow-ctrl=true'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] add-port $VSWITCH_BRIDGE_NAME dpdk1 -- set Interface dpdk1 type=dpdk options:dpdk-devargs=$NICS[1]["pci"] options:rx-flow-ctrl=true'],
                        ['vswitch', 'add_flow', '$VSWITCH_BRIDGE_NAME', {'in_port': '3', 'actions': ['output:4'], 'idle_timeout': '0'}],
                        ['vswitch', 'add_flow', '$VSWITCH_BRIDGE_NAME', {'in_port': '4', 'actions': ['output:3'], 'idle_timeout': '0'}],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show'],
                        ['trafficgen', 'send_traffic', {}],
                        ['trafficgen', 'get_results'],
                        # frame loss with flow control enabled should converge to 0%
                        ['tools', 'assert', 'float(#STEP[-1][0]["frame_loss_percent"]) == 0'],
                    ]
    },
    {
        "Name": "ovsdpdk_flow_ctrl_rx_dynamic",
        "Deployment": "p2p",
        "Description": "Change the rx flow control support at run time and ensure the system honored the changes.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFICGEN" : "IxNet",
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                "flow_control" : True,
                'bidir' : 'True',
            },
            "TRAFFICGEN_DURATION" : 10,
            "TRAFFICGEN_PKT_SIZES" : (64,)
        },
        "TestSteps": [
                        # send traffic before flow control is applied
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show'],
                        ['trafficgen', 'send_traffic', {}],
                        ['trafficgen', 'get_results'],
                        # frame loss with small packets should be detected
                        ['tools', 'assert', '#STEP[-1][0]["frame_loss_percent"] > 10'],
                        # turn on flow control
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 type=dpdk options:rx-flow-ctrl=true'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk1 type=dpdk options:rx-flow-ctrl=true'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show'],
                        ['trafficgen', 'send_traffic', {}],
                        ['trafficgen', 'get_results'],
                        # frame loss with flow control enabled should converge to 0%
                        ['tools', 'assert', 'float(#STEP[-1][0]["frame_loss_percent"]) == 0'],
                    ]
    },
    ############################################################
    #
    #  Multiqueue Support
    #
    ############################################################
    {
        "Name": "ovsdpdk_mq_p2p_rxqs",
        "Deployment": "p2p",
        "Description": "Setup rxqs on NIC port.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "TRAFFICGEN_DURATION" : 1,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_2_CORE,
            "VSWITCH_DPDK_MULTI_QUEUES" : _OVSDPDK_MQ,
        },
        "TestSteps": [
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpif-netdev/pmd-rxq-show','|dpdk[01]\s+queue-id: \d+'],
                        # check that requested nr of queues was created on both NICs
                        ['tools', 'assert', 'len(#STEP[-1])=={}'.format(int(_OVSDPDK_MQ)*2)],
                    ]
    },
    {
        "Name": "ovsdpdk_mq_p2p_rxqs_same_core_affinity",
        "Deployment": "p2p",
        "Description": "Affinitize rxqs to the same core.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "TRAFFICGEN_DURATION" : 1,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_2_CORE,
            "VSWITCH_DPDK_MULTI_QUEUES" : _OVSDPDK_MQ,
        },
        "TestSteps": [
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"]  -- set Interface dpdk0 other_config:pmd-rxq-affinity="0:{},1:{}"'.format(_OVSDPDK_1st_PMD_CORE, _OVSDPDK_1st_PMD_CORE)],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpif-netdev/pmd-rxq-show','|dpdk0\s+queue-id: 0 1'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                    ]
    },
    {
        "Name": "ovsdpdk_mq_p2p_rxqs_multi_core_affinity",
        "Deployment": "p2p",
        "Description": "Affinitize rxqs to separate cores.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "TRAFFICGEN_DURATION" : 1,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_2_CORE,
            "VSWITCH_DPDK_MULTI_QUEUES" : _OVSDPDK_MQ,
        },
        "TestSteps": [
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"]  -- set Interface dpdk0 other_config:pmd-rxq-affinity="0:{},1:{}"'.format(_OVSDPDK_1st_PMD_CORE, _OVSDPDK_2nd_PMD_CORE)],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpif-netdev/pmd-rxq-show','|dpdk0\s+queue-id: 0$'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpif-netdev/pmd-rxq-show','|dpdk0\s+queue-id: 1$'],
                        ['tools', 'assert', 'len(#STEP[-2])==1'],
                        ['tools', 'assert', 'len(#STEP[-2])==1'],
                    ]
    },
    {
        "Name" : "ovsdpdk_mq_pvp_rxqs",
        "Deployment" : "clean",
        "Description" : "Setup rxqs on vhost user port.",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "VSWITCH_DPDK_MULTI_QUEUES" : _OVSDPDK_MQ,
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_1_CORE,
            "GUEST_NIC_QUEUES" : [_OVSDPDK_MQ],
            "GUEST_LOOPBACK" : ['clean'],
        },
        "TestSteps": STEP_VSWITCH_PVP_INIT +
                     [
                        ['tools', 'exec_shell', "sudo $TOOLS['ovs-appctl'] dpif-netdev/pmd-rxq-show",
                         '|dpdkvhostuserclient0\s+queue-id: \d'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                        ['vnf', 'start'],
                        ['tools', 'exec_shell', "sudo $TOOLS['ovs-appctl'] dpif-netdev/pmd-rxq-show",
                         '|dpdkvhostuserclient0\s+queue-id: 0 1'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                        ['vnf', 'stop'],
                     ] +
                     STEP_VSWITCH_PVP_FINIT
    },
    {
        "Name" : "ovsdpdk_mq_pvp_rxqs_linux_bridge",
        "Deployment" : "clean",
        "Description" : "Confirm traffic received over vhost RXQs with Linux virtio device in guest.",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            # configure 2 queues at both OVS and QEMU
            "VSWITCH_DPDK_MULTI_QUEUES" : _OVSDPDK_MQ,
            "GUEST_NIC_QUEUES" : [_OVSDPDK_MQ],
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_2_CORE,
            "GUEST_LOOPBACK" : ['clean'],
            "TRAFFICGEN_DURATION" : 5,
            "TRAFFICGEN" : "IxNet",
            "TRAFFIC" : {
                "bidir" : "false",
                "traffic_type" : "rfc2544_continuous",
                "multistream" : 6,
                "stream_type" : "L3",
                "frame_rate" : 1,
                'l2': {
                    'srcmac': "00:00:07:00:0E:00",
                    'dstmac': "00:00:00:00:00:01"
                },
                'l3': {
                    'enabled': True,
                    'proto': 'udp',
                    'srcip': '6.6.6.6',
                    'dstip': '1.1.1.1',
                },
            }
        },
        "TestSteps": STEP_VSWITCH_PVP_INIT + [
                        # one flow will sent data to the VM
                        ['vswitch', 'add_flow', 'int_br0',
                         {'in_port': '#STEP[1][1]', 'actions': ['output:#STEP[3][1]'], 'idle_timeout': '0'}],
                        # second flow just forwards traffic to the traffic generator,
                        # so send_traffic() will end with success
                        ['vswitch', 'add_flow', 'int_br0',
                         {'in_port': '#STEP[2][1]', 'actions': ['output:#STEP[1][1]'], 'idle_timeout': '0'}],
                        ['vnf', 'start'],
                        # configure two channels, so multiple cores could be used
                        ['vnf', 'execute_and_wait', 'ethtool -L eth0 combined 2'],
                        ['vnf', 'execute_and_wait', 'ethtool -l eth0', '|Combined:\s+2'],
                        ['tools', 'assert', 'len(#STEP[-1])==2'],
                        # traffic will be sent to several DST IPs so it can be
                        # dispatched between channels; We have to insert routes
                        # and ARPs, otherwise traffic will be dropped
                        ['vnf', 'execute_and_wait', 'ifconfig eth0 5.5.5.1/24 up'],
                        ['vnf', 'execute_and_wait', 'sysctl -w net.ipv4.ip_forward=1'],
                        ['vnf', 'execute_and_wait', 'sysctl -w net.ipv4.conf.all.rp_filter=0'],
                        ['vnf', 'execute_and_wait', 'ip route add 6.6.6.0/24 dev eth0'],
                        ['vnf', 'execute_and_wait', 'route add default gw 6.6.6.6 eth0'],
                        ['vnf', 'execute_and_wait', 'arp -s 6.6.6.6 00:00:07:00:0E:00'],
                        ['vnf', 'execute_and_wait', 'ip route add 1.1.1.0/31 dev eth0'],
                        ['vnf', 'execute_and_wait', 'route add default gw 1.1.1.1 eth0'],
                        ['vnf', 'execute_and_wait', 'arp -s 1.1.1.1 DE:AD:BE:EF:CA:FA'],
                        ['vnf', 'execute_and_wait', 'ip route add 1.1.1.2/31 dev eth0'],
                        ['vnf', 'execute_and_wait', 'route add default gw 1.1.1.3 eth0'],
                        ['vnf', 'execute_and_wait', 'arp -s 1.1.1.3 DE:AD:BE:EF:CA:FB'],
                        ['vnf', 'execute_and_wait', 'ip route add 1.1.1.4/31 dev eth0'],
                        ['vnf', 'execute_and_wait', 'route add default gw 1.1.1.5 eth0'],
                        ['vnf', 'execute_and_wait', 'arp -s 1.1.1.5 DE:AD:BE:EF:CA:FC'],
                        ['vnf', 'execute_and_wait', 'ip a'],

                        ['trafficgen', 'send_traffic',{}],
                        # check interrupts to verify that traffic was corectly dispatched...
                        ['#result', 'vnf', 'execute_and_wait', 'cat /proc/interrupts',
                         '|^\s*\d+:\s+(\d+)\s+(\d+).+virtio0-input'],
                        # ...it means that two channels were created...
                        ['tools', 'assert', 'len(#STEP[result])==2'],
                        # ...and both channels processed data; Check that interrupt count is "much"
                        # higher than 0 to eliminate impact of rogue interrupts.
                        ['tools', 'assert', 'int(#STEP[result][0][0]) + int(#STEP[result][0][1]) > 1000'],
                        ['tools', 'assert', 'int(#STEP[result][1][0]) + int(#STEP[result][1][1]) > 1000'],
                        ['vnf', 'stop'],
                     ]
    },
    {
        "Name" : "ovsdpdk_mq_pvp_rxqs_testpmd",
        "Deployment" : "clean",
        "Description" : "Confirm traffic received over vhost RXQs with DPDK device in guest.",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "TRAFFICGEN" : "IxNet",
            # configure 2 queues at both OVS and QEMU
            "VSWITCH_DPDK_MULTI_QUEUES" : _OVSDPDK_MQ,
            "GUEST_NIC_QUEUES" : [_OVSDPDK_MQ],
            "VSWITCH_PMD_CPU_MASK" : _OVSDPDK_PMD_MASK_2_CORE,
            "GUEST_CORE_BINDING" : _OVSDPDK_GUEST_5_CORES,
            "GUEST_LOOPBACK" : ['testpmd'],
            # there must be separate CPU for each of RX/TX queues
            "GUEST_SMP" : ['5'],
            "GUEST_TESTPMD_PARAMS" : ['-c 0x1F -n 4 --socket-mem 512 -- '
                                      '--burst=64 -i --txqflags=0xf00 --nb-cores=4 '
                                      # map queue stats to separate regs to verify MQ functionality
                                      '--rx-queue-stats-mapping=\(0,0,0\),\(0,1,1\),\(1,0,2\),\(1,1,3\) '
                                      '--tx-queue-stats-mapping=\(0,0,4\),\(0,1,5\),\(1,0,6\),\(1,1,7\) '
                                      '--disable-hw-vlan --rxq=2 --txq=2'],
            "TRAFFICGEN_DURATION" : 5,
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "multistream" : 3,
                "stream_type" : "L3",
                'l3': {
                    'enabled': True,
                    'proto': 'udp',
                    'srcip': '6.6.6.6',
                    'dstip': '1.1.1.1',
                },
            },
        },
        "TestSteps": STEP_VSWITCH_PVP_FLOWS_INIT +
                     [
                        ['vnf', 'start'],
                        ['tools', 'exec_shell', "sudo $TOOLS['ovs-appctl'] dpif-netdev/pmd-rxq-show",
                         '|dpdk\w+\s+queue-id: \d'],
                        # there must be two standalone queue records for every interface (2x4)
                        ['tools', 'assert', 'len(#STEP[-1])==8'],
                        ['trafficgen', 'send_traffic', {}],

                        # check that packets were received by both queues at both ports
                        ['vnf', 'execute_and_wait', 'show port stats 0', 60, 'testpmd>',
                         '|Stats reg  [01] RX-packets:\s+(\d+)'],
                        ['tools', 'assert', '"0" not in #STEP[-1]'],
                        # rx queue of 2nd port should be mapped to reg 2 and 3, but mapping might not work
                        # so let us check that exactly two RX regs have non zero values
                        ['vnf', 'execute_and_wait', 'show port stats 1', 60, 'testpmd>',
                         '|Stats reg\s+\d+ RX-packets:\s+\d\d+'],
                        ['tools', 'assert', 'len(#STEP[-1])==2'],
                        # clean up
                        ['vnf', 'stop'],
                     ]
    },
    ############################################################
    #
    #  Vhost User
    #
    ############################################################
    {
        "Name": "ovsdpdk_vhostuser_client",
        "Deployment": "pvp",
        "Description": "Test vhost-user client mode",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "TRAFFICGEN_DURATION" : 1,
        },
        "TestSteps": [
                        # check that client ports are really used
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                                                '|type.*dpdkvhostuserclient'],
                        ['tools', 'assert', 'len(#STEP[-1])==2'],
                        # send traffic manually, so TC will fail in case
                        # that packets won't make it through
                        ['trafficgen', 'send_traffic', {}],
                     ],
    },
    {
        "Name": "ovsdpdk_vhostuser_client_reconnect",
        "Deployment": "pvp",
        "Description": "Test vhost-user client mode reconnect feature",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "TRAFFICGEN_DURATION" : 1,
        },
        "TestSteps": [
                        # send traffic to verify correct PVP configuration
                        ['trafficgen', 'send_traffic', {}],
                        ['vswitch', 'dump_flows', '$VSWITCH_BRIDGE_NAME'],
                        # restart vswitchd, ovsdb is kept untouched, so ovs configuration
                        # (except flows) will be restored
                        ['vswitch', 'restart'],
                        ['vswitch', 'del_flow', '$VSWITCH_BRIDGE_NAME', {}],
                        ['vswitch', 'dump_flows', '$VSWITCH_BRIDGE_NAME'],
                        ['vswitch', 'add_flow', '$VSWITCH_BRIDGE_NAME', {'in_port': '1', 'actions': ['output:3'], 'idle_timeout': '0'}],
                        ['vswitch', 'add_flow', '$VSWITCH_BRIDGE_NAME', {'in_port': '3', 'actions': ['output:1'], 'idle_timeout': '0'}],
                        ['vswitch', 'add_flow', '$VSWITCH_BRIDGE_NAME', {'in_port': '2', 'actions': ['output:4'], 'idle_timeout': '0'}],
                        ['vswitch', 'add_flow', '$VSWITCH_BRIDGE_NAME', {'in_port': '4', 'actions': ['output:2'], 'idle_timeout': '0'}],
                        ['vswitch', 'dump_flows', '$VSWITCH_BRIDGE_NAME'],
                        # send traffic to verify that OVS works correctly after restart
                        ['trafficgen', 'send_traffic', {}],
                     ],
    },
    {
        "Name": "ovsdpdk_vhostuser_server",
        "Deployment": "pvp",
        "Description": "Test vhost-user server mode",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'True',
            },
            "VSWITCH_VHOSTUSER_SERVER_MODE" : True,
            "TRAFFICGEN_DURATION" : 1,
        },
        "TestSteps": [
                        # check that server ports are really used
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                                                '|type.*dpdkvhostuser$'],
                        ['tools', 'assert', 'len(#STEP[-1])==2'],
                        # send traffic manually, so TC will fail in case
                        # that packets won't make it through
                        ['trafficgen', 'send_traffic', {}],
                     ],
    },
    {
        "Name": "ovsdpdk_vhostuser_sock_dir",
        "Deployment": "clean",
        "Description": "Verify functionality of vhost-sock-dir flag",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : True,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', '$VSWITCH_BRIDGE_NAME'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Open_vSwitch . '
                         'other_config:vhost-sock-dir=test_dir'],
                        # enforce vswitchd to read new configuration
                        ['vswitch', 'restart'],
                        ['tools', 'exec_shell', 'sudo mkdir $TOOLS["ovs_var_tmp"]/test_dir'],
                        ['vswitch', 'add_vport', '$VSWITCH_BRIDGE_NAME'],
                        ['tools', 'exec_shell', 'ls -1 $TOOLS["ovs_var_tmp"]/test_dir',
                         '|dpdkvhostuser0'],
                        ['tools', 'assert', 'len(#STEP[-1])'],
                     ],
    },
]
############################################################
#
#  Virtual Devices Support
#
############################################################
_OVSDPDK_VDEV_ADD_NULL = [
    ['vswitch', 'add_switch', 'int_br0'],
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"]  add-port int_br0 null0 -- '
     'set Interface null0 type=dpdk options:dpdk-devargs=eth_null0'],
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show', '|dpdk-devargs=\S+eth_null0'],
    ['tools', 'assert', 'len(#STEP[-1])==1'],
]

_OVSDPDK_VDEV_ADD_AF_PACKET = [
    # resore original NICS configuration, so we can use NICS dictionary
    ['settings', 'setValue', 'TEST_PARAMS', ''],
    # check if vsperf was able to read device name
    ['tools', 'assert', 'str(\"$NICS[0]["device"]\") != \"None\"'],
    ['tools', 'exec_shell', 'sudo ip link set dev $NICS[0]["device"] up'],
    ['vswitch', 'add_switch', 'int_br0'],
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"]  add-port int_br0 myeth0 -- '
     'set Interface myeth0 type=dpdk options:dpdk-devargs=eth_af_packet0,iface=$NICS[0]["device"]'],
    # check if device was created...
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show', '|dpdk-devargs=\S+eth_af_packet0'],
    ['tools', 'assert', 'len(#STEP[-1])==1'],
    # ...without errors
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show', '|Error attaching device'],
    ['tools', 'assert', 'not len(#STEP[-1])'],
]

INTEGRATION_TESTS = INTEGRATION_TESTS + [
    {
        "Name": "ovsdpdk_vdev_add_null_pmd",
        "Deployment": "clean",
        "Description": "Test addition of port using the null DPDK PMD driver.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": _OVSDPDK_VDEV_ADD_NULL
    },
    {
        "Name": "ovsdpdk_vdev_del_null_pmd",
        "Deployment": "clean",
        "Description": "Test deletion of port using the null DPDK PMD driver.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": _OVSDPDK_VDEV_ADD_NULL + [
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"]  del-port null0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                         '|dpdk-devargs=\S+eth_null0'],
                        ['tools', 'assert', 'not len(#STEP[-1])'],
                    ]
    },
    {
        "Name": "ovsdpdk_vdev_add_af_packet_pmd",
        "Deployment": "clean",
        "Description": "Test addition of port using the af_packet DPDK PMD driver.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            # suppress DPDK configuration, so physical interfaces are not bound to DPDK driver
            'WHITELIST_NICS' : [],
            'NICS' : [],
        },
        "TestSteps": _OVSDPDK_VDEV_ADD_AF_PACKET
    },
    {
        "Name": "ovsdpdk_vdev_del_af_packet_pmd",
        "Deployment": "clean",
        "Description": "Test deletion of port using the af_packet DPDK PMD driver.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            # suppress DPDK configuration, so physical interfaces are not bound to DPDK driver
            'WHITELIST_NICS' : [],
            'NICS' : [],
        },
        "TestSteps": _OVSDPDK_VDEV_ADD_AF_PACKET + [
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"]  del-port myeth0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] show',
                         '|dpdk-devargs=\S+eth_af_packet0'],
                        ['tools', 'assert', 'not len(#STEP[-1])'],
                    ]
    },
    ############################################################
    #
    #  NUMA Support
    #
    ############################################################
    {
        "Name": "ovsdpdk_numa",
        "Deployment": "clean",
        "Description": "Test vhost-user NUMA support. Vhostuser PMD threads should migrate "
                       "to the same numa slot, where QEMU is executed.",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            # ensure that memory and cpus are available at both numa slots
            "DPDK_SOCKET_MEM" : ['1024', '1024'],
            "VSWITCH_PMD_CPU_MASK" : 'FFFFFE',
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            # traffic won't be send, so speed up VNF deployment
            "GUEST_LOOPBACK" : ['clean']
        },
        "TestSteps": STEP_VSWITCH_PVP_INIT +
            [
                # check that at least 2 numa slots are available
                ['tools', 'exec_shell', 'numactl -H', '|available: ([0-9]+)'],
                ['tools', 'assert', '#STEP[-1][0]>1'],
                # check that PMD thread serving dpdkvhostuserclient0 runs at NUMA slot 0
                ['tools', 'exec_shell', "sudo $TOOLS['ovs-appctl'] "
                    "dpif-netdev/pmd-rxq-show | "
                    "sed -e '/dpdkvhostuserclient0/,$d' | tac",
                    '|pmd thread numa_id ([0-9])+'
                ],
                ['tools', 'assert', '#STEP[-1][0]==0'],
                # store last 2 cores from 2nd numa slot
                ['tools', 'exec_shell', 'numactl -H', '|node 1 cpus:.*\s+(\\d+) (\\d+)$'],
                # pin VNF to 2nd NUMA slot
                ['settings', 'setValue', 'GUEST_CORE_BINDING',
                    [("#STEP[-1][0][0]", "#STEP[-1][0][1]")]
                ],
                ['vnf', 'start'],
                # ...and check that PMD thread serving dpdkvhostuserclient0
                # has migrated to NUMA slot 1
                ['tools', 'exec_shell', "sudo $TOOLS['ovs-appctl'] "
                    "dpif-netdev/pmd-rxq-show | "
                    "sed -e '/dpdkvhostuserclient0/,$d' | tac",
                    '|pmd thread numa_id ([0-9])+'
                ],
                ['tools', 'assert', '#STEP[-1][0]==1'],
                ['vnf', 'stop'],
            ] +
            STEP_VSWITCH_PVP_FINIT
    },
    ############################################################
    #
    #  Jumbo Frame Support
    #
    ############################################################
    {
        "Name": "ovsdpdk_jumbo_increase_mtu_phy_port_ovsdb",
        "Deployment": "clean",
        "Description": "Ensure that the increased MTU for a DPDK physical port is updated in OVSDB.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==1500'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_increase_mtu_vport_ovsdb",
        "Deployment": "clean",
        "Description": "Ensure that the increased MTU for a DPDK vhost-user port is updated in OVSDB.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==1500'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_reduce_mtu_phy_port_ovsdb",
        "Deployment": "clean",
        "Description": "Ensure that the reduced MTU for a DPDK physical port is updated in OVSDB.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_JUMBO_FRAMES_ENABLED" : 'True',
            "VSWITCH_JUMBO_FRAMES_SIZE" : 9000,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=2000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==2000'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_reduce_mtu_vport_ovsdb",
        "Deployment": "clean",
        "Description": "Ensure that the reduced MTU for a DPDK vhost-user port is updated in OVSDB.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "VSWITCH_JUMBO_FRAMES_ENABLED" : 'True',
            "VSWITCH_JUMBO_FRAMES_SIZE" : 9000,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=2000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==2000'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_increase_mtu_phy_port_datapath",
        "Deployment": "clean",
        "Description": "Ensure that the MTU for a DPDK physical port is updated in the datapath itself when increased to a valid value.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=1500'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=9000'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_increase_mtu_vport_datapath",
        "Deployment": "clean",
        "Description": "Ensure that the MTU for a DPDK vhost-user port is updated in the datapath itself when increased to a valid value.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=1500'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=9000'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_reduce_mtu_phy_port_datapath",
        "Deployment": "clean",
        "Description": "Ensure that the MTU for a DPDK physical port is updated in the datapath itself when decreased to a valid value.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_JUMBO_FRAMES_ENABLED" : 'True',
            "VSWITCH_JUMBO_FRAMES_SIZE" : 9000,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=9000'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=2000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=2000'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_reduce_mtu_vport_datapath",
        "Deployment": "clean",
        "Description": "Ensure that the MTU for a DPDK vhost-user port is updated in the datapath itself when decreased to a valid value.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "VSWITCH_JUMBO_FRAMES_ENABLED" : 'True',
            "VSWITCH_JUMBO_FRAMES_SIZE" : 9000,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=9000'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=2000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] dpctl/show', '|mtu=2000'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_mtu_upper_bound_phy_port",
        "Deployment": "clean",
        "Description": "Verify that the upper bound limit is enforced for OvS DPDK Phy ports.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=9710'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9710'],
                        # get line number of next log file entry
                        ['tools', 'exec_shell', 'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=9711'],
                        # check vswitchd log file, that new MTU request was denied
                        ['tools', 'exec_shell', "sed -n '#STEP[-2][0],$ p' $_OVSDPDK_VSWITCH_LOG",
                         '|unsupported MTU 9711'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9710'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_mtu_upper_bound_vport",
        "Deployment": "clean",
        "Description": "Verify that the upper bound limit is enforced for OvS DPDK vhost-user ports.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=9710'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9710'],
                        # get line number of next log file entry
                        ['tools', 'exec_shell', 'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=9711'],
                        # check vswitchd log file, that new MTU request was denied
                        ['tools', 'exec_shell', "sed -n '#STEP[-2][0],$ p' $_OVSDPDK_VSWITCH_LOG",
                         '|unsupported MTU 9711'],
                        ['tools', 'assert', 'len(#STEP[-1])'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9710'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_mtu_lower_bound_phy_port",
        "Deployment": "clean",
        "Description": "Verify that the lower bound limit is enforced for OvS DPDK Phy ports.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=68'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==68'],
                        # get line number of next log file entry
                        ['tools', 'exec_shell', 'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdk0 mtu_request=67'],
                        # check vswitchd log file, that new MTU request was denied
                        ['tools', 'exec_shell', "sed -n '#STEP[-2][0],$ p' $_OVSDPDK_VSWITCH_LOG",
                         '|unsupported MTU 67'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==68'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_mtu_lower_bound_vport",
        "Deployment": "clean",
        "Description": "Verify that the lower bound limit is enforced for OvS DPDK vhost-user ports.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=68'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==68'],
                        # get line number of next log file entry
                        ['tools', 'exec_shell', 'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set Interface dpdkvhostuserclient0 mtu_request=67'],
                        # check vswitchd log file, that new MTU request was denied
                        ['tools', 'exec_shell', "sed -n '#STEP[-2][0],$ p' $_OVSDPDK_VSWITCH_LOG",
                         '|unsupported MTU 67'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==68'],
                    ]
    },
    {
        "Name": "ovsdpdk_jumbo_p2p",
        "Deployment": "p2p",
        "Description": "Ensure that jumbo frames are received, processed and forwarded correctly by DPDK physical ports.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
                'learning_frames' : False,
            },
            "TRAFFICGEN_PKT_SIZES" : (9018,),
            "VSWITCH_JUMBO_FRAMES_ENABLED" : 'True',
            "VSWITCH_JUMBO_FRAMES_SIZE" : 9000,
        },
        "TestSteps": [
                        # verify jumbo frame configuration
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk1 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['trafficgen', 'send_traffic', {}],
                        # check that jumbo frames were received by traffic generator
                        ['trafficgen', 'get_results'],
                        # i.e. (RX in Bytes/s) divide (RX frames/s) ~ 9018 Bytes
                        ['tools', 'assert', 'round(float(#STEP[-1][0]["throughput_rx_mbps"])*1000000/8 / '
                         'float(#STEP[-1][0]["throughput_rx_fps"]))==9018'],
                     ]
    },
{
        "Name": "ovsdpdk_jumbo_pvp",
        "Deployment": "clean",
        "Description": "Ensure that jumbo frames are received, processed and forwarded correctly by DPDK vhost-user ports.",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
                'learning_frames' : False,
            },
            "TRAFFICGEN_PKT_SIZES" : (9018,),
            "VSWITCH_JUMBO_FRAMES_ENABLED" : 'True',
            "VSWITCH_JUMBO_FRAMES_SIZE" : 9000,
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "GUEST_LOOPBACK" : ['linux_bridge'],
            "GUEST_NIC_MERGE_BUFFERS_DISABLE" : [False],
        },
        "TestSteps": STEP_VSWITCH_PVP_FLOWS_INIT + [
                        # verify jumbo frame configuration
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk1 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdkvhostuserclient1 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        # VNF startup, MTU configuration
                        ['vnf', 'start'],
                        ['vnf', 'execute_and_wait', 'ifconfig eth0 mtu 9000'],
                        ['vnf', 'execute_and_wait', 'ifconfig eth1 mtu 9000'],
                        ['trafficgen', 'send_traffic', {}],
                        # check that jumbo frames were received by traffic generator
                        ['trafficgen', 'get_results'],
                        # i.e. (RX in Bytes/s) divide (RX frames/s) ~ 9018 Bytes
                        ['tools', 'assert', 'round(float(#STEP[-1][0]["throughput_rx_mbps"])*1000000/8 / '
                         'float(#STEP[-1][0]["throughput_rx_fps"]))==9018'],
                        ['vnf', 'stop'],
                   ] + STEP_VSWITCH_PVP_FLOWS_FINIT
    },
    {
        "Name": "ovsdpdk_jumbo_p2p_upper_bound",
        "Deployment": "p2p",
        "Description": "Ensure that jumbo frames above the configured Rx port's MTU are not accepted",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 10,
                'bidir' : 'False',
                'learning_frames' : False,
            },
            "VSWITCH_JUMBO_FRAMES_ENABLED" : 'True',
            "VSWITCH_JUMBO_FRAMES_SIZE" : 9000,
        },
        "TestSteps": [
                        # set and verify jumbo frame support
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk0 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] get Interface dpdk1 mtu'],
                        ['tools', 'assert', 'int(#STEP[-1])==9000'],
                        # set packetsize to 9018 and send traffic
                        ['settings', 'setValue', 'TRAFFICGEN_PKT_SIZES', (9018,)],
                        ['trafficgen', 'send_traffic', {}],
                        ['trafficgen', 'get_results'],
                        # all traffic should pass through (i.e. 0% frame loss)
                        ['tools', 'assert', 'float(#STEP[-1][0]["frame_loss_percent"])==0'],
                        # set packetsize to 9019 and send traffic
                        ['settings', 'setValue', 'TRAFFICGEN_PKT_SIZES', (9019,)],
                        # disable verification of send_traffic "!" prefix, otherwise vsperf
                        # will fail when 100% packet loss is detected
                        ['!trafficgen', 'send_traffic', {}],
                        ['trafficgen', 'get_results'],
                        # all traffic should be dropped
                        ['tools', 'assert', 'float(#STEP[-1][0]["frame_loss_percent"])==100'],
                     ]
    },
]
############################################################
#
#  Rate Limiting
#
############################################################
# default settings of limiter used in macros and tests
_OVSDPDK_RATE_PORT = 'dpdk'
_OVSDPDK_RATE_NICID = '0'
_OVSDPDK_RATE_RATE = '10000'             # desired maximum rate of PAYLOAD carried by frames
_OVSDPDK_RATE_BURST = '8000'
_OVSDPDK_RATE_LIMITER_CREATED = 'True'   # set to False to verify that limiter was not created

_OVSDPDK_RATE_DEVIATION = '5'            # acceptable deviation from configured frame rate in %
# Formula used for validation of rate settings.
# Note: OVS parameter "ingress_policing_rate" configures maximum rate of payload in Kbps,
# but traffic generator measures throughput in Mbps based on whole frames including headers.
# Thus measured RX throughput value reported by traffic generator must be deducted by bit
# rate consumed by frame header transmission.
_OVSDPDK_RATE_CHECK = ('abs(1-float(#STEP[{}][{}]["throughput_rx_mbps"])*1000*'
                       '(1-$_OVSDPDK_HEADER_LEN/float(#STEP[{}][{}]["packet_size"]))'
                       '/float($_OVSDPDK_RATE_RATE))*100 < $_OVSDPDK_RATE_DEVIATION')

# macro will setup rate limiter at interface defined by _DPDK_RATE_PORT and
# _DPDK_RATE_NICID; It will verify, that limiter was created by parsing
# vswitchd log file. It will also check that proper limiter values are
# set for given interface.
_OVSDPDK_RATE_set_rate_limiter = [
    # get line number of next log file entry
    ['tools', 'exec_shell', 'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] '
     'set Interface $_OVSDPDK_RATE_PORT$_OVSDPDK_RATE_NICID '
     'ingress_policing_burst=$_OVSDPDK_RATE_BURST '
     'ingress_policing_rate=$_OVSDPDK_RATE_RATE'],
    # check vswitchd log file, that rate limiter was created
    ['tools', 'exec_shell', "sed -n '#STEP[-2][0],$ p' $_OVSDPDK_VSWITCH_LOG",
     '|CIR period'],
    ['tools', 'assert', '("CIR period" in #STEP[-1])==$_OVSDPDK_RATE_LIMITER_CREATED'],
    # verify that interface has correct rate limiter configuration
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] '
     'list interface $_OVSDPDK_RATE_PORT$_OVSDPDK_RATE_NICID',
     '(ingress_policing_\w+: \d+)'],
    ['tools', 'assert', '"ingress_policing_burst: $_OVSDPDK_RATE_BURST" in #STEP[-1]'],
    ['tools', 'assert', '"ingress_policing_rate: $_OVSDPDK_RATE_RATE" in #STEP[-2]'],
]

_OVSDPDK_RATE_set_rate_limiter_NIC0 = [
    ['settings', 'setValue', '_OVSDPDK_RATE_NICID', '0']
] + _OVSDPDK_RATE_set_rate_limiter

_OVSDPDK_RATE_set_rate_limiter_NIC1 = [
    ['settings', 'setValue', '_OVSDPDK_RATE_NICID', '1']
] + _OVSDPDK_RATE_set_rate_limiter

# macro will set different limiter values and sends traffic to verify proper
# limiter functionality
_OVSDPDK_RATE_confirm_multiple_rate_limit_setup = \
    _OVSDPDK_RATE_set_rate_limiter_NIC0 + _OVSDPDK_RATE_set_rate_limiter_NIC1 + [
        # by default rate limit is 10Mbits/s
        ['trafficgen', 'send_traffic', {}],
        ['trafficgen', 'get_results'],
        # check result and accept preconfigured deviation to the configured frame rate
        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("-1", "0", "-1", "0")],
        # set rate limit to 20Mbits/s
        ['settings', 'setValue', '_OVSDPDK_RATE_RATE', '20000']
     ] + _OVSDPDK_RATE_set_rate_limiter_NIC0 + _OVSDPDK_RATE_set_rate_limiter_NIC1 + [
        ['trafficgen', 'send_traffic', {}],
        ['trafficgen', 'get_results'],
        # check result and accept preconfigured deviation to the configured frame rate
        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("-1", "0", "-1", "0")],
        # set rate limit to 30Mbits/s
        ['settings', 'setValue', '_OVSDPDK_RATE_RATE', '30000']
     ] + _OVSDPDK_RATE_set_rate_limiter_NIC0 + _OVSDPDK_RATE_set_rate_limiter_NIC1 + [
        ['trafficgen', 'send_traffic', {}],
        ['trafficgen', 'get_results'],
        # check result and accept preconfigured deviation to the configured frame rate
        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("-1", "0", "-1", "0")],
        # disable rate limiter and verify unlimited speed
        ['settings', 'setValue', '_OVSDPDK_RATE_RATE', '0'],
        ['settings', 'setValue', '_OVSDPDK_RATE_BURST', '0'],
        ['settings', 'setValue', '_OVSDPDK_RATE_LIMITER_CREATED', 'False'],
     ] + _OVSDPDK_RATE_set_rate_limiter_NIC0 + _OVSDPDK_RATE_set_rate_limiter_NIC1 + [
        ['trafficgen', 'send_traffic', {}],
        # check that traffic rate is no longer limited
        ['trafficgen', 'get_results'],
        ['tools', 'assert', 'int(#STEP[-1][0]["throughput_rx_mbps"])>500'],
        ['vswitch', 'dump_flows', '$VSWITCH_BRIDGE_NAME'],
    ]

INTEGRATION_TESTS = INTEGRATION_TESTS + [
    {
        "Name": "ovsdpdk_rate_create_phy_port",
        "Deployment": "clean",
        "Description": "Ensure a rate limiting interface can be created on a physical DPDK port.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                    ] + _OVSDPDK_RATE_set_rate_limiter
    },
    {
        "Name": "ovsdpdk_rate_delete_phy_port",
        "Deployment": "clean",
        "Description": "Ensure a rate limiting interface can be destroyed on a physical DPDK port.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                    ] + _OVSDPDK_RATE_set_rate_limiter + [
                        ['settings', 'setValue', '_OVSDPDK_RATE_RATE', '0'],
                        ['settings', 'setValue', '_OVSDPDK_RATE_BURST', '0'],
                        ['settings', 'setValue', '_OVSDPDK_RATE_LIMITER_CREATED', 'False'],
                    ] + _OVSDPDK_RATE_set_rate_limiter
    },
    {
        "Name": "ovsdpdk_rate_create_vport",
        "Deployment": "clean",
        "Description": "Ensure a rate limiting interface can be created on a vhost-user port.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "_OVSDPDK_RATE_PORT" : 'dpdkvhostuserclient',
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                    ] + _OVSDPDK_RATE_set_rate_limiter
    },
    {
        "Name": "ovsdpdk_rate_delete_vport",
        "Deployment": "clean",
        "Description": "Ensure a rate limiting interface can be destroyed on a vhost-user port.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "_OVSDPDK_RATE_PORT" : 'dpdkvhostuserclient',
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                    ] + _OVSDPDK_RATE_set_rate_limiter + [
                        ['settings', 'setValue', '_OVSDPDK_RATE_RATE', '0'],
                        ['settings', 'setValue', '_OVSDPDK_RATE_BURST', '0'],
                        ['settings', 'setValue', '_OVSDPDK_RATE_LIMITER_CREATED', 'False'],
                    ] + _OVSDPDK_RATE_set_rate_limiter
    },
    {
        "Name": "ovsdpdk_rate_no_policing",
        "Deployment": "clean",
        "Description": "Ensure when a user attempts to create a rate limiting interface but is missing policing rate argument, no rate limitiner is created.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "_OVSDPDK_RATE_PORT" : 'dpdkvhostuserclient',
            "_OVSDPDK_RATE_RATE" : '0',
            "_OVSDPDK_RATE_BURST" : '1000',
            "_OVSDPDK_RATE_LIMITER_CREATED" : 'False',
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                    ] + _OVSDPDK_RATE_set_rate_limiter
    },
    {
        "Name": "ovsdpdk_rate_no_burst",
        "Deployment": "clean",
        "Description": "Ensure when a user attempts to create a rate limiting interface but is missing policing burst argument, rate limitiner is created.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "_OVSDPDK_RATE_PORT" : 'dpdkvhostuserclient',
            "_OVSDPDK_RATE_RATE" : '10000',
            "_OVSDPDK_RATE_BURST" : '0',
            "_OVSDPDK_RATE_LIMITER_CREATED" : 'True',
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                    ] + _OVSDPDK_RATE_set_rate_limiter
    },
    {
        "Name": "ovsdpdk_rate_p2p",
        "Deployment": "p2p",
        "Description": "Ensure when a user creates a rate limiting physical interface that the traffic is limited to the specified policer rate in a p2p setup.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "_OVSDPDK_RATE_PORT" : 'dpdk',
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
            },
        },
        "TestSteps": _OVSDPDK_RATE_confirm_multiple_rate_limit_setup
    },
    {
        "Name": "ovsdpdk_rate_pvp",
        "Deployment": "pvp",
        "Description": "Ensure when a user creates a rate limiting vHost User interface that the traffic is limited to the specified policer rate in a pvp setup.",
        "vSwitch" : "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "_OVSDPDK_RATE_PORT" : 'dpdkvhostuserclient',
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
            },
        },
        "TestSteps": _OVSDPDK_RATE_confirm_multiple_rate_limit_setup
    },
    {
        "Name": "ovsdpdk_rate_p2p_multi_pkt_sizes",
        "Deployment": "p2p",
        "Description": "Ensure that rate limiting works for various frame sizes.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "_OVSDPDK_RATE_PORT" : 'dpdk',
            "_OVSDPDK_RATE_RATE" : '10000',
            "TRAFFICGEN_PKT_SIZES" : _OVSDPDK_PKT_SIZES,
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
            },
        },
        "TestSteps": _OVSDPDK_RATE_set_rate_limiter_NIC0 + _OVSDPDK_RATE_set_rate_limiter_NIC1 + [
                        # dump rate limiter configuration of both NICs
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] '
                         'list interface dpdk0'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] '
                         'list interface dpdk1'],
                        ['trafficgen', 'send_traffic', {}],
                        ['#result', 'trafficgen', 'get_results'],
                        # check results and accept preconfigured deviation to the configured frame rates
                        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("result","0", "result","0")],
                        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("result","1", "result","1")],
                        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("result","2", "result","2")],
                        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("result","3", "result","3")],
                        ['tools', 'assert', _OVSDPDK_RATE_CHECK.format("result","4", "result","4")],
                    ],
    },
]
############################################################
#
#  Quality of Service
#
############################################################
# default settings of limiter used in macros and tests
_OVSDPDK_QOS_PORT = 'dpdk'
_OVSDPDK_QOS_NICID = '0'
_OVSDPDK_QOS_CIR = '1250000'  # desired maximum rate of PAYLOAD carried by frames in BYTEs
_OVSDPDK_QOS_CBS = '2048'

_OVSDPDK_QOS_DEVIATION = '5'            # acceptable deviation from configured frame rate in %
# Formula used for validation of rate settings.
# Note: OVS parameter "ingress_policing_rate" configures maximum rate of payload in Kbps,
# but traffic generator measures throughput in Mbps based on whole frames including headers.
# Thus measured RX throughput value reported by traffic generator must be deducted by bit
# rate consumed by frame header transmission.
_OVSDPDK_QOS_CHECK = ('abs(1-float(#STEP[{}][{}]["throughput_rx_mbps"])*1000000*'
                      '(1-$_OVSDPDK_HEADER_LEN/float(#STEP[{}][{}]["packet_size"]))'
                      '/float($_OVSDPDK_QOS_CIR*8))*100 < $_OVSDPDK_QOS_DEVIATION')


# macro will setup QoS at interface defined by _OVSDPDK_QOS_PORT and
# _OVSDPDK_QOS_NICID; It will verify, that QoS was created by parsing
# vswitchd log file. It will also check that proper QoS values are
# set for given interface.
_OVSDPDK_QOS_set_qos = [
    # get line number of next log file entry
    ['tools', 'exec_shell', 'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],

    # Crete QoS policy and check the returned policy ID
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] '
     'set port $_OVSDPDK_QOS_PORT$_OVSDPDK_QOS_NICID qos=@newqos -- '
     '--id=@newqos create qos type=egress-policer other-config:cir=$_OVSDPDK_QOS_CIR '
     'other-config:cbs=$_OVSDPDK_QOS_CBS','|\w{8}-\w{4}-\w{4}-\w{4}-\w{12}'],
    ['tools', 'assert', 'len(#STEP[-1])==1'],

    # Check the OVS logs
    ['tools', 'exec_shell', "sed -n '#STEP[-3][0],$ p' $_OVSDPDK_VSWITCH_LOG",
     '|CIR period'],
    ['tools', 'assert', '"CIR period" in #STEP[-1]'],

    # Check the QoS policy and attributes
    ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] -t ovs-vswitchd qos/show '
     '$_OVSDPDK_QOS_PORT$_OVSDPDK_QOS_NICID', '.+'],
    ['tools', 'assert', "'QoS: $_OVSDPDK_QOS_PORT$_OVSDPDK_QOS_NICID egress-policer' in #STEP[-1]"],
    ['tools', 'assert', "'cbs: $_OVSDPDK_QOS_CBS' in #STEP[-2]"],
    ['tools', 'assert', "'cir: $_OVSDPDK_QOS_CIR' in #STEP[-3]"],
]

_OVSDPDK_QOS_set_qos_NIC0 = [
    ['settings', 'setValue', '_OVSDPDK_QOS_NICID', '0']
] + _OVSDPDK_QOS_set_qos

_OVSDPDK_QOS_set_qos_NIC1 = [
    ['settings', 'setValue', '_OVSDPDK_QOS_NICID', '1']
] + _OVSDPDK_QOS_set_qos

# macro will set different limiter values and sends traffic to verify proper
# QoS functionality
_OVSDPDK_QOS_confirm_multiple_qos_setup = [
        # Create QoS policy with payload rate of 23*10^6 Bytes/s
        ['settings', 'setValue', '_OVSDPDK_QOS_CIR', '23000000']
     ] + _OVSDPDK_QOS_set_qos_NIC0 + _OVSDPDK_QOS_set_qos_NIC1 + [
        ['trafficgen', 'send_traffic', {}],
        ['trafficgen', 'get_results'],
        ['tools', 'assert', _OVSDPDK_QOS_CHECK.format("-1", "0", "-1", "0")],
        # Create QoS policy with payload rate of 46*10^6 Bytes/s
        ['settings', 'setValue', '_OVSDPDK_QOS_CIR', '46000000']
     ] + _OVSDPDK_QOS_set_qos_NIC0 + _OVSDPDK_QOS_set_qos_NIC1 + [
        ['trafficgen', 'send_traffic', {}],
        ['trafficgen', 'get_results'],
        ['tools', 'assert', _OVSDPDK_QOS_CHECK.format("-1", "0", "-1", "0")],
        # Create QoS policy with payload rate of 92*10^6 Bytes/s
        ['settings', 'setValue', '_OVSDPDK_QOS_CIR', '92000000']
     ] + _OVSDPDK_QOS_set_qos_NIC0 + _OVSDPDK_QOS_set_qos_NIC1 + [
        ['trafficgen', 'send_traffic', {}],
        ['trafficgen', 'get_results'],
        ['tools', 'assert', _OVSDPDK_QOS_CHECK.format("-1", "0", "-1", "0")],
     ]

INTEGRATION_TESTS = INTEGRATION_TESTS + [
    {
        "Name": "ovsdpdk_qos_create_phy_port",
        "Deployment": "clean",
        "Description": "Ensure a QoS policy can be created on a physical DPDK port",
        "vSwitch": "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                    ] + _OVSDPDK_QOS_set_qos
    },
    {
        "Name": "ovsdpdk_qos_delete_phy_port",
        "Deployment": "clean",
        "Description": "Ensure an existing QoS policy can be destroyed on a physical DPDK port.",
        "vSwitch": "OvsDpdkVhost",
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_phy_port', 'int_br0'],
                     ] + _OVSDPDK_QOS_set_qos + [
                        # Destroy the QoS policy and check the attributes
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] -- destroy QoS #STEP[1][0] -- clear Port #STEP[1][0] qos'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] -t ovs-vswitchd qos/show #STEP[1][0]', 'QoS not configured on #STEP[1][0]'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                     ]
    },
    {
        "Name": "ovsdpdk_qos_create_vport",
        "Deployment": "clean",
        "Description": "Ensure a QoS policy can be created on a virtual vhost user port.",
        "vSwitch": "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "_OVSDPDK_QOS_PORT" : 'dpdkvhostuserclient',
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                    ] + _OVSDPDK_QOS_set_qos
    },
    {
        "Name": "ovsdpdk_qos_delete_vport",
        "Deployment": "clean",
        "Description": "Ensure an existing QoS policy can be destroyed on a vhost user port.",
        "vSwitch": "OvsDpdkVhost",
        "Parameters" : {
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "_OVSDPDK_QOS_PORT" : 'dpdkvhostuserclient',
        },
        "TestSteps": [
                        ['vswitch', 'add_switch', 'int_br0'],
                        ['vswitch', 'add_vport', 'int_br0'],
                     ] + _OVSDPDK_QOS_set_qos + [
                        # Destroy the QoS policy and check the attributes
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] -- destroy QoS #STEP[1][0] -- clear Port #STEP[1][0] qos'],
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] -t ovs-vswitchd qos/show #STEP[1][0]', 'QoS not configured on #STEP[1][0]'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                     ]
    },
    {
        "Name": "ovsdpdk_qos_create_no_cir",
        "Deployment": "clean",
        "Description": "Ensure that a QoS policy cannot be created if the egress policer cir argument is missing.",
        "vSwitch": "OvsDpdkVhost",
        "Parameters" : {},
        "TestSteps": [
                         # Setup switch,port and logs
                        ['vswitch', 'add_switch', '$VSWITCH_BRIDGE_NAME'],
                        ['vswitch', 'add_vport', '$VSWITCH_BRIDGE_NAME'],
                        ['#LOG_MARK', 'tools', 'exec_shell',
                         'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],

                        # Crete QoS policy and check the returned policy ID
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set port #STEP[1][0] qos=@newqos -- '
                         '--id=@newqos create qos type=egress-policer other-config:cbs=2048',
                         '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],

                        # Check the OVS logs
                        ['tools', 'exec_shell', "sed -n '#STEP[LOG_MARK][0],$ p' $_OVSDPDK_VSWITCH_LOG",
                         'Failed to set QoS type egress-policer on port #STEP[1][0]: No such file or directory'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],

                        # Check the attributes for vhost0
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] -t ovs-vswitchd qos/show #STEP[1][0]',
                         'QoS not configured on #STEP[1][0]'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                    ]
    },
    {
        "Name": "ovsdpdk_qos_create_no_cbs",
        "Deployment": "clean",
        "Description": "Ensure that a QoS policy cannot be created if the egress policer cbs argument is missing.",
        "vSwitch": "OvsDpdkVhost",
        "Parameters" : {},
        "TestSteps": [
                         # Setup switch,port and logs
                        ['vswitch', 'add_switch', '$VSWITCH_BRIDGE_NAME'],
                        ['vswitch', 'add_vport', '$VSWITCH_BRIDGE_NAME'],
                        ['#LOG_MARK', 'tools', 'exec_shell',
                         'echo $((1+`wc -l $_OVSDPDK_VSWITCH_LOG | cut -d" " -f1`))', '(\d+)'],

                        # Crete QoS policy and check the returned policy ID
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-vsctl"] set port #STEP[1][0] qos=@newqos -- '
                         '--id=@newqos create qos type=egress-policer other-config:cir=1250000',
                         '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],

                        # Check the OVS logs
                        ['tools', 'exec_shell', "sed -n '#STEP[LOG_MARK][0],$ p' $_OVSDPDK_VSWITCH_LOG",
                         'Failed to set QoS type egress-policer on port #STEP[1][0]: No such file or directory'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],

                        # Check the attributes for vhost0
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-appctl"] -t ovs-vswitchd qos/show #STEP[1][0]',
                         'QoS not configured on #STEP[1][0]'],
                        ['tools', 'assert', 'len(#STEP[-1])==1'],
                    ]
    },
    {
        "Name": "ovsdpdk_qos_p2p",
        "Deployment": "p2p",
        "Description": "In a p2p setup, ensure when a QoS egress policer is created that the traffic is limited to the specified rate.",
        "vSwitch": "OvsDpdkVhost",
        "Parameters" : {
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
            },
        },
        "TestSteps": _OVSDPDK_QOS_confirm_multiple_qos_setup
    },
    {
        "Name": "ovsdpdk_qos_pvp",
        "Deployment": "pvp",
        "Description": "In a pvp setup, ensure when a QoS egress policer is created that the traffic is limited to the specified rate.",
        "vSwitch": "OvsDpdkVhost",
        "VNF" : "QemuDpdkVhostUser",
        "Parameters" : {
            "_OVSDPDK_QOS_PORT" : 'dpdkvhostuserclient',
            "VSWITCH_VHOSTUSER_SERVER_MODE" : False,
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 100,
                'bidir' : 'False',
            },
        },
        "TestSteps": _OVSDPDK_QOS_confirm_multiple_qos_setup
    },
    ############################################################
    #
    #  Custom statistics
    #
    ############################################################
    {
        "Name": "ovsdpdk_custstat_check",
        "Deployment": "clean",
        "Description": "Test if custom statistics are supported.",
        "vSwitch" : "OvsDpdkVhost",
        "TestSteps": [
                        # enable custom statistics
                        ['vswitch', 'add_switch', 'int_br0', [
                                                  'protocols=OpenFlow10,OpenFlow11,OpenFlow12,'
                                                  'OpenFlow13,OpenFlow14,OpenFlow15']],
                        ['#port', 'vswitch', 'add_phy_port', 'int_br0'],
                        # check that custom statistics are available for given interface
                        ['tools', 'exec_shell', 'sudo $TOOLS["ovs-ofctl"] -O OpenFlow14 '
                                                'dump-ports int_br0 #STEP[port][1]',
                                                '|CUSTOM Statistics'],
                        ['tools', 'assert', 'len(#STEP[-1])'],
                        ['vswitch', 'del_port', 'int_br0', '#STEP[port][0]'],
                        ['vswitch', 'del_switch', 'int_br0'],
                    ]
    },
    {
        "Name": "ovsdpdk_custstat_rx_error",
        "Deployment": "clean",
        "Description": "Test bad ethernet CRC counter 'rx_crc_errors' exposed by custom statistics.",
        "vSwitch" : "OvsDpdkVhost",
        "Parameters" : {
            "OVS_OFCTL_ARGS" : [],
            "TRAFFICGEN" : "IxNet",
            "TRAFFIC" : {
                "traffic_type" : "rfc2544_continuous",
                "frame_rate" : 10,
            },
            "TRAFFICGEN_DURATION" : 10,
            "TRAFFICGEN_IXNET_TCL_SCRIPT" : "ixnetrfc2544_bad_l2_crc.tcl",
        },
        "TestSteps": [
                        # enable custom statistics
                        ['vswitch', 'add_switch', 'int_br0', [
                                                  'protocols=OpenFlow10,OpenFlow11,OpenFlow12,'
                                                  'OpenFlow13,OpenFlow14,OpenFlow15']],
                        ['#port1', 'vswitch', 'add_phy_port', 'int_br0'],
                        ['#port2', 'vswitch', 'add_phy_port', 'int_br0'],
                        ['vswitch', 'add_flow', 'int_br0', {'in_port': '1', 'actions': ['output:2']}],
                        ['vswitch', 'add_flow', 'int_br0', {'in_port': '2', 'actions': ['output:1']}],
                        ['#crc_old', 'tools', 'exec_shell', 'sudo $TOOLS["ovs-ofctl"] -O OpenFlow14 '
                                              'dump-ports int_br0 #STEP[port1][1]',
                                              '|rx_crc_errors=(\d+)'],
                        # frames will be dropped by NIC, so we have to suppress send_traffic validation
                        # to avoid test failure
                        ['!trafficgen', 'send_traffic', {}],
                        # check that custom statistics are available for given interface
                        ['#crc_new', 'tools', 'exec_shell', 'sudo $TOOLS["ovs-ofctl"] -O OpenFlow14 '
                                              'dump-ports int_br0 #STEP[port1][1]',
                                              '|rx_crc_errors=(\d+)'],
                        ['tools', 'assert', '#STEP[crc_new] > #STEP[crc_old]'],
                        # tear down the environment
                        ['vswitch', 'dump_flows', 'int_br0'],
                        ['vswitch', 'del_flow', 'int_br0', {}],
                        ['vswitch', 'del_port', 'int_br0', '#STEP[port1][0]'],
                        ['vswitch', 'del_port', 'int_br0', '#STEP[port2][0]'],
                        ['vswitch', 'del_switch', 'int_br0'],
                    ]
    },
]