Commit dd815821 authored by Mohamad Rahhal's avatar Mohamad Rahhal
Browse files

CAMARA-QOD

parent 074e7d1a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -62,3 +62,10 @@ spec:
                name: nbiservice
                port:
                  number: 8080
          - path: /()(camara/.*)
            pathType: Prefix
            backend:
              service:
                name: nbiservice
                port:
                  number: 8080
+2 −2
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ export CRDB_DATABASE="tfs"
export CRDB_DEPLOY_MODE="single"

# Disable flag for dropping database, if it exists.
export CRDB_DROP_DATABASE_IF_EXISTS=""
export CRDB_DROP_DATABASE_IF_EXISTS="YES"

# Disable flag for re-deploying CockroachDB from scratch.
export CRDB_REDEPLOY=""
@@ -158,7 +158,7 @@ export QDB_TABLE_MONITORING_KPIS="tfs_monitoring_kpis"
export QDB_TABLE_SLICE_GROUPS="tfs_slice_groups"

# Disable flag for dropping tables if they exist.
export QDB_DROP_TABLES_IF_EXIST=""
export QDB_DROP_TABLES_IF_EXIST="YES"

# Disable flag for re-deploying QuestDB from scratch.
export QDB_REDEPLOY=""
+25 −0
Original line number Diff line number Diff line
#!/bin/bash
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


PROJECTDIR=`pwd`

cd $PROJECTDIR/src
RCFILE=$PROJECTDIR/coverage/.coveragerc

# Run unitary tests and analyze coverage of code at same time
# helpful pytest flags: --log-level=INFO -o log_cli=true --verbose --maxfail=1 --durations=0
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    nbi/tests/test_camara_qod.py
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ from common.Settings import (

from .NbiService import NbiService
from .rest_server.RestServer import RestServer
from .rest_server.nbi_plugins.camara_qod import register_camara_qod
from .rest_server.nbi_plugins.etsi_bwm import register_etsi_bwm_api
from .rest_server.nbi_plugins.ietf_hardware import register_ietf_hardware
from .rest_server.nbi_plugins.ietf_l2vpn import register_ietf_l2vpn
@@ -65,6 +66,7 @@ def main():
    grpc_service.start()

    rest_server = RestServer()
    register_camara_qod(rest_server)
    register_etsi_bwm_api(rest_server)
    register_ietf_hardware(rest_server)
    register_ietf_l2vpn(rest_server)  # Registering L2VPN entrypoint
+156 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import json
from flask.json import jsonify
from flask_restful import Resource, request, Api
from enum import Enum
import uuid



class SessionStatus(Enum):
    ACTIVE='ACTIVE'
    INACTIVE='INACTIVE'

class Rate():
    def __init__(self,value,unit):
        self.value=value
        self.unit=unit

class Duration():
    def __init__(self,value,unit):
        self.value=value
        self.unit=unit

class SessionCreate():
    def __init__(self,source_ipv4_address,destination_ipv4_address,name,session_profile,targetMinUpstreamRate=None,maxUpstreamRate=None,
                 maxUpstreamBurstRate=None,targetMinDownstreamRate=None,maxDownstreamRate=None,maxDownstreamBurstRate=None,minDuration=None,
                 maxDuration=None,priority=None,packetDelayBudget=None,jitter=None,packetErrorLossRate=None,description=None):
        self.source_ipv4_address = source_ipv4_address
        self.destination_ipv4_address = destination_ipv4_address
        self.name = name
        self.session_profile = session_profile
        self.targetMinUpstreamRate = targetMinUpstreamRate
        self.maxUpstreamRate = maxUpstreamRate
        self.maxUpstreamBurstRate = maxUpstreamBurstRate
        self.targetMinDownstreamRate = targetMinDownstreamRate
        self.maxDownstreamRate = maxDownstreamRate
        self.maxDownstreamBurstRate = maxDownstreamBurstRate
        self.minDuration = minDuration
        self.maxDuration = maxDuration
        self.priority = priority
        self.packetDelayBudget = packetDelayBudget
        self.jitter = jitter
        self.packetErrorLossRate = packetErrorLossRate
        self.description = description

class Session(SessionCreate):
    def __init__(self,session_id,status,**kwargs):
        super().__init__(**kwargs)
        self.session_id=session_id
        self.status=status

sessions=[]

class SessionList(Resource):
    def post(self):
        data = request.get_json()
        session_id=str(uuid.uuid4())
        new_session={
            "session_id": session_id,
            "name": data.get('name'),
            "source_ipv4_address": data.get('source_ipv4_address'),
            "destination_ipv4_address": data.get('destination_ipv4_address'),
            "session_profile": data.get('session_profile'),
            "targetMinUpstreamRate": data.get('targetMinUpstreamRate'),
            "maxUpstreamRate": data.get('maxUpstreamRate'),
            "maxUpstreamBurstRate": data.get('maxUpstreamBurstRate'),
            "targetMinDownstreamRate": data.get('targetMinDownstreamRate'),
            "maxDownstreamRate": data.get('maxDownstreamRate'),
            "maxDownstreamBurstRate": data.get('maxDownstreamBurstRate'),
            "minDuration": data.get('minDuration'),
            "maxDuration": data.get('maxDuration'),
            "priority": data.get('priority'),
            "packetDelayBudget": data.get('packetDelayBudget'),
            "jitter": data.get('jitter'),
            "packetErrorLossRate": data.get('packetErrorLossRate'),
            "description": data.get('description'),
            "status":SessionStatus.ACTIVE.value
        }
        sessions.append(new_session)
        return jsonify(new_session)
class AllSessions(Resource):
    def get(self):
        all_sessions = []
        for session in sessions:
            session_details = {
                "session_id": session["session_id"],
                "name": session["name"],
                "source_ipv4_address": session["source_ipv4_address"],
                "destination_ipv4_address": session["destination_ipv4_address"],
                "session_profile": session["session_profile"],
                "targetMinUpstreamRate": session["targetMinUpstreamRate"],
                "maxUpstreamRate": session["maxUpstreamRate"],
                "maxUpstreamBurstRate": session["maxUpstreamBurstRate"],
                "targetMinDownstreamRate": session["targetMinDownstreamRate"],
                "maxDownstreamRate": session["maxDownstreamRate"],
                "maxDownstreamBurstRate": session["maxDownstreamBurstRate"],
                "minDuration": session["minDuration"],
                "maxDuration": session["maxDuration"],
                "priority": session["priority"],
                "packetDelayBudget": session["packetDelayBudget"],
                "jitter": session["jitter"],
                "packetErrorLossRate": session["packetErrorLossRate"],
                "description": session["description"],
                "status": session["status"]
            }
            all_sessions.append(session_details)
        
        return jsonify(all_sessions)

class DeleteAllSessions(Resource):
    def delete(self):
        global sessions
        session_count = len(sessions)       
        if session_count > 0:
            sessions.clear()  
            return {"message": f"All {session_count} sessions deleted successfully"}
        else:
            return {"message": "No sessions to delete"}, 204

class Sessionlist2(Resource):
    def get(self, session_id): 
        for session in sessions:
            if session["session_id"] == session_id:
                return jsonify(session)
        
        abort(404, description="Session not found")
    def delete(self, session_id):
        global sessions
        for session in sessions[:]:
            if session["session_id"] == session_id:
                sessions.remove(session) 
                return {"message": "Session deleted successfully"}
        abort(404, description="Session not found")
    def put(self, session_id):
        data = request.get_json()
        session = next((s for s in sessions if s["session_id"] == session_id), None)
        if session:
            for key, value in data.items():
                if key in session:
                    session[key] = value
            return jsonify(session)
        abort(404, description="Session not found")
Loading