Skip to content
Snippets Groups Projects
Commit cea32672 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'develop' of https://labs.etsi.org/rep/tfs/controller into netx22-p4

parents 80f0bdc7 7ea968e5
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!12fix: Change directory structure to match hackfest
Showing
with 1518 additions and 26 deletions
......@@ -162,6 +162,10 @@ cython_debug/
# TeraFlowSDN-generated files
tfs_runtime_env_vars.sh
tfs_bchain_runtime_env_vars.sh
delete_local_deployment.sh
local_docker_deployment.sh
local_k8s_deployment.sh
# Other logs
**/logs/*.log.*
......@@ -42,3 +42,4 @@ include:
#- local: '/src/slice/.gitlab-ci.yml'
#- local: '/src/interdomain/.gitlab-ci.yml'
- local: '/src/pathcomp/.gitlab-ci.yml'
#- local: '/src/dlt/.gitlab-ci.yml'
......@@ -66,44 +66,71 @@ echo "export PYTHONPATH=${PYTHONPATH}" >> $ENV_VARS_SCRIPT
for COMPONENT in $TFS_COMPONENTS; do
echo "Processing '$COMPONENT' component..."
IMAGE_NAME="$COMPONENT:$TFS_IMAGE_TAG"
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$IMAGE_NAME" | sed 's,//,/,g' | sed 's,http:/,,g')
echo " Building Docker image..."
BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}.log"
if [ "$COMPONENT" == "automation" ] || [ "$COMPONENT" == "policy" ]; then
docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile ./src/"$COMPONENT"/ > "$BUILD_LOG"
docker build -t "$COMPONENT:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/Dockerfile ./src/"$COMPONENT"/ > "$BUILD_LOG"
elif [ "$COMPONENT" == "pathcomp" ]; then
BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}-frontend.log"
docker build -t "$COMPONENT-frontend:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/frontend/Dockerfile . >> "$BUILD_LOG"
docker build -t "$COMPONENT-frontend:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/frontend/Dockerfile . > "$BUILD_LOG"
BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}-backend.log"
docker build -t "$COMPONENT-backend:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/backend/Dockerfile . >> "$BUILD_LOG"
docker build -t "$COMPONENT-backend:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/backend/Dockerfile . > "$BUILD_LOG"
# next command is redundant, but helpful to keep cache updated between rebuilds
docker build -t "$COMPONENT-backend:$TFS_IMAGE_TAG-builder" --target builder -f ./src/"$COMPONENT"/backend/Dockerfile . >> "$BUILD_LOG"
IMAGE_NAME="$COMPONENT-backend:$TFS_IMAGE_TAG-builder"
docker build -t "$IMAGE_NAME" --target builder -f ./src/"$COMPONENT"/backend/Dockerfile . >> "$BUILD_LOG"
elif [ "$COMPONENT" == "dlt" ]; then
BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}-connector.log"
docker build -t "$COMPONENT-connector:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/connector/Dockerfile . > "$BUILD_LOG"
BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}-gateway.log"
docker build -t "$COMPONENT-gateway:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/gateway/Dockerfile . > "$BUILD_LOG"
else
docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile . > "$BUILD_LOG"
docker build -t "$COMPONENT:$TFS_IMAGE_TAG" -f ./src/"$COMPONENT"/Dockerfile . > "$BUILD_LOG"
fi
if [ -n "$TFS_REGISTRY_IMAGE" ]; then
echo " Pushing Docker image to '$TFS_REGISTRY_IMAGE'..."
if [ "$COMPONENT" == "pathcomp" ]; then
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}-frontend.log"
docker tag "$COMPONENT-frontend:$TFS_IMAGE_TAG" "$IMAGE_URL-frontend" > "$TAG_LOG"
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-frontend:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}-backend.log"
docker tag "$COMPONENT-backend:$TFS_IMAGE_TAG" "$IMAGE_URL-backend" > "$TAG_LOG"
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}-frontend.log"
docker tag "$COMPONENT-frontend:$TFS_IMAGE_TAG" "$IMAGE_URL" > "$TAG_LOG"
PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}-frontend.log"
docker push "$IMAGE_URL-frontend" > "$PUSH_LOG"
docker push "$IMAGE_URL" > "$PUSH_LOG"
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-backend:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}-backend.log"
docker tag "$COMPONENT-backend:$TFS_IMAGE_TAG" "$IMAGE_URL" > "$TAG_LOG"
PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}-backend.log"
docker push "$IMAGE_URL-backend" > "$PUSH_LOG"
docker push "$IMAGE_URL" > "$PUSH_LOG"
elif [ "$COMPONENT" == "dlt" ]; then
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-connector:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}-connector.log"
docker tag "$COMPONENT-connector:$TFS_IMAGE_TAG" "$IMAGE_URL" > "$TAG_LOG"
PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}-connector.log"
docker push "$IMAGE_URL" > "$PUSH_LOG"
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-gateway:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}-gateway.log"
docker tag "$COMPONENT-gateway:$TFS_IMAGE_TAG" "$IMAGE_URL" > "$TAG_LOG"
PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}-gateway.log"
docker push "$IMAGE_URL" > "$PUSH_LOG"
else
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}.log"
docker tag "$IMAGE_NAME" "$IMAGE_URL" > "$TAG_LOG"
docker tag "$COMPONENT:$TFS_IMAGE_TAG" "$IMAGE_URL" > "$TAG_LOG"
PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log"
docker push "$IMAGE_URL" > "$PUSH_LOG"
......@@ -117,33 +144,48 @@ for COMPONENT in $TFS_COMPONENTS; do
if [ -n "$TFS_REGISTRY_IMAGE" ]; then
# Registry is set
if [ "$COMPONENT" == "pathcomp" ]; then
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-frontend:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-frontend:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-frontend:${VERSION}#image: $IMAGE_URL-frontend#g" "$MANIFEST"
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-frontend:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST"
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-backend:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-backend:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-backend:${VERSION}#image: $IMAGE_URL-backend#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" "$MANIFEST"
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-backend:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST"
elif [ "$COMPONENT" == "dlt" ]; then
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-connector:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-connector:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-connector:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST"
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT-gateway:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-gateway:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-gateway:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST"
else
IMAGE_URL=$(echo "$TFS_REGISTRY_IMAGE/$COMPONENT:$TFS_IMAGE_TAG" | sed 's,//,/,g' | sed 's,http:/,,g')
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" "$MANIFEST"
fi
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" "$MANIFEST"
else
# Registry is not set
if [ "$COMPONENT" == "pathcomp" ]; then
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-frontend:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-frontend:${VERSION}#image: $IMAGE_NAME-frontend#g" "$MANIFEST"
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-frontend:${VERSION}#image: $COMPONENT-frontend:$TFS_IMAGE_TAG#g" "$MANIFEST"
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-backend:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-backend:${VERSION}#image: $IMAGE_NAME-backend#g" "$MANIFEST"
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-backend:${VERSION}#image: $COMPONENT-backend:$TFS_IMAGE_TAG#g" "$MANIFEST"
elif [ "$COMPONENT" == "dlt" ]; then
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-connector:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-connector:${VERSION}#image: $COMPONENT-connector:$TFS_IMAGE_TAG#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" "$MANIFEST"
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}-gateway:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT-gateway:${VERSION}#image: $COMPONENT-gateway:$TFS_IMAGE_TAG#g" "$MANIFEST"
else
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_NAME#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" "$MANIFEST"
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $COMPONENT:$TFS_IMAGE_TAG#g" "$MANIFEST"
fi
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" "$MANIFEST"
fi
# TODO: harmonize names of the monitoring component
......@@ -157,7 +199,7 @@ for COMPONENT in $TFS_COMPONENTS; do
echo " Collecting env-vars for '$COMPONENT' component..."
SERVICE_DATA=$(kubectl get service ${COMPONENT}service --namespace $TFS_K8S_NAMESPACE -o json)
SERVICE_DATA=$(kubectl get service ${COMPONENT_OBJNAME}service --namespace $TFS_K8S_NAMESPACE -o json)
if [ -z "${SERVICE_DATA}" ]; then continue; fi
# Env vars for service's host address
......@@ -189,6 +231,7 @@ for EXTRA_MANIFEST in $TFS_EXTRA_MANIFESTS; do
kubectl --namespace $TFS_K8S_NAMESPACE apply -f $EXTRA_MANIFEST
printf "\n"
done
printf "\n"
# By now, leave these controls here. Some component dependencies are not well handled.
......@@ -203,8 +246,9 @@ fi
for COMPONENT in $TFS_COMPONENTS; do
echo "Waiting for '$COMPONENT' component..."
COMPONENT_OBJNAME=$(echo "${COMPONENT}" | sed "s/\_/-/")
kubectl wait --namespace $TFS_K8S_NAMESPACE \
--for='condition=available' --timeout=300s deployment/${COMPONENT}service
--for='condition=available' --timeout=300s deployment/${COMPONENT_OBJNAME}service
printf "\n"
done
......
#!/bin/bash
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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.
########################################################################################################################
# Read deployment settings
########################################################################################################################
# Set the URL of your local Docker registry where the images will be uploaded to.
REGISTRY_IMAGE="http://localhost:32000/tfs/"
# Set the tag you want to use for your images.
IMAGE_TAG="dev"
# Set the name of the Kubernetes namespace to deploy to.
K8S_NAMESPACE="tfs-bchain"
COMPONENT="mock_blockchain"
########################################################################################################################
# Automated steps start here
########################################################################################################################
# Constants
GITLAB_REPO_URL="registry.gitlab.com/teraflow-h2020/controller"
TMP_FOLDER="./tmp"
# Create a tmp folder for files modified during the deployment
TMP_MANIFESTS_FOLDER="$TMP_FOLDER/manifests"
mkdir -p $TMP_MANIFESTS_FOLDER
TMP_LOGS_FOLDER="$TMP_FOLDER/logs"
mkdir -p $TMP_LOGS_FOLDER
echo "Deleting and Creating a new namespace..."
kubectl delete namespace $K8S_NAMESPACE
kubectl create namespace $K8S_NAMESPACE
printf "\n"
echo "Deploying components and collecting environment variables..."
ENV_VARS_SCRIPT=tfs_bchain_runtime_env_vars.sh
echo "# Environment variables for TeraFlow Mock-Blockchain deployment" > $ENV_VARS_SCRIPT
PYTHONPATH=$(pwd)/src
echo "Processing '$COMPONENT' component..."
IMAGE_NAME="$COMPONENT:$IMAGE_TAG"
IMAGE_URL=$(echo "$REGISTRY_IMAGE/$IMAGE_NAME" | sed 's,//,/,g' | sed 's,http:/,,g')
echo " Building Docker image..."
BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}.log"
docker build -t "$IMAGE_NAME" -f ./src/dlt/mock_blockchain/Dockerfile . > "$BUILD_LOG"
if [ -n "$REGISTRY_IMAGE" ]; then
echo " Pushing Docker image to '$REGISTRY_IMAGE'..."
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}.log"
docker tag "$IMAGE_NAME" "$IMAGE_URL" > "$TAG_LOG"
PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log"
docker push "$IMAGE_URL" > "$PUSH_LOG"
fi
echo " Adapting '$COMPONENT' manifest file..."
MANIFEST="$TMP_MANIFESTS_FOLDER/${COMPONENT}.yaml"
cp ./manifests/"${COMPONENT}".yaml "$MANIFEST"
if [ -n "$REGISTRY_IMAGE" ]; then
# Registry is set
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" "$MANIFEST"
else
# Registry is not set
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_NAME#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" "$MANIFEST"
fi
echo " Deploying '$COMPONENT' component to Kubernetes..."
DEPLOY_LOG="$TMP_LOGS_FOLDER/deploy_${COMPONENT}.log"
kubectl --namespace $K8S_NAMESPACE apply -f "$MANIFEST" > "$DEPLOY_LOG"
COMPONENT_OBJNAME=$(echo "${COMPONENT}" | sed "s/\_/-/")
kubectl --namespace $K8S_NAMESPACE scale deployment --replicas=0 ${COMPONENT_OBJNAME} >> "$DEPLOY_LOG"
kubectl --namespace $K8S_NAMESPACE scale deployment --replicas=1 ${COMPONENT_OBJNAME} >> "$DEPLOY_LOG"
echo " Collecting env-vars for '$COMPONENT' component..."
SERVICE_DATA=$(kubectl get service ${COMPONENT_OBJNAME} --namespace $K8S_NAMESPACE -o json)
# Env vars for service's host address
SERVICE_HOST=$(echo ${SERVICE_DATA} | jq -r '.spec.clusterIP')
ENVVAR_HOST=$(echo "${COMPONENT}_SERVICE_HOST" | tr '[:lower:]' '[:upper:]')
echo "export ${ENVVAR_HOST}=${SERVICE_HOST}" >> $ENV_VARS_SCRIPT
# Env vars for service's 'grpc' port
SERVICE_PORT_GRPC=$(echo ${SERVICE_DATA} | jq -r '.spec.ports[] | select(.name=="grpc") | .port')
ENVVAR_PORT_GRPC=$(echo "${COMPONENT}_SERVICE_PORT_GRPC" | tr '[:lower:]' '[:upper:]')
echo "export ${ENVVAR_PORT_GRPC}=${SERVICE_PORT_GRPC}" >> $ENV_VARS_SCRIPT
printf "\n"
echo "Waiting for '$COMPONENT' component..."
kubectl wait --namespace $K8S_NAMESPACE \
--for='condition=available' --timeout=300s deployment/${COMPONENT_OBJNAME}
printf "\n"
echo "Deployment Resources:"
kubectl --namespace $K8S_NAMESPACE get all
printf "\n"
echo "Done!"
This is a quick guide for having fast access to the commands.
################################################################################
# Prepare environment
################################################################################
# (done) Create PyEnv virtual environment
cd ~/tfs-ctrl
pyenv virtualenv 3.9.13 tfs
pyenv local 3.9.13/envs/tfs
./install_requirements.sh
# (done) Install Python dependencies
pip install pyang
pip install git+https://github.com/robshakir/pyangbind.git
pip install netconf
# (done) Install PlantUML
# (done) Install dependencies to run PlantUML
sudo apt-get install -y graphviz openjdk-11-jre
# (done) Download plantuml.7997.jar from http://sourceforge.net/projects/plantuml/files/plantuml.7997.jar/download
cp ~/Downloads/plantuml.7997.jar ~/tfs-ctrl/hackfest/yang/plantuml.jar
# (done) Install WireShark
# When asked "allow non-root users to capture?" answer "yes"
sudo apt-get install -y wireshark
# Add current user to wireshark group to allow capturing as non-root (requires log-out & log-in, or reboot)
sudo usermod -a -G wireshark $USER
################################################################################
# YANG
################################################################################
## GUIDED
# Convert Topology YANG to Text-based tree
pyang -f tree topology.yang
pyang -f tree topology.yang -o topology.tree
# Report a sample message following Topology YANG data model
pyang -f sample-xml-skeleton --sample-xml-skeleton-annotations topology.yang
pyang -f sample-xml-skeleton --sample-xml-skeleton-annotations topology.yang -o topology-sample.xml
# Convert Topology YANG to UML
pyang -f uml topology.yang -o topology.uml
java -jar plantuml.jar topology.uml
# Convert Topology YANG to Python bindings
export PYBINDPLUGIN=`/usr/bin/env python -c \
'import pyangbind; import os; print ("{}/plugin".format(os.path.dirname(pyangbind.__file__)))'`
echo $PYBINDPLUGIN
pyang -f pybind topology.yang --plugindir $PYBINDPLUGIN -o binding_topology.py
# Test creation of JSON-/XML-encoded Topology messages
python topology.py
## EXERCISE
# Convert Connection YANG to Text-based tree
pyang -f tree connection.yang
# Report a sample message following Connection YANG data model
pyang -f sample-xml-skeleton --sample-xml-skeleton-annotations connection.yang
# Convert Connection YANG to UML
pyang -f uml connection.yang -o connection.uml
java -jar plantuml.jar connection.uml
# Convert Connection YANG to Python bindings
export PYBINDPLUGIN=`/usr/bin/env python -c \
'import pyangbind; import os; print ("{}/plugin".format(os.path.dirname(pyangbind.__file__)))'`
pyang -f pybind connection.yang --plugindir $PYBINDPLUGIN -o binding_connection.py
# Test creation of JSON-/XML-encoded Connection messages
python connection.py
################################################################################
# NETCONF
################################################################################
## GUIDED
Run server:
cd ~/tfs-ctrl/hackfest/netconf
python3 server_topology.py
In another window, run client:
cd ~/tfs-ctrl/hackfest/netconf
python3 client_topology.py
## EXERCISE
Run server:
cd ~/tfs-ctrl/hackfest/netconf/connection
python3 server_topology_connection.py
In another window, run client:
cd ~/tfs-ctrl/hackfest/netconf/connection
python3 client_connection.py
################################################################################
# TAPI
################################################################################
## GUIDED
# (done) Install dependencies
cd ~/tfs-ctrl/hackfest/tapi/server
pip install -r requirements.txt
# (done) Build & Implement methods for the TAPI v2.1.3 server:
cd ~/tfs-ctrl/hackfest/tapi
wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.35/swagger-codegen-cli-3.0.35.jar
wget -O tapi-connectivity.yaml https://github.com/OpenNetworkingFoundation/TAPI/raw/v2.1.3/OAS/tapi-connectivity%402020-06-16.yaml
java -jar swagger-codegen-cli-3.0.35.jar generate --input-spec tapi-connectivity.yaml \
--lang python-flask --output server --disable-examples --config codegen-config.json
pip install connexion==2.14.1
cd ~/tfs-ctrl/hackfest/tapi/server
# Rename methods in "tapi_server/controllers/tapi_path_computation_controller.py" as follows:
# operations_tapi_path_computationcompute_p2_p_path_post => operations_tapi_path_computationcompute_p_2_p_path_post
# operations_tapi_path_computationdelete_p2_p_path_post => operations_tapi_path_computationdelete_p_2_p_path_post
# operations_tapi_path_computationoptimize_p2_ppath_post => operations_tapi_path_computationoptimize_p_2_ppath_post
# Implement database based on Reference Implementation [Ref-3] in tapi/server/Acknowledgements.txt
# Run the TAPI server:
cd ~/tfs-ctrl/hackfest/tapi/server
python3 -m tapi_server 8080 database/mini-ols-context.json
# Run TAPI client using cURL (In a new window):
$ cd ~/tfs-ctrl/hackfest/tapi/client
# Interrogate Context and SIPs:
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/service-interface-point=node-4-port-16-output/
# Interrogate Topology, Nodes and Links:
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-topology:topology-context/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-topology:topology-context/topology=ols-topo/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-topology:topology-context/topology=ols-topo/node=node-4/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-topology:topology-context/topology=ols-topo/node=node-4/owned-node-edge-point=node-4-port-13/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-topology:topology-context/topology=ols-topo/node=node-4/owned-node-edge-point=node-4-port-13/tapi-connectivity:cep-list/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-topology:topology-context/topology=ols-topo/link=link-4:2-2:4/
# Create ConnectivityServices and Connections:
curl -X POST -H "Content-Type: application/json" \
http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/connectivity-service/ \
-d @/home/tfs/tfs-ctrl/hackfest/tapi/client/cs1.json
# Interrogate ConnectivityServices and Connections:
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/connectivity-service=cs1/
curl -X GET -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/connection=cs1/
# Delete ConnectivityServices and Connections:
curl -X DELETE -H "Content-Type: application/json" http://127.0.0.1:8080/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/connectivity-service=cs1/
## EXERCISE
# Exercise: retrieve and draw the topology
# solution in folder tapi_app
cd ~/tfs-ctrl/hackfest/tapi/tapi_app
python3 tapi_app.py
################################################################################
# Deploy TeraFlowSDN
################################################################################
# Check status of Kubernetes
microk8s.status --wait-ready
# Check all resources in Kubernetes
microk8s.kubectl get all --all-namespaces
# Deploy TeraFlowSDN
cd ~/tfs-ctrl
source my_deploy.sh
./deploy.sh
# Show status of your deployment
(if new terminal) cd ~/tfs-ctrl && source my_deploy.sh
./show_deploy.sh
# Show logs of a specific component
(if new terminal) cd ~/tfs-ctrl && source my_deploy.sh
scripts/show_logs_device.sh
################################################################################
# Programmable L3 routers
################################################################################
# (done) Build a Netconf server supporting basic OpenConfig data model
# Start the Netconf/OpenConfig server
cd ~/tfs-ctrl/hackfest/netconf-oc
python3 server_openconfig.py 8300
################################################################################
# Service requests
################################################################################
## L3VPN service from JSON descriptors
# (in a new terminal) Start OLS TAPI server:
cd ~/tfs-ctrl/hackfest/tapi/server
python3 -m tapi_server 8080 database/mini-ols-context.json
# (in a new terminal) Start the Netconf/OpenConfig server for R1
cd ~/tfs-ctrl/hackfest/netconf-oc
python3 server_openconfig.py 8301
# (in a new terminal) Start the Netconf/OpenConfig server for R2
cd ~/tfs-ctrl/hackfest/netconf-oc
python3 server_openconfig.py 8302
# (in a new terminal) Start the Netconf/OpenConfig server for R3
cd ~/tfs-ctrl/hackfest/netconf-oc
python3 server_openconfig.py 8303
# (in a new terminal) Start the Netconf/OpenConfig server for R4
cd ~/tfs-ctrl/hackfest/netconf-oc
python3 server_openconfig.py 8304
############
# Mock OSM
############
$ cd ~/tfs-ctrl/hackfest/
$ python -m mock_osm
Welcome to the MockOSM shell.
Type help or ? to list commands.
(mock-osm) create
Service b8c99e2c-39d8-424d-9833-554634269555 created
# Service should be created in TFS. Check "Slice" and "Service" pages on WebUI.
# Check configuration rules in "Devices"
(mock-osm) status
response.status_code=200
Status of Service b8c99e2c-39d8-424d-9833-554634269555 is {'sdn_status': 'ACTIVE'}
(mock-osm) delete
Service b8c99e2c-39d8-424d-9833-554634269555 deleted
# Service should be removed from TFS. Check "Slice" and "Service" pages on WebUI.
# Check configuration rules in "Devices"
(mock-osm) exit
Bye!
== GNMI
$ cd /usr/share/gocode/src/
$ export GOPATH=/usr/share/gocode/
$ go run github.com/openconfig/ygot/generator/generator.go -generate_fakeroot -output_file github.com/google/gnxi/gnmi/modeldata/gostruct/generated.go -package_name gostruct github.com/rvilalta/OFC_SC472/yang/topology.yang
$ cd /usr/share/gocode/src/github.com/google/gnxi/gnmi_target
$ go run gnmi_target.go -bind_address :10161 -config ~/tfs-ctrl/hackfest/gnmi/topology.json --notls -alsologtostderr
RUN CLIENT (in another window)
$ export GOPATH=/usr/share/gocode/
$ cd /usr/share/gocode/src/github.com/google/gnxi/gnmi_get
$ go run gnmi_get.go -notls -xpath "/topology/" -target_addr localhost:10161 -alsologtostderr
$ go run gnmi_get.go -notls -xpath "/topology/node[node-id=A]" -target_addr localhost:10161 -alsologtostderr
USE PYTHON CLIENT
$ cd /usr/share/gocode/src/github.com/google/gnxi/gnmi_cli_py
$ python py_gnmicli.py -n -m get -t localhost -p 10161 -x /topology -u foo -pass bar
{
"topology" : {
"node" : [
{ "node-id" : "A" , "port" : [ { "port-id" : "portA1" } ] },
{ "node-id" : "B" , "port" : [ { "port-id" : "portB1" } ] }
]
}
}
== GRPC
$ cd ~/tfs-ctrl/hackfest/grpc
COMPILE connection.proto:
$ python -m grpc_tools.protoc -I=. --python_out=connection/ connection.proto
RUN CREATE AND LIST CONNECTION
$ cd ~/tfs-ctrl/hackfest/grpc/connection
$ python3 create.py connection.txt
$ python3 list.py connection.txt
COMPILE connectionService.proto
$ python -m grpc_tools.protoc -I=. --python_out=connectionService/ --grpc_python_out=connectionService/ connectionService.proto
RUN SERVER
$ cd ~/tfs-ctrl/hackfest/grpc/connectionService
$ python3 connectionService_server.py
RUN CLIENT (in another window)
$ cd ~/tfs-ctrl/hackfest/grpc/connectionService
$ python3 connectionService_client.py
### EXERCISE
COMPILE connectionServiceWithNotif.proto
$ cd ~/tfs-ctrl/hackfest/grpc/
$ python -m grpc_tools.protoc -I=. --python_out=connectionServiceWithNotif/ --grpc_python_out=connectionServiceWithNotif/ connectionServiceWithNotif.proto
RUN SERVER
$ cd ~/tfs-ctrl/hackfest/grpc/connectionServiceWithNotif
$ python3 connectionServiceWithNotif_server.py
RUN CLIENT (in another window)
$ cd ~/tfs-ctrl/hackfest/grpc/connectionServiceWithNotif
$ python3 connectionServiceWithNotif_client.py
//Example of connection
syntax = "proto3";
package connection;
message Connection {
string connectionId = 1;
string sourceNode = 2;
string targetNode = 3;
string sourcePort = 4;
string targetPort = 5;
uint32 bandwidth = 6;
enum LayerProtocolName {
ETH = 0;
OPTICAL = 1;
}
LayerProtocolName layerProtocolName = 7;
}
message ConnectionList {
repeated Connection connection = 1;
}
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: connection.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='connection.proto',
package='connection',
syntax='proto3',
serialized_options=None,
serialized_pb=_b('\n\x10\x63onnection.proto\x12\nconnection\"\xf5\x01\n\nConnection\x12\x14\n\x0c\x63onnectionId\x18\x01 \x01(\t\x12\x12\n\nsourceNode\x18\x02 \x01(\t\x12\x12\n\ntargetNode\x18\x03 \x01(\t\x12\x12\n\nsourcePort\x18\x04 \x01(\t\x12\x12\n\ntargetPort\x18\x05 \x01(\t\x12\x11\n\tbandwidth\x18\x06 \x01(\r\x12\x43\n\x11layerProtocolName\x18\x07 \x01(\x0e\x32(.connection.Connection.LayerProtocolName\")\n\x11LayerProtocolName\x12\x07\n\x03\x45TH\x10\x00\x12\x0b\n\x07OPTICAL\x10\x01\"<\n\x0e\x43onnectionList\x12*\n\nconnection\x18\x01 \x03(\x0b\x32\x16.connection.Connectionb\x06proto3')
)
_CONNECTION_LAYERPROTOCOLNAME = _descriptor.EnumDescriptor(
name='LayerProtocolName',
full_name='connection.Connection.LayerProtocolName',
filename=None,
file=DESCRIPTOR,
values=[
_descriptor.EnumValueDescriptor(
name='ETH', index=0, number=0,
serialized_options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='OPTICAL', index=1, number=1,
serialized_options=None,
type=None),
],
containing_type=None,
serialized_options=None,
serialized_start=237,
serialized_end=278,
)
_sym_db.RegisterEnumDescriptor(_CONNECTION_LAYERPROTOCOLNAME)
_CONNECTION = _descriptor.Descriptor(
name='Connection',
full_name='connection.Connection',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='connectionId', full_name='connection.Connection.connectionId', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sourceNode', full_name='connection.Connection.sourceNode', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='targetNode', full_name='connection.Connection.targetNode', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sourcePort', full_name='connection.Connection.sourcePort', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='targetPort', full_name='connection.Connection.targetPort', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='bandwidth', full_name='connection.Connection.bandwidth', index=5,
number=6, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='layerProtocolName', full_name='connection.Connection.layerProtocolName', index=6,
number=7, type=14, cpp_type=8, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
_CONNECTION_LAYERPROTOCOLNAME,
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=33,
serialized_end=278,
)
_CONNECTIONLIST = _descriptor.Descriptor(
name='ConnectionList',
full_name='connection.ConnectionList',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='connection', full_name='connection.ConnectionList.connection', index=0,
number=1, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=280,
serialized_end=340,
)
_CONNECTION.fields_by_name['layerProtocolName'].enum_type = _CONNECTION_LAYERPROTOCOLNAME
_CONNECTION_LAYERPROTOCOLNAME.containing_type = _CONNECTION
_CONNECTIONLIST.fields_by_name['connection'].message_type = _CONNECTION
DESCRIPTOR.message_types_by_name['Connection'] = _CONNECTION
DESCRIPTOR.message_types_by_name['ConnectionList'] = _CONNECTIONLIST
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
Connection = _reflection.GeneratedProtocolMessageType('Connection', (_message.Message,), dict(
DESCRIPTOR = _CONNECTION,
__module__ = 'connection_pb2'
# @@protoc_insertion_point(class_scope:connection.Connection)
))
_sym_db.RegisterMessage(Connection)
ConnectionList = _reflection.GeneratedProtocolMessageType('ConnectionList', (_message.Message,), dict(
DESCRIPTOR = _CONNECTIONLIST,
__module__ = 'connection_pb2'
# @@protoc_insertion_point(class_scope:connection.ConnectionList)
))
_sym_db.RegisterMessage(ConnectionList)
# @@protoc_insertion_point(module_scope)
#! /usr/bin/env python3
import connection_pb2
import sys
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
# This function fills in a Connection message based on user input.
def PromptForConnection(connection):
connection.connectionId = raw_input("Enter connectionID: ")
connection.sourceNode = raw_input("Enter sourceNode: ")
connection.targetNode = raw_input("Enter targetNode: ")
connection.sourcePort = raw_input("Enter sourcePort: ")
connection.targetPort = raw_input("Enter targetPort: ")
connection.bandwidth = int( raw_input("Enter bandwidth: ") )
type = raw_input("Is this a eth or optical connection? ")
if type == "eth":
connection.layerProtocolName = connection_pb2.Connection.ETH
elif type == "optical":
connection.layerProtocolName = connection_pb2.Connection.OPTICAL
else:
print("Unknown layerProtocolName type; leaving as default value.")
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage:", sys.argv[0], "CONNECTION_FILE")
sys.exit(-1)
connectionList = connection_pb2.ConnectionList()
# Read the existing address book.
try:
with open(sys.argv[1], "rb") as f:
connectionList.ParseFromString(f.read())
except IOError:
print(sys.argv[1] + ": File not found. Creating a new file.")
# Add an address.
PromptForConnection(connectionList.connection.add())
# Write the new address book back to disk.
with open(sys.argv[1], "wb") as f:
f.write(connectionList.SerializeToString())
#! /usr/bin/env python3
from __future__ import print_function
import connection_pb2
import sys
# Iterates though all connections in the ConnectionList and prints info about them.
def ListConnections(connectionList):
for connection in connectionList.connection:
print("connectionID:", connection.connectionId)
print(" sourceNode:", connection.sourceNode)
print(" targetNode:", connection.targetNode)
print(" sourcePort:", connection.sourcePort)
print(" targetPort:", connection.targetPort)
print(" bandwidth:", connection.bandwidth)
if connection.layerProtocolName == connection_pb2.Connection.ETH:
print(" layerProtocolName:ETH")
elif connection.layerProtocolName == connection_pb2.Connection.OPTICAL:
print(" layerProtocolName:OPTICAL")
if __name__ == '__main__':
if len(sys.argv) != 2:
print("Usage:", sys.argv[0], "CONNECTION_FILE")
sys.exit(-1)
connectionList = connection_pb2.ConnectionList()
# Read the existing address book.
with open(sys.argv[1], "rb") as f:
connectionList.ParseFromString(f.read())
ListConnections(connectionList)
//Example of connection
syntax = "proto3";
package connection;
import "google/protobuf/empty.proto";
service ConnectionService {
rpc CreateConnection (Connection) returns (google.protobuf.Empty) {}
rpc ListConnection (google.protobuf.Empty) returns (ConnectionList) {}
}
message Connection {
string connectionId = 1;
string sourceNode = 2;
string targetNode = 3;
string sourcePort = 4;
string targetPort = 5;
uint32 bandwidth = 6;
enum LayerProtocolName {
ETH = 0;
OPTICAL = 1;
}
LayerProtocolName layerProtocolName = 7;
}
message ConnectionList {
repeated Connection connection = 1;
}
from __future__ import print_function
import grpc
import connectionService_pb2
import connectionService_pb2_grpc
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def createConnection():
with grpc.insecure_channel('localhost:50051') as channel:
connection=connectionService_pb2.Connection()
connection.connectionId = raw_input("Enter connectionID: ")
connection.sourceNode = raw_input("Enter sourceNode: ")
connection.targetNode = raw_input("Enter targetNode: ")
connection.sourcePort = raw_input("Enter sourcePort: ")
connection.targetPort = raw_input("Enter targetPort: ")
connection.bandwidth = int( raw_input("Enter bandwidth: ") )
stub = connectionService_pb2_grpc.ConnectionServiceStub(channel)
response = stub.CreateConnection(connection)
print("ConnectionService client received: " + str(response) )
def listConnection():
with grpc.insecure_channel('localhost:50051') as channel:
stub = connectionService_pb2_grpc.ConnectionServiceStub(channel)
response = stub.ListConnection(google_dot_protobuf_dot_empty__pb2.Empty())
print("ConnectionService client received: " + str(response) )
if __name__ == '__main__':
createConnection()
listConnection()
\ No newline at end of file
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: connectionService.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name='connectionService.proto',
package='connection',
syntax='proto3',
serialized_options=None,
serialized_pb=_b('\n\x17\x63onnectionService.proto\x12\nconnection\x1a\x1bgoogle/protobuf/empty.proto\"\xf5\x01\n\nConnection\x12\x14\n\x0c\x63onnectionId\x18\x01 \x01(\t\x12\x12\n\nsourceNode\x18\x02 \x01(\t\x12\x12\n\ntargetNode\x18\x03 \x01(\t\x12\x12\n\nsourcePort\x18\x04 \x01(\t\x12\x12\n\ntargetPort\x18\x05 \x01(\t\x12\x11\n\tbandwidth\x18\x06 \x01(\r\x12\x43\n\x11layerProtocolName\x18\x07 \x01(\x0e\x32(.connection.Connection.LayerProtocolName\")\n\x11LayerProtocolName\x12\x07\n\x03\x45TH\x10\x00\x12\x0b\n\x07OPTICAL\x10\x01\"<\n\x0e\x43onnectionList\x12*\n\nconnection\x18\x01 \x03(\x0b\x32\x16.connection.Connection2\xa1\x01\n\x11\x43onnectionService\x12\x44\n\x10\x43reateConnection\x12\x16.connection.Connection\x1a\x16.google.protobuf.Empty\"\x00\x12\x46\n\x0eListConnection\x12\x16.google.protobuf.Empty\x1a\x1a.connection.ConnectionList\"\x00\x62\x06proto3')
,
dependencies=[google_dot_protobuf_dot_empty__pb2.DESCRIPTOR,])
_CONNECTION_LAYERPROTOCOLNAME = _descriptor.EnumDescriptor(
name='LayerProtocolName',
full_name='connection.Connection.LayerProtocolName',
filename=None,
file=DESCRIPTOR,
values=[
_descriptor.EnumValueDescriptor(
name='ETH', index=0, number=0,
serialized_options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='OPTICAL', index=1, number=1,
serialized_options=None,
type=None),
],
containing_type=None,
serialized_options=None,
serialized_start=273,
serialized_end=314,
)
_sym_db.RegisterEnumDescriptor(_CONNECTION_LAYERPROTOCOLNAME)
_CONNECTION = _descriptor.Descriptor(
name='Connection',
full_name='connection.Connection',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='connectionId', full_name='connection.Connection.connectionId', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sourceNode', full_name='connection.Connection.sourceNode', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='targetNode', full_name='connection.Connection.targetNode', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sourcePort', full_name='connection.Connection.sourcePort', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='targetPort', full_name='connection.Connection.targetPort', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='bandwidth', full_name='connection.Connection.bandwidth', index=5,
number=6, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='layerProtocolName', full_name='connection.Connection.layerProtocolName', index=6,
number=7, type=14, cpp_type=8, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
_CONNECTION_LAYERPROTOCOLNAME,
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=69,
serialized_end=314,
)
_CONNECTIONLIST = _descriptor.Descriptor(
name='ConnectionList',
full_name='connection.ConnectionList',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='connection', full_name='connection.ConnectionList.connection', index=0,
number=1, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=316,
serialized_end=376,
)
_CONNECTION.fields_by_name['layerProtocolName'].enum_type = _CONNECTION_LAYERPROTOCOLNAME
_CONNECTION_LAYERPROTOCOLNAME.containing_type = _CONNECTION
_CONNECTIONLIST.fields_by_name['connection'].message_type = _CONNECTION
DESCRIPTOR.message_types_by_name['Connection'] = _CONNECTION
DESCRIPTOR.message_types_by_name['ConnectionList'] = _CONNECTIONLIST
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
Connection = _reflection.GeneratedProtocolMessageType('Connection', (_message.Message,), dict(
DESCRIPTOR = _CONNECTION,
__module__ = 'connectionService_pb2'
# @@protoc_insertion_point(class_scope:connection.Connection)
))
_sym_db.RegisterMessage(Connection)
ConnectionList = _reflection.GeneratedProtocolMessageType('ConnectionList', (_message.Message,), dict(
DESCRIPTOR = _CONNECTIONLIST,
__module__ = 'connectionService_pb2'
# @@protoc_insertion_point(class_scope:connection.ConnectionList)
))
_sym_db.RegisterMessage(ConnectionList)
_CONNECTIONSERVICE = _descriptor.ServiceDescriptor(
name='ConnectionService',
full_name='connection.ConnectionService',
file=DESCRIPTOR,
index=0,
serialized_options=None,
serialized_start=379,
serialized_end=540,
methods=[
_descriptor.MethodDescriptor(
name='CreateConnection',
full_name='connection.ConnectionService.CreateConnection',
index=0,
containing_service=None,
input_type=_CONNECTION,
output_type=google_dot_protobuf_dot_empty__pb2._EMPTY,
serialized_options=None,
),
_descriptor.MethodDescriptor(
name='ListConnection',
full_name='connection.ConnectionService.ListConnection',
index=1,
containing_service=None,
input_type=google_dot_protobuf_dot_empty__pb2._EMPTY,
output_type=_CONNECTIONLIST,
serialized_options=None,
),
])
_sym_db.RegisterServiceDescriptor(_CONNECTIONSERVICE)
DESCRIPTOR.services_by_name['ConnectionService'] = _CONNECTIONSERVICE
# @@protoc_insertion_point(module_scope)
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
import grpc
import connectionService_pb2 as connectionService__pb2
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
class ConnectionServiceStub(object):
# missing associated documentation comment in .proto file
pass
def __init__(self, channel):
"""Constructor.
Args:
channel: A grpc.Channel.
"""
self.CreateConnection = channel.unary_unary(
'/connection.ConnectionService/CreateConnection',
request_serializer=connectionService__pb2.Connection.SerializeToString,
response_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
)
self.ListConnection = channel.unary_unary(
'/connection.ConnectionService/ListConnection',
request_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
response_deserializer=connectionService__pb2.ConnectionList.FromString,
)
class ConnectionServiceServicer(object):
# missing associated documentation comment in .proto file
pass
def CreateConnection(self, request, context):
# missing associated documentation comment in .proto file
pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def ListConnection(self, request, context):
# missing associated documentation comment in .proto file
pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def add_ConnectionServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'CreateConnection': grpc.unary_unary_rpc_method_handler(
servicer.CreateConnection,
request_deserializer=connectionService__pb2.Connection.FromString,
response_serializer=google_dot_protobuf_dot_empty__pb2.Empty.SerializeToString,
),
'ListConnection': grpc.unary_unary_rpc_method_handler(
servicer.ListConnection,
request_deserializer=google_dot_protobuf_dot_empty__pb2.Empty.FromString,
response_serializer=connectionService__pb2.ConnectionList.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'connection.ConnectionService', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
from concurrent import futures
import time
import logging
import grpc
import connectionService_pb2
import connectionService_pb2_grpc
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
class connectionService(connectionService_pb2_grpc.ConnectionServiceServicer):
def __init__(self):
self.connectionList = connectionService_pb2.ConnectionList()
def CreateConnection(self, request, context):
logging.debug("Received Connection " + request.connectionId)
self.connectionList.connection.extend([request])
return google_dot_protobuf_dot_empty__pb2.Empty()
def ListConnection(self, request, context):
logging.debug("List Connections")
return self.connectionList
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
connectionService_pb2_grpc.add_ConnectionServiceServicer_to_server(connectionService(), server)
server.add_insecure_port('[::]:50051')
logging.debug("Starting server")
server.start()
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
serve()
//Example of connection
syntax = "proto3";
package connection;
import "google/protobuf/empty.proto";
service ConnectionServiceWithNotif {
rpc CreateConnection (Connection) returns (google.protobuf.Empty) {}
rpc ListConnection (google.protobuf.Empty) returns (ConnectionList) {}
rpc GetBer(Connection) returns (stream Ber) {}
}
message Ber {
double value = 1;
}
message Connection {
string connectionId = 1;
string sourceNode = 2;
string targetNode = 3;
string sourcePort = 4;
string targetPort = 5;
uint32 bandwidth = 6;
enum LayerProtocolName {
ETH = 0;
OPTICAL = 1;
}
LayerProtocolName layerProtocolName = 7;
}
message ConnectionList {
repeated Connection connection = 1;
}
from __future__ import print_function
import grpc
import connectionServiceWithNotif_pb2
import connectionServiceWithNotif_pb2_grpc
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3
def createConnection(stub):
connection=connectionServiceWithNotif_pb2.Connection()
connection.connectionId = raw_input("Enter connectionID: ")
connection.sourceNode = raw_input("Enter sourceNode: ")
connection.targetNode = raw_input("Enter targetNode: ")
connection.sourcePort = raw_input("Enter sourcePort: ")
connection.targetPort = raw_input("Enter targetPort: ")
connection.bandwidth = int( raw_input("Enter bandwidth: ") )
response = stub.CreateConnection(connection)
print("ConnectionService client received: " + str(response) )
def listConnection(stub):
response = stub.ListConnection(google_dot_protobuf_dot_empty__pb2.Empty())
print("ConnectionService client received: " + str(response) )
def getBer(stub):
responses = stub.GetBer(connectionServiceWithNotif_pb2.Connection(connectionId="conn1"))
for response in responses:
print("Received Ber %s" % (response.value) )
if __name__ == '__main__':
with grpc.insecure_channel('localhost:50051') as channel:
stub = connectionServiceWithNotif_pb2_grpc.ConnectionServiceWithNotifStub(channel)
#createConnection(stub)
listConnection(stub)
getBer(stub)
\ No newline at end of file
# Generated by the protocol buffer compiler. DO NOT EDIT!
# source: connectionServiceWithNotif.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
DESCRIPTOR = _descriptor.FileDescriptor(
name='connectionServiceWithNotif.proto',
package='connection',
syntax='proto3',
serialized_options=None,
serialized_pb=_b('\n connectionServiceWithNotif.proto\x12\nconnection\x1a\x1bgoogle/protobuf/empty.proto\"\x14\n\x03\x42\x65r\x12\r\n\x05value\x18\x01 \x01(\x01\"\xf5\x01\n\nConnection\x12\x14\n\x0c\x63onnectionId\x18\x01 \x01(\t\x12\x12\n\nsourceNode\x18\x02 \x01(\t\x12\x12\n\ntargetNode\x18\x03 \x01(\t\x12\x12\n\nsourcePort\x18\x04 \x01(\t\x12\x12\n\ntargetPort\x18\x05 \x01(\t\x12\x11\n\tbandwidth\x18\x06 \x01(\r\x12\x43\n\x11layerProtocolName\x18\x07 \x01(\x0e\x32(.connection.Connection.LayerProtocolName\")\n\x11LayerProtocolName\x12\x07\n\x03\x45TH\x10\x00\x12\x0b\n\x07OPTICAL\x10\x01\"<\n\x0e\x43onnectionList\x12*\n\nconnection\x18\x01 \x03(\x0b\x32\x16.connection.Connection2\xe1\x01\n\x1a\x43onnectionServiceWithNotif\x12\x44\n\x10\x43reateConnection\x12\x16.connection.Connection\x1a\x16.google.protobuf.Empty\"\x00\x12\x46\n\x0eListConnection\x12\x16.google.protobuf.Empty\x1a\x1a.connection.ConnectionList\"\x00\x12\x35\n\x06GetBer\x12\x16.connection.Connection\x1a\x0f.connection.Ber\"\x00\x30\x01\x62\x06proto3')
,
dependencies=[google_dot_protobuf_dot_empty__pb2.DESCRIPTOR,])
_CONNECTION_LAYERPROTOCOLNAME = _descriptor.EnumDescriptor(
name='LayerProtocolName',
full_name='connection.Connection.LayerProtocolName',
filename=None,
file=DESCRIPTOR,
values=[
_descriptor.EnumValueDescriptor(
name='ETH', index=0, number=0,
serialized_options=None,
type=None),
_descriptor.EnumValueDescriptor(
name='OPTICAL', index=1, number=1,
serialized_options=None,
type=None),
],
containing_type=None,
serialized_options=None,
serialized_start=304,
serialized_end=345,
)
_sym_db.RegisterEnumDescriptor(_CONNECTION_LAYERPROTOCOLNAME)
_BER = _descriptor.Descriptor(
name='Ber',
full_name='connection.Ber',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='value', full_name='connection.Ber.value', index=0,
number=1, type=1, cpp_type=5, label=1,
has_default_value=False, default_value=float(0),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=77,
serialized_end=97,
)
_CONNECTION = _descriptor.Descriptor(
name='Connection',
full_name='connection.Connection',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='connectionId', full_name='connection.Connection.connectionId', index=0,
number=1, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sourceNode', full_name='connection.Connection.sourceNode', index=1,
number=2, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='targetNode', full_name='connection.Connection.targetNode', index=2,
number=3, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='sourcePort', full_name='connection.Connection.sourcePort', index=3,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='targetPort', full_name='connection.Connection.targetPort', index=4,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='bandwidth', full_name='connection.Connection.bandwidth', index=5,
number=6, type=13, cpp_type=3, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='layerProtocolName', full_name='connection.Connection.layerProtocolName', index=6,
number=7, type=14, cpp_type=8, label=1,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
_CONNECTION_LAYERPROTOCOLNAME,
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=100,
serialized_end=345,
)
_CONNECTIONLIST = _descriptor.Descriptor(
name='ConnectionList',
full_name='connection.ConnectionList',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='connection', full_name='connection.ConnectionList.connection', index=0,
number=1, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto3',
extension_ranges=[],
oneofs=[
],
serialized_start=347,
serialized_end=407,
)
_CONNECTION.fields_by_name['layerProtocolName'].enum_type = _CONNECTION_LAYERPROTOCOLNAME
_CONNECTION_LAYERPROTOCOLNAME.containing_type = _CONNECTION
_CONNECTIONLIST.fields_by_name['connection'].message_type = _CONNECTION
DESCRIPTOR.message_types_by_name['Ber'] = _BER
DESCRIPTOR.message_types_by_name['Connection'] = _CONNECTION
DESCRIPTOR.message_types_by_name['ConnectionList'] = _CONNECTIONLIST
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
Ber = _reflection.GeneratedProtocolMessageType('Ber', (_message.Message,), dict(
DESCRIPTOR = _BER,
__module__ = 'connectionServiceWithNotif_pb2'
# @@protoc_insertion_point(class_scope:connection.Ber)
))
_sym_db.RegisterMessage(Ber)
Connection = _reflection.GeneratedProtocolMessageType('Connection', (_message.Message,), dict(
DESCRIPTOR = _CONNECTION,
__module__ = 'connectionServiceWithNotif_pb2'
# @@protoc_insertion_point(class_scope:connection.Connection)
))
_sym_db.RegisterMessage(Connection)
ConnectionList = _reflection.GeneratedProtocolMessageType('ConnectionList', (_message.Message,), dict(
DESCRIPTOR = _CONNECTIONLIST,
__module__ = 'connectionServiceWithNotif_pb2'
# @@protoc_insertion_point(class_scope:connection.ConnectionList)
))
_sym_db.RegisterMessage(ConnectionList)
_CONNECTIONSERVICEWITHNOTIF = _descriptor.ServiceDescriptor(
name='ConnectionServiceWithNotif',
full_name='connection.ConnectionServiceWithNotif',
file=DESCRIPTOR,
index=0,
serialized_options=None,
serialized_start=410,
serialized_end=635,
methods=[
_descriptor.MethodDescriptor(
name='CreateConnection',
full_name='connection.ConnectionServiceWithNotif.CreateConnection',
index=0,
containing_service=None,
input_type=_CONNECTION,
output_type=google_dot_protobuf_dot_empty__pb2._EMPTY,
serialized_options=None,
),
_descriptor.MethodDescriptor(
name='ListConnection',
full_name='connection.ConnectionServiceWithNotif.ListConnection',
index=1,
containing_service=None,
input_type=google_dot_protobuf_dot_empty__pb2._EMPTY,
output_type=_CONNECTIONLIST,
serialized_options=None,
),
_descriptor.MethodDescriptor(
name='GetBer',
full_name='connection.ConnectionServiceWithNotif.GetBer',
index=2,
containing_service=None,
input_type=_CONNECTION,
output_type=_BER,
serialized_options=None,
),
])
_sym_db.RegisterServiceDescriptor(_CONNECTIONSERVICEWITHNOTIF)
DESCRIPTOR.services_by_name['ConnectionServiceWithNotif'] = _CONNECTIONSERVICEWITHNOTIF
# @@protoc_insertion_point(module_scope)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment