Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tfs/controller
1 result
Show changes
Commits on Source (19)
Showing
with 821 additions and 5 deletions
......@@ -228,3 +228,16 @@ export GRAF_EXT_PORT_HTTP=${GRAF_EXT_PORT_HTTP:-"3000"}
./deploy/show.sh
echo "Done!"
TFS_NAMESPACE="tfs"
PCEP_EXT_PORT_HTTP="4189"
PCEP_PORT_HTTP=$(kubectl --namespace ${TFS_NAMESPACE} get service pcepservice -o 'jsonpath={.spec.ports[?(@.name=="pcep")].port}')
PATCH='{"data": {"'${PCEP_EXT_PORT_HTTP}'": "'${TFS_NAMESPACE}'/pcepservice:'${PCEP_PORT_HTTP}'"}}'
kubectl patch configmap nginx-ingress-tcp-microk8s-conf --namespace ingress --patch "${PATCH}"
PORT_MAP='{"containerPort": '${PCEP_EXT_PORT_HTTP}', "hostPort": '${PCEP_EXT_PORT_HTTP}'}'
CONTAINER='{"name": "nginx-ingress-microk8s", "ports": ['${PORT_MAP}']}'
PATCH='{"spec": {"template": {"spec": {"containers": ['${CONTAINER}']}}}}'
kubectl patch daemonset nginx-ingress-microk8s-controller --namespace ingress --patch "${PATCH}"
\ No newline at end of file
TFS_NAMESPACE="tfs"
PCEP_EXT_PORT_HTTP="4189"
PCEP_PORT_HTTP=$(kubectl --namespace ${TFS_NAMESPACE} get service pcepservice -o 'jsonpath={.spec.ports[?(@.name=="pcep")].port}')
PATCH='{"data": {"'${PCEP_EXT_PORT_HTTP}'": "'${TFS_NAMESPACE}'/pcepservice:'${PCEP_PORT_HTTP}'"}}'
kubectl patch configmap nginx-ingress-tcp-microk8s-conf --namespace ingress --patch "${PATCH}"
PORT_MAP='{"containerPort": '${PCEP_EXT_PORT_HTTP}', "hostPort": '${PCEP_EXT_PORT_HTTP}'}'
CONTAINER='{"name": "nginx-ingress-microk8s", "ports": ['${PORT_MAP}']}'
PATCH='{"spec": {"template": {"spec": {"containers": ['${CONTAINER}']}}}}'
kubectl patch daemonset nginx-ingress-microk8s-controller --namespace ingress --patch "${PATCH}"
\ No newline at end of file
# 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:
annotations:
config.linkerd.io/skip-outbound-ports: "4189"
labels:
app: pcepservice
spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: localhost:32000/tfs/pcep:dev
imagePullPolicy: Always
ports:
- containerPort: 20050
- containerPort: 9192
- containerPort: 6666
- containerPort: 4189
env:
- name: LOG_LEVEL
value: "DEBUG"
readinessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:20050"]
livenessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:20050"]
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: 20050
targetPort: 20050
- name: metrics
protocol: TCP
port: 9192
targetPort: 9192
- name: pcep
protocol: TCP
port: 4189
targetPort: 4189
- name: managm
protocol: TCP
port: 6666
targetPort: 6666
......@@ -28,6 +28,9 @@ export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_gene
# Uncomment to activate Monitoring Framework (new)
#export TFS_COMPONENTS="${TFS_COMPONENTS} kpi_manager kpi_value_writer kpi_value_api"
# Uncomment to activate pcep
#export TFS_COMPONENTS="${TFS_COMPONENTS} pcep"
# Uncomment to activate BGP-LS Speaker
#export TFS_COMPONENTS="${TFS_COMPONENTS} bgpls_speaker"
......
// 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;
}
#!/bin/bash
# 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.
########################################################################################################################
# Define your deployment settings here
########################################################################################################################
# If not already set, set the name of the Kubernetes namespace to deploy to.
export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"}
########################################################################################################################
# Automated steps start here
########################################################################################################################
kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/pcepservice -c server
......@@ -56,6 +56,7 @@ class ServiceNameEnum(Enum):
OPTICALATTACKDETECTOR = 'opticalattackdetector'
OPTICALATTACKMITIGATOR = 'opticalattackmitigator'
CACHING = 'caching'
PCEP = 'pcep'
TE = 'te'
FORECASTER = 'forecaster'
E2EORCHESTRATOR = 'e2e-orchestrator'
......@@ -92,11 +93,13 @@ DEFAULT_SERVICE_GRPC_PORTS = {
ServiceNameEnum.OPTICALATTACKMANAGER .value : 10005,
ServiceNameEnum.INTERDOMAIN .value : 10010,
ServiceNameEnum.PATHCOMP .value : 10020,
ServiceNameEnum.PCEP .value : 10050,
ServiceNameEnum.TE .value : 10030,
ServiceNameEnum.FORECASTER .value : 10040,
ServiceNameEnum.E2EORCHESTRATOR .value : 10050,
ServiceNameEnum.OPTICALCONTROLLER .value : 10060,
ServiceNameEnum.BGPLS .value : 20030,
ServiceNameEnum.PCEP .value : 20050,
ServiceNameEnum.KPIMANAGER .value : 30010,
ServiceNameEnum.KPIVALUEAPI .value : 30020,
ServiceNameEnum.KPIVALUEWRITER .value : 30030,
......
......@@ -26,7 +26,6 @@ RESOURCE_SERVICES = '__services__'
RESOURCE_ACL = '__acl__'
RESOURCE_INVENTORY = '__inventory__'
class _Driver:
def __init__(self, name : str, address: str, port: int, **settings) -> None:
""" Initialize Driver.
......
......@@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from ast import List, Tuple
import json, logging, lxml.etree as ET, re
import time
from typing import Any, Dict, Optional
......@@ -33,7 +32,6 @@ from .acl.acl_adapter_ipinfusion_proprietary import acl_cr_to_dict_ipinfusion_pr
LOGGER = logging.getLogger(__name__)
ALL_RESOURCE_KEYS = [
RESOURCE_INVENTORY,
RESOURCE_ENDPOINTS,
RESOURCE_INTERFACES,
RESOURCE_ROUTING_POLICIES, # routing policies should come before network instances
......@@ -42,7 +40,6 @@ ALL_RESOURCE_KEYS = [
]
RESOURCE_KEY_MAPPINGS = {
RESOURCE_INVENTORY : 'inventory',
RESOURCE_ENDPOINTS : 'component',
RESOURCE_INTERFACES : 'interface',
RESOURCE_NETWORK_INSTANCES: 'network_instance',
......@@ -51,7 +48,6 @@ RESOURCE_KEY_MAPPINGS = {
}
RESOURCE_PARSERS = {
'inventory' : parse_inventory,
'component' : parse_endpoints,
'interface' : parse_interfaces,
'network_instance': parse_network_instances,
......
# Copyright 2022-2024 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 -p 4189:4189 -p 6666:6666
--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
# Copyright 2022-2024 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.
# 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.
FROM python:3.9-slim
# Install dependencies
RUN apt-get --yes --quiet --quiet update && \
apt-get --yes --quiet --quiet install wget g++ && \
rm -rf /var/lib/apt/lists/*
# Set Python to show logs as they occur
ENV PYTHONUNBUFFERED=0
# Download the gRPC health probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
#Ping
RUN apt-get update && apt-get install -y iputils-ping g++ && \
rm -rf /var/lib/apt/lists/*
# Get generic Python packages
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --upgrade setuptools wheel
RUN python3 -m pip install --upgrade pip-tools
# Install OpenJDK-11
RUN apt-get update && \
apt-get install -y openjdk-17-jre && \
apt-get clean;
# Get common Python packages
# Note: this step enables sharing the previous Docker build steps among all the Python components
WORKDIR /var/teraflow
COPY common_requirements.in common_requirements.in
RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in
RUN python3 -m pip install -r common_requirements.txt
# Add common files into working directory
WORKDIR /var/teraflow/common
COPY src/common/. ./
RUN rm -rf proto
# Create proto sub-folder, copy .proto files, and generate Python code
RUN mkdir -p /var/teraflow/common/proto
WORKDIR /var/teraflow/common/proto
RUN touch __init__.py
COPY proto/*.proto ./
RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto
RUN rm *.proto
RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \;
# Create component sub-folders, get specific Python packages
RUN mkdir -p /var/teraflow/pcep
WORKDIR /var/teraflow/pcep
COPY src/pcep/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN python3 -m pip install -r requirements.txt
# Java module necessary config files
WORKDIR /var/teraflow/pcep
RUN mkdir -p /resources
COPY src/pcep/service/resources/. resources/
# Add the Tools Module
WORKDIR /var/teraflow/pcep
RUN mkdir -p /tools
COPY src/pcep/service/tools/. resources/
# Add component files into working directory
WORKDIR /var/teraflow
COPY src/context/. context/
COPY src/device/. device/
COPY src/pathcomp/frontend/. pathcomp/frontend/
COPY src/service/. service/
COPY src/pcep/. pcep/
#Added
EXPOSE 4189
EXPOSE 6666
# Start the service
ENTRYPOINT ["python", "-m", "pcep.service"]
# Copyright 2022-2024 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.
# 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.
import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.context_pb2 import Empty, Service, ServiceId
from common.proto.pcep_pb2_grpc import PcepServiceStub
from common.proto.pcep_pb2 import RequestRq, RequestRp, PceIpRq, PceIpRp
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string
LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15
DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0)
RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
class PcepClient:
def __init__(self, host=None, port=None):
if not host: host = get_service_host(ServiceNameEnum.PCEP)
if not port: port = get_service_port_grpc(ServiceNameEnum.PCEP)
self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
LOGGER.debug('Creating channel to {:s}...'.format(str(self.endpoint)))
self.channel = None
self.stub = None
self.connect()
LOGGER.debug('Channel created')
def connect(self):
LOGGER.debug('Creating channel to {:s}...'.format(str(self.endpoint)))
self.channel = grpc.insecure_channel(self.endpoint)
self.stub = PcepServiceStub(self.channel)
self.host = get_service_host(ServiceNameEnum.PCEP)
LOGGER.debug('Channel created')
def close(self):
if self.channel is not None: self.channel.close()
self.channel = None
self.stub = None
@RETRY_DECORATOR
def sendRequest(self, request : RequestRq) -> RequestRp:
LOGGER.debug('Send request: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.sendRequest(request)
LOGGER.debug('Send request result: {:s}'.format(grpc_message_to_json_string(response)))
return response
@RETRY_DECORATOR
def configuratePCE(self, request : PceIpRq) -> PceIpRp:
LOGGER.debug("Configuring the PCE")
LOGGER.debug('Configurate PCE: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.configuratePCE(request)
LOGGER.debug('Configurate PCE result: {:s}'.format(grpc_message_to_json_string(response)))
return response
'''
@RETRY_DECORATOR
def showLSPDB(self):
LOGGER.debug("Showing the LSP Paths in the PCE")
#Make the gRPC call
requestlsp = LSPdb_Request()
port = 10060
channel = grpc.insecure_channel(f'{self.host}:{port}')
stub_lsp = pceServiceStub(channel)
responselsp = stub_lsp.getLSPdb(requestlsp)
return responselsp
'''
# 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.
# Copyright 2022-2024 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.
anytree==2.8.0
APScheduler==3.8.1
#networkx==2.6.3
#pydot==1.4.2
#redis==4.1.2
#fastcache==1.1.0
ncclient==0.6.13
python-json-logger==2.0.2
pytz==2021.3
xmltodict==0.12.0
# pip's dependency resolver does not take into account installed packages.
# p4runtime does not specify the version of grpcio/protobuf it needs, so it tries to install latest one
# adding here again grpcio==1.47.* and protobuf==3.20.* with explicit versions to prevent collisions
grpcio==1.47.*
protobuf==3.20.*
prometheus_client==0.13.0
\ No newline at end of file
# Copyright 2022-2024 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.
import logging
from pcep.service.tools.GrpcServer import GrpcServer
from common.Constants import ServiceNameEnum
from common.Settings import get_service_port_grpc, get_service_host
from common.proto.pcep_pb2_grpc import add_PcepServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService
from .PcepServiceServicerImpl import PcepServiceServicerImpl
LOGGER = logging.getLogger(__name__)
class PcepService(GenericGrpcService):
def __init__(self, pcepServer : GrpcServer,cls_name: str = __name__) -> None:
port = get_service_port_grpc(ServiceNameEnum.PCEP) #El enum en common.constants
LOGGER.debug('PORT... (PCEP Service)')
LOGGER.debug(port)
host = get_service_host(ServiceNameEnum.PCEP) #El enum en common.constants
LOGGER.debug('HOST... (PCEP Service)')
LOGGER.debug(host)
super().__init__(port, cls_name=cls_name)
self.pcep_servicer = PcepServiceServicerImpl(pcepServer)
LOGGER.debug('Creating Servicer... (PCEP Service)')
def install_servicers(self):
add_PcepServiceServicer_to_server(self.pcep_servicer, self.server)
# Copyright 2022-2024 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.
import grpc, logging
from pcep.service.tools.GrpcServer import GrpcServer
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.pcep_pb2 import (RequestRq, RequestRp, PceIpRq, PceIpRp)
from common.proto.pcep_pb2_grpc import PcepServiceServicer
LOGGER = logging.getLogger(__name__)
METRICS_POOL = MetricsPool('Service', 'RPC')
class PcepServiceServicerImpl(PcepServiceServicer):
def __init__(self, pcepServer : GrpcServer) -> None:
LOGGER.debug('Creating Servicer...')
self.pcepServer=pcepServer
LOGGER.debug('Servicer Created')
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def configuratePCE(self, request : PceIpRq, context : grpc.ServicerContext) -> PceIpRp:
LOGGER.debug("(ConfiguratePCE) Create pce instance %s",request)
configurateIP=self.pcepServer.connectToJavaPcep(request.address)
return PceIpRp(addressRp=configurateIP)
#return PceIpRp(addressRp="10.95.90.56")
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def sendRequest(self, request : RequestRq, context : grpc.ServicerContext) -> RequestRp:
LOGGER.debug("(Send Request) Send: %s",request.command)
message=self.pcepServer.requestToJavaPcep(request.command)
return RequestRp(commandRp=message)
# Copyright 2022-2024 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.
# Copyright 2022-2024 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.
import logging, signal, sys, threading
from prometheus_client import start_http_server
from common.Settings import get_log_level, get_metrics_port
from .PcepService import PcepService
from .tools.GrpcServer import GrpcServer
import socket
terminate = threading.Event()
LOGGER = logging.getLogger(__name__)
def signal_handler(signal, frame): # pylint: disable=redefined-outer-name
LOGGER.warning('Terminate signal received')
LOGGER.warning(signal)
terminate.set()
def main():
global LOGGER # pylint: disable=global-statement
log_level = get_log_level()
logging.basicConfig(level=log_level, format="[%(asctime)s] %(levelname)s:%(name)s:%(message)s")
LOGGER = logging.getLogger(__name__)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
LOGGER.info('Starting... (MAIN.py)')
# Start metrics server
metrics_port = get_metrics_port()
start_http_server(metrics_port)
# Initialize ServiceHandler Factory
#service_handler_factory = ServiceHandlerFactory(SERVICE_HANDLERS)
pcep_server = GrpcServer() #Create instance of the GRPC Server
# pcep_server.Connect()
ip_address = socket.gethostbyname(socket.gethostname())
LOGGER.debug("IP address of the PCEP POD: %s", ip_address)
LOGGER.debug(ip_address)
pcep_server.connectToJavaPcep(ip_address)
# Starting pcep service
pcep_service = PcepService(pcep_server)
pcep_service.start()
# Wait for Ctrl+C or termination signal
while not terminate.wait(timeout=0.1): pass
LOGGER.info('Terminating...')
pcep_server.terminateGrpcServer()
pcep_service.stop()
LOGGER.info('Bye')
return 0
if __name__ == '__main__':
sys.exit(main())