initial import (Boeing r1752, NRL r878)
This commit is contained in:
commit
f8f46d28be
394 changed files with 99738 additions and 0 deletions
0
daemon/core/api/__init__.py
Normal file
0
daemon/core/api/__init__.py
Normal file
630
daemon/core/api/coreapi.py
Normal file
630
daemon/core/api/coreapi.py
Normal file
|
@ -0,0 +1,630 @@
|
|||
#
|
||||
# CORE
|
||||
# Copyright (c)2010-2012 the Boeing Company.
|
||||
# See the LICENSE file included in this distribution.
|
||||
#
|
||||
# authors: Tom Goff <thomas.goff@boeing.com>
|
||||
# Jeff Ahrenholz <jeffrey.m.ahrenholz@boeing.com>
|
||||
#
|
||||
'''
|
||||
coreapi.py: uses coreapi_data for Message and TLV types, and defines TLV data
|
||||
types and objects used for parsing and building CORE API messages.
|
||||
'''
|
||||
|
||||
import struct
|
||||
|
||||
from core.api.data import *
|
||||
from core.misc.ipaddr import *
|
||||
|
||||
|
||||
class CoreTlvData(object):
|
||||
datafmt = None
|
||||
datatype = None
|
||||
padlen = None
|
||||
|
||||
@classmethod
|
||||
def pack(cls, value):
|
||||
"return: (tlvlen, tlvdata)"
|
||||
tmp = struct.pack(cls.datafmt, value)
|
||||
return len(tmp) - cls.padlen, tmp
|
||||
|
||||
@classmethod
|
||||
def unpack(cls, data):
|
||||
return struct.unpack(cls.datafmt, data)[0]
|
||||
|
||||
@classmethod
|
||||
def packstring(cls, strvalue):
|
||||
return cls.pack(cls.fromstring(strvalue))
|
||||
|
||||
@classmethod
|
||||
def fromstring(cls, s):
|
||||
return cls.datatype(s)
|
||||
|
||||
class CoreTlvDataObj(CoreTlvData):
|
||||
@classmethod
|
||||
def pack(cls, obj):
|
||||
"return: (tlvlen, tlvdata)"
|
||||
tmp = struct.pack(cls.datafmt, cls.getvalue(obj))
|
||||
return len(tmp) - cls.padlen, tmp
|
||||
|
||||
@classmethod
|
||||
def unpack(cls, data):
|
||||
return cls.newobj(struct.unpack(cls.datafmt, data)[0])
|
||||
|
||||
@staticmethod
|
||||
def getvalue(obj):
|
||||
raise NotImplementedError
|
||||
|
||||
@staticmethod
|
||||
def newobj(obj):
|
||||
raise NotImplementedError
|
||||
|
||||
class CoreTlvDataUint16(CoreTlvData):
|
||||
datafmt = "!H"
|
||||
datatype = int
|
||||
padlen = 0
|
||||
|
||||
class CoreTlvDataUint32(CoreTlvData):
|
||||
datafmt = "!2xI"
|
||||
datatype = int
|
||||
padlen = 2
|
||||
|
||||
class CoreTlvDataUint64(CoreTlvData):
|
||||
datafmt = "!2xQ"
|
||||
datatype = long
|
||||
padlen = 2
|
||||
|
||||
class CoreTlvDataString(CoreTlvData):
|
||||
datatype = str
|
||||
|
||||
@staticmethod
|
||||
def pack(value):
|
||||
if not isinstance(value, str):
|
||||
raise ValueError, "value not a string: %s" % value
|
||||
if len(value) < 256:
|
||||
hdrsiz = CoreTlv.hdrsiz
|
||||
else:
|
||||
hdrsiz = CoreTlv.longhdrsiz
|
||||
padlen = -(hdrsiz + len(value)) % 4
|
||||
return len(value), value + '\0' * padlen
|
||||
|
||||
@staticmethod
|
||||
def unpack(data):
|
||||
return data.rstrip('\0')
|
||||
|
||||
class CoreTlvDataUint16List(CoreTlvData):
|
||||
''' List of unsigned 16-bit values.
|
||||
'''
|
||||
datatype = tuple
|
||||
|
||||
@staticmethod
|
||||
def pack(values):
|
||||
if not isinstance(values, tuple):
|
||||
raise ValueError, "value not a tuple: %s" % values
|
||||
data = ""
|
||||
for v in values:
|
||||
data += struct.pack("!H", v)
|
||||
padlen = -(CoreTlv.hdrsiz + len(data)) % 4
|
||||
return len(data), data + '\0' * padlen
|
||||
|
||||
@staticmethod
|
||||
def unpack(data):
|
||||
datafmt = "!%dH" % (len(data)/2)
|
||||
return struct.unpack(datafmt, data)
|
||||
|
||||
@classmethod
|
||||
def fromstring(cls, s):
|
||||
return tuple(map(lambda(x): int(x), s.split()))
|
||||
|
||||
class CoreTlvDataIPv4Addr(CoreTlvDataObj):
|
||||
datafmt = "!2x4s"
|
||||
datatype = IPAddr.fromstring
|
||||
padlen = 2
|
||||
|
||||
@staticmethod
|
||||
def getvalue(obj):
|
||||
return obj.addr
|
||||
|
||||
@staticmethod
|
||||
def newobj(value):
|
||||
return IPAddr(af = AF_INET, addr = value)
|
||||
|
||||
class CoreTlvDataIPv6Addr(CoreTlvDataObj):
|
||||
datafmt = "!16s2x"
|
||||
datatype = IPAddr.fromstring
|
||||
padlen = 2
|
||||
|
||||
@staticmethod
|
||||
def getvalue(obj):
|
||||
return obj.addr
|
||||
|
||||
@staticmethod
|
||||
def newobj(value):
|
||||
return IPAddr(af = AF_INET6, addr = value)
|
||||
|
||||
class CoreTlvDataMacAddr(CoreTlvDataObj):
|
||||
datafmt = "!2x8s"
|
||||
datatype = MacAddr.fromstring
|
||||
padlen = 2
|
||||
|
||||
@staticmethod
|
||||
def getvalue(obj):
|
||||
return obj.addr
|
||||
|
||||
@staticmethod
|
||||
def newobj(value):
|
||||
return MacAddr(addr = value[2:]) # only use 48 bits
|
||||
|
||||
class CoreTlv(object):
|
||||
hdrfmt = "!BB"
|
||||
hdrsiz = struct.calcsize(hdrfmt)
|
||||
|
||||
longhdrfmt = "!BBH"
|
||||
longhdrsiz = struct.calcsize(longhdrfmt)
|
||||
|
||||
tlvtypemap = {}
|
||||
tlvdataclsmap = {}
|
||||
|
||||
def __init__(self, tlvtype, tlvdata):
|
||||
self.tlvtype = tlvtype
|
||||
if tlvdata:
|
||||
try:
|
||||
self.value = self.tlvdataclsmap[self.tlvtype].unpack(tlvdata)
|
||||
except KeyError:
|
||||
self.value = tlvdata
|
||||
else:
|
||||
self.value = None
|
||||
|
||||
@classmethod
|
||||
def unpack(cls, data):
|
||||
"parse data and return (tlv, remainingdata)"
|
||||
tlvtype, tlvlen = struct.unpack(cls.hdrfmt, data[:cls.hdrsiz])
|
||||
hdrsiz = cls.hdrsiz
|
||||
if tlvlen == 0:
|
||||
tlvtype, zero, tlvlen = struct.unpack(cls.longhdrfmt,
|
||||
data[:cls.longhdrsiz])
|
||||
hdrsiz = cls.longhdrsiz
|
||||
tlvsiz = hdrsiz + tlvlen
|
||||
tlvsiz += -tlvsiz % 4 # for 32-bit alignment
|
||||
return cls(tlvtype, data[hdrsiz:tlvsiz]), data[tlvsiz:]
|
||||
|
||||
@classmethod
|
||||
def pack(cls, tlvtype, value):
|
||||
try:
|
||||
tlvlen, tlvdata = cls.tlvdataclsmap[tlvtype].pack(value)
|
||||
except Exception, e:
|
||||
raise ValueError, "TLV packing error type=%s: %s" % (tlvtype, e)
|
||||
if tlvlen < 256:
|
||||
hdr = struct.pack(cls.hdrfmt, tlvtype, tlvlen)
|
||||
else:
|
||||
hdr = struct.pack(cls.longhdrfmt, tlvtype, 0, tlvlen)
|
||||
return hdr + tlvdata
|
||||
|
||||
@classmethod
|
||||
def packstring(cls, tlvtype, value):
|
||||
return cls.pack(tlvtype, cls.tlvdataclsmap[tlvtype].fromstring(value))
|
||||
|
||||
def typestr(self):
|
||||
try:
|
||||
return self.tlvtypemap[self.tlvtype]
|
||||
except KeyError:
|
||||
return "unknown tlv type: %s" % str(self.tlvtype)
|
||||
|
||||
def __str__(self):
|
||||
return "%s <tlvtype = %s, value = %s>" % \
|
||||
(self.__class__.__name__, self.typestr(), self.value)
|
||||
|
||||
class CoreNodeTlv(CoreTlv):
|
||||
tlvtypemap = node_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_NODE_NUMBER: CoreTlvDataUint32,
|
||||
CORE_TLV_NODE_TYPE: CoreTlvDataUint32,
|
||||
CORE_TLV_NODE_NAME: CoreTlvDataString,
|
||||
CORE_TLV_NODE_IPADDR: CoreTlvDataIPv4Addr,
|
||||
CORE_TLV_NODE_MACADDR: CoreTlvDataMacAddr,
|
||||
CORE_TLV_NODE_IP6ADDR: CoreTlvDataIPv6Addr,
|
||||
CORE_TLV_NODE_MODEL: CoreTlvDataString,
|
||||
CORE_TLV_NODE_EMUSRV: CoreTlvDataString,
|
||||
CORE_TLV_NODE_SESSION: CoreTlvDataString,
|
||||
CORE_TLV_NODE_XPOS: CoreTlvDataUint16,
|
||||
CORE_TLV_NODE_YPOS: CoreTlvDataUint16,
|
||||
CORE_TLV_NODE_CANVAS: CoreTlvDataUint16,
|
||||
CORE_TLV_NODE_EMUID: CoreTlvDataUint32,
|
||||
CORE_TLV_NODE_NETID: CoreTlvDataUint32,
|
||||
CORE_TLV_NODE_SERVICES: CoreTlvDataString,
|
||||
CORE_TLV_NODE_LAT: CoreTlvDataString,
|
||||
CORE_TLV_NODE_LONG: CoreTlvDataString,
|
||||
CORE_TLV_NODE_ALT: CoreTlvDataString,
|
||||
CORE_TLV_NODE_ICON: CoreTlvDataString,
|
||||
CORE_TLV_NODE_OPAQUE: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreLinkTlv(CoreTlv):
|
||||
tlvtypemap = link_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_LINK_N1NUMBER: CoreTlvDataUint32,
|
||||
CORE_TLV_LINK_N2NUMBER: CoreTlvDataUint32,
|
||||
CORE_TLV_LINK_DELAY: CoreTlvDataUint64,
|
||||
CORE_TLV_LINK_BW: CoreTlvDataUint64,
|
||||
CORE_TLV_LINK_PER: CoreTlvDataString,
|
||||
CORE_TLV_LINK_DUP: CoreTlvDataString,
|
||||
CORE_TLV_LINK_JITTER: CoreTlvDataUint32,
|
||||
CORE_TLV_LINK_MER: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_BURST: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_SESSION: CoreTlvDataString,
|
||||
CORE_TLV_LINK_MBURST: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_TYPE: CoreTlvDataUint32,
|
||||
CORE_TLV_LINK_GUIATTR: CoreTlvDataString,
|
||||
CORE_TLV_LINK_EMUID: CoreTlvDataUint32,
|
||||
CORE_TLV_LINK_NETID: CoreTlvDataUint32,
|
||||
CORE_TLV_LINK_KEY: CoreTlvDataUint32,
|
||||
CORE_TLV_LINK_IF1NUM: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_IF1IP4: CoreTlvDataIPv4Addr,
|
||||
CORE_TLV_LINK_IF1IP4MASK: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_IF1MAC: CoreTlvDataMacAddr,
|
||||
CORE_TLV_LINK_IF1IP6: CoreTlvDataIPv6Addr,
|
||||
CORE_TLV_LINK_IF1IP6MASK: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_IF2NUM: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_IF2IP4: CoreTlvDataIPv4Addr,
|
||||
CORE_TLV_LINK_IF2IP4MASK: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_IF2MAC: CoreTlvDataMacAddr,
|
||||
CORE_TLV_LINK_IF2IP6: CoreTlvDataIPv6Addr,
|
||||
CORE_TLV_LINK_IF2IP6MASK: CoreTlvDataUint16,
|
||||
CORE_TLV_LINK_OPAQUE: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreExecTlv(CoreTlv):
|
||||
tlvtypemap = exec_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_EXEC_NODE: CoreTlvDataUint32,
|
||||
CORE_TLV_EXEC_NUM: CoreTlvDataUint32,
|
||||
CORE_TLV_EXEC_TIME: CoreTlvDataUint32,
|
||||
CORE_TLV_EXEC_CMD: CoreTlvDataString,
|
||||
CORE_TLV_EXEC_RESULT: CoreTlvDataString,
|
||||
CORE_TLV_EXEC_STATUS: CoreTlvDataUint32,
|
||||
CORE_TLV_EXEC_SESSION: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreRegTlv(CoreTlv):
|
||||
tlvtypemap = reg_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_REG_WIRELESS: CoreTlvDataString,
|
||||
CORE_TLV_REG_MOBILITY: CoreTlvDataString,
|
||||
CORE_TLV_REG_UTILITY: CoreTlvDataString,
|
||||
CORE_TLV_REG_EXECSRV: CoreTlvDataString,
|
||||
CORE_TLV_REG_GUI: CoreTlvDataString,
|
||||
CORE_TLV_REG_EMULSRV: CoreTlvDataString,
|
||||
CORE_TLV_REG_SESSION: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreConfTlv(CoreTlv):
|
||||
tlvtypemap = conf_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_CONF_NODE: CoreTlvDataUint32,
|
||||
CORE_TLV_CONF_OBJ: CoreTlvDataString,
|
||||
CORE_TLV_CONF_TYPE: CoreTlvDataUint16,
|
||||
CORE_TLV_CONF_DATA_TYPES: CoreTlvDataUint16List,
|
||||
CORE_TLV_CONF_VALUES: CoreTlvDataString,
|
||||
CORE_TLV_CONF_CAPTIONS: CoreTlvDataString,
|
||||
CORE_TLV_CONF_BITMAP: CoreTlvDataString,
|
||||
CORE_TLV_CONF_POSSIBLE_VALUES: CoreTlvDataString,
|
||||
CORE_TLV_CONF_GROUPS: CoreTlvDataString,
|
||||
CORE_TLV_CONF_SESSION: CoreTlvDataString,
|
||||
CORE_TLV_CONF_NETID: CoreTlvDataUint32,
|
||||
CORE_TLV_CONF_OPAQUE: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreFileTlv(CoreTlv):
|
||||
tlvtypemap = file_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_FILE_NODE: CoreTlvDataUint32,
|
||||
CORE_TLV_FILE_NAME: CoreTlvDataString,
|
||||
CORE_TLV_FILE_MODE: CoreTlvDataString,
|
||||
CORE_TLV_FILE_NUM: CoreTlvDataUint16,
|
||||
CORE_TLV_FILE_TYPE: CoreTlvDataString,
|
||||
CORE_TLV_FILE_SRCNAME: CoreTlvDataString,
|
||||
CORE_TLV_FILE_SESSION: CoreTlvDataString,
|
||||
CORE_TLV_FILE_DATA: CoreTlvDataString,
|
||||
CORE_TLV_FILE_CMPDATA: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreIfaceTlv(CoreTlv):
|
||||
tlvtypemap = iface_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_IFACE_NODE: CoreTlvDataUint32,
|
||||
CORE_TLV_IFACE_NUM: CoreTlvDataUint16,
|
||||
CORE_TLV_IFACE_NAME: CoreTlvDataString,
|
||||
CORE_TLV_IFACE_IPADDR: CoreTlvDataIPv4Addr,
|
||||
CORE_TLV_IFACE_MASK: CoreTlvDataUint16,
|
||||
CORE_TLV_IFACE_MACADDR: CoreTlvDataMacAddr,
|
||||
CORE_TLV_IFACE_IP6ADDR: CoreTlvDataIPv6Addr,
|
||||
CORE_TLV_IFACE_IP6MASK: CoreTlvDataUint16,
|
||||
CORE_TLV_IFACE_TYPE: CoreTlvDataUint16,
|
||||
CORE_TLV_IFACE_SESSION: CoreTlvDataString,
|
||||
CORE_TLV_IFACE_STATE: CoreTlvDataUint16,
|
||||
CORE_TLV_IFACE_EMUID: CoreTlvDataUint32,
|
||||
CORE_TLV_IFACE_NETID: CoreTlvDataUint32,
|
||||
}
|
||||
|
||||
class CoreEventTlv(CoreTlv):
|
||||
tlvtypemap = event_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_EVENT_NODE: CoreTlvDataUint32,
|
||||
CORE_TLV_EVENT_TYPE: CoreTlvDataUint32,
|
||||
CORE_TLV_EVENT_NAME: CoreTlvDataString,
|
||||
CORE_TLV_EVENT_DATA: CoreTlvDataString,
|
||||
CORE_TLV_EVENT_TIME: CoreTlvDataString,
|
||||
CORE_TLV_EVENT_SESSION: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreSessionTlv(CoreTlv):
|
||||
tlvtypemap = session_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_SESS_NUMBER: CoreTlvDataString,
|
||||
CORE_TLV_SESS_NAME: CoreTlvDataString,
|
||||
CORE_TLV_SESS_FILE: CoreTlvDataString,
|
||||
CORE_TLV_SESS_NODECOUNT: CoreTlvDataString,
|
||||
CORE_TLV_SESS_DATE: CoreTlvDataString,
|
||||
CORE_TLV_SESS_THUMB: CoreTlvDataString,
|
||||
CORE_TLV_SESS_USER: CoreTlvDataString,
|
||||
CORE_TLV_SESS_OPAQUE: CoreTlvDataString,
|
||||
}
|
||||
|
||||
class CoreExceptionTlv(CoreTlv):
|
||||
tlvtypemap = exception_tlvs
|
||||
tlvdataclsmap = {
|
||||
CORE_TLV_EXCP_NODE: CoreTlvDataUint32,
|
||||
CORE_TLV_EXCP_SESSION: CoreTlvDataString,
|
||||
CORE_TLV_EXCP_LEVEL: CoreTlvDataUint16,
|
||||
CORE_TLV_EXCP_SOURCE: CoreTlvDataString,
|
||||
CORE_TLV_EXCP_DATE: CoreTlvDataString,
|
||||
CORE_TLV_EXCP_TEXT: CoreTlvDataString,
|
||||
CORE_TLV_EXCP_OPAQUE: CoreTlvDataString,
|
||||
}
|
||||
|
||||
|
||||
class CoreMessage(object):
|
||||
hdrfmt = "!BBH"
|
||||
hdrsiz = struct.calcsize(hdrfmt)
|
||||
|
||||
msgtype = None
|
||||
|
||||
flagmap = {}
|
||||
|
||||
tlvcls = CoreTlv
|
||||
|
||||
def __init__(self, flags, hdr, data):
|
||||
self.rawmsg = hdr + data
|
||||
self.flags = flags
|
||||
self.tlvdata = {}
|
||||
self.parsedata(data)
|
||||
|
||||
@classmethod
|
||||
def unpackhdr(cls, data):
|
||||
"parse data and return (msgtype, msgflags, msglen)"
|
||||
msgtype, msgflags, msglen = struct.unpack(cls.hdrfmt, data[:cls.hdrsiz])
|
||||
return msgtype, msgflags, msglen
|
||||
|
||||
@classmethod
|
||||
def pack(cls, msgflags, tlvdata):
|
||||
hdr = struct.pack(cls.hdrfmt, cls.msgtype, msgflags, len(tlvdata))
|
||||
return hdr + tlvdata
|
||||
|
||||
def addtlvdata(self, k, v):
|
||||
if k in self.tlvdata:
|
||||
raise KeyError, "key already exists: %s (val=%s)" % (k, v)
|
||||
self.tlvdata[k] = v
|
||||
|
||||
def gettlv(self, tlvtype):
|
||||
if tlvtype in self.tlvdata:
|
||||
return self.tlvdata[tlvtype]
|
||||
else:
|
||||
return None
|
||||
|
||||
def parsedata(self, data):
|
||||
while data:
|
||||
tlv, data = self.tlvcls.unpack(data)
|
||||
self.addtlvdata(tlv.tlvtype, tlv.value)
|
||||
|
||||
def packtlvdata(self):
|
||||
''' Opposite of parsedata(). Return packed TLV data using
|
||||
self.tlvdata dict. Used by repack().
|
||||
'''
|
||||
tlvdata = ""
|
||||
keys = sorted(self.tlvdata.keys())
|
||||
for k in keys:
|
||||
v = self.tlvdata[k]
|
||||
tlvdata += self.tlvcls.pack(k, v)
|
||||
return tlvdata
|
||||
|
||||
def repack(self):
|
||||
''' Invoke after updating self.tlvdata[] to rebuild self.rawmsg.
|
||||
Useful for modifying a message that has been parsed, before
|
||||
sending the raw data again.
|
||||
'''
|
||||
tlvdata = self.packtlvdata()
|
||||
self.rawmsg = self.pack(self.flags, tlvdata)
|
||||
|
||||
def typestr(self):
|
||||
try:
|
||||
return message_types[self.msgtype]
|
||||
except KeyError:
|
||||
return "unknown message type: %s" % str(self.msgtype)
|
||||
|
||||
def flagstr(self):
|
||||
msgflags = []
|
||||
flag = 1L
|
||||
while True:
|
||||
if (self.flags & flag):
|
||||
try:
|
||||
msgflags.append(self.flagmap[flag])
|
||||
except KeyError:
|
||||
msgflags.append("0x%x" % flag)
|
||||
flag <<= 1
|
||||
if not (self.flags & ~(flag - 1)):
|
||||
break
|
||||
return "0x%x <%s>" % (self.flags, " | ".join(msgflags))
|
||||
|
||||
def __str__(self):
|
||||
tmp = "%s <msgtype = %s, flags = %s>" % \
|
||||
(self.__class__.__name__, self.typestr(), self.flagstr())
|
||||
for k, v in self.tlvdata.iteritems():
|
||||
if k in self.tlvcls.tlvtypemap:
|
||||
tlvtype = self.tlvcls.tlvtypemap[k]
|
||||
else:
|
||||
tlvtype = "tlv type %s" % k
|
||||
tmp += "\n %s: %s" % (tlvtype, v)
|
||||
return tmp
|
||||
|
||||
def nodenumbers(self):
|
||||
''' Return a list of node numbers included in this message.
|
||||
'''
|
||||
n = None
|
||||
n2 = None
|
||||
# not all messages have node numbers
|
||||
if self.msgtype == CORE_API_NODE_MSG:
|
||||
n = self.gettlv(CORE_TLV_NODE_NUMBER)
|
||||
elif self.msgtype == CORE_API_LINK_MSG:
|
||||
n = self.gettlv(CORE_TLV_LINK_N1NUMBER)
|
||||
n2 = self.gettlv(CORE_TLV_LINK_N2NUMBER)
|
||||
elif self.msgtype == CORE_API_EXEC_MSG:
|
||||
n = self.gettlv(CORE_TLV_EXEC_NODE)
|
||||
elif self.msgtype == CORE_API_CONF_MSG:
|
||||
n = self.gettlv(CORE_TLV_CONF_NODE)
|
||||
elif self.msgtype == CORE_API_FILE_MSG:
|
||||
n = self.gettlv(CORE_TLV_FILE_NODE)
|
||||
elif self.msgtype == CORE_API_IFACE_MSG:
|
||||
n = self.gettlv(CORE_TLV_IFACE_NODE)
|
||||
elif self.msgtype == CORE_API_EVENT_MSG:
|
||||
n = self.gettlv(CORE_TLV_EVENT_NODE)
|
||||
r = []
|
||||
if n is not None:
|
||||
r.append(n)
|
||||
if n2 is not None:
|
||||
r.append(n2)
|
||||
return r
|
||||
|
||||
def sessionnumbers(self):
|
||||
''' Return a list of session numbers included in this message.
|
||||
'''
|
||||
r = []
|
||||
if self.msgtype == CORE_API_SESS_MSG:
|
||||
s = self.gettlv(CORE_TLV_SESS_NUMBER)
|
||||
elif self.msgtype == CORE_API_EXCP_MSG:
|
||||
s = self.gettlv(CORE_TLV_EXCP_SESSION)
|
||||
else:
|
||||
# All other messages share TLV number 0xA for the session number(s).
|
||||
s = self.gettlv(CORE_TLV_NODE_SESSION)
|
||||
if s is not None:
|
||||
for sid in s.split('|'):
|
||||
r.append(int(sid))
|
||||
return r
|
||||
|
||||
|
||||
class CoreNodeMessage(CoreMessage):
|
||||
msgtype = CORE_API_NODE_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreNodeTlv
|
||||
|
||||
class CoreLinkMessage(CoreMessage):
|
||||
msgtype = CORE_API_LINK_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreLinkTlv
|
||||
|
||||
class CoreExecMessage(CoreMessage):
|
||||
msgtype = CORE_API_EXEC_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreExecTlv
|
||||
|
||||
class CoreRegMessage(CoreMessage):
|
||||
msgtype = CORE_API_REG_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreRegTlv
|
||||
|
||||
class CoreConfMessage(CoreMessage):
|
||||
msgtype = CORE_API_CONF_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreConfTlv
|
||||
|
||||
class CoreFileMessage(CoreMessage):
|
||||
msgtype = CORE_API_FILE_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreFileTlv
|
||||
|
||||
class CoreIfaceMessage(CoreMessage):
|
||||
msgtype = CORE_API_IFACE_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreIfaceTlv
|
||||
|
||||
class CoreEventMessage(CoreMessage):
|
||||
msgtype = CORE_API_EVENT_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreEventTlv
|
||||
|
||||
class CoreSessionMessage(CoreMessage):
|
||||
msgtype = CORE_API_SESS_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreSessionTlv
|
||||
|
||||
class CoreExceptionMessage(CoreMessage):
|
||||
msgtype = CORE_API_EXCP_MSG
|
||||
flagmap = message_flags
|
||||
tlvcls = CoreExceptionTlv
|
||||
|
||||
msgclsmap = {
|
||||
CORE_API_NODE_MSG: CoreNodeMessage,
|
||||
CORE_API_LINK_MSG: CoreLinkMessage,
|
||||
CORE_API_EXEC_MSG: CoreExecMessage,
|
||||
CORE_API_REG_MSG: CoreRegMessage,
|
||||
CORE_API_CONF_MSG: CoreConfMessage,
|
||||
CORE_API_FILE_MSG: CoreFileMessage,
|
||||
CORE_API_IFACE_MSG: CoreIfaceMessage,
|
||||
CORE_API_EVENT_MSG: CoreEventMessage,
|
||||
CORE_API_SESS_MSG: CoreSessionMessage,
|
||||
CORE_API_EXCP_MSG: CoreExceptionMessage,
|
||||
}
|
||||
|
||||
def msg_class(msgtypeid):
|
||||
global msgclsmap
|
||||
return msgclsmap[msgtypeid]
|
||||
|
||||
nodeclsmap = {}
|
||||
|
||||
def add_node_class(name, nodetypeid, nodecls, change = False):
|
||||
global nodeclsmap
|
||||
if nodetypeid in nodeclsmap:
|
||||
if not change:
|
||||
raise ValueError, \
|
||||
"node class already exists for nodetypeid %s" % nodetypeid
|
||||
nodeclsmap[nodetypeid] = nodecls
|
||||
if nodetypeid not in node_types:
|
||||
node_types[nodetypeid] = name
|
||||
exec "%s = %s" % (name, nodetypeid) in globals()
|
||||
elif name != node_types[nodetypeid]:
|
||||
raise ValueError, "node type already exists for '%s'" % name
|
||||
else:
|
||||
pass
|
||||
|
||||
def change_node_class(name, nodetypeid, nodecls):
|
||||
return add_node_class(name, nodetypeid, nodecls, change = True)
|
||||
|
||||
def node_class(nodetypeid):
|
||||
global nodeclsmap
|
||||
return nodeclsmap[nodetypeid]
|
||||
|
||||
def str_to_list(s):
|
||||
''' Helper to convert pipe-delimited string ("a|b|c") into a list (a, b, c)
|
||||
'''
|
||||
if s is None:
|
||||
return None
|
||||
return s.split("|")
|
||||
|
||||
def state_name(n):
|
||||
''' Helper to convert state number into state name using event types.
|
||||
'''
|
||||
if n in event_types:
|
||||
eventname = event_types[n]
|
||||
name = eventname.split('_')[2]
|
||||
else:
|
||||
name = "unknown"
|
||||
return name
|
327
daemon/core/api/data.py
Normal file
327
daemon/core/api/data.py
Normal file
|
@ -0,0 +1,327 @@
|
|||
#
|
||||
# CORE
|
||||
# Copyright (c)2010-2012 the Boeing Company.
|
||||
# See the LICENSE file included in this distribution.
|
||||
#
|
||||
# author: Tom Goff <thomas.goff@boeing.com>
|
||||
#
|
||||
'''
|
||||
data.py: constant definitions for the CORE API, enumerating the
|
||||
different message and TLV types (these constants are also found in coreapi.h)
|
||||
'''
|
||||
|
||||
def enumdict(d):
|
||||
for k, v in d.iteritems():
|
||||
exec "%s = %s" % (v, k) in globals()
|
||||
|
||||
# Constants
|
||||
|
||||
CORE_API_VER = "1.21"
|
||||
CORE_API_PORT = 4038
|
||||
|
||||
# Message types
|
||||
|
||||
message_types = {
|
||||
0x01: "CORE_API_NODE_MSG",
|
||||
0x02: "CORE_API_LINK_MSG",
|
||||
0x03: "CORE_API_EXEC_MSG",
|
||||
0x04: "CORE_API_REG_MSG",
|
||||
0x05: "CORE_API_CONF_MSG",
|
||||
0x06: "CORE_API_FILE_MSG",
|
||||
0x07: "CORE_API_IFACE_MSG",
|
||||
0x08: "CORE_API_EVENT_MSG",
|
||||
0x09: "CORE_API_SESS_MSG",
|
||||
0x0A: "CORE_API_EXCP_MSG",
|
||||
0x0B: "CORE_API_MSG_MAX",
|
||||
}
|
||||
|
||||
enumdict(message_types)
|
||||
|
||||
# Generic Message Flags
|
||||
|
||||
message_flags = {
|
||||
0x01: "CORE_API_ADD_FLAG",
|
||||
0x02: "CORE_API_DEL_FLAG",
|
||||
0x04: "CORE_API_CRI_FLAG",
|
||||
0x08: "CORE_API_LOC_FLAG",
|
||||
0x10: "CORE_API_STR_FLAG",
|
||||
0x20: "CORE_API_TXT_FLAG",
|
||||
0x40: "CORE_API_TTY_FLAG",
|
||||
}
|
||||
|
||||
enumdict(message_flags)
|
||||
|
||||
# Node Message TLV Types
|
||||
|
||||
node_tlvs = {
|
||||
0x01: "CORE_TLV_NODE_NUMBER",
|
||||
0x02: "CORE_TLV_NODE_TYPE",
|
||||
0x03: "CORE_TLV_NODE_NAME",
|
||||
0x04: "CORE_TLV_NODE_IPADDR",
|
||||
0x05: "CORE_TLV_NODE_MACADDR",
|
||||
0x06: "CORE_TLV_NODE_IP6ADDR",
|
||||
0x07: "CORE_TLV_NODE_MODEL",
|
||||
0x08: "CORE_TLV_NODE_EMUSRV",
|
||||
0x0A: "CORE_TLV_NODE_SESSION",
|
||||
0x20: "CORE_TLV_NODE_XPOS",
|
||||
0x21: "CORE_TLV_NODE_YPOS",
|
||||
0x22: "CORE_TLV_NODE_CANVAS",
|
||||
0x23: "CORE_TLV_NODE_EMUID",
|
||||
0x24: "CORE_TLV_NODE_NETID",
|
||||
0x25: "CORE_TLV_NODE_SERVICES",
|
||||
0x30: "CORE_TLV_NODE_LAT",
|
||||
0x31: "CORE_TLV_NODE_LONG",
|
||||
0x32: "CORE_TLV_NODE_ALT",
|
||||
0x42: "CORE_TLV_NODE_ICON",
|
||||
0x50: "CORE_TLV_NODE_OPAQUE",
|
||||
}
|
||||
|
||||
enumdict(node_tlvs)
|
||||
|
||||
node_types = dict(enumerate([
|
||||
"CORE_NODE_DEF",
|
||||
"CORE_NODE_PHYS",
|
||||
"CORE_NODE_XEN",
|
||||
"CORE_NODE_TBD",
|
||||
"CORE_NODE_SWITCH",
|
||||
"CORE_NODE_HUB",
|
||||
"CORE_NODE_WLAN",
|
||||
"CORE_NODE_RJ45",
|
||||
"CORE_NODE_TUNNEL",
|
||||
"CORE_NODE_KTUNNEL",
|
||||
"CORE_NODE_EMANE",
|
||||
]))
|
||||
|
||||
enumdict(node_types)
|
||||
|
||||
rj45_models = dict(enumerate([
|
||||
"RJ45_MODEL_LINKED",
|
||||
"RJ45_MODEL_WIRELESS",
|
||||
"RJ45_MODEL_INSTALLED",
|
||||
]))
|
||||
|
||||
enumdict(rj45_models)
|
||||
|
||||
# Link Message TLV Types
|
||||
|
||||
link_tlvs = {
|
||||
0x01: "CORE_TLV_LINK_N1NUMBER",
|
||||
0x02: "CORE_TLV_LINK_N2NUMBER",
|
||||
0x03: "CORE_TLV_LINK_DELAY",
|
||||
0x04: "CORE_TLV_LINK_BW",
|
||||
0x05: "CORE_TLV_LINK_PER",
|
||||
0x06: "CORE_TLV_LINK_DUP",
|
||||
0x07: "CORE_TLV_LINK_JITTER",
|
||||
0x08: "CORE_TLV_LINK_MER",
|
||||
0x09: "CORE_TLV_LINK_BURST",
|
||||
CORE_TLV_NODE_SESSION: "CORE_TLV_LINK_SESSION",
|
||||
0x10: "CORE_TLV_LINK_MBURST",
|
||||
0x20: "CORE_TLV_LINK_TYPE",
|
||||
0x21: "CORE_TLV_LINK_GUIATTR",
|
||||
0x23: "CORE_TLV_LINK_EMUID",
|
||||
0x24: "CORE_TLV_LINK_NETID",
|
||||
0x25: "CORE_TLV_LINK_KEY",
|
||||
0x30: "CORE_TLV_LINK_IF1NUM",
|
||||
0x31: "CORE_TLV_LINK_IF1IP4",
|
||||
0x32: "CORE_TLV_LINK_IF1IP4MASK",
|
||||
0x33: "CORE_TLV_LINK_IF1MAC",
|
||||
0x34: "CORE_TLV_LINK_IF1IP6",
|
||||
0x35: "CORE_TLV_LINK_IF1IP6MASK",
|
||||
0x36: "CORE_TLV_LINK_IF2NUM",
|
||||
0x37: "CORE_TLV_LINK_IF2IP4",
|
||||
0x38: "CORE_TLV_LINK_IF2IP4MASK",
|
||||
0x39: "CORE_TLV_LINK_IF2MAC",
|
||||
0x40: "CORE_TLV_LINK_IF2IP6",
|
||||
0x41: "CORE_TLV_LINK_IF2IP6MASK",
|
||||
0x50: "CORE_TLV_LINK_OPAQUE",
|
||||
}
|
||||
|
||||
enumdict(link_tlvs)
|
||||
|
||||
link_types = dict(enumerate([
|
||||
"CORE_LINK_WIRELESS",
|
||||
"CORE_LINK_WIRED",
|
||||
]))
|
||||
|
||||
enumdict(link_types)
|
||||
|
||||
# Execute Message TLV Types
|
||||
|
||||
exec_tlvs = {
|
||||
0x01: "CORE_TLV_EXEC_NODE",
|
||||
0x02: "CORE_TLV_EXEC_NUM",
|
||||
0x03: "CORE_TLV_EXEC_TIME",
|
||||
0x04: "CORE_TLV_EXEC_CMD",
|
||||
0x05: "CORE_TLV_EXEC_RESULT",
|
||||
0x06: "CORE_TLV_EXEC_STATUS",
|
||||
CORE_TLV_NODE_SESSION: "CORE_TLV_EXEC_SESSION",
|
||||
}
|
||||
|
||||
enumdict(exec_tlvs)
|
||||
|
||||
# Register Message TLV Types
|
||||
|
||||
reg_tlvs = {
|
||||
0x01: "CORE_TLV_REG_WIRELESS",
|
||||
0x02: "CORE_TLV_REG_MOBILITY",
|
||||
0x03: "CORE_TLV_REG_UTILITY",
|
||||
0x04: "CORE_TLV_REG_EXECSRV",
|
||||
0x05: "CORE_TLV_REG_GUI",
|
||||
0x06: "CORE_TLV_REG_EMULSRV",
|
||||
CORE_TLV_NODE_SESSION: "CORE_TLV_REG_SESSION",
|
||||
}
|
||||
|
||||
enumdict(reg_tlvs)
|
||||
|
||||
# Configuration Message TLV Types
|
||||
|
||||
conf_tlvs = {
|
||||
0x01: "CORE_TLV_CONF_NODE",
|
||||
0x02: "CORE_TLV_CONF_OBJ",
|
||||
0x03: "CORE_TLV_CONF_TYPE",
|
||||
0x04: "CORE_TLV_CONF_DATA_TYPES",
|
||||
0x05: "CORE_TLV_CONF_VALUES",
|
||||
0x06: "CORE_TLV_CONF_CAPTIONS",
|
||||
0x07: "CORE_TLV_CONF_BITMAP",
|
||||
0x08: "CORE_TLV_CONF_POSSIBLE_VALUES",
|
||||
0x09: "CORE_TLV_CONF_GROUPS",
|
||||
CORE_TLV_NODE_SESSION: "CORE_TLV_CONF_SESSION",
|
||||
CORE_TLV_NODE_NETID: "CORE_TLV_CONF_NETID",
|
||||
0x50: "CORE_TLV_CONF_OPAQUE",
|
||||
}
|
||||
|
||||
enumdict(conf_tlvs)
|
||||
|
||||
conf_flags = {
|
||||
0x00: "CONF_TYPE_FLAGS_NONE",
|
||||
0x01: "CONF_TYPE_FLAGS_REQUEST",
|
||||
0x02: "CONF_TYPE_FLAGS_UPDATE",
|
||||
0x03: "CONF_TYPE_FLAGS_RESET",
|
||||
}
|
||||
|
||||
enumdict(conf_flags)
|
||||
|
||||
conf_data_types = {
|
||||
0x01: "CONF_DATA_TYPE_UINT8",
|
||||
0x02: "CONF_DATA_TYPE_UINT16",
|
||||
0x03: "CONF_DATA_TYPE_UINT32",
|
||||
0x04: "CONF_DATA_TYPE_UINT64",
|
||||
0x05: "CONF_DATA_TYPE_INT8",
|
||||
0x06: "CONF_DATA_TYPE_INT16",
|
||||
0x07: "CONF_DATA_TYPE_INT32",
|
||||
0x08: "CONF_DATA_TYPE_INT64",
|
||||
0x09: "CONF_DATA_TYPE_FLOAT",
|
||||
0x0A: "CONF_DATA_TYPE_STRING",
|
||||
0x0B: "CONF_DATA_TYPE_BOOL",
|
||||
}
|
||||
|
||||
enumdict(conf_data_types)
|
||||
|
||||
# File Message TLV Types
|
||||
|
||||
file_tlvs = {
|
||||
0x01: "CORE_TLV_FILE_NODE",
|
||||
0x02: "CORE_TLV_FILE_NAME",
|
||||
0x03: "CORE_TLV_FILE_MODE",
|
||||
0x04: "CORE_TLV_FILE_NUM",
|
||||
0x05: "CORE_TLV_FILE_TYPE",
|
||||
0x06: "CORE_TLV_FILE_SRCNAME",
|
||||
CORE_TLV_NODE_SESSION: "CORE_TLV_FILE_SESSION",
|
||||
0x10: "CORE_TLV_FILE_DATA",
|
||||
0x11: "CORE_TLV_FILE_CMPDATA",
|
||||
}
|
||||
|
||||
enumdict(file_tlvs)
|
||||
|
||||
# Interface Message TLV Types
|
||||
|
||||
iface_tlvs = {
|
||||
0x01: "CORE_TLV_IFACE_NODE",
|
||||
0x02: "CORE_TLV_IFACE_NUM",
|
||||
0x03: "CORE_TLV_IFACE_NAME",
|
||||
0x04: "CORE_TLV_IFACE_IPADDR",
|
||||
0x05: "CORE_TLV_IFACE_MASK",
|
||||
0x06: "CORE_TLV_IFACE_MACADDR",
|
||||
0x07: "CORE_TLV_IFACE_IP6ADDR",
|
||||
0x08: "CORE_TLV_IFACE_IP6MASK",
|
||||
0x09: "CORE_TLV_IFACE_TYPE",
|
||||
CORE_TLV_NODE_SESSION: "CORE_TLV_IFACE_SESSION",
|
||||
0x0B: "CORE_TLV_IFACE_STATE",
|
||||
CORE_TLV_NODE_EMUID: "CORE_TLV_IFACE_EMUID",
|
||||
CORE_TLV_NODE_NETID: "CORE_TLV_IFACE_NETID",
|
||||
}
|
||||
|
||||
enumdict(iface_tlvs)
|
||||
|
||||
# Event Message TLV Types
|
||||
|
||||
event_tlvs = {
|
||||
0x01: "CORE_TLV_EVENT_NODE",
|
||||
0x02: "CORE_TLV_EVENT_TYPE",
|
||||
0x03: "CORE_TLV_EVENT_NAME",
|
||||
0x04: "CORE_TLV_EVENT_DATA",
|
||||
0x05: "CORE_TLV_EVENT_TIME",
|
||||
CORE_TLV_NODE_SESSION: "CORE_TLV_EVENT_SESSION",
|
||||
}
|
||||
|
||||
enumdict(event_tlvs)
|
||||
|
||||
event_types = dict(enumerate([
|
||||
"CORE_EVENT_NONE",
|
||||
"CORE_EVENT_DEFINITION_STATE",
|
||||
"CORE_EVENT_CONFIGURATION_STATE",
|
||||
"CORE_EVENT_INSTANTIATION_STATE",
|
||||
"CORE_EVENT_RUNTIME_STATE",
|
||||
"CORE_EVENT_DATACOLLECT_STATE",
|
||||
"CORE_EVENT_SHUTDOWN_STATE",
|
||||
"CORE_EVENT_START",
|
||||
"CORE_EVENT_STOP",
|
||||
"CORE_EVENT_PAUSE",
|
||||
"CORE_EVENT_RESTART",
|
||||
"CORE_EVENT_FILE_OPEN",
|
||||
"CORE_EVENT_FILE_SAVE",
|
||||
"CORE_EVENT_SCHEDULED",
|
||||
]))
|
||||
|
||||
enumdict(event_types)
|
||||
|
||||
# Session Message TLV Types
|
||||
|
||||
session_tlvs = {
|
||||
0x01: "CORE_TLV_SESS_NUMBER",
|
||||
0x02: "CORE_TLV_SESS_NAME",
|
||||
0x03: "CORE_TLV_SESS_FILE",
|
||||
0x04: "CORE_TLV_SESS_NODECOUNT",
|
||||
0x05: "CORE_TLV_SESS_DATE",
|
||||
0x06: "CORE_TLV_SESS_THUMB",
|
||||
0x07: "CORE_TLV_SESS_USER",
|
||||
0x0A: "CORE_TLV_SESS_OPAQUE",
|
||||
}
|
||||
|
||||
enumdict(session_tlvs)
|
||||
|
||||
# Exception Message TLV Types
|
||||
|
||||
exception_tlvs = {
|
||||
0x01: "CORE_TLV_EXCP_NODE",
|
||||
0x02: "CORE_TLV_EXCP_SESSION",
|
||||
0x03: "CORE_TLV_EXCP_LEVEL",
|
||||
0x04: "CORE_TLV_EXCP_SOURCE",
|
||||
0x05: "CORE_TLV_EXCP_DATE",
|
||||
0x06: "CORE_TLV_EXCP_TEXT",
|
||||
0x0A: "CORE_TLV_EXCP_OPAQUE",
|
||||
}
|
||||
|
||||
enumdict(exception_tlvs)
|
||||
|
||||
exception_levels = dict(enumerate([
|
||||
"CORE_EXCP_LEVEL_NONE",
|
||||
"CORE_EXCP_LEVEL_FATAL",
|
||||
"CORE_EXCP_LEVEL_ERROR",
|
||||
"CORE_EXCP_LEVEL_WARNING",
|
||||
"CORE_EXCP_LEVEL_NOTICE",
|
||||
]))
|
||||
|
||||
enumdict(exception_levels)
|
||||
|
||||
del enumdict
|
Loading…
Add table
Add a link
Reference in a new issue