Commit a75cbc80 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'feat/389-cttc-spine-leaf-component' of...

Merge branch 'feat/389-cttc-spine-leaf-component' of ssh://gifrerenom_labs.etsi.org/tfs/controller into feat/390-cttc-integration-of-spine-leaf-fabric-management
parents fa053427 19434201
Loading
Loading
Loading
Loading

proto/spineleaf.proto

0 → 100644
+113 −0
Original line number Diff line number Diff line
// Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.


syntax = "proto3";
package spineleaf;

service SpineLeaf {
  rpc DefineSpineLeafFabric(FabricSettings) returns (FabricDefinitionResponse) {}
  rpc SetDeviceAsSpine(SetDeviceRoleRequest) returns (ConfigSetting) {}
  rpc SetDeviceAsLeaf(SetDeviceRoleRequest) returns (ConfigSetting) {}
  rpc SetDeviceAsGateway(SetDeviceRoleRequest) returns (ConfigSetting) {}
  rpc DeployDeviceConfig(DeployDeviceConfigRequest) returns (DeployResponse) {}
  rpc UnsetDeviceRole(UnsetDeviceRoleRequest) returns (OperationStatus) {}
  rpc GetFabricInventory(FabricScope) returns (FabricInventory) {}
  rpc GetDeviceConfig(DeviceConfigQuery) returns (ConfigSetting) {}
}

message FabricSettings {
  string fabric_name = 1;           // Fabric identifier like dc1-fabric or any other name 
  string underlay_type = 3;        // "bgp" | "ospf" | "isis"
  string overlay_type = 4;         // "vxlan" | "bgp_evpn"
  uint32 spine_count = 5;          // Number of spines
  uint32 leaf_count = 6;           // Number of leaves
  uint32 gateway_count = 7;        // Number of gateway 

}

message FabricDefinitionResponse {
  string fabric_id = 1;
}

message SetDeviceRoleRequest {
  string device_uuid = 1;          // Device UUID from context/web UI.
  string fabric_id = 2;            // Fabric ID from DefineSpineLeafFabric.
  string role = 3;                 // "spine" | "leaf" | "gateway".
}

message ConfigSetting {
    string device_uuid = 1;
    string endpoint_uuid = 2;
    string ip_address = 3;
    uint32 vlan_tag = 4;
    string mac_address = 5;
    uint32 asn = 6;
    string router_id = 7;
    uint32 vni = 8;
    string local_address = 9;
    uint32 port = 10;
    string bridge = 11;
    string interface = 12;
    string remote_address = 13;
    uint32 remote_as = 14;
    string local_role = 15;
    string routing_table = 16;
    bool multihop = 17;
    string afi = 18;
    string name = 19;
}

message DeployDeviceConfigRequest {
  string device_uuid = 1;
  string fabric_id = 2;
  ConfigSetting config = 3;        // config generated by SetDeviceAs
}

message DeployResponse {
  bool success = 1;
  string message = 2;
}

message OperationStatus {
  bool success = 1;
  string message = 2;
}

message UnsetDeviceRoleRequest {
  string device_uuid = 1;
  string fabric_id = 2;
}

message FabricScope {
  string fabric_id = 1;
}

message FabricNode {
  string device_uuid = 1;
  string role = 2;
  string state = 3;
}

message FabricInventory {
  string fabric_id = 1;
  repeated FabricNode spines = 2;
  repeated FabricNode leaves = 3;
  repeated FabricNode gateways = 4;
}

message DeviceConfigQuery {
  string device_uuid = 1;
  string fabric_id = 2;
}
+2 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ class ServiceNameEnum(Enum):
    OSMCLIENT              = 'osm-client'
    PLUGGABLES             = 'dscm-pluggable'
    LOGICALRESOURCE        = 'logical-resources'
    SPINELEAF              = 'spine-leaf'

    # Used for test and debugging only
    DLT_GATEWAY    = 'dltgateway'
