Loading Dockerfile +6 −6 Original line number Diff line number Diff line Loading @@ -16,23 +16,23 @@ FROM python:3.12-slim # Establece el directorio de trabajo # Stablish woking directory WORKDIR /app # Instala dependencias del sistema # Install system dependencies RUN apt-get update -qq && \ apt-get install -y -qq git python3-dev && \ apt-get clean && rm -rf /var/lib/apt/lists/* # Copia el contenido del proyecto # Copy project content COPY . /app # Instala dependencias de Python # Intall python dependencies RUN pip install --upgrade pip && \ pip install -r requirements.txt # Expone el puerto # Expose port EXPOSE 8081 # Comando de inicio # Init command ENTRYPOINT ["python3", "app.py"] app.py +1 −3 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ from src.config.config import create_config from src.database.db import init_db def create_app(): """Factory para crear la app Flask con la configuración cargada""" """Create Flask application with configured API and namespaces.""" init_db() app = Flask(__name__) app = create_config(app) Loading Loading @@ -59,8 +59,6 @@ def create_app(): return app # Solo arrancamos el servidor si ejecutamos el script directamente if __name__ == "__main__": app = create_app() app.run(host="0.0.0.0", port=NSC_PORT, debug=True) src/api/main.py +7 −5 Original line number Diff line number Diff line Loading @@ -39,8 +39,8 @@ class Api: POST /slice Raises: ValueError: If no transport network slices are found Exception: For unexpected errors during slice creation process RuntimeError: If there is no content to process Exception: For unexpected errors """ try: result = self.slice_service.nsc(intent) Loading Loading @@ -82,7 +82,7 @@ class Api: Raises: ValueError: If no transport network slices are found Exception: For unexpected errors during file processing Exception: For unexpected errors """ try: # Read slice database from JSON file Loading Loading @@ -120,6 +120,8 @@ class Api: API Endpoint: PUT /slice/{id} Raises: Exception: For unexpected errors """ try: result = self.slice_service.nsc(intent, slice_id) Loading Loading @@ -150,14 +152,14 @@ class Api: Defaults to None. Returns: dict: Response indicating successful deletion or error details dict: {} indicating successful deletion or error details API Endpoint: DELETE /slice/{id} Raises: ValueError: If no slices are found to delete Exception: For unexpected errors during deletion process Exception: For unexpected errors Notes: - If controller_type is TFS, attempts to delete from Teraflow Loading src/database/db.py +57 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,9 @@ DB_NAME = "slice.db" # Initialize database and create table def init_db(): """ Initialize the SQLite database and create the slice table if not exists. """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute(""" Loading @@ -33,12 +36,24 @@ def init_db(): # Save data to the database def save_data(slice_id: str, intent_dict: dict, controller: str): """ Save a new slice entry to the database. Args: slice_id (str): Unique identifier for the slice intent_dict (dict): Intent data controller (str): Controller type Raises: ValueError: If a slice with the given slice_id already exists """ intent_str = json.dumps(intent_dict) conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() try: cursor.execute("INSERT INTO slice (slice_id, intent, controller) VALUES (?, ?, ?)", (slice_id, intent_str, controller)) conn.commit() # Handle duplicate slice ID except sqlite3.IntegrityError: raise ValueError(f"Slice with id '{slice_id}' already exists.") finally: Loading @@ -46,6 +61,17 @@ def save_data(slice_id: str, intent_dict: dict, controller: str): # Update data in the database def update_data(slice_id: str, new_intent_dict: dict, controller: str): """ Update an existing slice entry in the database. Args: slice_id (str): Unique identifier for the slice new_intent_dict (dict): New intent data controller (str): Controller type Raises: ValueError: If no slice is found with the given slice_id """ intent_str = json.dumps(new_intent_dict) conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() Loading @@ -59,6 +85,15 @@ def update_data(slice_id: str, new_intent_dict: dict, controller: str): # Delete data from the database def delete_data(slice_id: str): """ Delete a slice entry from the database. Args: slice_id (str): Unique identifier for the slice to delete Raises: ValueError: If no slice is found with the given slice_id """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("DELETE FROM slice WHERE slice_id = ?", (slice_id,)) Loading @@ -71,6 +106,19 @@ def delete_data(slice_id: str): # Get data from the database def get_data(slice_id: str) -> dict[str, dict, str]: """ Retrieve a specific slice entry from the database. Args: slice_id (str): Unique identifier for the slice to retrieve Returns: dict: Slice data including slice_id, intent (as dict), and controller Raises: ValueError: If no slice is found with the given slice_id Exception: For JSON decoding errors """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("SELECT * FROM slice WHERE slice_id = ?", (slice_id,)) Loading @@ -92,6 +140,12 @@ def get_data(slice_id: str) -> dict[str, dict, str]: # Get all slices def get_all_data() -> dict[str, dict, str]: """ Retrieve all slice entries from the database. Returns: list: List of slice data dictionaries including slice_id, intent (as dict), and controller """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("SELECT * FROM slice") Loading @@ -107,6 +161,9 @@ def get_all_data() -> dict[str, dict, str]: ] def delete_all_data(): """ Delete all slice entries from the database. """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("DELETE FROM slice") Loading src/main.py +4 −4 Original line number Diff line number Diff line Loading @@ -50,10 +50,10 @@ class NSController: Attributes: controller_type (str): Flag for Teraflow or Ixia upload answer (dict): Stores slice creation responses response (dict): Stores slice creation responses start_time (float): Tracks slice setup start time end_time (float): Tracks slice setup end time need_l2vpn_support (bool): Flag for additional L2VPN configuration support setup_time (float): Total time taken for slice setup in milliseconds """ self.controller_type = controller_type Loading @@ -74,14 +74,14 @@ class NSController: 4. Store slice information 5. Map slice to Network Resource Pool (NRP) 6. Realize slice configuration 7. Upload to Teraflow (optional) 7. Send configuration to network controllers Args: intent_json (dict): Network slice intent in 3GPP or IETF format slice_id (str, optional): Existing slice identifier for modification Returns: tuple: Response status and HTTP status code dict: Contains slice creation responses and setup time in milliseconds """ # Start performance tracking Loading Loading
Dockerfile +6 −6 Original line number Diff line number Diff line Loading @@ -16,23 +16,23 @@ FROM python:3.12-slim # Establece el directorio de trabajo # Stablish woking directory WORKDIR /app # Instala dependencias del sistema # Install system dependencies RUN apt-get update -qq && \ apt-get install -y -qq git python3-dev && \ apt-get clean && rm -rf /var/lib/apt/lists/* # Copia el contenido del proyecto # Copy project content COPY . /app # Instala dependencias de Python # Intall python dependencies RUN pip install --upgrade pip && \ pip install -r requirements.txt # Expone el puerto # Expose port EXPOSE 8081 # Comando de inicio # Init command ENTRYPOINT ["python3", "app.py"]
app.py +1 −3 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ from src.config.config import create_config from src.database.db import init_db def create_app(): """Factory para crear la app Flask con la configuración cargada""" """Create Flask application with configured API and namespaces.""" init_db() app = Flask(__name__) app = create_config(app) Loading Loading @@ -59,8 +59,6 @@ def create_app(): return app # Solo arrancamos el servidor si ejecutamos el script directamente if __name__ == "__main__": app = create_app() app.run(host="0.0.0.0", port=NSC_PORT, debug=True)
src/api/main.py +7 −5 Original line number Diff line number Diff line Loading @@ -39,8 +39,8 @@ class Api: POST /slice Raises: ValueError: If no transport network slices are found Exception: For unexpected errors during slice creation process RuntimeError: If there is no content to process Exception: For unexpected errors """ try: result = self.slice_service.nsc(intent) Loading Loading @@ -82,7 +82,7 @@ class Api: Raises: ValueError: If no transport network slices are found Exception: For unexpected errors during file processing Exception: For unexpected errors """ try: # Read slice database from JSON file Loading Loading @@ -120,6 +120,8 @@ class Api: API Endpoint: PUT /slice/{id} Raises: Exception: For unexpected errors """ try: result = self.slice_service.nsc(intent, slice_id) Loading Loading @@ -150,14 +152,14 @@ class Api: Defaults to None. Returns: dict: Response indicating successful deletion or error details dict: {} indicating successful deletion or error details API Endpoint: DELETE /slice/{id} Raises: ValueError: If no slices are found to delete Exception: For unexpected errors during deletion process Exception: For unexpected errors Notes: - If controller_type is TFS, attempts to delete from Teraflow Loading
src/database/db.py +57 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,9 @@ DB_NAME = "slice.db" # Initialize database and create table def init_db(): """ Initialize the SQLite database and create the slice table if not exists. """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute(""" Loading @@ -33,12 +36,24 @@ def init_db(): # Save data to the database def save_data(slice_id: str, intent_dict: dict, controller: str): """ Save a new slice entry to the database. Args: slice_id (str): Unique identifier for the slice intent_dict (dict): Intent data controller (str): Controller type Raises: ValueError: If a slice with the given slice_id already exists """ intent_str = json.dumps(intent_dict) conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() try: cursor.execute("INSERT INTO slice (slice_id, intent, controller) VALUES (?, ?, ?)", (slice_id, intent_str, controller)) conn.commit() # Handle duplicate slice ID except sqlite3.IntegrityError: raise ValueError(f"Slice with id '{slice_id}' already exists.") finally: Loading @@ -46,6 +61,17 @@ def save_data(slice_id: str, intent_dict: dict, controller: str): # Update data in the database def update_data(slice_id: str, new_intent_dict: dict, controller: str): """ Update an existing slice entry in the database. Args: slice_id (str): Unique identifier for the slice new_intent_dict (dict): New intent data controller (str): Controller type Raises: ValueError: If no slice is found with the given slice_id """ intent_str = json.dumps(new_intent_dict) conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() Loading @@ -59,6 +85,15 @@ def update_data(slice_id: str, new_intent_dict: dict, controller: str): # Delete data from the database def delete_data(slice_id: str): """ Delete a slice entry from the database. Args: slice_id (str): Unique identifier for the slice to delete Raises: ValueError: If no slice is found with the given slice_id """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("DELETE FROM slice WHERE slice_id = ?", (slice_id,)) Loading @@ -71,6 +106,19 @@ def delete_data(slice_id: str): # Get data from the database def get_data(slice_id: str) -> dict[str, dict, str]: """ Retrieve a specific slice entry from the database. Args: slice_id (str): Unique identifier for the slice to retrieve Returns: dict: Slice data including slice_id, intent (as dict), and controller Raises: ValueError: If no slice is found with the given slice_id Exception: For JSON decoding errors """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("SELECT * FROM slice WHERE slice_id = ?", (slice_id,)) Loading @@ -92,6 +140,12 @@ def get_data(slice_id: str) -> dict[str, dict, str]: # Get all slices def get_all_data() -> dict[str, dict, str]: """ Retrieve all slice entries from the database. Returns: list: List of slice data dictionaries including slice_id, intent (as dict), and controller """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("SELECT * FROM slice") Loading @@ -107,6 +161,9 @@ def get_all_data() -> dict[str, dict, str]: ] def delete_all_data(): """ Delete all slice entries from the database. """ conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() cursor.execute("DELETE FROM slice") Loading
src/main.py +4 −4 Original line number Diff line number Diff line Loading @@ -50,10 +50,10 @@ class NSController: Attributes: controller_type (str): Flag for Teraflow or Ixia upload answer (dict): Stores slice creation responses response (dict): Stores slice creation responses start_time (float): Tracks slice setup start time end_time (float): Tracks slice setup end time need_l2vpn_support (bool): Flag for additional L2VPN configuration support setup_time (float): Total time taken for slice setup in milliseconds """ self.controller_type = controller_type Loading @@ -74,14 +74,14 @@ class NSController: 4. Store slice information 5. Map slice to Network Resource Pool (NRP) 6. Realize slice configuration 7. Upload to Teraflow (optional) 7. Send configuration to network controllers Args: intent_json (dict): Network slice intent in 3GPP or IETF format slice_id (str, optional): Existing slice identifier for modification Returns: tuple: Response status and HTTP status code dict: Contains slice creation responses and setup time in milliseconds """ # Start performance tracking Loading