Commit 5ea9daf2 authored by Carlos Natalino's avatar Carlos Natalino
Browse files

Including regex as a way to find the device index from the device name.

parent d167ccc7
Loading
Loading
Loading
Loading
+11 −11
Original line number Original line Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.


import logging, json, random, threading
import logging, json, random, re, threading
from typing import Dict, Optional, Set, Tuple
from typing import Dict, Optional, Set, Tuple
from common.proto.context_pb2 import Empty, IsolationLevelEnum, TopologyId
from common.proto.context_pb2 import Empty, IsolationLevelEnum, TopologyId
from common.tools.grpc.Tools import grpc_message_to_json
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_device_name = self._device_data[src_device_uuid]['name']
            src_endpoint_name = self._device_endpoint_data[src_device_uuid][src_endpoint_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_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)
            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_device_name = self._device_data[dst_device_uuid]['name']
            dst_endpoint_name = self._device_endpoint_data[dst_device_uuid][dst_endpoint_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)
            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)
            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_device_name = self._device_data[src_device_uuid]['name']
            src_endpoint_name = self._device_endpoint_data[src_device_uuid][src_endpoint_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_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)
            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)
            src_address_ip = '10.{:d}.{:d}.{:d}'.format(x, y, src_router_num)


            dst_device_name = self._device_data[dst_device_uuid]['name']
            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_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)
            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)
            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)
            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)
            circuit_id = '{:03d}'.format(vlan_id)


            src_device_name = self._device_data[src_device_uuid]['name']
            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_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 = [
            config_rules = [
                json_config_rule_set('/settings', {
                json_config_rule_set('/settings', {
@@ -460,13 +460,13 @@ class RequestGenerator:


            src_device_name = self._device_data[src_device_uuid]['name']
            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_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_router_id = '10.0.0.{:d}'.format(int(re.findall(r'^\D*(\d+)', src_device_name)[0]))
            src_address_ip = '.'.join([src_device_name.replace('R', ''), '0'] + src_endpoint_name.split('/'))
            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_device_name = self._device_data[dst_device_uuid]['name']
            dst_endpoint_name = self._device_endpoint_data[dst_device_uuid][dst_endpoint_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_router_id = '10.0.0.{:d}'.format(int(re.findall(r'^\D*(\d+)', dst_device_name)[0]))
            dst_address_ip = '.'.join([dst_device_name.replace('R', ''), '0'] + dst_endpoint_name.split('/'))
            dst_address_ip = '.'.join([re.findall(r'^\D*(\d+)', dst_device_name)[0], '0'] + dst_endpoint_name.split('/'))


            config_rules = [
            config_rules = [
                json_config_rule_set('/settings', {
                json_config_rule_set('/settings', {