Commit 446e0db8 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Intermediate backup, not functional.

- Implemented MonitorDeviceKPI RPC method
- Implemented Endpoint pre-configruation for Emulated Driver
- Implemented MockMonitoringService for testing Device monitoring capabilities
- Implemented Monitoring Loops to collect samples from drivers and forward them to Monitoring Service
- Test unit for Emulated Device Monitoring half implemented.
- Minor bug resolutions in OpenConfig Driver
parent 9cf94be4
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -2,19 +2,19 @@ syntax = "proto3";
package device;

import "context.proto";
//import "monitoring.proto";
import "monitoring.proto";

service DeviceService {
  rpc AddDevice       (context.Device    ) returns (context.DeviceId    ) {}
  rpc ConfigureDevice (context.Device    ) returns (context.DeviceId    ) {}
  rpc DeleteDevice    (context.DeviceId  ) returns (context.Empty       ) {}
  rpc GetInitialConfig(context.DeviceId  ) returns (context.DeviceConfig) {}
  //rpc MonitorDeviceKpi(MonitoringSettings) returns (context.Empty       ) {}
  rpc MonitorDeviceKpi(MonitoringSettings) returns (context.Empty       ) {}
}

//message MonitoringSettings {
//  monitoring.KpiId kpi_id = 1;
//  monitoring.KpiDescriptor kpi_descriptor = 2;
//  float sampling_duration_s = 3;
//  float sampling_interval_s = 4;
//}
message MonitoringSettings {
  monitoring.KpiId kpi_id = 1;
  monitoring.KpiDescriptor kpi_descriptor = 2;
  float sampling_duration_s = 3;
  float sampling_interval_s = 4;
}
+8 −8
Original line number Diff line number Diff line
syntax = "proto3";
//package kpi_sample_types;
package kpi_sample_types;

//enum KpiSampleType {
//    UNKNOWN = 0;
//    PACKETS_TRANSMITTED = 101;
//    PACKETS_RECEIVED    = 102;
//    BYTES_TRANSMITTED   = 201;
//    BYTES_RECEIVED      = 202;
//}
enum KpiSampleType {
    UNKNOWN = 0;
    PACKETS_TRANSMITTED = 101;
    PACKETS_RECEIVED    = 102;
    BYTES_TRANSMITTED   = 201;
    BYTES_RECEIVED      = 202;
}
+13 −20
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@ syntax = "proto3";
package monitoring;

import "context.proto";
//import "kpi_sample_types.proto";
import "kpi_sample_types.proto";

service MonitoringService {
  // Old RPCs:
@@ -22,22 +22,23 @@ service MonitoringService {
  //rpc GetInstantKpi   (KpiId            ) returns (Kpi          ) {}
}

message CreateKpiRequest /*New name: KpiDescriptor*/ {
  // Old fields:
// to be removed; will be replaced by KpiDescriptor
message CreateKpiRequest {
  string kpiDescription = 1;
  context.DeviceId device_id = 2;
  KpiSampleType kpi_sample_type = 3;
  kpi_sample_types.KpiSampleType kpi_sample_type = 3;
  //  context.EndpointId endpoint_id = 4;  // others might be added
  //  context.ServiceId  service_id  = 5;  // for monitoring other
  //  context.SliceId    slice_id    = 6;  // entities
}

  // New fields:
  //string kpi_description = 1;
  //kpi_sample_types.KpiSampleType kpi_sample_type = 2;
  //context.DeviceId device_id = 3;
  //context.EndPointId endpoint_id = 4;
  //context.ServiceId  service_id  = 5;
  ////context.SliceId    slice_id    = 6; // to be used in future features
message KpiDescriptor {
  string kpi_description = 1;
  kpi_sample_types.KpiSampleType kpi_sample_type = 2;
  context.DeviceId device_id = 3;
  context.EndPointId endpoint_id = 4;
  context.ServiceId  service_id  = 5;
  //context.SliceId    slice_id    = 6; // to be used in future features
}

message MonitorKpiRequest{
@@ -75,7 +76,7 @@ message Kpi {
  string timestamp = 2;
  string kpiDescription = 3;          // field to be removed
  KpiValue kpi_value = 4;             // field to be renumbered to 3
  KpiSampleType kpi_sample_type = 5;  // field to be removed
  kpi_sample_types.KpiSampleType kpi_sample_type = 5;  // field to be removed
  context.DeviceId device_id = 6;     // field to be removed
  //  context.EndpointId endpoint_id = 7;  // others might be added // field to be removed
  //  context.ServiceId  service_id  = 8;  // for monitoring other  // field to be removed
@@ -94,11 +95,3 @@ message KpiValue {
message KpiList {
  repeated Kpi kpiList = 1; // to be renamed to kpi_list
}

enum KpiSampleType {  // to be moved to file "kpi_sample_types.proto"
  UNKNOWN = 0;
  PACKETS_TRANSMITTED = 101;  // others might be added for
  PACKETS_RECEIVED    = 102;  // packet, optical, radio,...
  BYTES_TRANSMITTED   = 201;
  BYTES_RECEIVED      = 202;
}
+19 −19
Original line number Diff line number Diff line
@@ -25,32 +25,32 @@ export REDIS_SERVICE_PORT=$(kubectl get service redis-tests --namespace tf-dev -
# First destroy old coverage file
rm -f $COVERAGEFILE

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    common/orm/tests/test_unitary.py \
    common/message_broker/tests/test_unitary.py \
    common/rpc_method_wrapper/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    common/orm/tests/test_unitary.py \
#    common/message_broker/tests/test_unitary.py \
#    common/rpc_method_wrapper/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    centralizedattackdetector/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    centralizedattackdetector/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    context/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    context/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    device/tests/test_unitary_driverapi.py \
    device/tests/test_unitary.py
    #device/tests/test_unitary_driverapi.py \

coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
    l3_centralizedattackdetector/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
#    l3_centralizedattackdetector/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
    l3_distributedattackdetector/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
#    l3_distributedattackdetector/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
    l3_attackmitigator/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
#    l3_attackmitigator/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    service/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    service/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    compute/tests/test_unitary.py
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    compute/tests/test_unitary.py
+7 −7
Original line number Diff line number Diff line
import grpc, logging
from common.tools.client.RetryDecorator import retry, delay_exponential
from device.proto.context_pb2 import Device, DeviceConfig, DeviceId, Empty
#from device.proto.device_pb2 import MonitoringSettings
from device.proto.device_pb2 import MonitoringSettings
from device.proto.device_pb2_grpc import DeviceServiceStub

LOGGER = logging.getLogger(__name__)
@@ -54,9 +54,9 @@ class DeviceClient:
        LOGGER.debug('GetInitialConfig result: {:s}'.format(str(response)))
        return response

    #@retry(exceptions=set(), max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
    #def MonitorDeviceKpi(self, request : MonitoringSettings) -> Empty:
    #    LOGGER.debug('MonitorDeviceKpi request: {:s}'.format(str(request)))
    #    response = self.stub.MonitorDeviceKpi(request)
    #    LOGGER.debug('MonitorDeviceKpi result: {:s}'.format(str(response)))
    #    return response
    @retry(exceptions=set(), max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
    def MonitorDeviceKpi(self, request : MonitoringSettings) -> Empty:
        LOGGER.debug('MonitorDeviceKpi request: {:s}'.format(str(request)))
        response = self.stub.MonitorDeviceKpi(request)
        LOGGER.debug('MonitorDeviceKpi result: {:s}'.format(str(response)))
        return response
Loading