Commit c2aeea99 authored by Ville Hallivuori's avatar Ville Hallivuori
Browse files

Pull request #4: XR VTI mode support

Merge in XRCA/teraflow from vhallivu/vti_mode_prototyping to xr_development

Squashed commit of the following:

commit 6127856df3f3e4c9131f40972d799a6de32a38ef
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Thu Aug 18 09:15:59 2022 +0300

    Fix lint errors

commit dbea279626606f62553b1d6e1a80ae12748cdfd5
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Thu Aug 18 08:48:57 2022 +0300

    pytests improvements

commit e7218f6369df648c73782d7b41b062bc50670490
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Wed Aug 17 17:54:04 2022 +0300

    Some tests for TC

commit 8327392bfa22d06d334349fcf872579414141277
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Wed Aug 17 15:59:01 2022 +0300

    Unit test for connection

commit 5148a84534b332ee82458b080fbc89d19bec3c63
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Wed Aug 17 13:26:23 2022 +0300

    Incremental connection endpoint modifications support

commit 10f3e1e43de483c4dc84a6dcd7b0f8bba37d97a2
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Wed Aug 17 11:32:05 2022 +0300

    Refactored TF to use the new backend for create

commit 1e678b0222b9ef7dbdaf09b83696f561c6889c08
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Wed Aug 17 10:33:34 2022 +0300

    More code refactoring

commit 991d951485fb7fa02692c08da7fe6261cc7f4ce7
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 16 18:25:34 2022 +0300

    More refactoring

commit 62f0f407ca78cadd5c6c581d98e47c8688909318
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 16 17:33:03 2022 +0300

    Transport capacity testing and cm-cli support

commit a8d0bd8797d6754e7adbfacf292831eaf69c83f6
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 16 16:35:14 2022 +0300

    TC delete, more refactoring

commit ec70cefccdf4dd94c70a9bc31d4f9c841177db9c
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 16 14:48:23 2022 +0300

    Support for creating transport capacities

commit 3148f2c472452adcef78f1a80540091b6fcf505d
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Tue Aug 16 11:19:53 2022 +0300

    Code refactoring

commit 6e980925e3605ade0e5b6e6d0447c29fc3badce5
Author: Ville Hallivuori <VHallivuori@infinera.com>
Date:   Mon Aug 15 08:42:43 2022 +0300

    Refactoring + tuning gitignore + updating version controlled generated files
parent 6c9acafc
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -158,3 +158,11 @@ cython_debug/

# TeraFlowSDN-generated files
tfs_runtime_env_vars.sh

# Symlink for generated proto-files in host
src/context/proto

