Commit 72078a0e authored by Pablo Armingol's avatar Pablo Armingol
Browse files

changes to add PECP module

parent c6fce9ae
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (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.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: pcepservice
spec:
  selector:
    matchLabels:
      app: pcepservice
  replicas: 1
  template:
    metadata:
      labels:
        app: pcepservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
      - name: server
        image: localhost:32000/tfs/pcep:dev
        imagePullPolicy: Always
        ports:
        - containerPort: 10050
        - containerPort: 9192
        env:
        - name: LOG_LEVEL
          value: "DEBUG"
        readinessProbe:
          exec:
            command: ["/bin/grpc_health_probe", "-addr=:10050"]
        livenessProbe:
          exec:
            command: ["/bin/grpc_health_probe", "-addr=:10050"]
        resources:
          requests:
            cpu: 50m
            memory: 64Mi
          limits:
            cpu: 500m
            memory: 512Mi
---
apiVersion: v1
kind: Service
metadata:
  name: pcepservice
  labels:
    app: pcepservice
spec:
  type: ClusterIP
  selector:
    app: pcepservice
  ports:
  - name: grpc
    protocol: TCP
    port: 10050
    targetPort: 10050
  - name: metrics
    protocol: TCP
    port: 9192
    targetPort: 9192
+55 −3
Original line number Diff line number Diff line
@@ -34,6 +34,14 @@ service ContextService {
  rpc RemoveTopology     (TopologyId    ) returns (       Empty           ) {}
  rpc GetTopologyEvents  (Empty         ) returns (stream TopologyEvent   ) {}

  rpc ListInventoryIds   (Empty         ) returns (       InventoryIdList ) {}
  rpc ListInventory      (Empty         ) returns (       InventoryList   ) {}
  rpc ListInventoryNames (InventoryIdList) returns(     InventoryNameList ) {}
  rpc GetInventory       (InventoryId   ) returns (       Inventory       ) {}
  rpc SetInventory       (Inventory     ) returns (       InventoryId     ) {}
  rpc RemoveInventory    (InventoryId   ) returns (       Empty           ) {}
  rpc GetInventoryEvents (InventoryId   ) returns (stream InventoryEvent  ) {}

  rpc ListDeviceIds      (Empty         ) returns (       DeviceIdList    ) {}
  rpc ListDevices        (Empty         ) returns (       DeviceList      ) {}
  rpc GetDevice          (DeviceId      ) returns (       Device          ) {}
@@ -174,12 +182,17 @@ message Device {
  DeviceOperationalStatusEnum device_operational_status = 5;
  repeated DeviceDriverEnum device_drivers = 6;
  repeated EndPoint device_endpoints = 7;
  repeated Component component = 8; // Used for inventory
  // Used for inventory:
  map<string, Component> components = 8; // dict[comp.name => Component]
    DeviceId controller_id = 9; // Identifier of node controlling the actual device
}

message Component {
  repeated string comp_string = 1;
  Uuid uuid = 1;
  string name = 2;
  string type = 3;
  repeated string child = 4; // list[sub-component.name]
  map<string, string> attributes = 5; // dict[attr.name => json.dumps(attr.value)]
}

message DeviceConfig {
@@ -589,3 +602,42 @@ message AuthenticationResult {
  ContextId context_id = 1;
  bool authenticated = 2;
}

// -----Inventory ------------------------------------------------------------------------------------------------------
message InventoryId{
  TopologyId topology_id = 1;
  DeviceId device_id = 2;
  Uuid inventory_uuid = 3;
}

message Inventory{
  InventoryId inventory_id = 1;
  string name = 2;
  string inventory_type = 3;
  repeated kpi_sample_types.KpiSampleType kpi_sample_types = 4;
  string datos = 5;
}

message InventoryName {
  InventoryId inventory_id = 1;
  string device_name = 2;
  string inventory_name = 3;
  string inventory_type = 4;
}

message InventoryIdList {
  repeated InventoryId inventory_ids = 1;
}

message InventoryNameList {
  repeated InventoryName inventory_names = 1;
}

message InventoryList {
  repeated Inventory inventory = 1;
}

message InventoryEvent {
  Inventory event = 1;
  InventoryId inventory_id = 2;
}
 No newline at end of file

proto/pcep.proto

0 → 100644
+40 −0
Original line number Diff line number Diff line
// Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (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.

syntax = "proto3";
package pcep;


service PcepService {
  rpc sendRequest    ( RequestRq ) returns (       RequestRp      ) {}
  rpc configuratePCE ( PceIpRq   ) returns (       PceIpRp      ) {}
}

message RequestRq {
  string command = 1;
}

message RequestRp {
  string commandRp = 1;
}

message PceIpRq {
  string address=1;
  string port= 2;
  string asNumber=3;
}

message PceIpRp{
  string addressRp=1;
}
+2 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ class ServiceNameEnum(Enum):
    OPTICALATTACKDETECTOR  = 'opticalattackdetector'
    OPTICALATTACKMITIGATOR = 'opticalattackmitigator'
    CACHING                = 'caching'
    PCEP          = 'pcep'

    # Used for test and debugging only
    DLT_GATEWAY    = 'dltgateway'
@@ -80,6 +81,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
    ServiceNameEnum.OPTICALATTACKMANAGER   .value : 10005,
    ServiceNameEnum.INTERDOMAIN            .value : 10010,
    ServiceNameEnum.PATHCOMP               .value : 10020,
    ServiceNameEnum.PCEP         .value : 10050,

    # Used for test and debugging only
    ServiceNameEnum.DLT_GATEWAY   .value : 50051,
+224 −0
Original line number Diff line number Diff line
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (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.

# Build, tag, and push the Docker image to the GitLab Docker registry
build service:
  variables:
    IMAGE_NAME: 'pcep' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: build
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/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 images --filter="dangling=true" --quiet | xargs -r docker rmi
  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"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
      - manifests/${IMAGE_NAME}service.yaml
      - .gitlab-ci.yml

# Apply unit test to the component
unit_test service:
  variables:
    IMAGE_NAME: 'pcep' # name of the microservice
    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
  stage: unit_test
  needs:
    - build service
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create --driver=bridge teraflowbridge; fi

    # Context-related
    - if docker container ls | grep crdb; then docker rm -f crdb; else echo "CockroachDB container is not in the system"; fi
    - if docker volume ls | grep crdb; then docker volume rm -f crdb; else echo "CockroachDB volume is not in the system"; fi
    - if docker container ls | grep nats; then docker rm -f nats; else echo "NATS container is not in the system"; fi

    # Device-related
    - if docker container ls | grep context; then docker rm -f context; else echo "context image is not in the system"; fi
    - if docker container ls | grep device; then docker rm -f device; else echo "device image is not in the system"; fi

    # Pathcomp-related
    - if docker container ls | grep pathcomp-frontend; then docker rm -f pathcomp-frontend; else echo "pathcomp-frontend image is not in the system"; fi
    - if docker container ls | grep pathcomp-backend; then docker rm -f pathcomp-backend; else echo "pathcomp-backend image is not in the system"; fi

    # Service-related
    - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi

  script:
    - docker pull "cockroachdb/cockroach:latest-v22.2"
    - docker pull "nats:2.9"
    - docker pull "$CI_REGISTRY_IMAGE/context:$IMAGE_TAG"
    - docker pull "$CI_REGISTRY_IMAGE/device:$IMAGE_TAG"
    - docker pull "$CI_REGISTRY_IMAGE/pathcomp-frontend:$IMAGE_TAG"
    - docker pull "$CI_REGISTRY_IMAGE/pathcomp-backend:$IMAGE_TAG"
    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"

    # Context preparation
    - docker volume create crdb
    - >
      docker run --name crdb -d --network=teraflowbridge -p 26257:26257 -p 8080:8080
      --env COCKROACH_DATABASE=tfs_test --env COCKROACH_USER=tfs --env COCKROACH_PASSWORD=tfs123
      --volume "crdb:/cockroach/cockroach-data"
      cockroachdb/cockroach:latest-v22.2 start-single-node
    - >
      docker run --name nats -d --network=teraflowbridge -p 4222:4222 -p 8222:8222
      nats:2.9 --http_port 8222 --user tfs --pass tfs123
    - echo "Waiting for initialization..."
    - while ! docker logs crdb 2>&1 | grep -q 'finished creating default user \"tfs\"'; do sleep 1; done
    - docker logs crdb
    - while ! docker logs nats 2>&1 | grep -q 'Server is ready'; do sleep 1; done
    - docker logs nats
    - docker ps -a
    - CRDB_ADDRESS=$(docker inspect crdb --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $CRDB_ADDRESS
    - NATS_ADDRESS=$(docker inspect nats --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $NATS_ADDRESS
    - >
      docker run --name context -d -p 1010:1010
      --env "CRDB_URI=cockroachdb://tfs:tfs123@${CRDB_ADDRESS}:26257/tfs_test?sslmode=require"
      --env "MB_BACKEND=nats"
      --env "NATS_URI=nats://tfs:tfs123@${NATS_ADDRESS}:4222"
      --network=teraflowbridge
      $CI_REGISTRY_IMAGE/context:$IMAGE_TAG
    - CONTEXTSERVICE_SERVICE_HOST=$(docker inspect context --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $CONTEXTSERVICE_SERVICE_HOST

    # Device preparation
    - >
      docker run --name device -d -p 2020:2020
      --env "CONTEXTSERVICE_SERVICE_HOST=${CONTEXTSERVICE_SERVICE_HOST}"
      --network=teraflowbridge
      $CI_REGISTRY_IMAGE/device:$IMAGE_TAG
    - DEVICESERVICE_SERVICE_HOST=$(docker inspect device --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $DEVICESERVICE_SERVICE_HOST

    # PathComp preparation
    - >
      docker run --name pathcomp-backend -d -p 8081:8081
      --network=teraflowbridge
      $CI_REGISTRY_IMAGE/pathcomp-backend:$IMAGE_TAG
    - PATHCOMP_BACKEND_HOST=$(docker inspect pathcomp-backend --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $PATHCOMP_BACKEND_HOST
    - sleep 1
    - >
      docker run --name pathcomp-frontend -d -p 10020:10020
      --env "CONTEXTSERVICE_SERVICE_HOST=${CONTEXTSERVICE_SERVICE_HOST}"
      --env "PATHCOMP_BACKEND_HOST=${PATHCOMP_BACKEND_HOST}"
      --env "PATHCOMP_BACKEND_PORT=8081"
      --network=teraflowbridge
      $CI_REGISTRY_IMAGE/pathcomp-frontend:$IMAGE_TAG
    - sleep 1
    - PATHCOMPSERVICE_SERVICE_HOST=$(docker inspect pathcomp-frontend --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
    - echo $PATHCOMPSERVICE_SERVICE_HOST

    # Service preparation
    - >
      docker run --name $IMAGE_NAME -d -p 3030:3030
      --env "CONTEXTSERVICE_SERVICE_HOST=${CONTEXTSERVICE_SERVICE_HOST}"
      --env "DEVICESERVICE_SERVICE_HOST=${DEVICESERVICE_SERVICE_HOST}"
      --env "PATHCOMPSERVICE_SERVICE_HOST=${PATHCOMPSERVICE_SERVICE_HOST}"
      --volume "$PWD/src/$IMAGE_NAME/tests:/opt/results"
      --network=teraflowbridge
      $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG

    # Check status before the tests
    - sleep 5
    - docker ps -a
    - docker logs context
    - docker logs device
    - docker logs pathcomp-frontend
    - docker logs pathcomp-backend
    - docker logs $IMAGE_NAME

    # Run the tests
    - >
      docker exec -i $IMAGE_NAME bash -c
      "coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/opt/results/${IMAGE_NAME}_report.xml"
    - docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"

  coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
  after_script:
    # Check status after the tests
    - docker ps -a
    - docker logs context
    - docker logs device
    - docker logs pathcomp-frontend
    - docker logs pathcomp-backend
    - docker logs $IMAGE_NAME

    - docker rm -f $IMAGE_NAME
    - docker rm -f pathcomp-frontend
    - docker rm -f pathcomp-backend
    - docker rm -f device
    - docker rm -f context

    - docker rm -f $IMAGE_NAME crdb nats
    - docker volume rm -f crdb
    - docker network rm teraflowbridge
    - docker volume prune --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"'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
      - manifests/${IMAGE_NAME}service.yaml
      - .gitlab-ci.yml

  artifacts:
      when: always
      reports:
        junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml

## Deployment of the service in Kubernetes Cluster
#deploy service:
#  variables:
#    IMAGE_NAME: 'service' # name of the microservice
#    IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
#  stage: deploy
#  needs:
#    - unit test service
#    # - integ_test execute
#  script:
#    - 'sed -i "s/$IMAGE_NAME:.*/$IMAGE_NAME:$IMAGE_TAG/" manifests/${IMAGE_NAME}service.yaml'
#    - kubectl version
#    - kubectl get all
#    - kubectl apply -f "manifests/${IMAGE_NAME}service.yaml"
#    - kubectl get all
#  # environment:
#  #   name: test
#  #   url: https://example.com
#  #   kubernetes:
#  #     namespace: test
#  rules:
#    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
#      when: manual    
#    - if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
#      when: manual
Loading