@@ -121,6 +122,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
    ServiceNameEnum.OSMCLIENT              .value : 30210,
    ServiceNameEnum.PLUGGABLES             .value : 30220,
    ServiceNameEnum.LogicalResource        .value : 30230,
    ServiceNameEnum.SPINELEAF              .value : 10095,

    # Used for test and debugging only
    ServiceNameEnum.DLT_GATEWAY   .value : 50051,
+55 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM python:3.13-slim

RUN apt-get --yes --quiet --quiet update && \
    apt-get --yes --quiet --quiet install wget g++ git && \
    rm -rf /var/lib/apt/lists/*

ENV PYTHONUNBUFFERED=0

RUN python3 -m pip install --upgrade 'pip==25.2'
RUN python3 -m pip install --upgrade 'setuptools==79.0.0' 'wheel==0.45.1'
RUN python3 -m pip install --upgrade 'pip-tools==7.3.0'

WORKDIR /var/teraflow
COPY common_requirements_py313.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

WORKDIR /var/teraflow/common
COPY src/common/. ./
RUN rm -rf proto

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' {} \;

RUN mkdir -p /var/teraflow/spine_leaf
WORKDIR /var/teraflow/spine_leaf
COPY src/spine_leaf/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in /var/teraflow/common_requirements.in
RUN python3 -m pip install -r requirements.txt

WORKDIR /var/teraflow
COPY src/device/__init__.py device/__init__.py
COPY src/device/client/. device/client/
COPY src/spine_leaf/. spine_leaf/

ENTRYPOINT ["python", "-m", "spine_leaf.service"]
+13 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 No newline at end of file
+102 −0
Original line number Diff line number Diff line
# Copyright 2022-2025 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.spineleaf_pb2 import FabricSettings, SetDeviceRoleRequest, UnsetDeviceRoleRequest, FabricScope, DeviceConfigQuery
from common.proto.spineleaf_pb2_grpc import SpineLeafStub
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 SpineLeafClient:
    def __init__(self, host=None, port=None):
        if not host: host = get_service_host(ServiceNameEnum.SPINELEAF)
        if not port: port = get_service_port_grpc(ServiceNameEnum.SPINELEAF)
        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):
        self.channel = grpc.insecure_channel(self.endpoint)
        self.stub = SpineLeafStub(self.channel)

    def close(self):
        if self.channel is not None: self.channel.close()
        self.channel = None
        self.stub = None

    @RETRY_DECORATOR
    def DefineSpineLeafFabric(self, request):
        LOGGER.debug('DefineSpineLeafFabric request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.DefineSpineLeafFabric(request)
        LOGGER.debug('DefineSpineLeafFabric result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def SetDeviceAsSpine(self, request):
        LOGGER.debug('SetDeviceAsSpine request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.SetDeviceAsSpine(request)
        LOGGER.debug('SetDeviceAsSpine result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def SetDeviceAsLeaf(self, request):
        LOGGER.debug('SetDeviceAsLeaf request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.SetDeviceAsLeaf(request)
        LOGGER.debug('SetDeviceAsLeaf result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def SetDeviceAsGateway(self, request):
        LOGGER.debug('SetDeviceAsGateway request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.SetDeviceAsGateway(request)
        LOGGER.debug('SetDeviceAsGateway result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def DeployDeviceConfig(self, request):
        LOGGER.debug('DeployDeviceConfig request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.DeployDeviceConfig(request)
        LOGGER.debug('DeployDeviceConfig result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def UnsetDeviceRole(self, request):
        LOGGER.debug('UnsetDeviceRole request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.UnsetDeviceRole(request)
        LOGGER.debug('UnsetDeviceRole result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def GetFabricInventory(self, request):
        LOGGER.debug('GetFabricInventory request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetFabricInventory(request)
        LOGGER.debug('GetFabricInventory result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def GetDeviceConfig(self, request):
        LOGGER.debug('GetDeviceConfig request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetDeviceConfig(request)
        LOGGER.debug('GetDeviceConfig result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
Loading