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

Merge branch 'pr-p4-integration' into 'develop'

feat: support for SD-Fabric dataplane

See merge request !332
parents 186f9eee 08533d97
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -199,7 +199,7 @@ message Device {
  DeviceId controller_id = 9; // Identifier of node controlling the actual device
}

message Component {                         //Defined previously to this section - Tested OK
message Component {                         // Defined previously in this section
  Uuid component_uuid = 1;
  string name         = 2;
  string type         = 3;
@@ -271,6 +271,7 @@ enum LinkTypeEnum {
  LINKTYPE_FIBER   = 2;
  LINKTYPE_RADIO   = 3;
  LINKTYPE_VIRTUAL = 4;
  LINKTYPE_MANAGEMENT = 5;
}

message LinkAttributes {
@@ -325,6 +326,9 @@ enum ServiceTypeEnum {
  SERVICETYPE_E2E = 5;
  SERVICETYPE_OPTICAL_CONNECTIVITY = 6;
  SERVICETYPE_QKD = 7;
  SERVICETYPE_L1NM = 8;
  SERVICETYPE_INT = 9;
  SERVICETYPE_ACL = 10;
}

enum ServiceStatusEnum {
+1 −1
Original line number Diff line number Diff line
@@ -90,6 +90,6 @@ def json_service_p4_planned(
    ):

    return json_service(
        service_uuid, ServiceTypeEnum.SERVICETYPE_L2NM, context_id=json_context_id(context_uuid),
        service_uuid, ServiceTypeEnum.SERVICETYPE_L1NM, context_id=json_context_id(context_uuid),
        status=ServiceStatusEnum.SERVICESTATUS_PLANNED, endpoint_ids=endpoint_ids, constraints=constraints,
        config_rules=config_rules)
 No newline at end of file
+88 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
# limitations under the License.

import re
import ipaddress
from ctypes import c_uint16, sizeof
from typing import Any, Container, Dict, List, Optional, Pattern, Set, Sized, Tuple, Union

def chk_none(name : str, value : Any, reason=None) -> Any:
@@ -107,3 +109,89 @@ def chk_options(name : str, value : Any, options : Container) -> Any:
        msg = '{}({}) is not one of options({}).'
        raise ValueError(msg.format(str(name), str(value), str(options)))
    return value

# MAC address checker
mac_pattern = re.compile(r"^([\da-fA-F]{2}:){5}([\da-fA-F]{2})$")

def chk_address_mac(mac_addr : str):
    """
    Check whether input string is a valid MAC address or not.

    :param mac_addr: string-based MAC address
    :return: boolean status
    """
    return mac_pattern.match(mac_addr) is not None

# IPv4/IPv6 address checkers
IPV4_LOCALHOST = "localhost"

def chk_address_ipv4(ip_addr : str):
    """
    Check whether input string is a valid IPv4 address or not.

    :param ip_addr: string-based IPv4 address
    :return: boolean status
    """
    if ip_addr == IPV4_LOCALHOST:
        return True
    try:
        addr = ipaddress.ip_address(ip_addr)
        return isinstance(addr, ipaddress.IPv4Address)
    except ValueError:
        return False

def chk_prefix_len_ipv4(ip_prefix_len : int):
    """
    Check whether input integer is a valid IPv4 address prefix length.

    :param ip_prefix_len: IPv4 address prefix length
    :return: boolean status
    """
    return 0 <= ip_prefix_len <= 32

def chk_address_ipv6(ip_addr : str):
    """
    Check whether input string is a valid IPv6 address or not.

    :param ip_addr: string-based IPv6 address
    :return: boolean status
    """
    try:
        addr = ipaddress.ip_address(ip_addr)
        return isinstance(addr, ipaddress.IPv6Address)
    except ValueError:
        return False


# VLAN ID checker
VLAN_ID_MIN = 1
VLAN_ID_MAX = 4094

def chk_vlan_id(vlan_id : int):
    return VLAN_ID_MIN <= vlan_id <= VLAN_ID_MAX


# Transport port checker

def limits(c_int_type):
    """
    Discover limits of numerical type.

    :param c_int_type: numerical type
    :return: tuple of numerical type's limits
    """
    signed = c_int_type(-1).value < c_int_type(0).value
    bit_size = sizeof(c_int_type) * 8
    signed_limit = 2 ** (bit_size - 1)
    return (-signed_limit, signed_limit - 1) \
        if signed else (0, 2 * signed_limit - 1)

def chk_transport_port(trans_port : int):
    """
    Check whether input is a valid transport port number or not.

    :param trans_port: transport port number
    :return: boolean status
    """
    lim = limits(c_uint16)
    return lim[0] <= trans_port <= lim[1]
+7 −6
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ from ._GrpcToEnum import grpc_to_enum

# IMPORTANT: Entries of enum class ORM_LinkTypeEnum should be named as in
#            the proto files removing the prefixes. For example, proto item
#            LinkTypeEnum.DEVICEDRIVER_COPPER should be included as COPPER.
#            LinkTypeEnum.COPPER should be included as COPPER.
#            If item name does not match, automatic mapping of proto enums
#            to database enums will fail.
class ORM_LinkTypeEnum(enum.Enum):
@@ -27,6 +27,7 @@ class ORM_LinkTypeEnum(enum.Enum):
    FIBER      = LinkTypeEnum.LINKTYPE_FIBER
    RADIO      = LinkTypeEnum.LINKTYPE_RADIO
    VIRTUAL    = LinkTypeEnum.LINKTYPE_VIRTUAL
    MANAGEMENT = LinkTypeEnum.LINKTYPE_MANAGEMENT

grpc_to_enum__link_type_enum = functools.partial(
    grpc_to_enum, LinkTypeEnum, ORM_LinkTypeEnum
+3 −0
Original line number Diff line number Diff line
@@ -25,11 +25,14 @@ class ORM_ServiceTypeEnum(enum.Enum):
    UNKNOWN                   = ServiceTypeEnum.SERVICETYPE_UNKNOWN
    L3NM                      = ServiceTypeEnum.SERVICETYPE_L3NM
    L2NM                      = ServiceTypeEnum.SERVICETYPE_L2NM
    L1NM                      = ServiceTypeEnum.SERVICETYPE_L1NM
    TAPI_CONNECTIVITY_SERVICE = ServiceTypeEnum.SERVICETYPE_TAPI_CONNECTIVITY_SERVICE
    TE                        = ServiceTypeEnum.SERVICETYPE_TE
    E2E                       = ServiceTypeEnum.SERVICETYPE_E2E
    OPTICAL_CONNECTIVITY      = ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY
    QKD                       = ServiceTypeEnum.SERVICETYPE_QKD
    INT                       = ServiceTypeEnum.SERVICETYPE_INT
    ACL                       = ServiceTypeEnum.SERVICETYPE_ACL

grpc_to_enum__service_type = functools.partial(
    grpc_to_enum, ServiceTypeEnum, ORM_ServiceTypeEnum)
Loading