Commit 21dac162 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Load Generator component:

- Added logic to track and report num_released requests
parent bb5397fd
Loading
Loading
Loading
Loading
+25 −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, re, threading
import logging, json, random, re, threading, uuid
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
@@ -54,6 +54,7 @@ class RequestGenerator:
        self._parameters = parameters
        self._parameters = parameters
        self._lock = threading.Lock()
        self._lock = threading.Lock()
        self._num_generated = 0
        self._num_generated = 0
        self._num_released = 0
        self._available_device_endpoints : Dict[str, Set[str]] = dict()
        self._available_device_endpoints : Dict[str, Set[str]] = dict()
        self._used_device_endpoints : Dict[str, Dict[str, str]] = dict()
        self._used_device_endpoints : Dict[str, Dict[str, str]] = dict()
        self._endpoint_ids_to_types : Dict[Tuple[str, str], str] = dict()
        self._endpoint_ids_to_types : Dict[Tuple[str, str], str] = dict()
@@ -65,6 +66,9 @@ class RequestGenerator:
    @property
    @property
    def num_generated(self): return self._num_generated
    def num_generated(self): return self._num_generated


    @property
    def num_released(self): return self._num_released

    @property
    @property
    def infinite_loop(self): return self._parameters.num_requests == 0
    def infinite_loop(self): return self._parameters.num_requests == 0


@@ -192,23 +196,18 @@ class RequestGenerator:
            if not self.infinite_loop and (self._num_generated >= self._parameters.num_requests):
            if not self.infinite_loop and (self._num_generated >= self._parameters.num_requests):
                LOGGER.info('Generation Done!')
                LOGGER.info('Generation Done!')
                return True, None, None # completed
                return True, None, None # completed
            self._num_generated += 1
            num_request = self._num_generated

        #request_uuid = str(uuid.uuid4())
        request_uuid = 'svc_{:d}'.format(num_request)


        # choose request type
        request_uuid = str(uuid.uuid4())
        request_type = random.choice(self._parameters.request_types)
        request_type = random.choice(self._parameters.request_types)


        if request_type in {
        if request_type in {
            RequestType.SERVICE_L2NM, RequestType.SERVICE_L3NM, RequestType.SERVICE_TAPI, RequestType.SERVICE_MW
            RequestType.SERVICE_L2NM, RequestType.SERVICE_L3NM, RequestType.SERVICE_TAPI, RequestType.SERVICE_MW
        }:
        }:
            return False, self._compose_service(num_request, request_uuid, request_type), request_type
            return False, self._compose_service(request_uuid, request_type), request_type
        elif request_type in {RequestType.SLICE_L2NM, RequestType.SLICE_L3NM}:
        elif request_type in {RequestType.SLICE_L2NM, RequestType.SLICE_L3NM}:
            return False, self._compose_slice(num_request, request_uuid, request_type), request_type
            return False, self._compose_slice(request_uuid, request_type), request_type


    def _compose_service(self, num_request : int, request_uuid : str, request_type : str) -> Optional[Dict]:
    def _compose_service(self, request_uuid : str, request_type : str) -> Optional[Dict]:
        # choose source endpoint
        # choose source endpoint
        src_endpoint_types = set(ENDPOINT_COMPATIBILITY.keys()) if request_type in {RequestType.SERVICE_TAPI} else None
        src_endpoint_types = set(ENDPOINT_COMPATIBILITY.keys()) if request_type in {RequestType.SERVICE_TAPI} else None
        src = self._use_device_endpoint(request_uuid, request_type, endpoint_types=src_endpoint_types)
        src = self._use_device_endpoint(request_uuid, request_type, endpoint_types=src_endpoint_types)
