Commit 9f3b2ec8 authored by ldemarcosm's avatar ldemarcosm
Browse files

Updated AM and CAM

parent 5c0a9c30
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ unit_test l3_attackmitigator:
    - docker ps -a
    - docker port $IMAGE_NAME
    - docker logs $IMAGE_NAME
    - docker exec -i $IMAGE_NAME bash -c "pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py"
    - docker exec -i $IMAGE_NAME bash -c "pytest --log-level=DEBUG --verbose -o log_cli=true $IMAGE_NAME/tests/test_unitary.py"
  after_script:
    - docker stop $IMAGE_NAME
    - docker rm $IMAGE_NAME
+2 −2
Original line number Diff line number Diff line
@@ -71,8 +71,8 @@ class l3_attackmitigatorService:
        )  # pylint: disable=maybe-no-member

        LOGGER.debug("Service started")
        print('Setting up')
        self.l3_attackmitigator_servicer.setupl3_attackmitigator()
        #print('Setting up')
        #self.l3_attackmitigator_servicer.setupl3_attackmitigator()

    def stop(self):
        LOGGER.debug(
+20 −21
Original line number Diff line number Diff line
@@ -30,8 +30,7 @@ class l3_attackmitigatorServiceServicerImpl(L3AttackmitigatorServicer):
    def __init__(self):
        LOGGER.debug("Creating Servicer...")
    
    class Mitigator(L3AttackmitigatorServicer):
        def send_output(self, request, context):
    def SendOutput(self, request, context):
        # SEND CONFIDENCE TO MITIGATION SERVER
        logging.debug("")
        print("Server received mitigation values...", request.confidence)
@@ -42,7 +41,7 @@ class l3_attackmitigatorServiceServicerImpl(L3AttackmitigatorServicer):
            message=f"OK, received values: {LAST_TAG} with confidence {LAST_VALUE}."
        )

        def get_mitigation(self, request, context):
    def GetMitigation(self, request, context):
        # GET OR PERFORM MITIGATION STRATEGY
        logging.debug("")
        print("Returing mitigation strategy...")
@@ -51,7 +50,7 @@ class l3_attackmitigatorServiceServicerImpl(L3AttackmitigatorServicer):
            message=f"Mitigation with double confidence = {k}"
        )


    '''
    def serve(self):
        server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
        add_L3AttackmitigatorServicer_to_server(self.Mitigator(), server)
@@ -64,7 +63,7 @@ class l3_attackmitigatorServiceServicerImpl(L3AttackmitigatorServicer):
    def setupl3_attackmitigator(self):
        logging.basicConfig()
        self.serve()

    '''


    
+10 −21
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import grpc
import logging
import pytest
import multiprocessing
import subprocess
import time
from l3_attackmitigator.proto.monitoring_pb2 import Kpi, KpiList
from common.orm.Factory import get_database_backend as get_database, BackendEnum as DatabaseEngineEnum
@@ -21,12 +22,12 @@ port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports
LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG)

'''
@pytest.fixture(scope='session')
def l3_attackmitigator_service():
    _service = l3_attackmitigatorService(
        port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD)
    _service.start()
    LOGGER.info('Server started on '+str(port))
    yield _service
    _service.stop()

@@ -36,23 +37,13 @@ def l3_attackmitigator_client(l3_attackmitigator_service):
    _client = l3_attackmitigatorClient(address='127.0.0.1', port=port)
    yield _client
    _client.close()
'''


def test_demo():
    print('Demo Test')
    LOGGER.info('Demo Test')
    pass

def test_grpc_server():
    '''
    print('Starting AM')
    _service = l3_attackmitigatorService(
        port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD)
    p1 = multiprocessing.Process(target=_service.start, args=())
    #_service.start()
    p1.start()
    '''
    print('Test Started')
    time.sleep(10)
def test_grpc_server(l3_attackmitigator_service):
    output_message = {
            "confidence": 0.8,
            "timestamp": "date",
@@ -68,16 +59,14 @@ def test_grpc_server():
        }
    
    def open_channel(input_information):
        with grpc.insecure_channel("localhost:10002") as channel:
        LOGGER.info(str(f"localhost:{port}"))
        with grpc.insecure_channel(f"localhost:{port}") as channel:
            stub = L3AttackmitigatorStub(channel)
            response = stub.SendOutput(input_information)
            print("Inferencer send_input sent and received: ",response.message)
            LOGGER.info("Inferencer send_input sent and received: "+str(response.message))
    try:
        open_channel(Output(**output_message))
        LOGGER.info('Success!')
    except:
        #p1.terminate()
        assert 0=="Couldn't open channel"
        assert 0=="GRPC server failed"
    #p1.terminate()
    print('Test Stopped')
    #_service.stop()
+2 −1
Original line number Diff line number Diff line
@@ -34,8 +34,9 @@ unit_test l3_centralizedattackdetector:
    - docker ps -a
    - sleep 5
    - docker ps -a
    - docker port $IMAGE_NAME
    - docker logs $IMAGE_NAME
    - docker exec -i $IMAGE_NAME bash -c "pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py"
    - docker exec -i $IMAGE_NAME bash -c "pytest --log-level=DEBUG --verbose -o log_cli=true $IMAGE_NAME/tests/test_unitary.py"
  after_script:
    - docker stop $IMAGE_NAME
    - docker rm $IMAGE_NAME
Loading