broke out tlv specific enums into their own module

This commit is contained in:
Blake Harnden 2020-03-22 14:09:38 -07:00
parent c264634b5f
commit 7a5a0f34ea
9 changed files with 237 additions and 244 deletions

View file

@ -13,7 +13,7 @@ from enum import Enum
import netaddr import netaddr
from core.api.tlv import structutils from core.api.tlv import structutils
from core.emulator.enumerations import ( from core.api.tlv.enumerations import (
ConfigTlvs, ConfigTlvs,
EventTlvs, EventTlvs,
ExceptionTlvs, ExceptionTlvs,
@ -21,12 +21,11 @@ from core.emulator.enumerations import (
FileTlvs, FileTlvs,
InterfaceTlvs, InterfaceTlvs,
LinkTlvs, LinkTlvs,
MessageFlags,
MessageTypes, MessageTypes,
NodeTlvs, NodeTlvs,
RegisterTlvs,
SessionTlvs, SessionTlvs,
) )
from core.emulator.enumerations import MessageFlags, RegisterTlvs
class CoreTlvData: class CoreTlvData:

View file

@ -15,26 +15,28 @@ from queue import Empty, Queue
from core import utils from core import utils
from core.api.tlv import coreapi, dataconversion, structutils from core.api.tlv import coreapi, dataconversion, structutils
from core.api.tlv.enumerations import (
ConfigFlags,
ConfigTlvs,
EventTlvs,
ExceptionTlvs,
ExecuteTlvs,
FileTlvs,
LinkTlvs,
MessageTypes,
NodeTlvs,
SessionTlvs,
)
from core.config import ConfigShim from core.config import ConfigShim
from core.emulator.data import ConfigData, EventData, ExceptionData, FileData from core.emulator.data import ConfigData, EventData, ExceptionData, FileData
from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions from core.emulator.emudata import InterfaceData, LinkOptions, NodeOptions
from core.emulator.enumerations import ( from core.emulator.enumerations import (
ConfigDataTypes, ConfigDataTypes,
ConfigFlags,
ConfigTlvs,
EventTlvs,
EventTypes, EventTypes,
ExceptionTlvs,
ExecuteTlvs,
FileTlvs,
LinkTlvs,
LinkTypes, LinkTypes,
MessageFlags, MessageFlags,
MessageTypes,
NodeTlvs,
NodeTypes, NodeTypes,
RegisterTlvs, RegisterTlvs,
SessionTlvs,
) )
from core.errors import CoreCommandError, CoreError from core.errors import CoreCommandError, CoreError
from core.location.mobility import BasicRangeModel from core.location.mobility import BasicRangeModel

View file

@ -3,7 +3,7 @@ Converts CORE data objects into legacy API messages.
""" """
from core.api.tlv import coreapi, structutils from core.api.tlv import coreapi, structutils
from core.emulator.enumerations import ConfigTlvs, NodeTlvs from core.api.tlv.enumerations import ConfigTlvs, NodeTlvs
def convert_node(node_data): def convert_node(node_data):

View file

@ -0,0 +1,212 @@
"""
Enumerations specific to the CORE TLV API.
"""
from enum import Enum
CORE_API_PORT = 4038
class MessageTypes(Enum):
"""
CORE message types.
"""
NODE = 0x01
LINK = 0x02
EXECUTE = 0x03
REGISTER = 0x04
CONFIG = 0x05
FILE = 0x06
INTERFACE = 0x07
EVENT = 0x08
SESSION = 0x09
EXCEPTION = 0x0A
class NodeTlvs(Enum):
"""
Node type, length, value enumerations.
"""
NUMBER = 0x01
TYPE = 0x02
NAME = 0x03
IP_ADDRESS = 0x04
MAC_ADDRESS = 0x05
IP6_ADDRESS = 0x06
MODEL = 0x07
EMULATION_SERVER = 0x08
SESSION = 0x0A
X_POSITION = 0x20
Y_POSITION = 0x21
CANVAS = 0x22
EMULATION_ID = 0x23
NETWORK_ID = 0x24
SERVICES = 0x25
LATITUDE = 0x30
LONGITUDE = 0x31
ALTITUDE = 0x32
ICON = 0x42
OPAQUE = 0x50
class LinkTlvs(Enum):
"""
Link type, length, value enumerations.
"""
N1_NUMBER = 0x01
N2_NUMBER = 0x02
DELAY = 0x03
BANDWIDTH = 0x04
PER = 0x05
DUP = 0x06
JITTER = 0x07
MER = 0x08
BURST = 0x09
SESSION = 0x0A
MBURST = 0x10
TYPE = 0x20
GUI_ATTRIBUTES = 0x21
UNIDIRECTIONAL = 0x22
EMULATION_ID = 0x23
NETWORK_ID = 0x24
KEY = 0x25
INTERFACE1_NUMBER = 0x30
INTERFACE1_IP4 = 0x31
INTERFACE1_IP4_MASK = 0x32
INTERFACE1_MAC = 0x33
INTERFACE1_IP6 = 0x34
INTERFACE1_IP6_MASK = 0x35
INTERFACE2_NUMBER = 0x36
INTERFACE2_IP4 = 0x37
INTERFACE2_IP4_MASK = 0x38
INTERFACE2_MAC = 0x39
INTERFACE2_IP6 = 0x40
INTERFACE2_IP6_MASK = 0x41
INTERFACE1_NAME = 0x42
INTERFACE2_NAME = 0x43
OPAQUE = 0x50
class ExecuteTlvs(Enum):
"""
Execute type, length, value enumerations.
"""
NODE = 0x01
NUMBER = 0x02
TIME = 0x03
COMMAND = 0x04
RESULT = 0x05
STATUS = 0x06
SESSION = 0x0A
class ConfigTlvs(Enum):
"""
Configuration type, length, value enumerations.
"""
NODE = 0x01
OBJECT = 0x02
TYPE = 0x03
DATA_TYPES = 0x04
VALUES = 0x05
CAPTIONS = 0x06
BITMAP = 0x07
POSSIBLE_VALUES = 0x08
GROUPS = 0x09
SESSION = 0x0A
INTERFACE_NUMBER = 0x0B
NETWORK_ID = 0x24
OPAQUE = 0x50
class ConfigFlags(Enum):
"""
Configuration flags.
"""
NONE = 0x00
REQUEST = 0x01
UPDATE = 0x02
RESET = 0x03
class FileTlvs(Enum):
"""
File type, length, value enumerations.
"""
NODE = 0x01
NAME = 0x02
MODE = 0x03
NUMBER = 0x04
TYPE = 0x05
SOURCE_NAME = 0x06
SESSION = 0x0A
DATA = 0x10
COMPRESSED_DATA = 0x11
class InterfaceTlvs(Enum):
"""
Interface type, length, value enumerations.
"""
NODE = 0x01
NUMBER = 0x02
NAME = 0x03
IP_ADDRESS = 0x04
MASK = 0x05
MAC_ADDRESS = 0x06
IP6_ADDRESS = 0x07
IP6_MASK = 0x08
TYPE = 0x09
SESSION = 0x0A
STATE = 0x0B
EMULATION_ID = 0x23
NETWORK_ID = 0x24
class EventTlvs(Enum):
"""
Event type, length, value enumerations.
"""
NODE = 0x01
TYPE = 0x02
NAME = 0x03
DATA = 0x04
TIME = 0x05
SESSION = 0x0A
class SessionTlvs(Enum):
"""
Session type, length, value enumerations.
"""
NUMBER = 0x01
NAME = 0x02
FILE = 0x03
NODE_COUNT = 0x04
DATE = 0x05
THUMB = 0x06
USER = 0x07
OPAQUE = 0x0A
class ExceptionTlvs(Enum):
"""
Exception type, length, value enumerations.
"""
NODE = 0x01
SESSION = 0x02
LEVEL = 0x03
SOURCE = 0x04
DATE = 0x05
TEXT = 0x06
OPAQUE = 0x0A

View file

@ -1,29 +1,9 @@
""" """
Contains all legacy enumerations for interacting with legacy CORE code. Common enumerations used within CORE.
""" """
from enum import Enum from enum import Enum
CORE_API_VERSION = "1.23"
CORE_API_PORT = 4038
class MessageTypes(Enum):
"""
CORE message types.
"""
NODE = 0x01
LINK = 0x02
EXECUTE = 0x03
REGISTER = 0x04
CONFIG = 0x05
FILE = 0x06
INTERFACE = 0x07
EVENT = 0x08
SESSION = 0x09
EXCEPTION = 0x0A
class MessageFlags(Enum): class MessageFlags(Enum):
""" """
@ -40,33 +20,6 @@ class MessageFlags(Enum):
TTY = 0x40 TTY = 0x40
class NodeTlvs(Enum):
"""
Node type, length, value enumerations.
"""
NUMBER = 0x01
TYPE = 0x02
NAME = 0x03
IP_ADDRESS = 0x04
MAC_ADDRESS = 0x05
IP6_ADDRESS = 0x06
MODEL = 0x07
EMULATION_SERVER = 0x08
SESSION = 0x0A
X_POSITION = 0x20
Y_POSITION = 0x21
CANVAS = 0x22
EMULATION_ID = 0x23
NETWORK_ID = 0x24
SERVICES = 0x25
LATITUDE = 0x30
LONGITUDE = 0x31
ALTITUDE = 0x32
ICON = 0x42
OPAQUE = 0x50
class NodeTypes(Enum): class NodeTypes(Enum):
""" """
Node types. Node types.
@ -87,46 +40,6 @@ class NodeTypes(Enum):
LXC = 16 LXC = 16
# Link Message TLV Types
class LinkTlvs(Enum):
"""
Link type, length, value enumerations.
"""
N1_NUMBER = 0x01
N2_NUMBER = 0x02
DELAY = 0x03
BANDWIDTH = 0x04
PER = 0x05
DUP = 0x06
JITTER = 0x07
MER = 0x08
BURST = 0x09
SESSION = 0x0A
MBURST = 0x10
TYPE = 0x20
GUI_ATTRIBUTES = 0x21
UNIDIRECTIONAL = 0x22
EMULATION_ID = 0x23
NETWORK_ID = 0x24
KEY = 0x25
INTERFACE1_NUMBER = 0x30
INTERFACE1_IP4 = 0x31
INTERFACE1_IP4_MASK = 0x32
INTERFACE1_MAC = 0x33
INTERFACE1_IP6 = 0x34
INTERFACE1_IP6_MASK = 0x35
INTERFACE2_NUMBER = 0x36
INTERFACE2_IP4 = 0x37
INTERFACE2_IP4_MASK = 0x38
INTERFACE2_MAC = 0x39
INTERFACE2_IP6 = 0x40
INTERFACE2_IP6_MASK = 0x41
INTERFACE1_NAME = 0x42
INTERFACE2_NAME = 0x43
OPAQUE = 0x50
class LinkTypes(Enum): class LinkTypes(Enum):
""" """
Link types. Link types.
@ -136,20 +49,7 @@ class LinkTypes(Enum):
WIRED = 1 WIRED = 1
class ExecuteTlvs(Enum): # TODO: cleanup usage of .value
"""
Execute type, length, value enumerations.
"""
NODE = 0x01
NUMBER = 0x02
TIME = 0x03
COMMAND = 0x04
RESULT = 0x05
STATUS = 0x06
SESSION = 0x0A
class RegisterTlvs(Enum): class RegisterTlvs(Enum):
""" """
Register type, length, value enumerations. Register type, length, value enumerations.
@ -164,37 +64,6 @@ class RegisterTlvs(Enum):
SESSION = 0x0A SESSION = 0x0A
class ConfigTlvs(Enum):
"""
Configuration type, length, value enumerations.
"""
NODE = 0x01
OBJECT = 0x02
TYPE = 0x03
DATA_TYPES = 0x04
VALUES = 0x05
CAPTIONS = 0x06
BITMAP = 0x07
POSSIBLE_VALUES = 0x08
GROUPS = 0x09
SESSION = 0x0A
INTERFACE_NUMBER = 0x0B
NETWORK_ID = 0x24
OPAQUE = 0x50
class ConfigFlags(Enum):
"""
Configuration flags.
"""
NONE = 0x00
REQUEST = 0x01
UPDATE = 0x02
RESET = 0x03
class ConfigDataTypes(Enum): class ConfigDataTypes(Enum):
""" """
Configuration data types. Configuration data types.
@ -213,55 +82,6 @@ class ConfigDataTypes(Enum):
BOOL = 0x0B BOOL = 0x0B
class FileTlvs(Enum):
"""
File type, length, value enumerations.
"""
NODE = 0x01
NAME = 0x02
MODE = 0x03
NUMBER = 0x04
TYPE = 0x05
SOURCE_NAME = 0x06
SESSION = 0x0A
DATA = 0x10
COMPRESSED_DATA = 0x11
class InterfaceTlvs(Enum):
"""
Interface type, length, value enumerations.
"""
NODE = 0x01
NUMBER = 0x02
NAME = 0x03
IP_ADDRESS = 0x04
MASK = 0x05
MAC_ADDRESS = 0x06
IP6_ADDRESS = 0x07
IP6_MASK = 0x08
TYPE = 0x09
SESSION = 0x0A
STATE = 0x0B
EMULATION_ID = 0x23
NETWORK_ID = 0x24
class EventTlvs(Enum):
"""
Event type, length, value enumerations.
"""
NODE = 0x01
TYPE = 0x02
NAME = 0x03
DATA = 0x04
TIME = 0x05
SESSION = 0x0A
class EventTypes(Enum): class EventTypes(Enum):
""" """
Event types. Event types.
@ -288,35 +108,6 @@ class EventTypes(Enum):
return self.value > self.DEFINITION_STATE.value return self.value > self.DEFINITION_STATE.value
class SessionTlvs(Enum):
"""
Session type, length, value enumerations.
"""
NUMBER = 0x01
NAME = 0x02
FILE = 0x03
NODE_COUNT = 0x04
DATE = 0x05
THUMB = 0x06
USER = 0x07
OPAQUE = 0x0A
class ExceptionTlvs(Enum):
"""
Exception type, length, value enumerations.
"""
NODE = 0x01
SESSION = 0x02
LEVEL = 0x03
SOURCE = 0x04
DATE = 0x05
TEXT = 0x06
OPAQUE = 0x0A
class ExceptionLevels(Enum): class ExceptionLevels(Enum):
""" """
Exception levels. Exception levels.

View file

@ -17,8 +17,8 @@ from core import constants
from core.api.grpc.server import CoreGrpcServer from core.api.grpc.server import CoreGrpcServer
from core.api.tlv.corehandlers import CoreHandler, CoreUdpHandler from core.api.tlv.corehandlers import CoreHandler, CoreUdpHandler
from core.api.tlv.coreserver import CoreServer, CoreUdpServer from core.api.tlv.coreserver import CoreServer, CoreUdpServer
from core.api.tlv.enumerations import CORE_API_PORT
from core.constants import CORE_CONF_DIR, COREDPY_VERSION from core.constants import CORE_CONF_DIR, COREDPY_VERSION
from core.emulator.enumerations import CORE_API_PORT
from core.utils import close_onexec, load_logging_config from core.utils import close_onexec, load_logging_config

View file

@ -9,12 +9,8 @@ import socket
import sys import sys
from core.api.tlv import coreapi from core.api.tlv import coreapi
from core.emulator.enumerations import ( from core.api.tlv.enumerations import CORE_API_PORT, MessageTypes, SessionTlvs
CORE_API_PORT, from core.emulator.enumerations import MessageFlags
MessageFlags,
MessageTypes,
SessionTlvs,
)
def print_available_tlvs(t, tlv_class): def print_available_tlvs(t, tlv_class):

View file

@ -7,16 +7,12 @@ from mock import patch
from core.api.grpc import core_pb2 from core.api.grpc import core_pb2
from core.api.grpc.client import CoreGrpcClient, InterfaceHelper from core.api.grpc.client import CoreGrpcClient, InterfaceHelper
from core.api.tlv.enumerations import ConfigFlags
from core.config import ConfigShim from core.config import ConfigShim
from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.data import EventData from core.emulator.data import EventData
from core.emulator.emudata import NodeOptions from core.emulator.emudata import NodeOptions
from core.emulator.enumerations import ( from core.emulator.enumerations import EventTypes, ExceptionLevels, NodeTypes
ConfigFlags,
EventTypes,
ExceptionLevels,
NodeTypes,
)
from core.errors import CoreError from core.errors import CoreError
from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility from core.location.mobility import BasicRangeModel, Ns2ScriptedMobility
from core.xml.corexml import CoreXmlWriter from core.xml.corexml import CoreXmlWriter

View file

@ -10,21 +10,18 @@ import pytest
from mock import MagicMock from mock import MagicMock
from core.api.tlv import coreapi from core.api.tlv import coreapi
from core.emane.ieee80211abg import EmaneIeee80211abgModel from core.api.tlv.enumerations import (
from core.emulator.enumerations import (
ConfigFlags, ConfigFlags,
ConfigTlvs, ConfigTlvs,
EventTlvs, EventTlvs,
EventTypes,
ExecuteTlvs, ExecuteTlvs,
FileTlvs, FileTlvs,
LinkTlvs, LinkTlvs,
MessageFlags,
NodeTlvs, NodeTlvs,
NodeTypes,
RegisterTlvs,
SessionTlvs, SessionTlvs,
) )
from core.emane.ieee80211abg import EmaneIeee80211abgModel
from core.emulator.enumerations import EventTypes, MessageFlags, NodeTypes, RegisterTlvs
from core.errors import CoreError from core.errors import CoreError
from core.location.mobility import BasicRangeModel from core.location.mobility import BasicRangeModel