# Generated files in dlt
src/dlt/.gradle
src/dlt/bin
src/dlt/gateway/bin
+97 −87
Original line number Diff line number Diff line
@@ -173,6 +173,10 @@ public final class ContextOuterClass {
     * <code>DEVICEDRIVER_ONF_TR_352 = 5;</code>
     */
    DEVICEDRIVER_ONF_TR_352(5),
    /**
     * <code>DEVICEDRIVER_XR = 6;</code>
     */
    DEVICEDRIVER_XR(6),
    UNRECOGNIZED(-1),
    ;
@@ -204,6 +208,10 @@ public final class ContextOuterClass {
     * <code>DEVICEDRIVER_ONF_TR_352 = 5;</code>
     */
    public static final int DEVICEDRIVER_ONF_TR_352_VALUE = 5;
    /**
     * <code>DEVICEDRIVER_XR = 6;</code>
     */
    public static final int DEVICEDRIVER_XR_VALUE = 6;
    public final int getNumber() {
@@ -236,6 +244,7 @@ public final class ContextOuterClass {
        case 3: return DEVICEDRIVER_P4;
        case 4: return DEVICEDRIVER_IETF_NETWORK_TOPOLOGY;
        case 5: return DEVICEDRIVER_ONF_TR_352;
        case 6: return DEVICEDRIVER_XR;
        default: return null;
      }
    }
@@ -62114,97 +62123,98 @@ public final class ContextOuterClass {
      "ontextId\022\025\n\rauthenticated\030\002 \001(\010*j\n\rEvent" +
      "TypeEnum\022\027\n\023EVENTTYPE_UNDEFINED\020\000\022\024\n\020EVE" +
      "NTTYPE_CREATE\020\001\022\024\n\020EVENTTYPE_UPDATE\020\002\022\024\n" +
      "\020EVENTTYPE_REMOVE\020\003*\305\001\n\020DeviceDriverEnum" +
      "\020EVENTTYPE_REMOVE\020\003*\332\001\n\020DeviceDriverEnum" +
      "\022\032\n\026DEVICEDRIVER_UNDEFINED\020\000\022\033\n\027DEVICEDR" +
      "IVER_OPENCONFIG\020\001\022\036\n\032DEVICEDRIVER_TRANSP" +
      "ORT_API\020\002\022\023\n\017DEVICEDRIVER_P4\020\003\022&\n\"DEVICE" +
      "DRIVER_IETF_NETWORK_TOPOLOGY\020\004\022\033\n\027DEVICE" +
      "DRIVER_ONF_TR_352\020\005*\217\001\n\033DeviceOperationa" +
      "lStatusEnum\022%\n!DEVICEOPERATIONALSTATUS_U" +
      "NDEFINED\020\000\022$\n DEVICEOPERATIONALSTATUS_DI" +
      "SABLED\020\001\022#\n\037DEVICEOPERATIONALSTATUS_ENAB" +
      "LED\020\002*\201\001\n\017ServiceTypeEnum\022\027\n\023SERVICETYPE" +
      "_UNKNOWN\020\000\022\024\n\020SERVICETYPE_L3NM\020\001\022\024\n\020SERV" +
      "ICETYPE_L2NM\020\002\022)\n%SERVICETYPE_TAPI_CONNE" +
      "CTIVITY_SERVICE\020\003*\250\001\n\021ServiceStatusEnum\022" +
      "\033\n\027SERVICESTATUS_UNDEFINED\020\000\022\031\n\025SERVICES" +
      "TATUS_PLANNED\020\001\022\030\n\024SERVICESTATUS_ACTIVE\020" +
      "\002\022!\n\035SERVICESTATUS_PENDING_REMOVAL\020\003\022\036\n\032" +
      "SERVICESTATUS_SLA_VIOLATED\020\004*\251\001\n\017SliceSt" +
      "atusEnum\022\031\n\025SLICESTATUS_UNDEFINED\020\000\022\027\n\023S" +
      "LICESTATUS_PLANNED\020\001\022\024\n\020SLICESTATUS_INIT" +
      "\020\002\022\026\n\022SLICESTATUS_ACTIVE\020\003\022\026\n\022SLICESTATU" +
      "S_DEINIT\020\004\022\034\n\030SLICESTATUS_SLA_VIOLATED\020\005" +
      "*]\n\020ConfigActionEnum\022\032\n\026CONFIGACTION_UND" +
      "EFINED\020\000\022\024\n\020CONFIGACTION_SET\020\001\022\027\n\023CONFIG" +
      "ACTION_DELETE\020\002*\203\002\n\022IsolationLevelEnum\022\020" +
      "\n\014NO_ISOLATION\020\000\022\026\n\022PHYSICAL_ISOLATION\020\001" +
      "\022\025\n\021LOGICAL_ISOLATION\020\002\022\025\n\021PROCESS_ISOLA" +
      "TION\020\003\022\035\n\031PHYSICAL_MEMORY_ISOLATION\020\004\022\036\n" +
      "\032PHYSICAL_NETWORK_ISOLATION\020\005\022\036\n\032VIRTUAL" +
      "_RESOURCE_ISOLATION\020\006\022\037\n\033NETWORK_FUNCTIO" +
      "NS_ISOLATION\020\007\022\025\n\021SERVICE_ISOLATION\020\0102\357\022" +
      "\n\016ContextService\022:\n\016ListContextIds\022\016.con" +
      "text.Empty\032\026.context.ContextIdList\"\000\0226\n\014" +
      "ListContexts\022\016.context.Empty\032\024.context.C" +
      "ontextList\"\000\0224\n\nGetContext\022\022.context.Con" +
      "textId\032\020.context.Context\"\000\0224\n\nSetContext" +
      "\022\020.context.Context\032\022.context.ContextId\"\000" +
      "\0225\n\rRemoveContext\022\022.context.ContextId\032\016." +
      "context.Empty\"\000\022=\n\020GetContextEvents\022\016.co" +
      "ntext.Empty\032\025.context.ContextEvent\"\0000\001\022@" +
      "\n\017ListTopologyIds\022\022.context.ContextId\032\027." +
      "context.TopologyIdList\"\000\022=\n\016ListTopologi" +
      "es\022\022.context.ContextId\032\025.context.Topolog" +
      "yList\"\000\0227\n\013GetTopology\022\023.context.Topolog" +
      "yId\032\021.context.Topology\"\000\0227\n\013SetTopology\022" +
      "\021.context.Topology\032\023.context.TopologyId\"" +
      "\000\0227\n\016RemoveTopology\022\023.context.TopologyId" +
      "\032\016.context.Empty\"\000\022?\n\021GetTopologyEvents\022" +
      "\016.context.Empty\032\026.context.TopologyEvent\"" +
      "\0000\001\0228\n\rListDeviceIds\022\016.context.Empty\032\025.c" +
      "ontext.DeviceIdList\"\000\0224\n\013ListDevices\022\016.c" +
      "ontext.Empty\032\023.context.DeviceList\"\000\0221\n\tG" +
      "etDevice\022\021.context.DeviceId\032\017.context.De" +
      "vice\"\000\0221\n\tSetDevice\022\017.context.Device\032\021.c" +
      "ontext.DeviceId\"\000\0223\n\014RemoveDevice\022\021.cont" +
      "ext.DeviceId\032\016.context.Empty\"\000\022;\n\017GetDev" +
      "iceEvents\022\016.context.Empty\032\024.context.Devi" +
      "ceEvent\"\0000\001\0224\n\013ListLinkIds\022\016.context.Emp" +
      "ty\032\023.context.LinkIdList\"\000\0220\n\tListLinks\022\016" +
      ".context.Empty\032\021.context.LinkList\"\000\022+\n\007G" +
      "etLink\022\017.context.LinkId\032\r.context.Link\"\000" +
      "\022+\n\007SetLink\022\r.context.Link\032\017.context.Lin" +
      "kId\"\000\022/\n\nRemoveLink\022\017.context.LinkId\032\016.c" +
      "ontext.Empty\"\000\0227\n\rGetLinkEvents\022\016.contex" +
      "t.Empty\032\022.context.LinkEvent\"\0000\001\022>\n\016ListS" +
      "erviceIds\022\022.context.ContextId\032\026.context." +
      "ServiceIdList\"\000\022:\n\014ListServices\022\022.contex" +
      "t.ContextId\032\024.context.ServiceList\"\000\0224\n\nG" +
      "etService\022\022.context.ServiceId\032\020.context." +
      "Service\"\000\0224\n\nSetService\022\020.context.Servic" +
      "e\032\022.context.ServiceId\"\000\0225\n\rRemoveService" +
      "\022\022.context.ServiceId\032\016.context.Empty\"\000\022=" +
      "\n\020GetServiceEvents\022\016.context.Empty\032\025.con" +
      "text.ServiceEvent\"\0000\001\022:\n\014ListSliceIds\022\022." +
      "context.ContextId\032\024.context.SliceIdList\"" +
      "\000\0226\n\nListSlices\022\022.context.ContextId\032\022.co" +
      "ntext.SliceList\"\000\022.\n\010GetSlice\022\020.context." +
      "SliceId\032\016.context.Slice\"\000\022.\n\010SetSlice\022\016." +
      "context.Slice\032\020.context.SliceId\"\000\0221\n\013Rem" +
      "oveSlice\022\020.context.SliceId\032\016.context.Emp" +
      "ty\"\000\0229\n\016GetSliceEvents\022\016.context.Empty\032\023" +
      ".context.SliceEvent\"\0000\001\022D\n\021ListConnectio" +
      "nIds\022\022.context.ServiceId\032\031.context.Conne" +
      "ctionIdList\"\000\022@\n\017ListConnections\022\022.conte" +
      "xt.ServiceId\032\027.context.ConnectionList\"\000\022" +
      "=\n\rGetConnection\022\025.context.ConnectionId\032" +
      "\023.context.Connection\"\000\022=\n\rSetConnection\022" +
      "\023.context.Connection\032\025.context.Connectio" +
      "nId\"\000\022;\n\020RemoveConnection\022\025.context.Conn" +
      "ectionId\032\016.context.Empty\"\000\022C\n\023GetConnect" +
      "ionEvents\022\016.context.Empty\032\030.context.Conn" +
      "ectionEvent\"\0000\001b\006proto3"
      "DRIVER_ONF_TR_352\020\005\022\023\n\017DEVICEDRIVER_XR\020\006" +
      "*\217\001\n\033DeviceOperationalStatusEnum\022%\n!DEVI" +
      "CEOPERATIONALSTATUS_UNDEFINED\020\000\022$\n DEVIC" +
      "EOPERATIONALSTATUS_DISABLED\020\001\022#\n\037DEVICEO" +
      "PERATIONALSTATUS_ENABLED\020\002*\201\001\n\017ServiceTy" +
      "peEnum\022\027\n\023SERVICETYPE_UNKNOWN\020\000\022\024\n\020SERVI" +
      "CETYPE_L3NM\020\001\022\024\n\020SERVICETYPE_L2NM\020\002\022)\n%S" +
      "ERVICETYPE_TAPI_CONNECTIVITY_SERVICE\020\003*\250" +
      "\001\n\021ServiceStatusEnum\022\033\n\027SERVICESTATUS_UN" +
      "DEFINED\020\000\022\031\n\025SERVICESTATUS_PLANNED\020\001\022\030\n\024" +
      "SERVICESTATUS_ACTIVE\020\002\022!\n\035SERVICESTATUS_" +
      "PENDING_REMOVAL\020\003\022\036\n\032SERVICESTATUS_SLA_V" +
      "IOLATED\020\004*\251\001\n\017SliceStatusEnum\022\031\n\025SLICEST" +
      "ATUS_UNDEFINED\020\000\022\027\n\023SLICESTATUS_PLANNED\020" +
      "\001\022\024\n\020SLICESTATUS_INIT\020\002\022\026\n\022SLICESTATUS_A" +
      "CTIVE\020\003\022\026\n\022SLICESTATUS_DEINIT\020\004\022\034\n\030SLICE" +
      "STATUS_SLA_VIOLATED\020\005*]\n\020ConfigActionEnu" +
      "m\022\032\n\026CONFIGACTION_UNDEFINED\020\000\022\024\n\020CONFIGA" +
      "CTION_SET\020\001\022\027\n\023CONFIGACTION_DELETE\020\002*\203\002\n" +
      "\022IsolationLevelEnum\022\020\n\014NO_ISOLATION\020\000\022\026\n" +
      "\022PHYSICAL_ISOLATION\020\001\022\025\n\021LOGICAL_ISOLATI" +
      "ON\020\002\022\025\n\021PROCESS_ISOLATION\020\003\022\035\n\031PHYSICAL_" +
      "MEMORY_ISOLATION\020\004\022\036\n\032PHYSICAL_NETWORK_I" +
      "SOLATION\020\005\022\036\n\032VIRTUAL_RESOURCE_ISOLATION" +
      "\020\006\022\037\n\033NETWORK_FUNCTIONS_ISOLATION\020\007\022\025\n\021S" +
      "ERVICE_ISOLATION\020\0102\357\022\n\016ContextService\022:\n" +
      "\016ListContextIds\022\016.context.Empty\032\026.contex" +
      "t.ContextIdList\"\000\0226\n\014ListContexts\022\016.cont" +
      "ext.Empty\032\024.context.ContextList\"\000\0224\n\nGet" +
      "Context\022\022.context.ContextId\032\020.context.Co" +
      "ntext\"\000\0224\n\nSetContext\022\020.context.Context\032" +
      "\022.context.ContextId\"\000\0225\n\rRemoveContext\022\022" +
      ".context.ContextId\032\016.context.Empty\"\000\022=\n\020" +
      "GetContextEvents\022\016.context.Empty\032\025.conte" +
      "xt.ContextEvent\"\0000\001\022@\n\017ListTopologyIds\022\022" +
      ".context.ContextId\032\027.context.TopologyIdL" +
      "ist\"\000\022=\n\016ListTopologies\022\022.context.Contex" +
      "tId\032\025.context.TopologyList\"\000\0227\n\013GetTopol" +
      "ogy\022\023.context.TopologyId\032\021.context.Topol" +
      "ogy\"\000\0227\n\013SetTopology\022\021.context.Topology\032" +
      "\023.context.TopologyId\"\000\0227\n\016RemoveTopology" +
      "\022\023.context.TopologyId\032\016.context.Empty\"\000\022" +
      "?\n\021GetTopologyEvents\022\016.context.Empty\032\026.c" +
      "ontext.TopologyEvent\"\0000\001\0228\n\rListDeviceId" +
      "s\022\016.context.Empty\032\025.context.DeviceIdList" +
      "\"\000\0224\n\013ListDevices\022\016.context.Empty\032\023.cont" +
      "ext.DeviceList\"\000\0221\n\tGetDevice\022\021.context." +
      "DeviceId\032\017.context.Device\"\000\0221\n\tSetDevice" +
      "\022\017.context.Device\032\021.context.DeviceId\"\000\0223" +
      "\n\014RemoveDevice\022\021.context.DeviceId\032\016.cont" +
      "ext.Empty\"\000\022;\n\017GetDeviceEvents\022\016.context" +
      ".Empty\032\024.context.DeviceEvent\"\0000\001\0224\n\013List" +
      "LinkIds\022\016.context.Empty\032\023.context.LinkId" +
      "List\"\000\0220\n\tListLinks\022\016.context.Empty\032\021.co" +
      "ntext.LinkList\"\000\022+\n\007GetLink\022\017.context.Li" +
      "nkId\032\r.context.Link\"\000\022+\n\007SetLink\022\r.conte" +
      "xt.Link\032\017.context.LinkId\"\000\022/\n\nRemoveLink" +
      "\022\017.context.LinkId\032\016.context.Empty\"\000\0227\n\rG" +
      "etLinkEvents\022\016.context.Empty\032\022.context.L" +
      "inkEvent\"\0000\001\022>\n\016ListServiceIds\022\022.context" +
      ".ContextId\032\026.context.ServiceIdList\"\000\022:\n\014" +
      "ListServices\022\022.context.ContextId\032\024.conte" +
      "xt.ServiceList\"\000\0224\n\nGetService\022\022.context" +
      ".ServiceId\032\020.context.Service\"\000\0224\n\nSetSer" +
      "vice\022\020.context.Service\032\022.context.Service" +
      "Id\"\000\0225\n\rRemoveService\022\022.context.ServiceI" +
      "d\032\016.context.Empty\"\000\022=\n\020GetServiceEvents\022" +
      "\016.context.Empty\032\025.context.ServiceEvent\"\000" +
      "0\001\022:\n\014ListSliceIds\022\022.context.ContextId\032\024" +
      ".context.SliceIdList\"\000\0226\n\nListSlices\022\022.c" +
      "ontext.ContextId\032\022.context.SliceList\"\000\022." +
      "\n\010GetSlice\022\020.context.SliceId\032\016.context.S" +
      "lice\"\000\022.\n\010SetSlice\022\016.context.Slice\032\020.con" +
      "text.SliceId\"\000\0221\n\013RemoveSlice\022\020.context." +
      "SliceId\032\016.context.Empty\"\000\0229\n\016GetSliceEve" +
      "nts\022\016.context.Empty\032\023.context.SliceEvent" +
      "\"\0000\001\022D\n\021ListConnectionIds\022\022.context.Serv" +
      "iceId\032\031.context.ConnectionIdList\"\000\022@\n\017Li" +
      "stConnections\022\022.context.ServiceId\032\027.cont" +
      "ext.ConnectionList\"\000\022=\n\rGetConnection\022\025." +
      "context.ConnectionId\032\023.context.Connectio" +
      "n\"\000\022=\n\rSetConnection\022\023.context.Connectio" +
      "n\032\025.context.ConnectionId\"\000\022;\n\020RemoveConn" +
      "ection\022\025.context.ConnectionId\032\016.context." +
      "Empty\"\000\022C\n\023GetConnectionEvents\022\016.context" +
      ".Empty\032\030.context.ConnectionEvent\"\0000\001b\006pr" +
      "oto3"
    };
    descriptor = com.google.protobuf.Descriptors.FileDescriptor
      .internalBuildGeneratedFileFrom(descriptorData,
+22 −4
Original line number Diff line number Diff line
# Infinera Readme

This file will be removed before uploading to origin.

There are some instructions at https://gitlab.com/teraflow-h2020/controller/-/tree/develop/tutorial . They are not completely up to date and don't 100% work.

Note that many of the scripts expect this and that K8s namespace being used, they are not consistent, so use manual kubectl commands where necessary.
@@ -66,6 +64,13 @@ cd ../src/context
ln -s ../../proto/src/python proto
```

For VS Code python extension imports it is convenient to set file .env to top level with content:

```
PYTHONPATH=src
```
This will make imports to work properly in all cases.

## Building

Run deploy script to build in docker containers and then instantiate to configured K8s cluster. Deploy script must be sources for this to work!
@@ -90,6 +95,15 @@ Good logs to check are:
* kubectl logs   service/deviceservice     --namespace tfs
* kubectl logs   service/webuiservice     --namespace tfs

## Unit Tests
Run in src directory (src under repo top level) with command:

```bash
PYTHONPATH=. pytest device/service/drivers/xr/cm
```

The PYTHONPATH is vital for imports to work properly.

## cm-cli

The tool cm-cli in the xr driver directory can be use to connect to CM and test the connectivity. For example:
@@ -100,8 +114,12 @@ The tool cm-cli in the xr driver directory can be use to connect to CM and test
./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --create-connection="FOO;XR HUB 1|XR-T4;XR LEAF 1|XR-T1"
./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --show-connection-by-name="FooBar123"
./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --list-connections
# Modify argumens: href;uuid;ifname;ifname or href;uuid
# Modify argumens: href;uuid;ifname;ifname
# uuid translates to name TF:uuid
./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --modify-connection="/network-connections/138f0cc0-3dc6-4195-97c0-2cbed5fd59ba;FooBarAaa"
./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --modify-connection="/network-connections/0637da3b-3b20-4b44-a513-035e6ef897a3;MyCon1;XR HUB 1|XR-T1;XR LEAF 1|XR-T2;25"
./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --delete-connection=/network-connections/138f0cc0-3dc6-4195-97c0-2cbed5fd59ba
 ./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --create-transport-capacity="FOO;XR HUB 1|XR-T4;XR LEAF 1|XR-T1;12"
 ./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --list-transport-capacities
# Exercise almost full path of SetConfig. Can also be used for changing bandwidth (e.g. in demos) of an service
./cm-cli.py 172.19.219.44  443 xr-user-1 xr-user-1 --emulate-tf-set-config-service="XR HUB 1;teraflow_service_uuid;XR HUB 1|XR-T4;XR LEAF 1|XR-T1;125"
```
+34 −20
Original line number Diff line number Diff line
@@ -13,18 +13,18 @@
# limitations under the License.
#pylint: disable=invalid-name, missing-function-docstring, line-too-long, logging-fstring-interpolation, missing-class-docstring, missing-module-docstring

import logging, requests, threading
import logging
import threading
import json
from typing import Any, Iterator, List, Optional, Tuple, Union
from common.type_checkers.Checkers import chk_string, chk_type
import urllib3
from common.type_checkers.Checkers import chk_type
from device.service.driver_api._Driver import _Driver
from . import ALL_RESOURCE_KEYS
#from .Tools import create_connectivity_service, find_key, config_getter, delete_connectivity_service
import json
from .CmConnection import CmConnection
from .cm.cm_connection import CmConnection
from .cm import tf

# Don't complain about non-verified SSL certificate. This driver is demo only
# and CM is not provisioned in demos with a proper certificate.
import urllib3
urllib3.disable_warnings()

LOGGER = logging.getLogger(__name__)
@@ -43,12 +43,14 @@ class XrDriver(_Driver):
        password = settings["password"] if "password" in settings else "xr-user-1"

        self.__cm_connection = CmConnection(address, int(port), username, password, self.__timeout, tls_verify = tls_verify)
        self.__constellation = None

        LOGGER.info(f"XrDriver instantiated, cm {address}:{port}, {settings=}")

    def Connect(self) -> bool:
        with self.__lock:
            if self.__started.is_set(): return True
            if self.__started.is_set():
                return True
            if not self.__cm_connection.Connect():
                return False
            else:
@@ -64,23 +66,31 @@ class XrDriver(_Driver):
        with self.__lock:
            return []

    #pylint: disable=dangerous-default-value
    def GetConfig(self, resource_keys : List[str] = []) -> List[Tuple[str, Union[Any, None, Exception]]]:
        chk_type('resources', resource_keys, list)

        constellation = self.__cm_connection.get_constellation_by_hub_name(self.__hub_module_name)
        if constellation:
            _cid, if_list = constellation
            return [(f"/endpoints/endpoint[{ifname}]", {'uuid': ifname, 'type': 'optical', 'sample_types': {}}) for ifname in if_list]
            self.__constellation = constellation
            return [(f"/endpoints/endpoint[{ifname}]", {'uuid': ifname, 'type': 'optical', 'sample_types': {}}) for ifname in constellation.ifnames()]
        else:
            return []


    def SetConfig(self, resources: List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        LOGGER.info(f"SetConfig {resources=}");
        LOGGER.info(f"SetConfig {resources=}")

        # Logged config seems like:
           #[('/service[52ff5f0f-fda4-40bd-a0b1-066f4ff04079:optical]', '{"capacity_unit": "GHz", "capacity_value": 1, "direction": "UNIDIRECTIONAL", "input_sip": "XR HUB 1|XR-T4", "layer_protocol_name": "PHOTONIC_MEDIA", "layer_protocol_qualifier": "tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC", "output_sip": "XR LEAF 1|XR-T1", "uuid": "52ff5f0f-fda4-40bd-a0b1-066f4ff04079:optical"}')]

        if self.__constellation is None:
            self.__constellation = self.__cm_connection.get_constellation_by_hub_name(self.__hub_module_name)

        if self.__constellation is None:
            LOGGER.error("SetConfig: no valid constellation")
            return [False] * len(resources)

        results = []
        if len(resources) == 0:
            return results
@@ -89,26 +99,21 @@ class XrDriver(_Driver):
            service_uuid = self.__cm_connection.service_uuid(key)
            if service_uuid:
                config = json.loads(config)
                href = self.__cm_connection.create_or_update_connection_ifnames(service_uuid, config["input_sip"], config["output_sip"])
                if href:
                    LOGGER.info(f"SetConfig: Created service {service_uuid} as {href}")
                    results.append(True)
                else:
                    LOGGER.error(f"SetConfig: Service creation failure for {service_uuid}")
                    results.append(False)
                results.append(tf.set_config_for_service(self.__cm_connection, self.__constellation, service_uuid, config))
            else:
                results.append(False)

        return results

    def DeleteConfig(self, resources: List[Tuple[str, Any]]) -> List[Union[bool, Exception]]:
        LOGGER.info(f"DeleteConfig {resources=}");
        LOGGER.info(f"DeleteConfig {resources=}")

        # Input looks like:
        #  resources=[('/service[c8a35e81-88d8-4468-9afc-a8abd92a64d0:optical]', '{"uuid": "c8a35e81-88d8-4468-9afc-a8abd92a64d0:optical"}')]

        results = []
        if len(resources) == 0: return results
        if len(resources) == 0:
            return results

        # Temporary dummy version
        for key, _config in resources:
@@ -124,6 +129,15 @@ class XrDriver(_Driver):
                        LOGGER.info(f"DeleteConfig: Connection {service_uuid} deleted (was {str(connection)})")
                    else:
                        LOGGER.info(f"DeleteConfig: Connection {service_uuid} delete failure (was {str(connection)})")

                    if self.__constellation.is_vti_mode():
                        active_tc = self.__cm_connection.get_transport_capacity_by_teraflow_uuid(service_uuid)
                        if active_tc is not None:
                            if self.__cm_connection.delete_transport_capacity(active_tc.href):
                                LOGGER.info(f"DeleteConfig: Transport Capacity {active_tc} deleted")
                            else:
                                LOGGER.error(f"DeleteConfig: Transport Capacity {active_tc} delete failure")

                    results.append(was_deleted)
            else:
                results.append(False)
+0 −27
Original line number Diff line number Diff line
# 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.

from device.service.driver_api._Driver import RESOURCE_ENDPOINTS, RESOURCE_INTERFACES, RESOURCE_NETWORK_INSTANCES

ALL_RESOURCE_KEYS = [
    RESOURCE_ENDPOINTS,
    RESOURCE_INTERFACES,
#    RESOURCE_NETWORK_INSTANCES,
]

RESOURCE_KEY_MAPPINGS = {
    RESOURCE_ENDPOINTS        : 'component',
    RESOURCE_INTERFACES       : 'interface',
#    RESOURCE_NETWORK_INSTANCES: 'network_instance',
}
Loading