Resolve "(TID) New BGP-LS Speaker component"

Closes #40 (closed)

Merge request reports

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

apiVersion: apps/v1
kind: Deployment
metadata:
  name: bgpls-speakerservice
spec:
  selector:
    matchLabels:
      app: bgpls-speakerservice
  replicas: 1
  template:
    metadata:
      labels:
        app: bgpls-speakerservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
      - name: server
        image: localhost:32000/tfs/bgpls_speaker:dev
        imagePullPolicy: Always
        ports:
        - containerPort: 20030
        - containerPort: 9192
        env:
        - name: LOG_LEVEL
          value: "INFO"
        readinessProbe:
          exec:
            command: ["/bin/grpc_health_probe", "-addr=:20030"]
        livenessProbe:
          exec:
            command: ["/bin/grpc_health_probe", "-addr=:20030"]
        resources:
          requests:
            cpu: 250m
            memory: 128Mi
          limits:
            cpu: 1000m
            memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: bgpls-speakerservice
  labels:
    app: bgpls-speakerservice
spec:
  type: ClusterIP
  selector:
    app: bgpls-speakerservice
  ports:
  - name: grpc
    protocol: TCP
    port: 20030
    targetPort: 20030
  - name: metrics
    protocol: TCP
    port: 9192
    targetPort: 9192

proto/bgpls.proto

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

syntax = "proto3";
package bgpls;

import "context.proto";

service BgplsService {
  rpc ListDiscoveredDevices (context.Empty  ) returns (DiscoveredDeviceList) {}
  rpc ListDiscoveredLinks   (context.Empty  ) returns (DiscoveredLinkList  ) {}
  rpc AddBgplsSpeaker       (BgplsSpeaker   ) returns (BgplsSpeakerId      ) {}
  rpc ListBgplsSpeakers     (context.Empty  ) returns (BgplsSpeakerList    ) {}
  rpc DisconnectFromSpeaker (BgplsSpeaker   ) returns (context.Empty       ) {}
  rpc GetSpeakerInfoFromId  (BgplsSpeakerId ) returns (BgplsSpeaker        ) {}
  rpc NotifyAddNodeToContext(NodeDescriptors) returns (context.Empty       ) {}
}

message DiscoveredDevice {
  string nodeName = 1;
  string ip = 2;
  string igpID = 3;
  string learntFrom = 4;
}

message DiscoveredDeviceList {
  repeated DiscoveredDevice discovereddevices = 1;
}

message DiscoveredLinkList{
  repeated DiscoveredLink discoveredlinks = 1;
}

message DiscoveredLink{
  NodeDescriptors local  = 1;
	NodeDescriptors remote = 2;
  string learntFrom      = 3;
  string local_ipv4      = 4;
  string remote_ipv4     = 5;
}

message NodeDescriptors{
	string asNumber = 1;
	string igp_id   = 2;
  string nodeName = 3;
}

message BgplsSpeaker{
  string address  = 1;
  string port     = 2;
  string asNumber = 3;
}
message BgplsSpeakerId{
  uint32 id = 1;
}

message BgplsSpeakerList{
  repeated BgplsSpeakerId speakers = 1;
}
+27 −0
Changes for scripts/show_logs_bgp.sh: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/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/bgpls_speakerservice -c server
+91 −0
Changes for src/bgpls_speaker/client/BgplsClient.py: 91 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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.service_pb2_grpc import ServiceServiceStub
from common.proto.bgpls_pb2_grpc import BgplsServiceStub
from common.proto.bgpls_pb2 import BgplsSpeaker, DiscoveredDeviceList,DiscoveredLinkList,BgplsSpeakerId, NodeDescriptors
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 BgplsClient:
    def __init__(self, host=None, port=None):
        if not host: host = get_service_host(ServiceNameEnum.BGPLS)
        if not port: port = get_service_port_grpc(ServiceNameEnum.BGPLS)
        self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
        LOGGER.info('Creating channel to {:s}...'.format(str(self.endpoint)))
        self.channel = None
        self.stub = None
        self.connect()
        LOGGER.info('Channel created')

    def connect(self):
        self.channel = grpc.insecure_channel(self.endpoint)
        self.stub = BgplsServiceStub(self.channel)

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

    @RETRY_DECORATOR
    def ListDiscoveredDevices(self, request: Empty) -> DiscoveredDeviceList:
        LOGGER.info('ListDiscoveredDevices request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.ListDiscoveredDevices(request)
        LOGGER.info('ListDiscoveredDevices result: {:s}'.format(grpc_message_to_json_string(response)))
        return response    
    @RETRY_DECORATOR
    def ListDiscoveredLinks(self, request: Empty) -> DiscoveredLinkList:
        LOGGER.info('ListDiscoveredDevices request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.ListDiscoveredLinks(request)
        LOGGER.info('ListDiscoveredDevices result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
    @RETRY_DECORATOR
    def AddBgplsSpeaker(self, request: BgplsSpeaker) -> str:
        LOGGER.info('AddBgplsSpeaker request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.AddBgplsSpeaker(request)
        LOGGER.info('AddBgplsSpeaker result: {:s}'.format(grpc_message_to_json_string(response)))
        return response    
    @RETRY_DECORATOR
    def ListBgplsSpeakers(self, request: Empty) -> BgplsSpeakerId:
        LOGGER.info('ListBgplsSpeakers request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.ListBgplsSpeakers(request)
        LOGGER.info('ListBgplsSpeakers result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
    @RETRY_DECORATOR
    def DisconnectFromSpeaker(self, request: BgplsSpeaker) -> bool:
        LOGGER.info('DisconnectFromSpeaker request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.DisconnectFromSpeaker(request)
        LOGGER.info('DisconnectFromSpeaker result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
    @RETRY_DECORATOR
    def GetSpeakerInfoFromId(self, request: BgplsSpeakerId) -> BgplsSpeaker:
        LOGGER.info('GetSpeakerInfoFromId request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetSpeakerInfoFromId(request)
        LOGGER.info('GetSpeakerInfoFromId result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
    @RETRY_DECORATOR
    def NotifyAddNodeToContext(self, request: NodeDescriptors) -> str:
        LOGGER.info('NotifyAddNodeToContext request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.NotifyAddNodeToContext(request)
        LOGGER.info('NotifyAddNodeToContext result: {:s}'.format(grpc_message_to_json_string(response)))
        return response
+13 −0
Changes for src/bgpls_speaker/client/__init__.py: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading
Loading