Commit 590a893a authored by Pablo Armingol's avatar Pablo Armingol
Browse files

Merge branch 'develop' of https://labs.etsi.org/rep/tfs/nsc into feat/15-tid-new-ipowdm-realizer

parents d49046bd 4865020a
Loading
Loading
Loading
Loading
Loading

.dockerignore

0 → 100644
+5 −0
Original line number Diff line number Diff line
__pycache__/
*.pyc
*.db
.env
.git/
 No newline at end of file

.gitlab-ci.yml

0 → 100644
+81 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI 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.

stages:
  - build
  - unit_test

# Build, tag, and push the Docker image to the GitLab Docker registry
build nsc:
  variables:
    IMAGE_NAME: 'nsc'
    IMAGE_TAG: 'test'
  stage: build
  before_script:
    - docker image prune --force
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./Dockerfile .
    - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  after_script:
    - docker image prune --force
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'

# Apply unit test to the component
unit_test nsc:
  timeout: 15m
  variables:
    IMAGE_NAME: 'nsc' # name of the microservice
    IMAGE_TAG: 'test' # tag of the container image (production, development, etc)
  stage: unit_test
  needs:
    - build nsc
  before_script:
    # Do Docker cleanup
    - docker ps --all --quiet | xargs --no-run-if-empty docker stop
    - docker container prune --force
    - docker ps --all --quiet | xargs --no-run-if-empty docker rm --force
    - docker image prune --force
    - docker network prune --force
    - docker volume prune --all --force
    - docker buildx prune --force

    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker run --name $IMAGE_NAME -d -p 8081:8081 -v "$PWD/src/tests:/opt/results" $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
    - sleep 5
    - docker ps -a
    - docker logs $IMAGE_NAME
    - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose --junitxml=/opt/results/report.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage report --show-missing"
  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  after_script:
    # Clean up
    - docker ps --all --quiet | xargs --no-run-if-empty docker stop
    - docker container prune --force
    - docker ps --all --quiet | xargs --no-run-if-empty docker rm --force
    - docker network prune --force
    - docker volume prune --all --force
    - docker image prune --force
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
  artifacts:
      when: always
      reports:
        junit: src/tests/report.xml

Dockerfile

0 → 100644
+38 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI 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.

# This file is an original contribution from Telefonica Innovación Digital S.L.

FROM python:3.12-slim

# Stablish woking directory
WORKDIR /app

# 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/*

# Copy project content
COPY . /app

# Intall python dependencies
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

# Expose port
EXPOSE 8081

# Init command
ENTRYPOINT ["python3", "app.py"]
+25 −14
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ The Network Slice Controller (NSC) is a component defined by the IETF to orchest
   - [Ixia Configuration](#ixia-configuration)  
   - [WebUI](#webui-1)  
9. [Usage](#usage)  
10. [Available Branches and Releases](#available-branches-and-releases)

---

@@ -115,7 +116,7 @@ It is accessed at `{ip}:{NSC_PORT}/webui`

## Configuration

In the `.env` file, several constants can be adjusted to customize the Network Slice Controller (NSC) behavior:
In the `src/config/.env.example` file, several constants can be adjusted to customize the Network Slice Controller (NSC) behaviour:

### Logging
- `DEFAULT_LOGGING_LEVEL`: Sets logging verbosity
@@ -133,6 +134,13 @@ In the `.env` file, several constants can be adjusted to customize the Network S
  - Default: `false`
- `PCE_EXTERNAL`: Flag to determine if external PCE is used
  - Default: `false`
- `PLANNER_TYPE`:  Type of planner to be used
  - Default: `ENERGY`
  - Options: `ENERGY`, `HRAT`, `TFS_OPTICAL`
- `HRAT_IP`: HRAT planner IP
  - Default: `10.0.0.1`
- `OPTICAL_PLANNER_IP`: Optical planner IP
  - Default: `10.0.0.1`

## Realizer
- `DUMMY_MODE`: If true, no config sent to controllers
@@ -157,24 +165,27 @@ In the `.env` file, several constants can be adjusted to customize the Network S

## Usage

To deploy and execute the NSC, follow these steps:
To use the NSC, just build the image an run it in a container following these steps:

0. **Preparation**
1. **Deploy**
    ```
    git clone https://labs.etsi.org/rep/tfs/nsc.git
    cd nsc
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    cp ./src/config/.env.example ./.env
    ```

1. **Start NSC Server**:
    ```
    python3 app.py
    ./deploy.sh
    ```

2. **Send Slice Requests**:

    Send slice requests via **API** (/nsc) or **WebUI** (/webui)

## Available branches and releases

[![Latest Release](https://labs.etsi.org/rep/tfs/nsc/-/badges/release.svg)](https://labs.etsi.org/rep/tfs/nsc/-/releases)

- The branch `main` ([![pipeline status](https://labs.etsi.org/rep/tfs/nsc/badges/main/pipeline.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/main) [![coverage report](https://labs.etsi.org/rep/tfs/nsc/badges/main/coverage.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/main)), points always to the latest stable version of the TeraFlowSDN Network Slice Controller (NSC).

- The branches `release/X.Y.Z`, point to the code for the different release versions indicated in the branch name.
  - Code in these branches can be considered stable, and no new features are planned.
  - In case of bugs, point releases increasing revision number (Z) might be created.

- The `develop` ([![pipeline status](https://labs.etsi.org/rep/tfs/nsc/badges/develop/pipeline.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/develop) [![coverage report](https://labs.etsi.org/rep/tfs/nsc/badges/develop/coverage.svg)](https://labs.etsi.org/rep/tfs/nsc/-/commits/develop)) branch is the main development branch and contains the latest contributions.
  - **Use it with care! It might not be stable.**
  - The latest developments and contributions are added to this branch for testing and validation before reaching a release.
+3 −3
Original line number Diff line number Diff line
@@ -20,13 +20,14 @@ from flask_restx import Api
from flask_cors import CORS
from swagger.tfs_namespace import tfs_ns
from swagger.ixia_namespace import ixia_ns
from swagger.E2E_namespace import e2e_ns
from src.config.constants import NSC_PORT
from src.webui.gui import gui_bp
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)
@@ -50,6 +51,7 @@ def create_app():
    # Register namespaces
    api.add_namespace(tfs_ns, path="/tfs")
    api.add_namespace(ixia_ns, path="/ixia")
    api.add_namespace(e2e_ns, path="/e2e")

    if app.config["WEBUI_DEPLOY"]:
        app.secret_key = "clave-secreta-dev"
@@ -57,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)
Loading