From 58f64476800d800968fa9b0e7a88cb55bf79d9c9 Mon Sep 17 00:00:00 2001 From: nforsg Date: Thu, 17 Aug 2023 11:54:19 +0200 Subject: [PATCH] network_servide.py --- .../dao/emulation_config/network_service.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/simulation-system/libs/csle-common/src/csle_common/dao/emulation_config/network_service.py b/simulation-system/libs/csle-common/src/csle_common/dao/emulation_config/network_service.py index 62472bc31..4dba55b97 100644 --- a/simulation-system/libs/csle-common/src/csle_common/dao/emulation_config/network_service.py +++ b/simulation-system/libs/csle-common/src/csle_common/dao/emulation_config/network_service.py @@ -1,4 +1,5 @@ from typing import Optional, List, Dict, Any +import random import csle_common.constants.constants as constants from csle_common.dao.emulation_config.transport_protocol import TransportProtocol from csle_common.dao.emulation_config.credential import Credential @@ -40,7 +41,7 @@ def to_dict(self) -> Dict[str, Any]: :return: a dict representation of the object """ - d = {} + d: Dict[str, Any] = {} d["protocol"] = self.protocol d["port"] = self.port d["name"] = self.name @@ -102,9 +103,16 @@ def from_credential(credential: Credential) -> "NetworkService": :return: the network service representation """ - service = NetworkService(protocol=credential.protocol, port=credential.port, - name=credential.service, - credentials=[credential]) + if credential.protocol is None: + protocol = TransportProtocol(random.choice([0, 1])) + else: + protocol = credential.protocol + if credential.service is None: + name = "" + else: + name = credential.service + service = NetworkService(protocol=protocol, port=credential.port, + name=name, credentials=[credential]) return service @staticmethod