From patchwork Wed Jul 19 14:12:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 129641 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 23CEC42EB9; Wed, 19 Jul 2023 16:13:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB463427E9; Wed, 19 Jul 2023 16:13:07 +0200 (CEST) Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by mails.dpdk.org (Postfix) with ESMTP id 59F9040685 for ; Wed, 19 Jul 2023 16:13:06 +0200 (CEST) Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-51f7fb9a944so9723447a12.3 for ; Wed, 19 Jul 2023 07:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1689775986; x=1690380786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=azSSDMeHYQKYS5dSNFwXPRhScxzp840mhdCDnJCfUNg=; b=khSCDdFRu5dcOpNyzYpS1qoW8/FpjwV3xKfcHpjCbKX6cAEUOvXAgz3jb+ID6t/JZ1 8B+VbAO4xh2gNo2cJSgGxdnlTkGSdzQgvSn5F1vOJUXoY+pzKPTrXm9poNyWwLwO+qME 66G4xsQmH8IMP/lWemoMAwwO2S81x3zMjAcDZMzVV3204eHtvwRQuML9qu03QglaVppL FKNE60pFVIMb2GxthXoDpW3/rhERpUa7lrmBaySulUKpKj1jt9ed/QXeL0R6RpcSEr9z JUh0D4YvNsY0zEIsBFI5g5TMWi597ismHmbAuRWz1GG8URKPbT88n2xiu2AUl9l1AiTV phKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689775986; x=1690380786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=azSSDMeHYQKYS5dSNFwXPRhScxzp840mhdCDnJCfUNg=; b=KhRj1fxG0qR92dFCL6nd9yxRHzUofn9s23eL8YeSNcOq6+qcjXBBEtP1/fjAMaaGpf QOSN5iKiVv11ac3v5mgbus0bbvZqHkptgztXosFG3FriFQK7G3qhsk9V8Qh5mzGUGphR Pa42HJMmHabYn8NRok8JbhrDdrvLD6RAqbmC7pEpIZCTS0SQ310Wcfwa/MIukKh1hqEd zqPk3bRvoTOP0dwzVMa4bGOVeT/YixFqhEhbi4Sq4AD2JJ8ty/JWBCoKP58zmM1UfsFS Rhdroj7YQ0YOXOJReOuKH6S8+/8894HKMceRr88kilONi9UO542OD171D28xeGMiYteB zp8A== X-Gm-Message-State: ABy/qLYkn/o7TCWAutdPLwuQoLpTJAtT2vGbJ/dZMF3pPD6KNJUnf5QX PAyexA1w0/k/GixDUbIdduA6Xw== X-Google-Smtp-Source: APBJJlFBmweuuUnSceiVdDqSNQbqtugAYGbF7UmXiLkaW3PPJtjsyu1irjGEhYAc24SypH8qYWP+Rw== X-Received: by 2002:a50:ed94:0:b0:51b:c714:a2a1 with SMTP id h20-20020a50ed94000000b0051bc714a2a1mr2655536edr.7.1689775985950; Wed, 19 Jul 2023 07:13:05 -0700 (PDT) Received: from jlinkes-PT-Latitude-5530.. (ip-46.34.247.144.o2inet.sk. [46.34.247.144]) by smtp.gmail.com with ESMTPSA id q8-20020a056402040800b0051e2809395bsm2721979edv.63.2023.07.19.07.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 07:13:05 -0700 (PDT) From: =?utf-8?q?Juraj_Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, lijuan.tu@intel.com, bruce.richardson@intel.com, jspewock@iol.unh.edu, probb@iol.unh.edu Cc: dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= Subject: [PATCH v3 1/6] dts: add scapy dependency Date: Wed, 19 Jul 2023 16:12:58 +0200 Message-Id: <20230719141303.33284-2-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230719141303.33284-1-juraj.linkes@pantheon.tech> References: <20230717110709.39220-1-juraj.linkes@pantheon.tech> <20230719141303.33284-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Required for scapy traffic generator. Signed-off-by: Juraj Linkeš --- dts/poetry.lock | 21 ++++++++++++++++----- dts/pyproject.toml | 1 + 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dts/poetry.lock b/dts/poetry.lock index 2438f337cd..8cb9920ec7 100644 --- a/dts/poetry.lock +++ b/dts/poetry.lock @@ -346,6 +346,19 @@ category = "main" optional = false python-versions = ">=3.6" +[[package]] +name = "scapy" +version = "2.5.0" +description = "Scapy: interactive packet manipulation tool" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4" + +[package.extras] +basic = ["ipython"] +complete = ["ipython", "pyx", "cryptography (>=2.0)", "matplotlib"] +docs = ["sphinx (>=3.0.0)", "sphinx_rtd_theme (>=0.4.3)", "tox (>=3.0.0)"] + [[package]] name = "six" version = "1.16.0" @@ -409,7 +422,7 @@ jsonschema = ">=4,<5" [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "719c43bcaa5d181921debda884f8f714063df0b2336d61e9f64ecab034e8b139" +content-hash = "907bf4ae92b05bbdb7cf2f37fc63e530702f1fff9990afa1f8e6c369b97ba592" [metadata.files] attrs = [] @@ -431,10 +444,7 @@ mypy-extensions = [] paramiko = [] pathlib2 = [] pathspec = [] -platformdirs = [ - {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"}, - {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"}, -] +platformdirs = [] pycodestyle = [] pycparser = [] pydocstyle = [] @@ -443,6 +453,7 @@ pylama = [] pynacl = [] pyrsistent = [] pyyaml = [] +scapy = [] six = [] snowballstemmer = [] toml = [] diff --git a/dts/pyproject.toml b/dts/pyproject.toml index 50bcdb327a..bd7591f7fb 100644 --- a/dts/pyproject.toml +++ b/dts/pyproject.toml @@ -13,6 +13,7 @@ warlock = "^2.0.1" PyYAML = "^6.0" types-PyYAML = "^6.0.8" fabric = "^2.7.1" +scapy = "^2.5.0" [tool.poetry.dev-dependencies] mypy = "^0.961" From patchwork Wed Jul 19 14:12:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 129642 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1EBFD42EB9; Wed, 19 Jul 2023 16:13:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BA18042B8E; Wed, 19 Jul 2023 16:13:09 +0200 (CEST) Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by mails.dpdk.org (Postfix) with ESMTP id 7F91740F16 for ; Wed, 19 Jul 2023 16:13:07 +0200 (CEST) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-51f90f713b2so10425118a12.1 for ; Wed, 19 Jul 2023 07:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1689775987; x=1690380787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0HoQxKjOSEmlpyi5I7Z/o2GdsKqCSB/veXBPkZGCVSI=; b=PS8B7wNfpnu9ZNb8PZOWKVXscNVdLbJxKWbuecBVoeJKspM4KAJzfsrz6H37rd61Li OJYUIYC+xUeZ4hrMvV2yMMw0j4/WaRKlzcwDCy5ZGgYEqVfXMxjXZUW7Cs651EhxR05R Ofmv1Qzfo0vvSnDXtMTlUxidLp4kj5rIH3lZRs6edonFSIqTSn19exmfao214WkN2yy2 YzvVPImNca4HEVOjLtzUAGRLHqTVruaAg2ydYrXKCqKkrcjNY4lszgxJuAY7hfGbxIJ1 VfTaMR3npyO+dSUOFDwyfPbrdMv6hv0S4EviPIAW4wU8Nkawk16o+Y9PRx9SysHT6C/C ZM3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689775987; x=1690380787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0HoQxKjOSEmlpyi5I7Z/o2GdsKqCSB/veXBPkZGCVSI=; b=iKHv7cN8c85LnMRQqNRC3osf/DELE84INnnVHL5VYPhu/+GtnBV0G/F+T3Vzm+jIpl WVwM3Ck5T/iljpFx7N+tJI79WQEUasrSfFhNIQKCVf22NiF/2zv2kqNvpQAVbJV4n+op HczKV0JXusB88hcJoYNvz9XYEQqCJamkgj3zRpBJZfTFnbbsDFX8jBcKKxtaVJOZvF/k gaFn7AHAfgRNJkXk8xB1Nuy2dgNMgaoEePwHrWfKrF/BLgJsI665G8Bf4NPEvfLv0/Qu nXfF8Yd4z5nFHeWICcKMVSa1rcp+BDrE9Dck2bQFDQaxJdZtw5bWCpCl91X/HldGjTyh obLg== X-Gm-Message-State: ABy/qLa54BT8UgZAQdmCH+Vj3JnWng0ob6D+ZxBFzPWPiH7GwYIoeRoH XoKJILabVP0HzwF6/xLjt3qK3A== X-Google-Smtp-Source: APBJJlEbXv5seKxF6mIN5LUNu6CIGUjhErb60lo9I8fyeR4QKqSJtHznd2dPmbV8LnpBmnEn+UOZjQ== X-Received: by 2002:a05:6402:1b19:b0:51e:253e:1e0c with SMTP id by25-20020a0564021b1900b0051e253e1e0cmr2656819edb.25.1689775986935; Wed, 19 Jul 2023 07:13:06 -0700 (PDT) Received: from jlinkes-PT-Latitude-5530.. (ip-46.34.247.144.o2inet.sk. [46.34.247.144]) by smtp.gmail.com with ESMTPSA id q8-20020a056402040800b0051e2809395bsm2721979edv.63.2023.07.19.07.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 07:13:06 -0700 (PDT) From: =?utf-8?q?Juraj_Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, lijuan.tu@intel.com, bruce.richardson@intel.com, jspewock@iol.unh.edu, probb@iol.unh.edu Cc: dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= Subject: [PATCH v3 2/6] dts: add traffic generator config Date: Wed, 19 Jul 2023 16:12:59 +0200 Message-Id: <20230719141303.33284-3-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230719141303.33284-1-juraj.linkes@pantheon.tech> References: <20230717110709.39220-1-juraj.linkes@pantheon.tech> <20230719141303.33284-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Node configuration - where to connect, what ports to use and what TG to use. Signed-off-by: Juraj Linkeš --- dts/conf.yaml | 26 ++++++- dts/framework/config/__init__.py | 84 +++++++++++++++++++--- dts/framework/config/conf_yaml_schema.json | 29 +++++++- dts/framework/dts.py | 12 ++-- dts/framework/testbed_model/sut_node.py | 5 +- 5 files changed, 135 insertions(+), 21 deletions(-) diff --git a/dts/conf.yaml b/dts/conf.yaml index 0825d958a6..0440d1d20a 100644 --- a/dts/conf.yaml +++ b/dts/conf.yaml @@ -13,10 +13,11 @@ executions: skip_smoke_tests: false # optional flag that allows you to skip smoke tests test_suites: - hello_world - system_under_test: + system_under_test_node: node_name: "SUT 1" vdevs: # optional; if removed, vdevs won't be used in the execution - "crypto_openssl" + traffic_generator_node: "TG 1" nodes: - name: "SUT 1" hostname: sut1.change.me.localhost @@ -40,3 +41,26 @@ nodes: os_driver: i40e peer_node: "TG 1" peer_pci: "0000:00:08.1" + - name: "TG 1" + hostname: tg1.change.me.localhost + user: dtsuser + arch: x86_64 + os: linux + lcores: "" + ports: + - pci: "0000:00:08.0" + os_driver_for_dpdk: rdma + os_driver: rdma + peer_node: "SUT 1" + peer_pci: "0000:00:08.0" + - pci: "0000:00:08.1" + os_driver_for_dpdk: rdma + os_driver: rdma + peer_node: "SUT 1" + peer_pci: "0000:00:08.1" + use_first_core: false + hugepages: # optional; if removed, will use system hugepage configuration + amount: 256 + force_first_numa: false + traffic_generator: + type: SCAPY diff --git a/dts/framework/config/__init__.py b/dts/framework/config/__init__.py index aa7ff358a2..9b5aff8509 100644 --- a/dts/framework/config/__init__.py +++ b/dts/framework/config/__init__.py @@ -12,7 +12,7 @@ import pathlib from dataclasses import dataclass from enum import auto, unique -from typing import Any, TypedDict +from typing import Any, TypedDict, Union import warlock # type: ignore import yaml @@ -54,6 +54,11 @@ class Compiler(StrEnum): msvc = auto() +@unique +class TrafficGeneratorType(StrEnum): + SCAPY = auto() + + # Slots enables some optimizations, by pre-allocating space for the defined # attributes in the underlying data structure. # @@ -79,6 +84,26 @@ def from_dict(node: str, d: dict) -> "PortConfig": return PortConfig(node=node, **d) +@dataclass(slots=True, frozen=True) +class TrafficGeneratorConfig: + traffic_generator_type: TrafficGeneratorType + + @staticmethod + def from_dict(d: dict): + # This looks useless now, but is designed to allow expansion to traffic + # generators that require more configuration later. + match TrafficGeneratorType(d["type"]): + case TrafficGeneratorType.SCAPY: + return ScapyTrafficGeneratorConfig( + traffic_generator_type=TrafficGeneratorType.SCAPY + ) + + +@dataclass(slots=True, frozen=True) +class ScapyTrafficGeneratorConfig(TrafficGeneratorConfig): + pass + + @dataclass(slots=True, frozen=True) class NodeConfiguration: name: str @@ -89,17 +114,17 @@ class NodeConfiguration: os: OS lcores: str use_first_core: bool - memory_channels: int hugepages: HugepageConfiguration | None ports: list[PortConfig] @staticmethod - def from_dict(d: dict) -> "NodeConfiguration": + def from_dict(d: dict) -> Union["SutNodeConfiguration", "TGNodeConfiguration"]: hugepage_config = d.get("hugepages") if hugepage_config: if "force_first_numa" not in hugepage_config: hugepage_config["force_first_numa"] = False hugepage_config = HugepageConfiguration(**hugepage_config) + common_config = { "name": d["name"], "hostname": d["hostname"], @@ -109,12 +134,31 @@ def from_dict(d: dict) -> "NodeConfiguration": "os": OS(d["os"]), "lcores": d.get("lcores", "1"), "use_first_core": d.get("use_first_core", False), - "memory_channels": d.get("memory_channels", 1), "hugepages": hugepage_config, "ports": [PortConfig.from_dict(d["name"], port) for port in d["ports"]], } - return NodeConfiguration(**common_config) + if "traffic_generator" in d: + return TGNodeConfiguration( + traffic_generator=TrafficGeneratorConfig.from_dict( + d["traffic_generator"] + ), + **common_config, + ) + else: + return SutNodeConfiguration( + memory_channels=d.get("memory_channels", 1), **common_config + ) + + +@dataclass(slots=True, frozen=True) +class SutNodeConfiguration(NodeConfiguration): + memory_channels: int + + +@dataclass(slots=True, frozen=True) +class TGNodeConfiguration(NodeConfiguration): + traffic_generator: ScapyTrafficGeneratorConfig @dataclass(slots=True, frozen=True) @@ -193,23 +237,40 @@ class ExecutionConfiguration: perf: bool func: bool test_suites: list[TestSuiteConfig] - system_under_test: NodeConfiguration + system_under_test_node: SutNodeConfiguration + traffic_generator_node: TGNodeConfiguration vdevs: list[str] skip_smoke_tests: bool @staticmethod - def from_dict(d: dict, node_map: dict) -> "ExecutionConfiguration": + def from_dict( + d: dict, node_map: dict[str, Union[SutNodeConfiguration | TGNodeConfiguration]] + ) -> "ExecutionConfiguration": build_targets: list[BuildTargetConfiguration] = list( map(BuildTargetConfiguration.from_dict, d["build_targets"]) ) test_suites: list[TestSuiteConfig] = list( map(TestSuiteConfig.from_dict, d["test_suites"]) ) - sut_name = d["system_under_test"]["node_name"] + sut_name = d["system_under_test_node"]["node_name"] skip_smoke_tests = d.get("skip_smoke_tests", False) assert sut_name in node_map, f"Unknown SUT {sut_name} in execution {d}" + system_under_test_node = node_map[sut_name] + assert isinstance( + system_under_test_node, SutNodeConfiguration + ), f"Invalid SUT configuration {system_under_test_node}" + + tg_name = d["traffic_generator_node"] + assert tg_name in node_map, f"Unknown TG {tg_name} in execution {d}" + traffic_generator_node = node_map[tg_name] + assert isinstance( + traffic_generator_node, TGNodeConfiguration + ), f"Invalid TG configuration {traffic_generator_node}" + vdevs = ( - d["system_under_test"]["vdevs"] if "vdevs" in d["system_under_test"] else [] + d["system_under_test_node"]["vdevs"] + if "vdevs" in d["system_under_test_node"] + else [] ) return ExecutionConfiguration( build_targets=build_targets, @@ -217,7 +278,8 @@ def from_dict(d: dict, node_map: dict) -> "ExecutionConfiguration": func=d["func"], skip_smoke_tests=skip_smoke_tests, test_suites=test_suites, - system_under_test=node_map[sut_name], + system_under_test_node=system_under_test_node, + traffic_generator_node=traffic_generator_node, vdevs=vdevs, ) @@ -228,7 +290,7 @@ class Configuration: @staticmethod def from_dict(d: dict) -> "Configuration": - nodes: list[NodeConfiguration] = list( + nodes: list[Union[SutNodeConfiguration | TGNodeConfiguration]] = list( map(NodeConfiguration.from_dict, d["nodes"]) ) assert len(nodes) > 0, "There must be a node to test" diff --git a/dts/framework/config/conf_yaml_schema.json b/dts/framework/config/conf_yaml_schema.json index 67722213dd..936a4bac5b 100644 --- a/dts/framework/config/conf_yaml_schema.json +++ b/dts/framework/config/conf_yaml_schema.json @@ -164,6 +164,11 @@ "amount" ] }, + "mac_address": { + "type": "string", + "description": "A MAC address", + "pattern": "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$" + }, "pci_address": { "type": "string", "pattern": "^[\\da-fA-F]{4}:[\\da-fA-F]{2}:[\\da-fA-F]{2}.\\d:?\\w*$" @@ -286,6 +291,22 @@ ] }, "minimum": 1 + }, + "traffic_generator": { + "oneOf": [ + { + "type": "object", + "description": "Scapy traffic generator. Used for functional testing.", + "properties": { + "type": { + "type": "string", + "enum": [ + "SCAPY" + ] + } + } + } + ] } }, "additionalProperties": false, @@ -336,7 +357,7 @@ "description": "Optional field that allows you to skip smoke testing", "type": "boolean" }, - "system_under_test": { + "system_under_test_node": { "type":"object", "properties": { "node_name": { @@ -353,6 +374,9 @@ "required": [ "node_name" ] + }, + "traffic_generator_node": { + "$ref": "#/definitions/node_name" } }, "additionalProperties": false, @@ -361,7 +385,8 @@ "perf", "func", "test_suites", - "system_under_test" + "system_under_test_node", + "traffic_generator_node" ] }, "minimum": 1 diff --git a/dts/framework/dts.py b/dts/framework/dts.py index 3ba7fd2478..1c4a637fbd 100644 --- a/dts/framework/dts.py +++ b/dts/framework/dts.py @@ -38,17 +38,17 @@ def run_all() -> None: # for all Execution sections for execution in CONFIGURATION.executions: sut_node = None - if execution.system_under_test.name in nodes: + if execution.system_under_test_node.name in nodes: # a Node with the same name already exists - sut_node = nodes[execution.system_under_test.name] + sut_node = nodes[execution.system_under_test_node.name] else: # the SUT has not been initialized yet try: - sut_node = SutNode(execution.system_under_test) + sut_node = SutNode(execution.system_under_test_node) result.update_setup(Result.PASS) except Exception as e: dts_logger.exception( - f"Connection to node {execution.system_under_test} failed." + f"Connection to node {execution.system_under_test_node} failed." ) result.update_setup(Result.FAIL, e) else: @@ -87,7 +87,9 @@ def _run_execution( Run the given execution. This involves running the execution setup as well as running all build targets in the given execution. """ - dts_logger.info(f"Running execution with SUT '{execution.system_under_test.name}'.") + dts_logger.info( + f"Running execution with SUT '{execution.system_under_test_node.name}'." + ) execution_result = result.add_execution(sut_node.config) execution_result.add_sut_info(sut_node.node_info) diff --git a/dts/framework/testbed_model/sut_node.py b/dts/framework/testbed_model/sut_node.py index e3227d9bc2..ad3bffd9d3 100644 --- a/dts/framework/testbed_model/sut_node.py +++ b/dts/framework/testbed_model/sut_node.py @@ -12,8 +12,8 @@ from framework.config import ( BuildTargetConfiguration, BuildTargetInfo, - NodeConfiguration, NodeInfo, + SutNodeConfiguration, ) from framework.remote_session import CommandResult, InteractiveShellType, OSSession from framework.settings import SETTINGS @@ -77,6 +77,7 @@ class SutNode(Node): Another key capability is building DPDK according to given build target. """ + config: SutNodeConfiguration _dpdk_prefix_list: list[str] _dpdk_timestamp: str _build_target_config: BuildTargetConfiguration | None @@ -89,7 +90,7 @@ class SutNode(Node): _node_info: NodeInfo | None _compiler_version: str | None - def __init__(self, node_config: NodeConfiguration): + def __init__(self, node_config: SutNodeConfiguration): super(SutNode, self).__init__(node_config) self._dpdk_prefix_list = [] self._build_target_config = None From patchwork Wed Jul 19 14:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 129643 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2269042EB9; Wed, 19 Jul 2023 16:13:26 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C6C5E42BDA; Wed, 19 Jul 2023 16:13:10 +0200 (CEST) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by mails.dpdk.org (Postfix) with ESMTP id 7C7AE427F5 for ; Wed, 19 Jul 2023 16:13:09 +0200 (CEST) Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-4fb96e2b573so11724174e87.3 for ; Wed, 19 Jul 2023 07:13:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1689775989; x=1690380789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b7OwBlv73Wxiy3NTj06FuS+nRUEc+Rjry3WMh+cg214=; b=VFlftBlyiDRNgcEFoY0nTiJ2/r9czWKmQcIjAOdQq6wwwsAL/Sc5KpN0Wvi1g43KDF w8dkIkxBWGenahyG2QrhSiCQeH7S+xYq8fJwlfvegVdvVvTObc3EROfB2FDVHa5QGCTw esWneUEw3owjN8SSVRAF20PNXREcV3Rz+uku311AMZm5qYKT78D1fldQXQcbmsvM5iCq Gt3DZIMMRD1wUGpY2MG0yEDQGtwZ5k5eHMQq0TC+AxFqx1AJ8iplYCXtKjRh6qQxES9v hy4ep5yatXlvZLlk8tuuPI/NIPr+iFzZkx9yweoDCEyWc0L2UMFdzUNk6/fpYI4+KC1/ JZqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689775989; x=1690380789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b7OwBlv73Wxiy3NTj06FuS+nRUEc+Rjry3WMh+cg214=; b=S9pcH2xU0yWGv/R7gwv5JLW6I2pRxGsaAUqlXEI2auZxTWAejMKz05NFE/BI8qx0If Nlf/pldnWYP3CKAlrW+vUo7N32LeMma1QgwUrqy0/6g9+hCyXE7keSdqBEDJLp1Rn06G Al+MkiM9j1PTZS4jYvQHbBDIkQ/yaY3Cq5uChJJMM7F3kKCRTxegFJQFRE+LQ8O3rpNE nETY4Yx7spfDCBjO6dNPM8AiwL7LKFV1ZUcr3SadSon+0hKz6a8HE09hZJnfzkO/ao8/ s6mQAE2O/TKOJYbqRlGBeDhXAhQv9jxELVoFZlrFWDHA28/hM8g3aQvkVi4R56dehJEm WqCg== X-Gm-Message-State: ABy/qLanRZT7WtE5gKtzW87gMhxE0KwqbJDN47pEH7GmvqPrOy5kEtih Fnry/1Ia5dWlujx6WxPhxx+nDw== X-Google-Smtp-Source: APBJJlHU5F8Vu6T4DLezaODikzL7EUbI8qQ5Z1vtEc+sz8K8C44FXTAndVAzCC112Uk6zIzQOus4kA== X-Received: by 2002:a19:4312:0:b0:4f8:5d2f:902a with SMTP id q18-20020a194312000000b004f85d2f902amr3639895lfa.60.1689775988153; Wed, 19 Jul 2023 07:13:08 -0700 (PDT) Received: from jlinkes-PT-Latitude-5530.. (ip-46.34.247.144.o2inet.sk. [46.34.247.144]) by smtp.gmail.com with ESMTPSA id q8-20020a056402040800b0051e2809395bsm2721979edv.63.2023.07.19.07.13.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 07:13:07 -0700 (PDT) From: =?utf-8?q?Juraj_Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, lijuan.tu@intel.com, bruce.richardson@intel.com, jspewock@iol.unh.edu, probb@iol.unh.edu Cc: dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= Subject: [PATCH v3 3/6] dts: traffic generator abstractions Date: Wed, 19 Jul 2023 16:13:00 +0200 Message-Id: <20230719141303.33284-4-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230719141303.33284-1-juraj.linkes@pantheon.tech> References: <20230717110709.39220-1-juraj.linkes@pantheon.tech> <20230719141303.33284-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org There are traffic abstractions for all traffic generators and for traffic generators that can capture (not just count) packets. There also related abstractions, such as TGNode where the traffic generators reside and some related code. Signed-off-by: Juraj Linkeš --- doc/guides/tools/dts.rst | 31 ++++ dts/framework/dts.py | 61 ++++---- dts/framework/remote_session/linux_session.py | 78 ++++++++++ dts/framework/remote_session/os_session.py | 15 ++ dts/framework/test_suite.py | 4 +- dts/framework/testbed_model/__init__.py | 1 + .../capturing_traffic_generator.py | 136 ++++++++++++++++++ dts/framework/testbed_model/hw/port.py | 60 ++++++++ dts/framework/testbed_model/node.py | 20 ++- dts/framework/testbed_model/scapy.py | 74 ++++++++++ dts/framework/testbed_model/sut_node.py | 1 + dts/framework/testbed_model/tg_node.py | 99 +++++++++++++ .../testbed_model/traffic_generator.py | 72 ++++++++++ dts/framework/utils.py | 13 ++ 14 files changed, 637 insertions(+), 28 deletions(-) create mode 100644 dts/framework/testbed_model/capturing_traffic_generator.py create mode 100644 dts/framework/testbed_model/hw/port.py create mode 100644 dts/framework/testbed_model/scapy.py create mode 100644 dts/framework/testbed_model/tg_node.py create mode 100644 dts/framework/testbed_model/traffic_generator.py diff --git a/doc/guides/tools/dts.rst b/doc/guides/tools/dts.rst index c7b31623e4..2f97d1df6e 100644 --- a/doc/guides/tools/dts.rst +++ b/doc/guides/tools/dts.rst @@ -153,6 +153,37 @@ There are two areas that need to be set up on a System Under Test: sudo usermod -aG sudo + +Setting up Traffic Generator Node +--------------------------------- + +These need to be set up on a Traffic Generator Node: + +#. **Traffic generator dependencies** + + The traffic generator running on the traffic generator node must be installed beforehand. + For Scapy traffic generator, only a few Python libraries need to be installed: + + .. code-block:: console + + sudo apt install python3-pip + sudo pip install --upgrade pip + sudo pip install scapy==2.5.0 + +#. **Hardware dependencies** + + The traffic generators, like DPDK, need a proper driver and firmware. + The Scapy traffic generator doesn't have strict requirements - the drivers that come + with most OS distributions will be satisfactory. + + +#. **User with administrator privileges** + + Similarly to the System Under Test, traffic generators need administrator privileges + to be able to use the devices. + Refer to the `System Under Test section ` for details. + + Running DTS ----------- diff --git a/dts/framework/dts.py b/dts/framework/dts.py index 1c4a637fbd..f773f0c38d 100644 --- a/dts/framework/dts.py +++ b/dts/framework/dts.py @@ -15,7 +15,7 @@ from .logger import DTSLOG, getLogger from .test_result import BuildTargetResult, DTSResult, ExecutionResult, Result from .test_suite import get_test_suites -from .testbed_model import SutNode +from .testbed_model import SutNode, TGNode from .utils import check_dts_python_version dts_logger: DTSLOG = getLogger("DTSRunner") @@ -33,29 +33,31 @@ def run_all() -> None: # check the python version of the server that run dts check_dts_python_version() - nodes: dict[str, SutNode] = {} + sut_nodes: dict[str, SutNode] = {} + tg_nodes: dict[str, TGNode] = {} try: # for all Execution sections for execution in CONFIGURATION.executions: - sut_node = None - if execution.system_under_test_node.name in nodes: - # a Node with the same name already exists - sut_node = nodes[execution.system_under_test_node.name] - else: - # the SUT has not been initialized yet - try: + sut_node = sut_nodes.get(execution.system_under_test_node.name) + tg_node = tg_nodes.get(execution.traffic_generator_node.name) + + try: + if not sut_node: sut_node = SutNode(execution.system_under_test_node) - result.update_setup(Result.PASS) - except Exception as e: - dts_logger.exception( - f"Connection to node {execution.system_under_test_node} failed." - ) - result.update_setup(Result.FAIL, e) - else: - nodes[sut_node.name] = sut_node - - if sut_node: - _run_execution(sut_node, execution, result) + sut_nodes[sut_node.name] = sut_node + if not tg_node: + tg_node = TGNode(execution.traffic_generator_node) + tg_nodes[tg_node.name] = tg_node + result.update_setup(Result.PASS) + except Exception as e: + failed_node = execution.system_under_test_node.name + if sut_node: + failed_node = execution.traffic_generator_node.name + dts_logger.exception(f"Creation of node {failed_node} failed.") + result.update_setup(Result.FAIL, e) + + else: + _run_execution(sut_node, tg_node, execution, result) except Exception as e: dts_logger.exception("An unexpected error has occurred.") @@ -64,7 +66,7 @@ def run_all() -> None: finally: try: - for node in nodes.values(): + for node in (sut_nodes | tg_nodes).values(): node.close() result.update_teardown(Result.PASS) except Exception as e: @@ -81,7 +83,10 @@ def run_all() -> None: def _run_execution( - sut_node: SutNode, execution: ExecutionConfiguration, result: DTSResult + sut_node: SutNode, + tg_node: TGNode, + execution: ExecutionConfiguration, + result: DTSResult, ) -> None: """ Run the given execution. This involves running the execution setup as well as @@ -102,7 +107,9 @@ def _run_execution( else: for build_target in execution.build_targets: - _run_build_target(sut_node, build_target, execution, execution_result) + _run_build_target( + sut_node, tg_node, build_target, execution, execution_result + ) finally: try: @@ -115,6 +122,7 @@ def _run_execution( def _run_build_target( sut_node: SutNode, + tg_node: TGNode, build_target: BuildTargetConfiguration, execution: ExecutionConfiguration, execution_result: ExecutionResult, @@ -135,7 +143,7 @@ def _run_build_target( build_target_result.update_setup(Result.FAIL, e) else: - _run_all_suites(sut_node, execution, build_target_result) + _run_all_suites(sut_node, tg_node, execution, build_target_result) finally: try: @@ -148,6 +156,7 @@ def _run_build_target( def _run_all_suites( sut_node: SutNode, + tg_node: TGNode, execution: ExecutionConfiguration, build_target_result: BuildTargetResult, ) -> None: @@ -162,7 +171,7 @@ def _run_all_suites( for test_suite_config in execution.test_suites: try: _run_single_suite( - sut_node, execution, build_target_result, test_suite_config + sut_node, tg_node, execution, build_target_result, test_suite_config ) except BlockingTestSuiteError as e: dts_logger.exception( @@ -178,6 +187,7 @@ def _run_all_suites( def _run_single_suite( sut_node: SutNode, + tg_node: TGNode, execution: ExecutionConfiguration, build_target_result: BuildTargetResult, test_suite_config: TestSuiteConfig, @@ -206,6 +216,7 @@ def _run_single_suite( for test_suite_class in test_suite_classes: test_suite = test_suite_class( sut_node, + tg_node, test_suite_config.test_cases, execution.func, build_target_result, diff --git a/dts/framework/remote_session/linux_session.py b/dts/framework/remote_session/linux_session.py index f64aa8efb0..decce4039c 100644 --- a/dts/framework/remote_session/linux_session.py +++ b/dts/framework/remote_session/linux_session.py @@ -2,13 +2,47 @@ # Copyright(c) 2023 PANTHEON.tech s.r.o. # Copyright(c) 2023 University of New Hampshire +import json +from typing import TypedDict + +from typing_extensions import NotRequired + from framework.exception import RemoteCommandExecutionError from framework.testbed_model import LogicalCore +from framework.testbed_model.hw.port import Port from framework.utils import expand_range from .posix_session import PosixSession +class LshwConfigurationOutput(TypedDict): + link: str + + +class LshwOutput(TypedDict): + """ + A model of the relevant information from json lshw output, e.g.: + { + ... + "businfo" : "pci@0000:08:00.0", + "logicalname" : "enp8s0", + "version" : "00", + "serial" : "52:54:00:59:e1:ac", + ... + "configuration" : { + ... + "link" : "yes", + ... + }, + ... + """ + + businfo: str + logicalname: NotRequired[str] + serial: NotRequired[str] + configuration: LshwConfigurationOutput + + class LinuxSession(PosixSession): """ The implementation of non-Posix compliant parts of Linux remote sessions. @@ -103,3 +137,47 @@ def _configure_huge_pages( self.send_command( f"echo {amount} | tee {hugepage_config_path}", privileged=True ) + + def update_ports(self, ports: list[Port]) -> None: + self._logger.debug("Gathering port info.") + for port in ports: + assert ( + port.node == self.name + ), "Attempted to gather port info on the wrong node" + + port_info_list = self._get_lshw_info() + for port in ports: + for port_info in port_info_list: + if f"pci@{port.pci}" == port_info.get("businfo"): + self._update_port_attr( + port, port_info.get("logicalname"), "logical_name" + ) + self._update_port_attr(port, port_info.get("serial"), "mac_address") + port_info_list.remove(port_info) + break + else: + self._logger.warning(f"No port at pci address {port.pci} found.") + + def _get_lshw_info(self) -> list[LshwOutput]: + output = self.send_command("lshw -quiet -json -C network", verify=True) + return json.loads(output.stdout) + + def _update_port_attr( + self, port: Port, attr_value: str | None, attr_name: str + ) -> None: + if attr_value: + setattr(port, attr_name, attr_value) + self._logger.debug( + f"Found '{attr_name}' of port {port.pci}: '{attr_value}'." + ) + else: + self._logger.warning( + f"Attempted to get '{attr_name}' of port {port.pci}, " + f"but it doesn't exist." + ) + + def configure_port_state(self, port: Port, enable: bool) -> None: + state = "up" if enable else "down" + self.send_command( + f"ip link set dev {port.logical_name} {state}", privileged=True + ) diff --git a/dts/framework/remote_session/os_session.py b/dts/framework/remote_session/os_session.py index f543ce3acc..ab4bfbfe4c 100644 --- a/dts/framework/remote_session/os_session.py +++ b/dts/framework/remote_session/os_session.py @@ -12,6 +12,7 @@ from framework.remote_session.remote import InteractiveShell from framework.settings import SETTINGS from framework.testbed_model import LogicalCore +from framework.testbed_model.hw.port import Port from framework.utils import MesonArgs from .remote import ( @@ -249,3 +250,17 @@ def get_node_info(self) -> NodeInfo: """ Collect information about the node """ + + @abstractmethod + def update_ports(self, ports: list[Port]) -> None: + """ + Get additional information about ports: + Logical name (e.g. enp7s0) if applicable + Mac address + """ + + @abstractmethod + def configure_port_state(self, port: Port, enable: bool) -> None: + """ + Enable/disable port. + """ diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py index de94c9332d..056460dd05 100644 --- a/dts/framework/test_suite.py +++ b/dts/framework/test_suite.py @@ -20,7 +20,7 @@ from .logger import DTSLOG, getLogger from .settings import SETTINGS from .test_result import BuildTargetResult, Result, TestCaseResult, TestSuiteResult -from .testbed_model import SutNode +from .testbed_model import SutNode, TGNode class TestSuite(object): @@ -51,11 +51,13 @@ class TestSuite(object): def __init__( self, sut_node: SutNode, + tg_node: TGNode, test_cases: list[str], func: bool, build_target_result: BuildTargetResult, ): self.sut_node = sut_node + self.tg_node = tg_node self._logger = getLogger(self.__class__.__name__) self._test_cases_to_run = test_cases self._test_cases_to_run.extend(SETTINGS.test_cases) diff --git a/dts/framework/testbed_model/__init__.py b/dts/framework/testbed_model/__init__.py index f54a947051..5cbb859e47 100644 --- a/dts/framework/testbed_model/__init__.py +++ b/dts/framework/testbed_model/__init__.py @@ -20,3 +20,4 @@ ) from .node import Node from .sut_node import SutNode +from .tg_node import TGNode diff --git a/dts/framework/testbed_model/capturing_traffic_generator.py b/dts/framework/testbed_model/capturing_traffic_generator.py new file mode 100644 index 0000000000..ab98987f8e --- /dev/null +++ b/dts/framework/testbed_model/capturing_traffic_generator.py @@ -0,0 +1,136 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2022 University of New Hampshire +# Copyright(c) 2023 PANTHEON.tech s.r.o. + +"""Traffic generator that can capture packets. + +In functional testing, we need to interrogate received packets to check their validity. +The module defines the interface common to all traffic generators capable of capturing +traffic. +""" + +import uuid +from abc import abstractmethod + +import scapy.utils # type: ignore[import] +from scapy.packet import Packet # type: ignore[import] + +from framework.settings import SETTINGS +from framework.utils import get_packet_summaries + +from .hw.port import Port +from .traffic_generator import TrafficGenerator + + +def _get_default_capture_name() -> str: + """ + This is the function used for the default implementation of capture names. + """ + return str(uuid.uuid4()) + + +class CapturingTrafficGenerator(TrafficGenerator): + """Capture packets after sending traffic. + + A mixin interface which enables a packet generator to declare that it can capture + packets and return them to the user. + + The methods of capturing traffic generators obey the following workflow: + 1. send packets + 2. capture packets + 3. write the capture to a .pcap file + 4. return the received packets + """ + + @property + def is_capturing(self) -> bool: + return True + + def send_packet_and_capture( + self, + packet: Packet, + send_port: Port, + receive_port: Port, + duration: float, + capture_name: str = _get_default_capture_name(), + ) -> list[Packet]: + """Send a packet, return received traffic. + + Send a packet on the send_port and then return all traffic captured + on the receive_port for the given duration. Also record the captured traffic + in a pcap file. + + Args: + packet: The packet to send. + send_port: The egress port on the TG node. + receive_port: The ingress port in the TG node. + duration: Capture traffic for this amount of time after sending the packet. + capture_name: The name of the .pcap file where to store the capture. + + Returns: + A list of received packets. May be empty if no packets are captured. + """ + return self.send_packets_and_capture( + [packet], send_port, receive_port, duration, capture_name + ) + + def send_packets_and_capture( + self, + packets: list[Packet], + send_port: Port, + receive_port: Port, + duration: float, + capture_name: str = _get_default_capture_name(), + ) -> list[Packet]: + """Send packets, return received traffic. + + Send packets on the send_port and then return all traffic captured + on the receive_port for the given duration. Also record the captured traffic + in a pcap file. + + Args: + packets: The packets to send. + send_port: The egress port on the TG node. + receive_port: The ingress port in the TG node. + duration: Capture traffic for this amount of time after sending the packets. + capture_name: The name of the .pcap file where to store the capture. + + Returns: + A list of received packets. May be empty if no packets are captured. + """ + self._logger.debug(get_packet_summaries(packets)) + self._logger.debug( + f"Sending packet on {send_port.logical_name}, " + f"receiving on {receive_port.logical_name}." + ) + received_packets = self._send_packets_and_capture( + packets, + send_port, + receive_port, + duration, + ) + + self._logger.debug( + f"Received packets: {get_packet_summaries(received_packets)}" + ) + self._write_capture_from_packets(capture_name, received_packets) + return received_packets + + @abstractmethod + def _send_packets_and_capture( + self, + packets: list[Packet], + send_port: Port, + receive_port: Port, + duration: float, + ) -> list[Packet]: + """ + The extended classes must implement this method which + sends packets on send_port and receives packets on the receive_port + for the specified duration. It must be able to handle no received packets. + """ + + def _write_capture_from_packets(self, capture_name: str, packets: list[Packet]): + file_name = f"{SETTINGS.output_dir}/{capture_name}.pcap" + self._logger.debug(f"Writing packets to {file_name}.") + scapy.utils.wrpcap(file_name, packets) diff --git a/dts/framework/testbed_model/hw/port.py b/dts/framework/testbed_model/hw/port.py new file mode 100644 index 0000000000..680c29bfe3 --- /dev/null +++ b/dts/framework/testbed_model/hw/port.py @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2022 University of New Hampshire +# Copyright(c) 2023 PANTHEON.tech s.r.o. + +from dataclasses import dataclass + +from framework.config import PortConfig + + +@dataclass(slots=True, frozen=True) +class PortIdentifier: + node: str + pci: str + + +@dataclass(slots=True) +class Port: + """ + identifier: The PCI address of the port on a node. + + os_driver: The driver used by this port when the OS is controlling it. + Example: i40e + os_driver_for_dpdk: The driver the device must be bound to for DPDK to use it, + Example: vfio-pci. + + Note: os_driver and os_driver_for_dpdk may be the same thing. + Example: mlx5_core + + peer: The identifier of a port this port is connected with. + """ + + identifier: PortIdentifier + os_driver: str + os_driver_for_dpdk: str + peer: PortIdentifier + mac_address: str = "" + logical_name: str = "" + + def __init__(self, node_name: str, config: PortConfig): + self.identifier = PortIdentifier( + node=node_name, + pci=config.pci, + ) + self.os_driver = config.os_driver + self.os_driver_for_dpdk = config.os_driver_for_dpdk + self.peer = PortIdentifier(node=config.peer_node, pci=config.peer_pci) + + @property + def node(self) -> str: + return self.identifier.node + + @property + def pci(self) -> str: + return self.identifier.pci + + +@dataclass(slots=True, frozen=True) +class PortLink: + sut_port: Port + tg_port: Port diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py index d237b3f75b..c666dfbf4e 100644 --- a/dts/framework/testbed_model/node.py +++ b/dts/framework/testbed_model/node.py @@ -7,6 +7,7 @@ A node is a generic host that DTS connects to and manages. """ +from abc import ABC from typing import Any, Callable, Type from framework.config import ( @@ -26,9 +27,10 @@ VirtualDevice, lcore_filter, ) +from .hw.port import Port -class Node(object): +class Node(ABC): """ Basic class for node management. This class implements methods that manage a node, such as information gathering (of CPU/PCI/NIC) and @@ -39,6 +41,7 @@ class Node(object): config: NodeConfiguration name: str lcores: list[LogicalCore] + ports: list[Port] _logger: DTSLOG _other_sessions: list[OSSession] _execution_config: ExecutionConfiguration @@ -50,6 +53,8 @@ def __init__(self, node_config: NodeConfiguration): self._logger = getLogger(self.name) self.main_session = create_session(self.config, self.name, self._logger) + self._logger.info(f"Connected to node: {self.name}") + self._get_remote_cpus() # filter the node lcores according to user config self.lcores = LogicalCoreListFilter( @@ -58,8 +63,13 @@ def __init__(self, node_config: NodeConfiguration): self._other_sessions = [] self.virtual_devices = [] + self._init_ports() - self._logger.info(f"Created node: {self.name}") + def _init_ports(self) -> None: + self.ports = [Port(self.name, port_config) for port_config in self.config.ports] + self.main_session.update_ports(self.ports) + for port in self.ports: + self.configure_port_state(port) def set_up_execution(self, execution_config: ExecutionConfiguration) -> None: """ @@ -205,6 +215,12 @@ def _setup_hugepages(self): self.config.hugepages.amount, self.config.hugepages.force_first_numa ) + def configure_port_state(self, port: Port, enable: bool = True) -> None: + """ + Enable/disable port. + """ + self.main_session.configure_port_state(port, enable) + def close(self) -> None: """ Close all connections and free other resources. diff --git a/dts/framework/testbed_model/scapy.py b/dts/framework/testbed_model/scapy.py new file mode 100644 index 0000000000..1a23dc9fa3 --- /dev/null +++ b/dts/framework/testbed_model/scapy.py @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2022 University of New Hampshire +# Copyright(c) 2023 PANTHEON.tech s.r.o. + +"""Scapy traffic generator. + +Traffic generator used for functional testing, implemented using the Scapy library. +The traffic generator uses an XML-RPC server to run Scapy on the remote TG node. + +The XML-RPC server runs in an interactive remote SSH session running Python console, +where we start the server. The communication with the server is facilitated with +a local server proxy. +""" + +from scapy.packet import Packet # type: ignore[import] + +from framework.config import OS, ScapyTrafficGeneratorConfig +from framework.logger import getLogger + +from .capturing_traffic_generator import ( + CapturingTrafficGenerator, + _get_default_capture_name, +) +from .hw.port import Port +from .tg_node import TGNode + + +class ScapyTrafficGenerator(CapturingTrafficGenerator): + """Provides access to scapy functions via an RPC interface. + + The traffic generator first starts an XML-RPC on the remote TG node. + Then it populates the server with functions which use the Scapy library + to send/receive traffic. + + Any packets sent to the remote server are first converted to bytes. + They are received as xmlrpc.client.Binary objects on the server side. + When the server sends the packets back, they are also received as + xmlrpc.client.Binary object on the client side, are converted back to Scapy + packets and only then returned from the methods. + + Arguments: + tg_node: The node where the traffic generator resides. + config: The user configuration of the traffic generator. + """ + + _config: ScapyTrafficGeneratorConfig + _tg_node: TGNode + + def __init__(self, tg_node: TGNode, config: ScapyTrafficGeneratorConfig): + self._config = config + self._tg_node = tg_node + self._logger = getLogger( + f"{self._tg_node.name} {self._config.traffic_generator_type}" + ) + + assert ( + self._tg_node.config.os == OS.linux + ), "Linux is the only supported OS for scapy traffic generation" + + def _send_packets(self, packets: list[Packet], port: Port) -> None: + raise NotImplementedError() + + def _send_packets_and_capture( + self, + packets: list[Packet], + send_port: Port, + receive_port: Port, + duration: float, + capture_name: str = _get_default_capture_name(), + ) -> list[Packet]: + raise NotImplementedError() + + def close(self): + pass diff --git a/dts/framework/testbed_model/sut_node.py b/dts/framework/testbed_model/sut_node.py index ad3bffd9d3..f0b017a383 100644 --- a/dts/framework/testbed_model/sut_node.py +++ b/dts/framework/testbed_model/sut_node.py @@ -105,6 +105,7 @@ def __init__(self, node_config: SutNodeConfiguration): self._dpdk_version = None self._node_info = None self._compiler_version = None + self._logger.info(f"Created node: {self.name}") @property def _remote_dpdk_dir(self) -> PurePath: diff --git a/dts/framework/testbed_model/tg_node.py b/dts/framework/testbed_model/tg_node.py new file mode 100644 index 0000000000..27025cfa31 --- /dev/null +++ b/dts/framework/testbed_model/tg_node.py @@ -0,0 +1,99 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2010-2014 Intel Corporation +# Copyright(c) 2022 University of New Hampshire +# Copyright(c) 2023 PANTHEON.tech s.r.o. + +"""Traffic generator node. + +This is the node where the traffic generator resides. +The distinction between a node and a traffic generator is as follows: +A node is a host that DTS connects to. It could be a baremetal server, +a VM or a container. +A traffic generator is software running on the node. +A traffic generator node is a node running a traffic generator. +A node can be a traffic generator node as well as system under test node. +""" + +from scapy.packet import Packet # type: ignore[import] + +from framework.config import ( + ScapyTrafficGeneratorConfig, + TGNodeConfiguration, + TrafficGeneratorType, +) +from framework.exception import ConfigurationError + +from .capturing_traffic_generator import CapturingTrafficGenerator +from .hw.port import Port +from .node import Node + + +class TGNode(Node): + """Manage connections to a node with a traffic generator. + + Apart from basic node management capabilities, the Traffic Generator node has + specialized methods for handling the traffic generator running on it. + + Arguments: + node_config: The user configuration of the traffic generator node. + + Attributes: + traffic_generator: The traffic generator running on the node. + """ + + traffic_generator: CapturingTrafficGenerator + + def __init__(self, node_config: TGNodeConfiguration): + super(TGNode, self).__init__(node_config) + self.traffic_generator = create_traffic_generator( + self, node_config.traffic_generator + ) + self._logger.info(f"Created node: {self.name}") + + def send_packet_and_capture( + self, + packet: Packet, + send_port: Port, + receive_port: Port, + duration: float = 1, + ) -> list[Packet]: + """Send a packet, return received traffic. + + Send a packet on the send_port and then return all traffic captured + on the receive_port for the given duration. Also record the captured traffic + in a pcap file. + + Args: + packet: The packet to send. + send_port: The egress port on the TG node. + receive_port: The ingress port in the TG node. + duration: Capture traffic for this amount of time after sending the packet. + + Returns: + A list of received packets. May be empty if no packets are captured. + """ + return self.traffic_generator.send_packet_and_capture( + packet, send_port, receive_port, duration + ) + + def close(self) -> None: + """Free all resources used by the node""" + self.traffic_generator.close() + super(TGNode, self).close() + + +def create_traffic_generator( + tg_node: TGNode, traffic_generator_config: ScapyTrafficGeneratorConfig +) -> CapturingTrafficGenerator: + """A factory function for creating traffic generator object from user config.""" + + from .scapy import ScapyTrafficGenerator + + match traffic_generator_config.traffic_generator_type: + case TrafficGeneratorType.SCAPY: + return ScapyTrafficGenerator(tg_node, traffic_generator_config) + case _: + raise ConfigurationError( + "Unknown traffic generator: " + f"{traffic_generator_config.traffic_generator_type}" + ) diff --git a/dts/framework/testbed_model/traffic_generator.py b/dts/framework/testbed_model/traffic_generator.py new file mode 100644 index 0000000000..28c35d3ce4 --- /dev/null +++ b/dts/framework/testbed_model/traffic_generator.py @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2022 University of New Hampshire +# Copyright(c) 2023 PANTHEON.tech s.r.o. + +"""The base traffic generator. + +These traffic generators can't capture received traffic, +only count the number of received packets. +""" + +from abc import ABC, abstractmethod + +from scapy.packet import Packet # type: ignore[import] + +from framework.logger import DTSLOG +from framework.utils import get_packet_summaries + +from .hw.port import Port + + +class TrafficGenerator(ABC): + """The base traffic generator. + + Defines the few basic methods that each traffic generator must implement. + """ + + _logger: DTSLOG + + def send_packet(self, packet: Packet, port: Port) -> None: + """Send a packet and block until it is fully sent. + + What fully sent means is defined by the traffic generator. + + Args: + packet: The packet to send. + port: The egress port on the TG node. + """ + self.send_packets([packet], port) + + def send_packets(self, packets: list[Packet], port: Port) -> None: + """Send packets and block until they are fully sent. + + What fully sent means is defined by the traffic generator. + + Args: + packets: The packets to send. + port: The egress port on the TG node. + """ + self._logger.info(f"Sending packet{'s' if len(packets) > 1 else ''}.") + self._logger.debug(get_packet_summaries(packets)) + self._send_packets(packets, port) + + @abstractmethod + def _send_packets(self, packets: list[Packet], port: Port) -> None: + """ + The extended classes must implement this method which + sends packets on send_port. The method should block until all packets + are fully sent. + """ + + @property + def is_capturing(self) -> bool: + """Whether this traffic generator can capture traffic. + + Returns: + True if the traffic generator can capture traffic, False otherwise. + """ + return False + + @abstractmethod + def close(self) -> None: + """Free all resources used by the traffic generator.""" diff --git a/dts/framework/utils.py b/dts/framework/utils.py index 60abe46edf..d27c2c5b5f 100644 --- a/dts/framework/utils.py +++ b/dts/framework/utils.py @@ -4,6 +4,7 @@ # Copyright(c) 2022-2023 University of New Hampshire import atexit +import json import os import subprocess import sys @@ -11,6 +12,8 @@ from pathlib import Path from subprocess import SubprocessError +from scapy.packet import Packet # type: ignore[import] + from .exception import ConfigurationError @@ -64,6 +67,16 @@ def expand_range(range_str: str) -> list[int]: return expanded_range +def get_packet_summaries(packets: list[Packet]): + if len(packets) == 1: + packet_summaries = packets[0].summary() + else: + packet_summaries = json.dumps( + list(map(lambda pkt: pkt.summary(), packets)), indent=4 + ) + return f"Packet contents: \n{packet_summaries}" + + def RED(text: str) -> str: return f"\u001B[31;1m{str(text)}\u001B[0m" From patchwork Wed Jul 19 14:13:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 129644 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 29E1142EB9; Wed, 19 Jul 2023 16:13:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0F7C542D10; Wed, 19 Jul 2023 16:13:12 +0200 (CEST) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by mails.dpdk.org (Postfix) with ESMTP id 11C22427F5 for ; Wed, 19 Jul 2023 16:13:10 +0200 (CEST) Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-4f95bf5c493so11418433e87.3 for ; Wed, 19 Jul 2023 07:13:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1689775989; x=1690380789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LFdTReZBu+KtiY+0s22o7a7A1yqos7Hmw7I0rKI61lQ=; b=Lg0NgzoY7LxW18mF/UG326Izke5nDR6Frn1I1AUTIA2/7pI3EPDIVoBjpLDnmUT0xN c5OUIRlbrDHvPA8Y0GhUvQjWQjV69b4IntzT3OE/o1S0qiq6ths/MQUxMGMryIJECgJ6 uc0XYOVweIHfTx7ujmnpDyaU5dJ1wY+Es+ROnTW6n+5VCfq0P4b+Yb59jwRwB3reiPsb 7bTpP5HdZncqJYr4OxXprgWU70Azr7u3Xw92unLw6Jckg+YUFF96wccS6ccb6M57xh4Q odyk97KmS7fNMpo7kxKHgkLxno0/8NbOALthCPvdBQ8mupR064dRVJkT10H0kvtMK07k 6rUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689775989; x=1690380789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LFdTReZBu+KtiY+0s22o7a7A1yqos7Hmw7I0rKI61lQ=; b=gUKsb3OvalhqnX3c+6BkSmXQ8lti8Xr7NEXGBvC/Y/llKH+QDnaI4dzqv0pzmUCW// xCKyoNrGt5y0vgg2NFL9/Zwrt7WW3ud5rOp95saCGbboxq4kZRc8xiV8hJ1if6ZFH/Pu FG1GuO1Eczk25Tz9LNCQiXmWyTuMfqukvg+Wv4YP+Z6sH6PzItMlxaKLG8cUg6ydxXb2 YYST5mvyGO+44X4YgC9mwSI1Lpoc0qb2iuRyJAEqnD8fw4pvCYiuXHDZjTf333MvZk9n 1fit9ez5juUevrwaWy6aMLqyTVxrbOiExihW5YzFJMtX7H6rOrW6PMrkHfeoLR4MQXAF x5IA== X-Gm-Message-State: ABy/qLYwVcePM2Ef1HwpGAI80ouj+uV9JAclhwiuCjqjx2Q6gqkZ+Rf+ KCGoJbCSRehDUHUYwGiXydEZ6Q== X-Google-Smtp-Source: APBJJlF0F7bOceEV2mvgfnLS/ZxOaNo1+5akulQ5Mv8+jCZ5S4wdnVw0QGhlmvhK09muzxM7noYqgg== X-Received: by 2002:a19:7b0f:0:b0:4f8:6833:b13c with SMTP id w15-20020a197b0f000000b004f86833b13cmr24751lfc.14.1689775989639; Wed, 19 Jul 2023 07:13:09 -0700 (PDT) Received: from jlinkes-PT-Latitude-5530.. (ip-46.34.247.144.o2inet.sk. [46.34.247.144]) by smtp.gmail.com with ESMTPSA id q8-20020a056402040800b0051e2809395bsm2721979edv.63.2023.07.19.07.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 07:13:08 -0700 (PDT) From: =?utf-8?q?Juraj_Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, lijuan.tu@intel.com, bruce.richardson@intel.com, jspewock@iol.unh.edu, probb@iol.unh.edu Cc: dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= Subject: [PATCH v3 4/6] dts: add python remote interactive shell Date: Wed, 19 Jul 2023 16:13:01 +0200 Message-Id: <20230719141303.33284-5-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230719141303.33284-1-juraj.linkes@pantheon.tech> References: <20230717110709.39220-1-juraj.linkes@pantheon.tech> <20230719141303.33284-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The shell can be used to remotely run any Python code interactively. Signed-off-by: Juraj Linkeš --- dts/framework/remote_session/remote/python_shell.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 dts/framework/remote_session/remote/python_shell.py diff --git a/dts/framework/remote_session/remote/python_shell.py b/dts/framework/remote_session/remote/python_shell.py new file mode 100644 index 0000000000..cc3ad48a68 --- /dev/null +++ b/dts/framework/remote_session/remote/python_shell.py @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 PANTHEON.tech s.r.o. + +from pathlib import PurePath + +from .interactive_shell import InteractiveShell + + +class PythonShell(InteractiveShell): + _default_prompt: str = ">>>" + _command_extra_chars: str = "\n" + path: PurePath = PurePath("python3") From patchwork Wed Jul 19 14:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 129645 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7704642EB9; Wed, 19 Jul 2023 16:13:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3F5AE42D2C; Wed, 19 Jul 2023 16:13:13 +0200 (CEST) Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by mails.dpdk.org (Postfix) with ESMTP id 0CC1442C4D for ; Wed, 19 Jul 2023 16:13:11 +0200 (CEST) Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-51e28b299adso9714318a12.2 for ; Wed, 19 Jul 2023 07:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1689775990; x=1690380790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/ocCeGggALcPese7oorKm8tk1DZe7EJvyi6nf35oZQQ=; b=E8g/QpYnGpIqlp6yOCTeBbpTeXwfGPT1aA78c8402eTAcyXflW1XV3AqvcGncsePtP FFTRci+nab5QbP2L0enek320PAWefhh1IC36BSHu7fAt4pPnUYl10o4/zzvb/LUXgPAY mi2M/eCA7r2gnY5WAS8RuMv//eKguz8DdF8InoIc39Uy6FlOuLO/RVK0UTHa5jlsNUXs TJczqy7jqsoAy4cvn4T5cHIAHZRop+fMGWAA0RsdQ2OUsynUQtM7UAqBEJJ7HLyM1Jd4 joZ9H61KTcrUUbg1fBd8bRd1vY8QD+yclMYE93aiVFPjCbCY5jpgYc0uf2/pyrZfroO7 2ppQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689775990; x=1690380790; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/ocCeGggALcPese7oorKm8tk1DZe7EJvyi6nf35oZQQ=; b=Ze8/zdMbI3zVZWoSkQH07blu5G4L0dMJcYujmjxMFFDIvo+cW9Ukm2L3+UASv+X2q0 cbhrgBPpaAlANx8eI1i19q3KXqYaSP8/iUvjgLGQoAW/3xMl7PN9v0piBSQJqlUOfZpl mnZo6SxykFGZOm88Bs2XVTg0P9NAGgJe3WST4/0qR/dSqqEQ7GkHWhRQ0r5FtYTom97d acns5MqVVeczAatmSkM3ijdbkLNgBHsWmJ2jCamO9PWCOHMnTy+Rc9UAclr8y9/FiCUY mDY6Hi1z+YxKaVjQ/CSdZjEhXPceFiQsSxMe8urduKqn1i955WvidmoXssxtWfVuYL/q dSyg== X-Gm-Message-State: ABy/qLZAxXbDYgmqtQhQ6LJIsV6ZhQaCZ2jQES4Rlmci+YoSpc/KUxo5 3hUNVIYRj/fG5plTzc0LKeQnMw== X-Google-Smtp-Source: APBJJlG4/n5DP77Ru7HtmlhoUdu5RIfIiYMylT7/n5nAe5WzNiiMnFPZOXr3PyCBaSa1KK/705Vtbg== X-Received: by 2002:aa7:d7d1:0:b0:51e:ebd:9f5b with SMTP id e17-20020aa7d7d1000000b0051e0ebd9f5bmr2437193eds.36.1689775990733; Wed, 19 Jul 2023 07:13:10 -0700 (PDT) Received: from jlinkes-PT-Latitude-5530.. (ip-46.34.247.144.o2inet.sk. [46.34.247.144]) by smtp.gmail.com with ESMTPSA id q8-20020a056402040800b0051e2809395bsm2721979edv.63.2023.07.19.07.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 07:13:10 -0700 (PDT) From: =?utf-8?q?Juraj_Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, lijuan.tu@intel.com, bruce.richardson@intel.com, jspewock@iol.unh.edu, probb@iol.unh.edu Cc: dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= Subject: [PATCH v3 5/6] dts: scapy traffic generator implementation Date: Wed, 19 Jul 2023 16:13:02 +0200 Message-Id: <20230719141303.33284-6-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230719141303.33284-1-juraj.linkes@pantheon.tech> References: <20230717110709.39220-1-juraj.linkes@pantheon.tech> <20230719141303.33284-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Scapy is a traffic generator capable of sending and receiving traffic. Since it's a software traffic generator, it's not suitable for performance testing, but it is suitable for functional testing. Signed-off-by: Juraj Linkeš --- dts/framework/remote_session/__init__.py | 1 + .../remote_session/remote/__init__.py | 1 + dts/framework/testbed_model/scapy.py | 224 +++++++++++++++++- 3 files changed, 222 insertions(+), 4 deletions(-) diff --git a/dts/framework/remote_session/__init__.py b/dts/framework/remote_session/__init__.py index 1155dd8318..00b6d1f03a 100644 --- a/dts/framework/remote_session/__init__.py +++ b/dts/framework/remote_session/__init__.py @@ -22,6 +22,7 @@ CommandResult, InteractiveRemoteSession, InteractiveShell, + PythonShell, RemoteSession, SSHSession, TestPmdDevice, diff --git a/dts/framework/remote_session/remote/__init__.py b/dts/framework/remote_session/remote/__init__.py index 1d29c3ea0d..06403691a5 100644 --- a/dts/framework/remote_session/remote/__init__.py +++ b/dts/framework/remote_session/remote/__init__.py @@ -9,6 +9,7 @@ from .interactive_remote_session import InteractiveRemoteSession from .interactive_shell import InteractiveShell +from .python_shell import PythonShell from .remote_session import CommandResult, RemoteSession from .ssh_session import SSHSession from .testpmd_shell import TestPmdDevice, TestPmdShell diff --git a/dts/framework/testbed_model/scapy.py b/dts/framework/testbed_model/scapy.py index 1a23dc9fa3..af0d4dbb25 100644 --- a/dts/framework/testbed_model/scapy.py +++ b/dts/framework/testbed_model/scapy.py @@ -12,10 +12,21 @@ a local server proxy. """ +import inspect +import marshal +import time +import types +import xmlrpc.client +from xmlrpc.server import SimpleXMLRPCServer + +import scapy.all # type: ignore[import] +from scapy.layers.l2 import Ether # type: ignore[import] from scapy.packet import Packet # type: ignore[import] from framework.config import OS, ScapyTrafficGeneratorConfig -from framework.logger import getLogger +from framework.logger import DTSLOG, getLogger +from framework.remote_session import PythonShell +from framework.settings import SETTINGS from .capturing_traffic_generator import ( CapturingTrafficGenerator, @@ -24,6 +35,134 @@ from .hw.port import Port from .tg_node import TGNode +""" +========= BEGIN RPC FUNCTIONS ========= + +All of the functions in this section are intended to be exported to a python +shell which runs a scapy RPC server. These functions are made available via that +RPC server to the packet generator. To add a new function to the RPC server, +first write the function in this section. Then, if you need any imports, make sure to +add them to SCAPY_RPC_SERVER_IMPORTS as well. After that, add the function to the list +in EXPORTED_FUNCTIONS. Note that kwargs (keyword arguments) do not work via xmlrpc, +so you may need to construct wrapper functions around many scapy types. +""" + +""" +Add the line needed to import something in a normal python environment +as an entry to this array. It will be imported before any functions are +sent to the server. +""" +SCAPY_RPC_SERVER_IMPORTS = [ + "from scapy.all import *", + "import xmlrpc", + "import sys", + "from xmlrpc.server import SimpleXMLRPCServer", + "import marshal", + "import pickle", + "import types", + "import time", +] + + +def scapy_send_packets_and_capture( + xmlrpc_packets: list[xmlrpc.client.Binary], + send_iface: str, + recv_iface: str, + duration: float, +) -> list[bytes]: + """RPC function to send and capture packets. + + The function is meant to be executed on the remote TG node. + + Args: + xmlrpc_packets: The packets to send. These need to be converted to + xmlrpc.client.Binary before sending to the remote server. + send_iface: The logical name of the egress interface. + recv_iface: The logical name of the ingress interface. + duration: Capture for this amount of time, in seconds. + + Returns: + A list of bytes. Each item in the list represents one packet, which needs + to be converted back upon transfer from the remote node. + """ + scapy_packets = [scapy.all.Packet(packet.data) for packet in xmlrpc_packets] + sniffer = scapy.all.AsyncSniffer( + iface=recv_iface, + store=True, + started_callback=lambda *args: scapy.all.sendp(scapy_packets, iface=send_iface), + ) + sniffer.start() + time.sleep(duration) + return [scapy_packet.build() for scapy_packet in sniffer.stop(join=True)] + + +def scapy_send_packets( + xmlrpc_packets: list[xmlrpc.client.Binary], send_iface: str +) -> None: + """RPC function to send packets. + + The function is meant to be executed on the remote TG node. + It doesn't return anything, only sends packets. + + Args: + xmlrpc_packets: The packets to send. These need to be converted to + xmlrpc.client.Binary before sending to the remote server. + send_iface: The logical name of the egress interface. + + Returns: + A list of bytes. Each item in the list represents one packet, which needs + to be converted back upon transfer from the remote node. + """ + scapy_packets = [scapy.all.Packet(packet.data) for packet in xmlrpc_packets] + scapy.all.sendp(scapy_packets, iface=send_iface, realtime=True, verbose=True) + + +""" +Functions to be exposed by the scapy RPC server. +""" +RPC_FUNCTIONS = [ + scapy_send_packets, + scapy_send_packets_and_capture, +] + +""" +========= END RPC FUNCTIONS ========= +""" + + +class QuittableXMLRPCServer(SimpleXMLRPCServer): + """Basic XML-RPC server that may be extended + by functions serializable by the marshal module. + """ + + def __init__(self, *args, **kwargs): + kwargs["allow_none"] = True + super().__init__(*args, **kwargs) + self.register_introspection_functions() + self.register_function(self.quit) + self.register_function(self.add_rpc_function) + + def quit(self) -> None: + self._BaseServer__shutdown_request = True + return None + + def add_rpc_function(self, name: str, function_bytes: xmlrpc.client.Binary): + """Add a function to the server. + + This is meant to be executed remotely. + + Args: + name: The name of the function. + function_bytes: The code of the function. + """ + function_code = marshal.loads(function_bytes.data) + function = types.FunctionType(function_code, globals(), name) + self.register_function(function) + + def serve_forever(self, poll_interval: float = 0.5) -> None: + print("XMLRPC OK") + super().serve_forever(poll_interval) + class ScapyTrafficGenerator(CapturingTrafficGenerator): """Provides access to scapy functions via an RPC interface. @@ -41,10 +180,19 @@ class ScapyTrafficGenerator(CapturingTrafficGenerator): Arguments: tg_node: The node where the traffic generator resides. config: The user configuration of the traffic generator. + + Attributes: + session: The exclusive interactive remote session created by the Scapy + traffic generator where the XML-RPC server runs. + rpc_server_proxy: The object used by clients to execute functions + on the XML-RPC server. """ + session: PythonShell + rpc_server_proxy: xmlrpc.client.ServerProxy _config: ScapyTrafficGeneratorConfig _tg_node: TGNode + _logger: DTSLOG def __init__(self, tg_node: TGNode, config: ScapyTrafficGeneratorConfig): self._config = config @@ -57,8 +205,58 @@ def __init__(self, tg_node: TGNode, config: ScapyTrafficGeneratorConfig): self._tg_node.config.os == OS.linux ), "Linux is the only supported OS for scapy traffic generation" + self.session = self._tg_node.create_interactive_shell( + PythonShell, timeout=5, privileged=True + ) + + # import libs in remote python console + for import_statement in SCAPY_RPC_SERVER_IMPORTS: + self.session.send_command(import_statement) + + # start the server + xmlrpc_server_listen_port = 8000 + self._start_xmlrpc_server_in_remote_python(xmlrpc_server_listen_port) + + # connect to the server + server_url = ( + f"http://{self._tg_node.config.hostname}:{xmlrpc_server_listen_port}" + ) + self.rpc_server_proxy = xmlrpc.client.ServerProxy( + server_url, allow_none=True, verbose=SETTINGS.verbose + ) + + # add functions to the server + for function in RPC_FUNCTIONS: + # A slightly hacky way to move a function to the remote server. + # It is constructed from the name and code on the other side. + # Pickle cannot handle functions, nor can any of the other serialization + # frameworks aside from the libraries used to generate pyc files, which + # are even more messy to work with. + function_bytes = marshal.dumps(function.__code__) + self.rpc_server_proxy.add_rpc_function(function.__name__, function_bytes) + + def _start_xmlrpc_server_in_remote_python(self, listen_port: int): + # load the source of the function + src = inspect.getsource(QuittableXMLRPCServer) + # Lines with only whitespace break the repl if in the middle of a function + # or class, so strip all lines containing only whitespace + src = "\n".join( + [line for line in src.splitlines() if not line.isspace() and line != ""] + ) + + spacing = "\n" * 4 + + # execute it in the python terminal + self.session.send_command(spacing + src + spacing) + self.session.send_command( + f"server = QuittableXMLRPCServer(('0.0.0.0', {listen_port}));" + f"server.serve_forever()", + "XMLRPC OK", + ) + def _send_packets(self, packets: list[Packet], port: Port) -> None: - raise NotImplementedError() + packets = [packet.build() for packet in packets] + self.rpc_server_proxy.scapy_send_packets(packets, port.logical_name) def _send_packets_and_capture( self, @@ -68,7 +266,25 @@ def _send_packets_and_capture( duration: float, capture_name: str = _get_default_capture_name(), ) -> list[Packet]: - raise NotImplementedError() + binary_packets = [packet.build() for packet in packets] + + xmlrpc_packets: list[ + xmlrpc.client.Binary + ] = self.rpc_server_proxy.scapy_send_packets_and_capture( + binary_packets, + send_port.logical_name, + receive_port.logical_name, + duration, + ) # type: ignore[assignment] + + scapy_packets = [Ether(packet.data) for packet in xmlrpc_packets] + return scapy_packets def close(self): - pass + try: + self.rpc_server_proxy.quit() + except ConnectionRefusedError: + # Because the python instance closes, we get no RPC response. + # Thus, this error is expected + pass + self.session.close() From patchwork Wed Jul 19 14:13:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juraj_Linke=C5=A1?= X-Patchwork-Id: 129646 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EFDCF42EB9; Wed, 19 Jul 2023 16:13:47 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8A52842D33; Wed, 19 Jul 2023 16:13:14 +0200 (CEST) Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by mails.dpdk.org (Postfix) with ESMTP id 26FD042D1A for ; Wed, 19 Jul 2023 16:13:12 +0200 (CEST) Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-51e5e4c6026so9856917a12.0 for ; Wed, 19 Jul 2023 07:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1689775992; x=1690380792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hbBQxh6qZUKii8+3FXzVySz2o7TnPCxR6Sn2yjaMZdI=; b=tfUajYQN6sob9oasohOuLTXR4ZJqP9x8kUDWyBIpxryBJg4Fni5y+AbP+MEhWDr9NQ YRGM38FKTT9TsG0x7uDXPgXMPPSxw8Mi6nPRfBoSSvx3be3cQktZoLqhtaYskvWSJACw ANbAalIya+tiKdAQpI0e46PNuyqquJkYyg0/amNiON9syzjoxg0Scs0HQsSJgXjAMlDT HaqsD7Hro765qXSOC/oBNi4qmQeXVG5jfG0pN4cqypvdv+3bLVLOvWBNyMc6Tlc5P2nK 54uZXEHs+3+YLdFkTuztR1GerNb9B6M5cc3DcsZAF2HNWcxGHrkugOOwM4Av/ntFsn8M 9Eqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689775992; x=1690380792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hbBQxh6qZUKii8+3FXzVySz2o7TnPCxR6Sn2yjaMZdI=; b=MJnwXc/LEcpXxMchYxpxbbK65eOspo1XdhgXFKQK6+Yuxj3aF6k36SNLuEn7KOTbew bq7K4YUHI26ZLXZDRDyFgmrABgRCy2Z/7k3gdGsXxLnx3qLg68BRvRzVTZ2tcrhfK9IO y9zobI0gjC0GpJ9fJ1vX+6+OfKKdqEO6shqXiTl7SPo6hU0m4Q3xFUusg73Zo1d0c99Q 5KoXRf2MVqot2gErs1m82UzcFwnQbbXe7QssHQMpHKWwZchEWoYMvszyzjXSOCxoRrVk kFL8Jjj9G9LvDOiRqqBlFZHeSha0nPCnK4Kyey+DGN/kAQhTJj5COnJQPqYibAF2cTqH s2yQ== X-Gm-Message-State: ABy/qLbiPmqItm5ZVFaSRNrCnFmdz5LRdPYbuYiXwS39EEuwVUVU0GBC Cic9vB1HBxSwYlapLg86yo7OGg== X-Google-Smtp-Source: APBJJlHRYCqwazyA+z069RXCuC2RIwGo4tLN5yCScktIUL+bZcIRnHAq4yGIyPJyRxe08YXI/6cDqw== X-Received: by 2002:a05:6402:517b:b0:51e:5169:6262 with SMTP id d27-20020a056402517b00b0051e51696262mr2629814ede.15.1689775991730; Wed, 19 Jul 2023 07:13:11 -0700 (PDT) Received: from jlinkes-PT-Latitude-5530.. (ip-46.34.247.144.o2inet.sk. [46.34.247.144]) by smtp.gmail.com with ESMTPSA id q8-20020a056402040800b0051e2809395bsm2721979edv.63.2023.07.19.07.13.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 07:13:11 -0700 (PDT) From: =?utf-8?q?Juraj_Linke=C5=A1?= To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, lijuan.tu@intel.com, bruce.richardson@intel.com, jspewock@iol.unh.edu, probb@iol.unh.edu Cc: dev@dpdk.org, =?utf-8?q?Juraj_Linke=C5=A1?= Subject: [PATCH v3 6/6] dts: add basic UDP test case Date: Wed, 19 Jul 2023 16:13:03 +0200 Message-Id: <20230719141303.33284-7-juraj.linkes@pantheon.tech> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230719141303.33284-1-juraj.linkes@pantheon.tech> References: <20230717110709.39220-1-juraj.linkes@pantheon.tech> <20230719141303.33284-1-juraj.linkes@pantheon.tech> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The test cases showcases the scapy traffic generator code. Signed-off-by: Juraj Linkeš Acked-by: Jeremy Spewock --- dts/conf.yaml | 1 + dts/framework/config/conf_yaml_schema.json | 3 +- dts/framework/remote_session/linux_session.py | 20 +- dts/framework/remote_session/os_session.py | 20 +- dts/framework/test_suite.py | 217 +++++++++++++++++- dts/framework/testbed_model/node.py | 14 +- dts/framework/testbed_model/sut_node.py | 3 + dts/tests/TestSuite_os_udp.py | 45 ++++ 8 files changed, 315 insertions(+), 8 deletions(-) create mode 100644 dts/tests/TestSuite_os_udp.py diff --git a/dts/conf.yaml b/dts/conf.yaml index 0440d1d20a..37967daea0 100644 --- a/dts/conf.yaml +++ b/dts/conf.yaml @@ -13,6 +13,7 @@ executions: skip_smoke_tests: false # optional flag that allows you to skip smoke tests test_suites: - hello_world + - os_udp system_under_test_node: node_name: "SUT 1" vdevs: # optional; if removed, vdevs won't be used in the execution diff --git a/dts/framework/config/conf_yaml_schema.json b/dts/framework/config/conf_yaml_schema.json index 936a4bac5b..84e45fe3c2 100644 --- a/dts/framework/config/conf_yaml_schema.json +++ b/dts/framework/config/conf_yaml_schema.json @@ -185,7 +185,8 @@ "test_suite": { "type": "string", "enum": [ - "hello_world" + "hello_world", + "os_udp" ] }, "test_target": { diff --git a/dts/framework/remote_session/linux_session.py b/dts/framework/remote_session/linux_session.py index decce4039c..a3f1a6bf3b 100644 --- a/dts/framework/remote_session/linux_session.py +++ b/dts/framework/remote_session/linux_session.py @@ -3,7 +3,8 @@ # Copyright(c) 2023 University of New Hampshire import json -from typing import TypedDict +from ipaddress import IPv4Interface, IPv6Interface +from typing import TypedDict, Union from typing_extensions import NotRequired @@ -181,3 +182,20 @@ def configure_port_state(self, port: Port, enable: bool) -> None: self.send_command( f"ip link set dev {port.logical_name} {state}", privileged=True ) + + def configure_port_ip_address( + self, + address: Union[IPv4Interface, IPv6Interface], + port: Port, + delete: bool, + ) -> None: + command = "del" if delete else "add" + self.send_command( + f"ip address {command} {address} dev {port.logical_name}", + privileged=True, + verify=True, + ) + + def configure_ipv4_forwarding(self, enable: bool) -> None: + state = 1 if enable else 0 + self.send_command(f"sysctl -w net.ipv4.ip_forward={state}", privileged=True) diff --git a/dts/framework/remote_session/os_session.py b/dts/framework/remote_session/os_session.py index ab4bfbfe4c..8a709eac1c 100644 --- a/dts/framework/remote_session/os_session.py +++ b/dts/framework/remote_session/os_session.py @@ -4,8 +4,9 @@ from abc import ABC, abstractmethod from collections.abc import Iterable +from ipaddress import IPv4Interface, IPv6Interface from pathlib import PurePath -from typing import Type, TypeVar +from typing import Type, TypeVar, Union from framework.config import Architecture, NodeConfiguration, NodeInfo from framework.logger import DTSLOG @@ -264,3 +265,20 @@ def configure_port_state(self, port: Port, enable: bool) -> None: """ Enable/disable port. """ + + @abstractmethod + def configure_port_ip_address( + self, + address: Union[IPv4Interface, IPv6Interface], + port: Port, + delete: bool, + ) -> None: + """ + Configure (add or delete) an IP address of the input port. + """ + + @abstractmethod + def configure_ipv4_forwarding(self, enable: bool) -> None: + """ + Enable IPv4 forwarding in the underlying OS. + """ diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py index 056460dd05..3b890c0451 100644 --- a/dts/framework/test_suite.py +++ b/dts/framework/test_suite.py @@ -9,7 +9,13 @@ import importlib import inspect import re +from ipaddress import IPv4Interface, IPv6Interface, ip_interface from types import MethodType +from typing import Union + +from scapy.layers.inet import IP # type: ignore[import] +from scapy.layers.l2 import Ether # type: ignore[import] +from scapy.packet import Packet, Padding # type: ignore[import] from .exception import ( BlockingTestSuiteError, @@ -21,6 +27,8 @@ from .settings import SETTINGS from .test_result import BuildTargetResult, Result, TestCaseResult, TestSuiteResult from .testbed_model import SutNode, TGNode +from .testbed_model.hw.port import Port, PortLink +from .utils import get_packet_summaries class TestSuite(object): @@ -47,6 +55,15 @@ class TestSuite(object): _test_cases_to_run: list[str] _func: bool _result: TestSuiteResult + _port_links: list[PortLink] + _sut_port_ingress: Port + _sut_port_egress: Port + _sut_ip_address_ingress: Union[IPv4Interface, IPv6Interface] + _sut_ip_address_egress: Union[IPv4Interface, IPv6Interface] + _tg_port_ingress: Port + _tg_port_egress: Port + _tg_ip_address_ingress: Union[IPv4Interface, IPv6Interface] + _tg_ip_address_egress: Union[IPv4Interface, IPv6Interface] def __init__( self, @@ -63,6 +80,31 @@ def __init__( self._test_cases_to_run.extend(SETTINGS.test_cases) self._func = func self._result = build_target_result.add_test_suite(self.__class__.__name__) + self._port_links = [] + self._process_links() + self._sut_port_ingress, self._tg_port_egress = ( + self._port_links[0].sut_port, + self._port_links[0].tg_port, + ) + self._sut_port_egress, self._tg_port_ingress = ( + self._port_links[1].sut_port, + self._port_links[1].tg_port, + ) + self._sut_ip_address_ingress = ip_interface("192.168.100.2/24") + self._sut_ip_address_egress = ip_interface("192.168.101.2/24") + self._tg_ip_address_egress = ip_interface("192.168.100.3/24") + self._tg_ip_address_ingress = ip_interface("192.168.101.3/24") + + def _process_links(self) -> None: + for sut_port in self.sut_node.ports: + for tg_port in self.tg_node.ports: + if (sut_port.identifier, sut_port.peer) == ( + tg_port.peer, + tg_port.identifier, + ): + self._port_links.append( + PortLink(sut_port=sut_port, tg_port=tg_port) + ) def set_up_suite(self) -> None: """ @@ -85,14 +127,181 @@ def tear_down_test_case(self) -> None: Tear down the previously created test fixtures after each test case. """ + def configure_testbed_ipv4(self, restore: bool = False) -> None: + delete = True if restore else False + enable = False if restore else True + self._configure_ipv4_forwarding(enable) + self.sut_node.configure_port_ip_address( + self._sut_ip_address_egress, self._sut_port_egress, delete + ) + self.sut_node.configure_port_state(self._sut_port_egress, enable) + self.sut_node.configure_port_ip_address( + self._sut_ip_address_ingress, self._sut_port_ingress, delete + ) + self.sut_node.configure_port_state(self._sut_port_ingress, enable) + self.tg_node.configure_port_ip_address( + self._tg_ip_address_ingress, self._tg_port_ingress, delete + ) + self.tg_node.configure_port_state(self._tg_port_ingress, enable) + self.tg_node.configure_port_ip_address( + self._tg_ip_address_egress, self._tg_port_egress, delete + ) + self.tg_node.configure_port_state(self._tg_port_egress, enable) + + def _configure_ipv4_forwarding(self, enable: bool) -> None: + self.sut_node.configure_ipv4_forwarding(enable) + + def send_packet_and_capture( + self, packet: Packet, duration: float = 1 + ) -> list[Packet]: + """ + Send a packet through the appropriate interface and + receive on the appropriate interface. + Modify the packet with l3/l2 addresses corresponding + to the testbed and desired traffic. + """ + packet = self._adjust_addresses(packet) + return self.tg_node.send_packet_and_capture( + packet, self._tg_port_egress, self._tg_port_ingress, duration + ) + + def get_expected_packet(self, packet: Packet) -> Packet: + return self._adjust_addresses(packet, expected=True) + + def _adjust_addresses(self, packet: Packet, expected: bool = False) -> Packet: + """ + Assumptions: + Two links between SUT and TG, one link is TG -> SUT, + the other SUT -> TG. + """ + if expected: + # The packet enters the TG from SUT + # update l2 addresses + packet.src = self._sut_port_egress.mac_address + packet.dst = self._tg_port_ingress.mac_address + + # The packet is routed from TG egress to TG ingress + # update l3 addresses + packet.payload.src = self._tg_ip_address_egress.ip.exploded + packet.payload.dst = self._tg_ip_address_ingress.ip.exploded + else: + # The packet leaves TG towards SUT + # update l2 addresses + packet.src = self._tg_port_egress.mac_address + packet.dst = self._sut_port_ingress.mac_address + + # The packet is routed from TG egress to TG ingress + # update l3 addresses + packet.payload.src = self._tg_ip_address_egress.ip.exploded + packet.payload.dst = self._tg_ip_address_ingress.ip.exploded + + return Ether(packet.build()) + def verify(self, condition: bool, failure_description: str) -> None: if not condition: + self._fail_test_case_verify(failure_description) + + def _fail_test_case_verify(self, failure_description: str) -> None: + self._logger.debug( + "A test case failed, showing the last 10 commands executed on SUT:" + ) + for command_res in self.sut_node.main_session.remote_session.history[-10:]: + self._logger.debug(command_res.command) + self._logger.debug( + "A test case failed, showing the last 10 commands executed on TG:" + ) + for command_res in self.tg_node.main_session.remote_session.history[-10:]: + self._logger.debug(command_res.command) + raise TestCaseVerifyError(failure_description) + + def verify_packets( + self, expected_packet: Packet, received_packets: list[Packet] + ) -> None: + for received_packet in received_packets: + if self._compare_packets(expected_packet, received_packet): + break + else: + self._logger.debug( + f"The expected packet {get_packet_summaries(expected_packet)} " + f"not found among received {get_packet_summaries(received_packets)}" + ) + self._fail_test_case_verify( + "An expected packet not found among received packets." + ) + + def _compare_packets( + self, expected_packet: Packet, received_packet: Packet + ) -> bool: + self._logger.debug( + "Comparing packets: \n" + f"{expected_packet.summary()}\n" + f"{received_packet.summary()}" + ) + + l3 = IP in expected_packet.layers() + self._logger.debug("Found l3 layer") + + received_payload = received_packet + expected_payload = expected_packet + while received_payload and expected_payload: + self._logger.debug("Comparing payloads:") + self._logger.debug(f"Received: {received_payload}") + self._logger.debug(f"Expected: {expected_payload}") + if received_payload.__class__ == expected_payload.__class__: + self._logger.debug("The layers are the same.") + if received_payload.__class__ == Ether: + if not self._verify_l2_frame(received_payload, l3): + return False + elif received_payload.__class__ == IP: + if not self._verify_l3_packet(received_payload, expected_payload): + return False + else: + # Different layers => different packets + return False + received_payload = received_payload.payload + expected_payload = expected_payload.payload + + if expected_payload: self._logger.debug( - "A test case failed, showing the last 10 commands executed on SUT:" + f"The expected packet did not contain {expected_payload}." ) - for command_res in self.sut_node.main_session.remote_session.history[-10:]: - self._logger.debug(command_res.command) - raise TestCaseVerifyError(failure_description) + return False + if received_payload and received_payload.__class__ != Padding: + self._logger.debug( + "The received payload had extra layers which were not padding." + ) + return False + return True + + def _verify_l2_frame(self, received_packet: Ether, l3: bool) -> bool: + self._logger.debug("Looking at the Ether layer.") + self._logger.debug( + f"Comparing received dst mac '{received_packet.dst}' " + f"with expected '{self._tg_port_ingress.mac_address}'." + ) + if received_packet.dst != self._tg_port_ingress.mac_address: + return False + + expected_src_mac = self._tg_port_egress.mac_address + if l3: + expected_src_mac = self._sut_port_egress.mac_address + self._logger.debug( + f"Comparing received src mac '{received_packet.src}' " + f"with expected '{expected_src_mac}'." + ) + if received_packet.src != expected_src_mac: + return False + + return True + + def _verify_l3_packet(self, received_packet: IP, expected_packet: IP) -> bool: + self._logger.debug("Looking at the IP layer.") + if ( + received_packet.src != expected_packet.src + or received_packet.dst != expected_packet.dst + ): + return False + return True def run(self) -> None: """ diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py index c666dfbf4e..fc01e0bf8e 100644 --- a/dts/framework/testbed_model/node.py +++ b/dts/framework/testbed_model/node.py @@ -8,7 +8,8 @@ """ from abc import ABC -from typing import Any, Callable, Type +from ipaddress import IPv4Interface, IPv6Interface +from typing import Any, Callable, Type, Union from framework.config import ( BuildTargetConfiguration, @@ -221,6 +222,17 @@ def configure_port_state(self, port: Port, enable: bool = True) -> None: """ self.main_session.configure_port_state(port, enable) + def configure_port_ip_address( + self, + address: Union[IPv4Interface, IPv6Interface], + port: Port, + delete: bool = False, + ) -> None: + """ + Configure the IP address of a port on this node. + """ + self.main_session.configure_port_ip_address(address, port, delete) + def close(self) -> None: """ Close all connections and free other resources. diff --git a/dts/framework/testbed_model/sut_node.py b/dts/framework/testbed_model/sut_node.py index f0b017a383..202aebfd06 100644 --- a/dts/framework/testbed_model/sut_node.py +++ b/dts/framework/testbed_model/sut_node.py @@ -351,6 +351,9 @@ def run_dpdk_app( f"{app_path} {eal_args}", timeout, privileged=True, verify=True ) + def configure_ipv4_forwarding(self, enable: bool) -> None: + self.main_session.configure_ipv4_forwarding(enable) + def create_interactive_shell( self, shell_cls: Type[InteractiveShellType], diff --git a/dts/tests/TestSuite_os_udp.py b/dts/tests/TestSuite_os_udp.py new file mode 100644 index 0000000000..9b5f39711d --- /dev/null +++ b/dts/tests/TestSuite_os_udp.py @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2023 PANTHEON.tech s.r.o. + +""" +Configure SUT node to route traffic from if1 to if2. +Send a packet to the SUT node, verify it comes back on the second port on the TG node. +""" + +from scapy.layers.inet import IP, UDP # type: ignore[import] +from scapy.layers.l2 import Ether # type: ignore[import] + +from framework.test_suite import TestSuite + + +class TestOSUdp(TestSuite): + def set_up_suite(self) -> None: + """ + Setup: + Configure SUT ports and SUT to route traffic from if1 to if2. + """ + + self.configure_testbed_ipv4() + + def test_os_udp(self) -> None: + """ + Steps: + Send a UDP packet. + Verify: + The packet with proper addresses arrives at the other TG port. + """ + + packet = Ether() / IP() / UDP() + + received_packets = self.send_packet_and_capture(packet) + + expected_packet = self.get_expected_packet(packet) + + self.verify_packets(expected_packet, received_packets) + + def tear_down_suite(self) -> None: + """ + Teardown: + Remove the SUT port configuration configured in setup. + """ + self.configure_testbed_ipv4(restore=True)