From 5ea9daf28652ec8adac2cb0b514d264fa0009a45 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Wed, 19 Apr 2023 14:49:00 +0200 Subject: [PATCH] Including regex as a way to find the device index from the device name. --- .../load_gen/RequestGenerator.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/load_generator/load_gen/RequestGenerator.py b/src/load_generator/load_gen/RequestGenerator.py index 5c56ea6ec..cf56e221d 100644 --- a/src/load_generator/load_gen/RequestGenerator.py +++ b/src/load_generator/load_gen/RequestGenerator.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging, json, random, threading +import logging, json, random, re, threading from typing import Dict, Optional, Set, Tuple from common.proto.context_pb2 import Empty, IsolationLevelEnum, TopologyId from common.tools.grpc.Tools import grpc_message_to_json @@ -261,12 +261,12 @@ class RequestGenerator: src_device_name = self._device_data[src_device_uuid]['name'] src_endpoint_name = self._device_endpoint_data[src_device_uuid][src_endpoint_uuid]['name'] src_router_id = ROUTER_ID.get(src_device_name) - src_router_num = int(src_device_name.replace('R', '')) + src_router_num = int(re.findall(r'^\D*(\d+)', src_device_name)[0]) if src_router_id is None: src_router_id = '10.0.0.{:d}'.format(src_router_num) dst_device_name = self._device_data[dst_device_uuid]['name'] dst_endpoint_name = self._device_endpoint_data[dst_device_uuid][dst_endpoint_uuid]['name'] - dst_router_num = int(dst_device_name.replace('R', '')) + dst_router_num = int(re.findall(r'^\D*(\d+)', dst_device_name)[0]) dst_router_id = ROUTER_ID.get(dst_device_name) if dst_router_id is None: dst_router_id = '10.0.0.{:d}'.format(dst_router_num) @@ -314,13 +314,13 @@ class RequestGenerator: src_device_name = self._device_data[src_device_uuid]['name'] src_endpoint_name = self._device_endpoint_data[src_device_uuid][src_endpoint_uuid]['name'] src_router_id = ROUTER_ID.get(src_device_name) - src_router_num = int(src_device_name.replace('R', '')) + src_router_num = int(re.findall(r'^\D*(\d+)', src_device_name)[0]) if src_router_id is None: src_router_id = '10.0.0.{:d}'.format(src_router_num) src_address_ip = '10.{:d}.{:d}.{:d}'.format(x, y, src_router_num) dst_device_name = self._device_data[dst_device_uuid]['name'] dst_endpoint_name = self._device_endpoint_data[dst_device_uuid][dst_endpoint_uuid]['name'] - dst_router_num = int(dst_device_name.replace('R', '')) + dst_router_num = int(re.findall(r'^\D*(\d+)', dst_device_name)[0]) dst_router_id = ROUTER_ID.get(dst_device_name) if dst_router_id is None: dst_router_id = '10.0.0.{:d}'.format(dst_router_num) dst_address_ip = '10.{:d}.{:d}.{:d}'.format(y, x, dst_router_num) @@ -425,10 +425,10 @@ class RequestGenerator: circuit_id = '{:03d}'.format(vlan_id) src_device_name = self._device_data[src_device_uuid]['name'] - src_router_id = '10.0.0.{:d}'.format(int(src_device_name.replace('R', ''))) + src_router_id = '10.0.0.{:d}'.format(int(re.findall(r'^\D*(\d+)', src_device_name)[0])) dst_device_name = self._device_data[dst_device_uuid]['name'] - dst_router_id = '10.0.0.{:d}'.format(int(dst_device_name.replace('R', ''))) + dst_router_id = '10.0.0.{:d}'.format(int(re.findall(r'^\D*(\d+)', dst_device_name)[0])) config_rules = [ json_config_rule_set('/settings', { @@ -460,13 +460,13 @@ class RequestGenerator: src_device_name = self._device_data[src_device_uuid]['name'] src_endpoint_name = self._device_endpoint_data[src_device_uuid][src_endpoint_uuid]['name'] - src_router_id = '10.0.0.{:d}'.format(int(src_device_name.replace('R', ''))) - src_address_ip = '.'.join([src_device_name.replace('R', ''), '0'] + src_endpoint_name.split('/')) + src_router_id = '10.0.0.{:d}'.format(int(re.findall(r'^\D*(\d+)', src_device_name)[0])) + src_address_ip = '.'.join([re.findall(r'^\D*(\d+)', src_device_name)[0], '0'] + src_endpoint_name.split('/')) dst_device_name = self._device_data[dst_device_uuid]['name'] dst_endpoint_name = self._device_endpoint_data[dst_device_uuid][dst_endpoint_uuid]['name'] - dst_router_id = '10.0.0.{:d}'.format(int(dst_device_name.replace('R', ''))) - dst_address_ip = '.'.join([dst_device_name.replace('R', ''), '0'] + dst_endpoint_name.split('/')) + dst_router_id = '10.0.0.{:d}'.format(int(re.findall(r'^\D*(\d+)', dst_device_name)[0])) + dst_address_ip = '.'.join([re.findall(r'^\D*(\d+)', dst_device_name)[0], '0'] + dst_endpoint_name.split('/')) config_rules = [ json_config_rule_set('/settings', { -- GitLab