@@ -237,6 +236,10 @@ class RequestGenerator:
            self._release_device_endpoint(src_device_uuid, src_endpoint_uuid)
            self._release_device_endpoint(src_device_uuid, src_endpoint_uuid)
            return None
            return None


        with self._lock:
            self._num_generated += 1
            num_request = self._num_generated

        # compose endpoints
        # compose endpoints
        dst_device_uuid,dst_endpoint_uuid = dst
        dst_device_uuid,dst_endpoint_uuid = dst
        endpoint_ids = [
        endpoint_ids = [
@@ -383,7 +386,7 @@ class RequestGenerator:
            return json_service_l2nm_planned(
            return json_service_l2nm_planned(
                request_uuid, endpoint_ids=endpoint_ids, constraints=[], config_rules=config_rules)
                request_uuid, endpoint_ids=endpoint_ids, constraints=[], config_rules=config_rules)


    def _compose_slice(self, num_request : int, request_uuid : str, request_type : str) -> Optional[Dict]:
    def _compose_slice(self, request_uuid : str, request_type : str) -> Optional[Dict]:
        # choose source endpoint
        # choose source endpoint
        src = self._use_device_endpoint(request_uuid, request_type)
        src = self._use_device_endpoint(request_uuid, request_type)
        if src is None:
        if src is None:
@@ -404,6 +407,10 @@ class RequestGenerator:
            self._release_device_endpoint(src_device_uuid, src_endpoint_uuid)
            self._release_device_endpoint(src_device_uuid, src_endpoint_uuid)
            return None
            return None


        with self._lock:
            self._num_generated += 1
            num_request = self._num_generated

        # compose endpoints
        # compose endpoints
        dst_device_uuid,dst_endpoint_uuid = dst
        dst_device_uuid,dst_endpoint_uuid = dst
        endpoint_ids = [
        endpoint_ids = [
@@ -505,8 +512,15 @@ class RequestGenerator:
                device_uuid = endpoint_id['device_id']['device_uuid']['uuid']
                device_uuid = endpoint_id['device_id']['device_uuid']['uuid']
                endpoint_uuid = endpoint_id['endpoint_uuid']['uuid']
                endpoint_uuid = endpoint_id['endpoint_uuid']['uuid']
                self._release_device_endpoint(device_uuid, endpoint_uuid)
                self._release_device_endpoint(device_uuid, endpoint_uuid)

            with self._lock:
                self._num_released += 1

        elif 'slice_id' in json_request:
        elif 'slice_id' in json_request:
            for endpoint_id in json_request['slice_endpoint_ids']:
            for endpoint_id in json_request['slice_endpoint_ids']:
                device_uuid = endpoint_id['device_id']['device_uuid']['uuid']
                device_uuid = endpoint_id['device_id']['device_uuid']['uuid']
                endpoint_uuid = endpoint_id['endpoint_uuid']['uuid']
                endpoint_uuid = endpoint_id['endpoint_uuid']['uuid']
                self._release_device_endpoint(device_uuid, endpoint_uuid)
                self._release_device_endpoint(device_uuid, endpoint_uuid)

            with self._lock:
                self._num_released += 1
+3 −0
Original line number Original line Diff line number Diff line
@@ -57,6 +57,9 @@ class RequestScheduler:
    @property
    @property
    def num_generated(self): return min(self._generator.num_generated, self._parameters.num_requests)
    def num_generated(self): return min(self._generator.num_generated, self._parameters.num_requests)


    @property
    def num_released(self): return min(self._generator.num_released, self._parameters.num_requests)

    @property
    @property
    def infinite_loop(self): return self._generator.infinite_loop
    def infinite_loop(self): return self._generator.infinite_loop


+1 −0
Original line number Original line Diff line number Diff line
@@ -73,6 +73,7 @@ class LoadGeneratorServiceServicerImpl(LoadGeneratorServiceServicer):


        status = Status()
        status = Status()
        status.num_generated = self._scheduler.num_generated
        status.num_generated = self._scheduler.num_generated
        status.num_released  = self._scheduler.num_released
        status.infinite_loop = self._scheduler.infinite_loop
        status.infinite_loop = self._scheduler.infinite_loop
        status.running       = self._scheduler.running
        status.running       = self._scheduler.running