progressing ....
This commit is contained in:
parent
821d78dfb5
commit
6538490c41
2 changed files with 546 additions and 41 deletions
|
@ -11,40 +11,75 @@
|
|||
|
||||
import core_pb2
|
||||
import struct
|
||||
from core.api.coreapi import *
|
||||
from core.api import *
|
||||
|
||||
class CoreMessage(object):
|
||||
hdrfmt = "H"
|
||||
hdrsiz = struct.calcsize(hdrfmt)
|
||||
legacy = coreapi
|
||||
|
||||
HDRFMT = "H"
|
||||
HDRSIZ = struct.calcsize(HDRFMT)
|
||||
|
||||
|
||||
|
||||
|
||||
class CoreApiBridge(object):
|
||||
|
||||
@staticmethod
|
||||
def toLegacyApi(data):
|
||||
def Api2toLegacy(data):
|
||||
message = core_pb2.CoreMessage()
|
||||
message.ParseFromString(data)
|
||||
if message.HasField('session'):
|
||||
return CoreMessage.translateSessionMsg(message.session)
|
||||
return CoreApiBridge.translateApi2SessionMsg(message.session)
|
||||
if message.HasField('experiment'):
|
||||
return CoreMessage.translateExperimentMsg(message.experiment)
|
||||
return CoreApiBridge.translateExperimentMsg(message.experiment)
|
||||
if message.HasField('event'):
|
||||
return CoreMessage.translateEvent(message.event)
|
||||
return CoreApiBridge.translateEvent(message.event)
|
||||
|
||||
@staticmethod
|
||||
def toApi2(messages):
|
||||
for msg in messages:
|
||||
msgtype, msgflags, msglen = coreapi.CoreMessage.unpackhdr(msg)
|
||||
data = msg[coreapi.CoreMessage.hdrsiz:]
|
||||
if msgtype == coreapi.CORE_API_REG_MSG:
|
||||
pass
|
||||
elif msgtype == coreapi.CORE_API_SESS_MSG:
|
||||
|
||||
|
||||
def LegacytoApi2(messages):
|
||||
api2msgs = []
|
||||
for msgstr in messages:
|
||||
# Unpack the message
|
||||
msgtype, msgflags, msglen = legacy.CoreMessage.unpackhdr(msgstr)
|
||||
hdr = msgstr[0:legacy.CoreMessage.hdrsiz]
|
||||
data = msgstr[legacy.CoreMessage.hdrsiz:]
|
||||
msgcls = legacy.msg_class(msgtype)
|
||||
if msgtype == legacy.CORE_API_REG_MSG:
|
||||
oldMsg = RegisterMsgWrapper(msgflags, hdr, data)
|
||||
print "RegisterMessage"
|
||||
print "\twireless=", oldMsg.getWireless()
|
||||
print "\tmobility=", oldMsg.getMobility()
|
||||
print "\tutility=", oldMsg.getUtility()
|
||||
print "\texec=", oldMsg.getExecsrv()
|
||||
print "\tgui=", oldMsg.getGui()
|
||||
print "\temul=", oldMsg.getEmulsrv()
|
||||
print "\tsess=", oldMsg.getSession()
|
||||
elif msgtype == legacy.CORE_API_SESS_MSG:
|
||||
oldMsg = SessionMsgWrapper(msgflags, hdr, data)
|
||||
print "SessionMessage"
|
||||
print "\tnumber=", oldMsg.getNumber()
|
||||
print "\tname=", oldMsg.getName()
|
||||
print "\tfile=", oldMsg.getFile()
|
||||
print "\tnodecount=", oldMsg.getNodecount()
|
||||
print "\tdate=", oldMsg.getDate()
|
||||
print "\tthumb=", oldMsg.getThumb()
|
||||
print "\tuser=", oldMsg.getUser()
|
||||
print "\topaque=", oldMsg.getOpaque()
|
||||
sessions = oldMsg.getNumber().split("|")
|
||||
port_num = int(sessions[0])
|
||||
newMsg = core_pb2.CoreMessage()
|
||||
newMsg.session.SetInParent()
|
||||
newMsg.session.clientId = 'client' + sessions[0]
|
||||
newMsg.session.port_num = port_num
|
||||
print "len=", len(newMsg.SerializeToString())
|
||||
api2msgs.append(newMsg.SerializeToString())
|
||||
return api2msgs
|
||||
|
||||
|
||||
@staticmethod
|
||||
def translateSessionMsg(message):
|
||||
def translateApi2SessionMsg(message):
|
||||
print 'Received session request message'
|
||||
msgs = []
|
||||
msgs.append(CoreMessage.createRegisterMessage(0, gui='true'))
|
||||
msgs.append(RegisterMsgWrapper.createLegacyMessage(0, gui='true'))
|
||||
return msgs
|
||||
|
||||
|
||||
|
@ -52,6 +87,47 @@ class CoreMessage(object):
|
|||
@staticmethod
|
||||
def translateExperimentMsg(message):
|
||||
print 'Received experiment message'
|
||||
msgs = []
|
||||
# Flag need to be 0 otherwise CORE will not enter runtime state (per JavaAdaptor, need verification)
|
||||
msgs.append(SessionMsgWrapper.createLegacyMessage(
|
||||
0, "0",
|
||||
nodecount=str(len(message.nodes) + len(message.devices))))
|
||||
# Quickly transition through the definition and configuration states
|
||||
msgs.append(EventMsgWrapper.createLegacyMessage(legacy.CORE_EVENT_DEFINITION_STATE))
|
||||
msgs.append(EventMsgWrapper.createLegacyMessage(legacy.CORE_EVENT_CONFIGURATION_STATE))
|
||||
|
||||
# Send location
|
||||
msgs.append(ConfigMsgWrapper.createLegacyMessage(obj="location",
|
||||
dataTypes=(9,9,9,9,9,9),
|
||||
dataValues='0|0| 47.5766974863|-122.125920191|0.0|150.0'))
|
||||
|
||||
# Send control net configuration
|
||||
# TODO
|
||||
|
||||
# send node types
|
||||
# TODO
|
||||
|
||||
# send services
|
||||
# TODO
|
||||
|
||||
# send nodes
|
||||
for node in message.nodes:
|
||||
# TODO: Add other fields
|
||||
msgs.append(NodeMsgWrapper.createLegacyMessage(
|
||||
legacy.CORE_API_ADD_FLAG|legacy.CORE_API_STR_FLAG,
|
||||
node.idx,
|
||||
str(node.name)))
|
||||
|
||||
# send metadata
|
||||
# TODO
|
||||
|
||||
|
||||
# transition to instantiation state
|
||||
# TODO
|
||||
|
||||
|
||||
|
||||
return msgs
|
||||
|
||||
|
||||
@staticmethod
|
||||
|
@ -60,23 +136,451 @@ class CoreMessage(object):
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Legacy API wrapper classes for decoding messages generated by the CORE daemon
|
||||
'''
|
||||
|
||||
|
||||
class NodeMsgWrapper(legacy.CoreNodeMessage):
|
||||
|
||||
@staticmethod
|
||||
def createRegisterMessage(flags, wireless=None, mobility=None, utility=None, execsrv=None,
|
||||
gui=None, emulsrv=None, session=None):
|
||||
def createLegacyMessage(flags, number, name=None, type=legacy.CORE_NODE_DEF, model=None, \
|
||||
emusrv=None, session=None, emuid=-1, netid=-1, services=None, \
|
||||
ipaddr=None, macaddr=None, ip6addr=None, \
|
||||
xpos=-1, ypos=-1, canvas=-1, \
|
||||
lat=None, long=None, alt=None, icon=None, opaque=None):
|
||||
tlvdata = legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_NUMBER,number)
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_TYPE,type)
|
||||
if name is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_NAME,name)
|
||||
if ipaddr is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_IPADDR,IPAddr(AF_INET, socket.inet_aton(ipaddr)))
|
||||
if macaddr is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_MACADDR,MacAddr.fromstring(macaddr))
|
||||
if ip6addr is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_IP6ADDR,IPAddr(AF_INET6, ip6addr))
|
||||
if model is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_MODEL,model)
|
||||
if emusrv is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_EMUSRV,emusrv)
|
||||
if session is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_SESSION,session)
|
||||
if xpos >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_XPOS,xpos)
|
||||
if ypos >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_YPOS,ypos)
|
||||
if canvas >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_CANVAS,canvas)
|
||||
# if emuid >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_EMUID,number)
|
||||
if netid >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_NETID,netid)
|
||||
if services is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_SERVICES,services)
|
||||
if lat is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_LAT,lat)
|
||||
if long is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_LONG,long)
|
||||
if alt is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_ALT,alt)
|
||||
if icon is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_ICON,icon)
|
||||
if opaque is not None:
|
||||
tlvdata = tlvdata + legacy.CoreNodeTlv.pack(legacy.CORE_TLV_NODE_OPAQUE,opaque)
|
||||
hdr = struct.pack(legacy.CoreMessage.hdrfmt, legacy.CoreNodeMessage.msgtype, flags, len(tlvdata))
|
||||
return legacy.CoreNodeMessage(flags, hdr, tlvdata)
|
||||
|
||||
|
||||
def getNumber(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_NUMBER)
|
||||
def getType(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_TYPE)
|
||||
def getName(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_NAME)
|
||||
def getIpaddr(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_IPADDR)
|
||||
def getMacaddr(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_MACADDR)
|
||||
def getIp6addr(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_IP6ADDR)
|
||||
def getModel(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_MODEL)
|
||||
def getEmusrv(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_EMUSRV)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_SESSION)
|
||||
def getXpos(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_XPOS)
|
||||
def getYpos(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_YPOS)
|
||||
def getCanvas(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_CANVAS)
|
||||
def getEmuid(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_EMUID)
|
||||
def getNetid(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_NETID)
|
||||
def getServices(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_SERVICES)
|
||||
def getLat(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_LAT)
|
||||
def getLong(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_LONG)
|
||||
def getAlt(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_ALT)
|
||||
def getIcon(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_ICON)
|
||||
def getOpaque(self):
|
||||
return self.gettlv(legacy.CORE_TLV_NODE_OPAQUE)
|
||||
|
||||
class LinkMsgWrapper(legacy.CoreLinkMessage):
|
||||
def getN1number(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_N1NUMBER)
|
||||
def getN2number(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_N2NUMBER)
|
||||
def getDelay(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_DELAY)
|
||||
def getBw(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_BW)
|
||||
def getPer(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_PER)
|
||||
def getDup(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_DUP)
|
||||
def getJitter(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_JITTER)
|
||||
def getMer(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_MER)
|
||||
def getBurst(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_BURST)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_SESSION)
|
||||
def getMburst(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_MBURST)
|
||||
def getType(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_TYPE)
|
||||
def getGuiattr(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_GUIATTR)
|
||||
def getEmuid(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_EMUID)
|
||||
def getNetid(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_NETID)
|
||||
def getKey(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_KEY)
|
||||
def getIf1num(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF1NUM)
|
||||
def getIf1ip4(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF1IP4)
|
||||
def getIf1ip4mask(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF1IP4MASK)
|
||||
def getIf1mac(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF1MAC)
|
||||
def getIf1ip6(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF1IP6)
|
||||
def getIf1ip6mask(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF1IP6MASK)
|
||||
def getIf2num(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF2NUM)
|
||||
def getIf2ip4(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF2IP4)
|
||||
def getIf2ip4mask(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF2IP4MASK)
|
||||
def getIf2mac(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF2MAC)
|
||||
def getIf2ip6(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF2IP6)
|
||||
def getIf2ip6mask(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_IF2IP6MASK)
|
||||
def getOpaque(self):
|
||||
return self.gettlv(legacy.CORE_TLV_LINK_OPAQUE)
|
||||
|
||||
class ExecMsgWrapper(legacy.CoreExecMessage):
|
||||
def getNode(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXEC_NODE)
|
||||
def getNum(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXEC_NUM)
|
||||
def getTime(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXEC_TIME)
|
||||
def getCmd(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXEC_CMD)
|
||||
def getResult(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXEC_RESULT)
|
||||
def getStatus(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXEC_STATUS)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXEC_SESSION)
|
||||
|
||||
class RegisterMsgWrapper(legacy.CoreRegMessage):
|
||||
#
|
||||
# Overrides of CoreMessage methods to account for multiple values per key in
|
||||
# RegisterMessages.
|
||||
#
|
||||
|
||||
def addtlvdata(self, k, v):
|
||||
''' Append the value 'v' to list of values corresponding to key 'k'
|
||||
'''
|
||||
if k in self.tlvdata:
|
||||
self.tlvdata[k].append(v)
|
||||
else:
|
||||
self.tlvdata[k] = [v]
|
||||
|
||||
def gettlv(self, tlvtype, idx=0):
|
||||
if tlvtype in self.tlvdata:
|
||||
return self.tlvdata[tlvtype][idx]
|
||||
else:
|
||||
return None
|
||||
|
||||
def packtlvdata(self):
|
||||
''' Return packed TLV data as in CoreMessage. Account for multiple values per key.
|
||||
'''
|
||||
tlvdata = ""
|
||||
keys = sorted(self.tlvdata.keys())
|
||||
for k in keys:
|
||||
for v in self.tlvdata[k]:
|
||||
tlvdata += self.tlvcls.pack(k, v)
|
||||
return tlvdata
|
||||
|
||||
def __str__(self):
|
||||
tmp = "%s <msgtype = %s, flags = %s>" % \
|
||||
(self.__class__.__name__, self.typestr(), self.flagstr())
|
||||
for k, m in self.tlvdata.iteritems():
|
||||
if k in self.tlvcls.tlvtypemap:
|
||||
tlvtype = self.tlvcls.tlvtypemap[k]
|
||||
else:
|
||||
tlvtype = "tlv type %s" % k
|
||||
tmp += "\n %s: " % tlvtype
|
||||
for v in m:
|
||||
tmp += "%s " % v
|
||||
return tmp
|
||||
|
||||
@staticmethod
|
||||
def createLegacyMessage(flags, wireless=None, mobility=None, utility=None, execsrv=None,
|
||||
gui=None, emulsrv=None, session=None):
|
||||
tlvdata = ""
|
||||
if wireless is not None:
|
||||
tlvdata = tlvdata + CoreRegTlv.pack(CORE_TLV_REG_WIRELESS,wireless)
|
||||
tlvdata = tlvdata + legacy.CoreRegTlv.pack(legacy.CORE_TLV_REG_WIRELESS,wireless)
|
||||
if mobility is not None:
|
||||
tlvdata = tlvdata + CoreRegTlv.pack(CORE_TLV_REG_MOBILITY,mobility)
|
||||
tlvdata = tlvdata + legacy.CoreRegTlv.pack(legacy.CORE_TLV_REG_MOBILITY,mobility)
|
||||
if utility is not None:
|
||||
tlvdata = tlvdata + CoreRegTlv.pack(CORE_TLV_REG_UTILITY,utility)
|
||||
tlvdata = tlvdata + legacy.CoreRegTlv.pack(legacy.CORE_TLV_REG_UTILITY,utility)
|
||||
if execsrv is not None:
|
||||
tlvdata = tlvdata + CoreRegTlv.pack(CORE_TLV_REG_EXECSRV,execsrv)
|
||||
tlvdata = tlvdata + legacy.CoreRegTlv.pack(legacy.CORE_TLV_REG_EXECSRV,execsrv)
|
||||
if gui is not None:
|
||||
tlvdata = tlvdata + CoreRegTlv.pack(CORE_TLV_REG_GUI,gui)
|
||||
tlvdata = tlvdata + legacy.CoreRegTlv.pack(legacy.CORE_TLV_REG_GUI,gui)
|
||||
if emulsrv is not None:
|
||||
tlvdata = tlvdata + CoreRegTlv.pack(CORE_TLV_REG_EMULSRV,emulsrv)
|
||||
tlvdata = tlvdata + legacy.CoreRegTlv.pack(legacy.CORE_TLV_REG_EMULSRV,emulsrv)
|
||||
if session is not None:
|
||||
tlvdata = tlvdata + CoreRegTlv.pack(CORE_TLV_REG_SESSION,session)
|
||||
hdr = struct.pack(CoreRegMessage.hdrfmt, CoreRegMessage.msgtype, flags, len(tlvdata))
|
||||
return CoreRegMessage(flags, hdr, tlvdata)
|
||||
tlvdata = tlvdata + legacy.CoreRegTlv.pack(legacy.CORE_TLV_REG_SESSION,session)
|
||||
hdr = struct.pack(legacy.CoreMessage.hdrfmt, legacy.CoreRegMessage.msgtype, flags, len(tlvdata))
|
||||
return legacy.CoreRegMessage(flags, hdr, tlvdata)
|
||||
|
||||
|
||||
def getWireless(self):
|
||||
return self.gettlv(legacy.CORE_TLV_REG_WIRELESS)
|
||||
def getMobility(self):
|
||||
return self.gettlv(legacy.CORE_TLV_REG_MOBILITY)
|
||||
def getUtility(self):
|
||||
return self.gettlv(legacy.CORE_TLV_REG_UTILITY)
|
||||
def getExecsrv(self):
|
||||
return self.gettlv(legacy.CORE_TLV_REG_EXECSRV)
|
||||
def getGui(self):
|
||||
return self.gettlv(legacy.CORE_TLV_REG_GUI)
|
||||
def getEmulsrv(self):
|
||||
return self.gettlv(legacy.CORE_TLV_REG_EMULSRV)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_REG_SESSION)
|
||||
|
||||
class ConfigMsgWrapper(legacy.CoreConfMessage):
|
||||
|
||||
@staticmethod
|
||||
def createLegacyMessage(obj, type=legacy.CONF_TYPE_FLAGS_NONE, node=-1, netid=-1, session=None, \
|
||||
dataTypes=None, dataValues=None, possibleValues=None, valueGroups=None, \
|
||||
captions=None, bitmap=None, opaque=None):
|
||||
tlvdata = legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_OBJ,obj)
|
||||
if type != legacy.CONF_TYPE_FLAGS_NONE:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_TYPE,type)
|
||||
if node >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_NODE,node)
|
||||
if dataTypes is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_DATA_TYPES,dataTypes)
|
||||
if dataValues is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_VALUES,dataValues)
|
||||
if captions is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_CAPTIONS,captions)
|
||||
if bitmap is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_BITMAP,bitmap)
|
||||
if possibleValues is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_POSSIBLE_VALUES,possibleValues)
|
||||
if valueGroups is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_GROUPS,valueGroups)
|
||||
if session is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_SESSION,session)
|
||||
if netid >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_NETID,netid)
|
||||
if opaque is not None:
|
||||
tlvdata = tlvdata + legacy.CoreConfTlv.pack(legacy.CORE_TLV_CONF_OPAQUE,opaque)
|
||||
hdr = struct.pack(legacy.CoreMessage.hdrfmt, legacy.CoreConfMessage.msgtype, 0, len(tlvdata))
|
||||
return legacy.CoreConfMessage(0, hdr, tlvdata)
|
||||
|
||||
|
||||
|
||||
def getNode(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_NODE)
|
||||
def getObj(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_OBJ)
|
||||
def getType(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_TYPE)
|
||||
def getData(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_DATA_TYPES)
|
||||
def getValues(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_VALUES)
|
||||
def getCaptions(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_CAPTIONS)
|
||||
def getBitmap(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_BITMAP)
|
||||
def getPossible(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_POSSIBLE_VALUES)
|
||||
def getGroups(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_GROUPS)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_SESSION)
|
||||
def getNetid(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_NETID)
|
||||
def getOpaque(self):
|
||||
return self.gettlv(legacy.CORE_TLV_CONF_OPAQUE)
|
||||
|
||||
class FileMsgWrapper(legacy.CoreFileMessage):
|
||||
def getNode(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_NODE)
|
||||
def getName(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_NAME)
|
||||
def getMode(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_MODE)
|
||||
def getNum(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_NUM)
|
||||
def getType(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_TYPE)
|
||||
def getSrcname(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_SRCNAME)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_SESSION)
|
||||
def getData(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_DATA)
|
||||
def getCmpdata(self):
|
||||
return self.gettlv(legacy.CORE_TLV_FILE_CMPDATA)
|
||||
|
||||
class InterfaceMsgWrapper(legacy.CoreIfaceMessage):
|
||||
def getNode(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_NODE)
|
||||
def getNum(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_NUM)
|
||||
def getName(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_NAME)
|
||||
def getIpaddr(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_IPADDR)
|
||||
def getMask(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_MASK)
|
||||
def getMacaddr(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_MACADDR)
|
||||
def getIp6addr(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_IP6ADDR)
|
||||
def getIp6mask(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_IP6MASK)
|
||||
def getType(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_TYPE)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_SESSION)
|
||||
def getState(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_STATE)
|
||||
def getEmuid(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_EMUID)
|
||||
def getNetid(self):
|
||||
return self.gettlv(legacy.CORE_TLV_IFACE_NETID)
|
||||
|
||||
class EventMsgWrapper(legacy.CoreEventMessage):
|
||||
|
||||
@staticmethod
|
||||
def createLegacyMessage(type, flags=0, nodenum=-1, name=None, data=None, session=None):
|
||||
tlvdata = legacy.CoreEventTlv.pack(legacy.CORE_TLV_EVENT_TYPE, type)
|
||||
if nodenum >= 0:
|
||||
tlvdata = tlvdata + legacy.CoreEventTlv.pack(legacy.CORE_TLV_EVENT_NODE, nodenum)
|
||||
if name is not None:
|
||||
tlvdata = tlvdata + legacy.CoreEventTlv.pack(legacy.CORE_TLV_EVENT_NAME, name)
|
||||
if data is not None:
|
||||
tlvdata = tlvdata + legacy.CoreEventTlv.pack(legacy.CORE_TLV_EVENT_DATA, data)
|
||||
if session is not None:
|
||||
tlvdata = tlvdata + legacy.CoreEventTlv.pack(legacy.CORE_TLV_EVENT_SESSION, session)
|
||||
hdr = struct.pack(legacy.CoreMessage.hdrfmt, legacy.CoreEventMessage.msgtype, flags, len(tlvdata))
|
||||
return legacy.CoreEventMessage(flags, hdr, tlvdata)
|
||||
|
||||
def getNode(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EVENT_NODE)
|
||||
def getType(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EVENT_TYPE)
|
||||
def getName(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EVENT_NAME)
|
||||
def getData(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EVENT_DATA)
|
||||
def getTime(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EVENT_TIME)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EVENT_SESSION)
|
||||
|
||||
class SessionMsgWrapper(legacy.CoreSessionMessage):
|
||||
|
||||
@staticmethod
|
||||
def createLegacyMessage(flags, number, name=None, file=None, nodecount=None, thumb=None, user=None, opaque=None):
|
||||
tlvdata = legacy.CoreSessionTlv.pack(legacy.CORE_TLV_SESS_NUMBER,number)
|
||||
if name is not None:
|
||||
tlvdata = tlvdata + legacy.CoreSessionTlv.pack(legacy.CORE_TLV_SESS_NAME,name)
|
||||
if file is not None:
|
||||
tlvdata = tlvdata + legacy.CoreSessionTlv.pack(legacy.CORE_TLV_SESS_FILE,file)
|
||||
if nodecount is not None: # CORE API expects a string, which can be a list of node numbers
|
||||
tlvdata = tlvdata + legacy.CoreSessionTlv.pack(legacy.CORE_TLV_SESS_NODECOUNT,nodecount)
|
||||
if thumb is not None:
|
||||
tlvdata = tlvdata + legacy.CoreSessionTlv.pack(legacy.CORE_TLV_SESS_THUMB,thumb)
|
||||
if user is not None:
|
||||
tlvdata = tlvdata + legacy.CoreSessionTlv.pack(legacy.CORE_TLV_SESS_USER,user)
|
||||
if opaque is not None:
|
||||
tlvdata = tlvdata + legacy.CoreSessionTlv.pack(legacy.CORE_TLV_SESS_OPAQUE,opaque)
|
||||
hdr = struct.pack(legacy.CoreMessage.hdrfmt, legacy.CoreSessionMessage.msgtype, flags, len(tlvdata))
|
||||
return legacy.CoreSessionMessage(flags, hdr, tlvdata)
|
||||
|
||||
|
||||
def getNumber(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_NUMBER)
|
||||
def getName(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_NAME)
|
||||
def getFile(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_FILE)
|
||||
def getNodecount(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_NODECOUNT)
|
||||
def getDate(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_DATE)
|
||||
def getThumb(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_THUMB)
|
||||
def getUser(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_USER)
|
||||
def getOpaque(self):
|
||||
return self.gettlv(legacy.CORE_TLV_SESS_OPAQUE)
|
||||
|
||||
class ExceptionMsgWrapper(legacy.CoreExceptionMessage):
|
||||
def getNode(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXCP_NODE)
|
||||
def getSession(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXCP_SESSION)
|
||||
def getLevel(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXCP_LEVEL)
|
||||
def getSource(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXCP_SOURCE)
|
||||
def getDate(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXCP_DATE)
|
||||
def getText(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXCP_TEXT)
|
||||
def getOpaque(self):
|
||||
return self.gettlv(legacy.CORE_TLV_EXCP_OPAQUE)
|
||||
|
||||
class UnknownMsgWrapper(legacy.CoreMessage):
|
||||
"No method"
|
||||
pass
|
||||
|
|
|
@ -1412,7 +1412,7 @@ class CoreApi2RequestHandler(CoreRequestHandler):
|
|||
while True:
|
||||
try:
|
||||
data = self.recvmsg()
|
||||
msgs = coreapi2.CoreMessage.toLegacyApi(data)
|
||||
msgs = coreapi2.CoreApiBridge.Api2toLegacy(data)
|
||||
if msgs:
|
||||
for msg in msgs:
|
||||
print msg
|
||||
|
@ -1427,12 +1427,14 @@ class CoreApi2RequestHandler(CoreRequestHandler):
|
|||
def dispatchreplies(self, replies):
|
||||
''' Dispatch a reply to a previously received message.
|
||||
'''
|
||||
api2Replies = coreapi2.CoreMessage.toApi2(replies)
|
||||
for reply in api2Replies:
|
||||
try:
|
||||
self.sendall(reply)
|
||||
except Exception, e:
|
||||
self.warn("Error sending reply data: %s" % e)
|
||||
api2Replies = coreapi2.CoreApiBridge.LegacytoApi2(replies)
|
||||
if api2Replies:
|
||||
for reply in api2Replies:
|
||||
try:
|
||||
self.request.sendall(struct.pack(coreapi2.HDRFMT, len(reply)))
|
||||
self.sendall(reply)
|
||||
except Exception, e:
|
||||
self.warn("Error sending reply data: %s" % e)
|
||||
|
||||
def finish(self):
|
||||
return SocketServer.BaseRequestHandler.finish(self)
|
||||
|
@ -1443,20 +1445,19 @@ class CoreApi2RequestHandler(CoreRequestHandler):
|
|||
'''
|
||||
|
||||
try:
|
||||
hdr = self.request.recv(coreapi2.CoreMessage.hdrsiz)
|
||||
hdr = self.request.recv(coreapi2.HDRSIZ)
|
||||
if self.debug and len(msghdr) > 0:
|
||||
self.info("received message header:\n%s" % hexdump(msghdr))
|
||||
except Exception, e:
|
||||
raise IOError, "error receiving API 2 header (%s)" % e
|
||||
|
||||
if len(hdr) != coreapi2.CoreMessage.hdrsiz:
|
||||
if len(hdr) != coreapi2.HDRSIZ:
|
||||
if len(hdr) == 0:
|
||||
raise EOFError, "client disconnected"
|
||||
else:
|
||||
print coreapi2.CoreMessage.hdrsiz, len(hdr)
|
||||
raise IOError, "invalid message header size"
|
||||
|
||||
dataToRead = struct.unpack(coreapi2.CoreMessage.hdrfmt, hdr)[0]
|
||||
dataToRead = struct.unpack(coreapi2.HDRFMT, hdr)[0]
|
||||
data = ""
|
||||
while len(data) < dataToRead:
|
||||
data += self.request.recv(dataToRead - len(data))
|
||||
|
|
Loading…
Reference in a new issue