remove old utility examples for now
This commit is contained in:
parent
2662a36f09
commit
7e03202ba4
3 changed files with 0 additions and 465 deletions
|
@ -1,214 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
from emanesh import manifest
|
|
||||||
import os.path
|
|
||||||
import re
|
|
||||||
import textwrap
|
|
||||||
|
|
||||||
class EmaneManifest2Model(object):
|
|
||||||
|
|
||||||
class EmaneModel(object):
|
|
||||||
|
|
||||||
class EmaneModelParameter(object):
|
|
||||||
|
|
||||||
intfloat_regex = re.compile(r'^([0-9]+)\.(0*)$')
|
|
||||||
indent = ' ' * 16
|
|
||||||
|
|
||||||
def __init__(self, name, apitype, default, caption,
|
|
||||||
possible_values = ()):
|
|
||||||
self.name = name
|
|
||||||
self.apitype = apitype
|
|
||||||
self.default = self.intfloat_regex.sub(r'\1.0', default)
|
|
||||||
self.possible_values = possible_values
|
|
||||||
self.caption = caption
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return '''%s('%s', %s,\n%s '%s', '%s', '%s')''' % \
|
|
||||||
(self.indent, self.name, self.apitype,
|
|
||||||
self.indent, self.default,
|
|
||||||
','.join(self.possible_values), self.caption)
|
|
||||||
|
|
||||||
def __init__(self, name):
|
|
||||||
self.name = name
|
|
||||||
self.parameters = []
|
|
||||||
|
|
||||||
def add_parameter(self, name, apitype, default, caption,
|
|
||||||
possible_values = ()):
|
|
||||||
p = self.EmaneModelParameter(name, apitype, default, caption,
|
|
||||||
possible_values)
|
|
||||||
self.parameters.append(p)
|
|
||||||
|
|
||||||
mac_xml_path = '/usr/share/emane/xml/models/mac'
|
|
||||||
|
|
||||||
# map emane parameter types to CORE api data types
|
|
||||||
core_api_type = {
|
|
||||||
'uint8': 'coreapi.CONF_DATA_TYPE_UINT8',
|
|
||||||
'uint16': 'coreapi.CONF_DATA_TYPE_UINT16',
|
|
||||||
'uint32': 'coreapi.CONF_DATA_TYPE_UINT32',
|
|
||||||
'uint64': 'coreapi.CONF_DATA_TYPE_UINT64',
|
|
||||||
'int8': 'coreapi.CONF_DATA_TYPE_INT8',
|
|
||||||
'int16': 'coreapi.CONF_DATA_TYPE_INT16',
|
|
||||||
'int32': 'coreapi.CONF_DATA_TYPE_INT32',
|
|
||||||
'int64': 'coreapi.CONF_DATA_TYPE_INT64',
|
|
||||||
'float': 'coreapi.CONF_DATA_TYPE_FLOAT',
|
|
||||||
'double': 'coreapi.CONF_DATA_TYPE_FLOAT',
|
|
||||||
'bool': 'coreapi.CONF_DATA_TYPE_BOOL',
|
|
||||||
'string': 'coreapi.CONF_DATA_TYPE_STRING',
|
|
||||||
}
|
|
||||||
|
|
||||||
parameter_regex = re.compile(r'^\^\(([\|\-\w]+)\)\$$')
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def emane_model(cls, xmlfile):
|
|
||||||
m = manifest.Manifest(xmlfile)
|
|
||||||
model = cls.EmaneModel(m.getName())
|
|
||||||
for name in m.getAllConfiguration():
|
|
||||||
info = m.getConfigurationInfo(name)
|
|
||||||
apitype = None
|
|
||||||
for t in 'numeric', 'nonnumeric':
|
|
||||||
if t in info:
|
|
||||||
apitype = cls.core_api_type[info[t]['type']]
|
|
||||||
break
|
|
||||||
default = ''
|
|
||||||
if info['default']:
|
|
||||||
values = info['values']
|
|
||||||
if values:
|
|
||||||
default = values[0]
|
|
||||||
caption = name
|
|
||||||
possible_values = []
|
|
||||||
if apitype == 'coreapi.CONF_DATA_TYPE_BOOL':
|
|
||||||
possible_values = ['On,Off']
|
|
||||||
elif apitype == 'coreapi.CONF_DATA_TYPE_STRING':
|
|
||||||
if name == 'pcrcurveuri':
|
|
||||||
default = os.path.join(cls.mac_xml_path,
|
|
||||||
model.name, model.name + 'pcr.xml')
|
|
||||||
else:
|
|
||||||
regex = info['regex']
|
|
||||||
if regex:
|
|
||||||
match = cls.parameter_regex.match(regex)
|
|
||||||
if match:
|
|
||||||
possible_values = match.group(1).split('|')
|
|
||||||
model.add_parameter(name, apitype, default,
|
|
||||||
caption, possible_values)
|
|
||||||
model.parameters.sort(key = lambda x: x.name)
|
|
||||||
return model
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def core_emane_model(cls, class_name, macmanifest_filename,
|
|
||||||
phymanifest_filename):
|
|
||||||
template = '''\
|
|
||||||
from core.emane.emane import EmaneModel
|
|
||||||
from core.api import coreapi
|
|
||||||
|
|
||||||
class BaseEmaneModel(EmaneModel):
|
|
||||||
def __init__(self, session, objid = None, verbose = False):
|
|
||||||
EmaneModel.__init__(self, session, objid, verbose)
|
|
||||||
|
|
||||||
def buildnemxmlfiles(self, e, ifc):
|
|
||||||
\'\'\'\\
|
|
||||||
Build the necessary nem, mac, and phy XMLs in the given path.
|
|
||||||
If an individual NEM has a nonstandard config, we need to
|
|
||||||
build that file also. Otherwise the WLAN-wide
|
|
||||||
nXXemane_*nem.xml, nXXemane_*mac.xml, nXXemane_*phy.xml are
|
|
||||||
used.
|
|
||||||
\'\'\'
|
|
||||||
values = e.getifcconfig(self.objid, self._name,
|
|
||||||
self.getdefaultvalues(), ifc)
|
|
||||||
if values is None:
|
|
||||||
return
|
|
||||||
|
|
||||||
nemdoc = e.xmldoc('nem')
|
|
||||||
nem = nemdoc.getElementsByTagName('nem').pop()
|
|
||||||
e.appendtransporttonem(nemdoc, nem, self.objid, ifc)
|
|
||||||
|
|
||||||
def append_definition(tag, name, xmlname, doc):
|
|
||||||
el = doc.createElement(name)
|
|
||||||
el.setAttribute('definition', xmlname)
|
|
||||||
tag.appendChild(el)
|
|
||||||
|
|
||||||
append_definition(nem, 'mac', self.macxmlname(ifc), nemdoc)
|
|
||||||
append_definition(nem, 'phy', self.phyxmlname(ifc), nemdoc)
|
|
||||||
|
|
||||||
e.xmlwrite(nemdoc, self.nemxmlname(ifc))
|
|
||||||
|
|
||||||
names = list(self.getnames())
|
|
||||||
|
|
||||||
def append_options(tag, optnames, doc):
|
|
||||||
for name in optnames:
|
|
||||||
value = self.valueof(name, values).strip()
|
|
||||||
if value:
|
|
||||||
tag.appendChild(e.xmlparam(doc, name, value))
|
|
||||||
|
|
||||||
macdoc = e.xmldoc('mac')
|
|
||||||
mac = macdoc.getElementsByTagName('mac').pop()
|
|
||||||
mac.setAttribute('library', '%(modelLibrary)s')
|
|
||||||
# append MAC options to macdoc
|
|
||||||
append_options(mac, names[:len(self._confmatrix_mac)], macdoc)
|
|
||||||
e.xmlwrite(macdoc, self.macxmlname(ifc))
|
|
||||||
|
|
||||||
phydoc = e.xmldoc('phy')
|
|
||||||
phy = phydoc.getElementsByTagName('phy').pop()
|
|
||||||
# append PHY options to phydoc
|
|
||||||
append_options(phy, names[len(self._confmatrix_mac):], phydoc)
|
|
||||||
e.xmlwrite(phydoc, self.phyxmlname(ifc))
|
|
||||||
|
|
||||||
class %(modelClass)s(BaseEmaneModel):
|
|
||||||
# model name
|
|
||||||
_name = 'emane_%(modelName)s'
|
|
||||||
|
|
||||||
# configuration parameters are
|
|
||||||
# ( 'name', 'type', 'default', 'possible-value-list', 'caption')
|
|
||||||
# MAC parameters
|
|
||||||
_confmatrix_mac = [\n%(confMatrixMac)s
|
|
||||||
]
|
|
||||||
|
|
||||||
# PHY parameters
|
|
||||||
_confmatrix_phy = [\n%(confMatrixPhy)s
|
|
||||||
]
|
|
||||||
|
|
||||||
_confmatrix = _confmatrix_mac + _confmatrix_phy
|
|
||||||
|
|
||||||
# value groupings
|
|
||||||
_confgroups = 'MAC Parameters:1-%%s|PHY Parameters:%%s-%%s' %% \\
|
|
||||||
(len(_confmatrix_mac), \\
|
|
||||||
len(_confmatrix_mac) + 1, len(_confmatrix))
|
|
||||||
'''
|
|
||||||
macmodel = cls.emane_model(macmanifest_filename)
|
|
||||||
phymodel = cls.emane_model(phymanifest_filename)
|
|
||||||
d = {
|
|
||||||
'modelClass': 'Emane%sModel' % (class_name),
|
|
||||||
'modelName': macmodel.name,
|
|
||||||
'confMatrixMac': ',\n'.join(map(str, macmodel.parameters)) + ',',
|
|
||||||
'confMatrixPhy': ',\n'.join(map(str, phymodel.parameters)) + ',',
|
|
||||||
'modelLibrary': macmodel.name,
|
|
||||||
}
|
|
||||||
return textwrap.dedent(template % d)
|
|
||||||
|
|
||||||
def main():
|
|
||||||
import argparse
|
|
||||||
import sys
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
||||||
description = 'Create skeleton CORE bindings from ' \
|
|
||||||
'EMANE model manifest files.',
|
|
||||||
epilog = 'example:\n' \
|
|
||||||
' %(prog)s -c RadioX \\\n' \
|
|
||||||
' -m /usr/share/emane/manifest/radiox.xml \\\n' \
|
|
||||||
' -p /usr/share/emane/manifest/emanephy.xml')
|
|
||||||
parser.add_argument('-c', '--class-name', dest = 'classname',
|
|
||||||
required = True, help = 'corresponding python '
|
|
||||||
'class name: RadioX -> EmaneRadioXModel')
|
|
||||||
parser.add_argument('-m', '--mac-xmlfile', dest = 'macxmlfilename',
|
|
||||||
required = True,
|
|
||||||
help = 'MAC model manifest XML filename')
|
|
||||||
parser.add_argument('-p', '--phy-xmlfile', dest = 'phyxmlfilename',
|
|
||||||
required = True,
|
|
||||||
help = 'PHY model manifest XML filename')
|
|
||||||
args = parser.parse_args()
|
|
||||||
model = EmaneManifest2Model.core_emane_model(args.classname,
|
|
||||||
args.macxmlfilename,
|
|
||||||
args.phyxmlfilename)
|
|
||||||
sys.stdout.write(model)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
|
@ -1,173 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
'''
|
|
||||||
emanemodel2core.py: scans an EMANE model source file
|
|
||||||
(e.g. emane/models/rfpipe/maclayer/rfpipemaclayer.cc) and outputs Python
|
|
||||||
bindings that allow the model to be used in CORE.
|
|
||||||
|
|
||||||
When using this conversion utility, you should replace XYZ, Xyz, and xyz with
|
|
||||||
the actual model name. Note the capitalization convention.
|
|
||||||
'''
|
|
||||||
|
|
||||||
import os, sys, optparse
|
|
||||||
|
|
||||||
MODEL_TEMPLATE_PART1 = """
|
|
||||||
'''
|
|
||||||
xyz.py: EMANE XYZ model bindings for CORE
|
|
||||||
'''
|
|
||||||
|
|
||||||
from core.api import coreapi
|
|
||||||
from emane import EmaneModel
|
|
||||||
from universal import EmaneUniversalModel
|
|
||||||
|
|
||||||
class EmaneXyzModel(EmaneModel):
|
|
||||||
def __init__(self, session, objid = None, verbose = False):
|
|
||||||
EmaneModel.__init__(self, session, objid, verbose)
|
|
||||||
|
|
||||||
# model name
|
|
||||||
_name = "emane_xyz"
|
|
||||||
# MAC parameters
|
|
||||||
_confmatrix_mac = [
|
|
||||||
"""
|
|
||||||
|
|
||||||
MODEL_TEMPLATE_PART2 = """
|
|
||||||
]
|
|
||||||
|
|
||||||
# PHY parameters from Universal PHY
|
|
||||||
_confmatrix_phy = EmaneUniversalModel._confmatrix
|
|
||||||
|
|
||||||
_confmatrix = _confmatrix_mac + _confmatrix_phy
|
|
||||||
|
|
||||||
# value groupings
|
|
||||||
_confgroups = "XYZ MAC Parameters:1-%d|Universal PHY Parameters:%d-%d" \
|
|
||||||
% ( len(_confmatrix_mac), len(_confmatrix_mac) + 1, len(_confmatrix))
|
|
||||||
|
|
||||||
def buildnemxmlfiles(self, e, ifc):
|
|
||||||
''' Build the necessary nem, mac, and phy XMLs in the given path.
|
|
||||||
If an individual NEM has a nonstandard config, we need to build
|
|
||||||
that file also. Otherwise the WLAN-wide nXXemane_xyznem.xml,
|
|
||||||
nXXemane_xyzmac.xml, nXXemane_xyzphy.xml are used.
|
|
||||||
'''
|
|
||||||
values = e.getifcconfig(self.objid, self._name,
|
|
||||||
self.getdefaultvalues(), ifc)
|
|
||||||
if values is None:
|
|
||||||
return
|
|
||||||
nemdoc = e.xmldoc("nem")
|
|
||||||
nem = nemdoc.getElementsByTagName("nem").pop()
|
|
||||||
nem.setAttribute("name", "XYZ NEM")
|
|
||||||
mactag = nemdoc.createElement("mac")
|
|
||||||
mactag.setAttribute("definition", self.macxmlname(ifc))
|
|
||||||
nem.appendChild(mactag)
|
|
||||||
phytag = nemdoc.createElement("phy")
|
|
||||||
phytag.setAttribute("definition", self.phyxmlname(ifc))
|
|
||||||
nem.appendChild(phytag)
|
|
||||||
e.xmlwrite(nemdoc, self.nemxmlname(ifc))
|
|
||||||
|
|
||||||
names = list(self.getnames())
|
|
||||||
macnames = names[:len(self._confmatrix_mac)]
|
|
||||||
phynames = names[len(self._confmatrix_mac):]
|
|
||||||
# make any changes to the mac/phy names here to e.g. exclude them from
|
|
||||||
# the XML output
|
|
||||||
|
|
||||||
macdoc = e.xmldoc("mac")
|
|
||||||
mac = macdoc.getElementsByTagName("mac").pop()
|
|
||||||
mac.setAttribute("name", "XYZ MAC")
|
|
||||||
mac.setAttribute("library", "xyzmaclayer")
|
|
||||||
# append MAC options to macdoc
|
|
||||||
map( lambda n: mac.appendChild(e.xmlparam(macdoc, n, \
|
|
||||||
self.valueof(n, values))), macnames)
|
|
||||||
e.xmlwrite(macdoc, self.macxmlname(ifc))
|
|
||||||
|
|
||||||
phydoc = EmaneUniversalModel.getphydoc(e, self, values, phynames)
|
|
||||||
e.xmlwrite(phydoc, self.phyxmlname(ifc))
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def emane_model_source_to_core(infile, outfile):
|
|
||||||
do_parse_line = False
|
|
||||||
output = MODEL_TEMPLATE_PART1
|
|
||||||
|
|
||||||
with open(infile, 'r') as f:
|
|
||||||
for line in f:
|
|
||||||
# begin marker
|
|
||||||
if "EMANE::ConfigurationDefinition" in line:
|
|
||||||
do_parse_line = True
|
|
||||||
# end marker -- all done
|
|
||||||
if "{0, 0, 0, 0, 0, 0" in line:
|
|
||||||
break
|
|
||||||
if do_parse_line:
|
|
||||||
outstr = convert_line(line)
|
|
||||||
if outstr is not None:
|
|
||||||
output += outstr
|
|
||||||
continue
|
|
||||||
output += MODEL_TEMPLATE_PART2
|
|
||||||
|
|
||||||
if outfile == sys.stdout:
|
|
||||||
sys.stdout.write(output)
|
|
||||||
else:
|
|
||||||
with open(outfile, 'w') as f:
|
|
||||||
f.write(output)
|
|
||||||
|
|
||||||
def convert_line(line):
|
|
||||||
line = line.strip()
|
|
||||||
# skip comments
|
|
||||||
if line.startswith(('/*', '//')):
|
|
||||||
return None
|
|
||||||
items = line.strip('{},').split(',')
|
|
||||||
if len(items) != 7:
|
|
||||||
#print "continuning on line=", len(items), items
|
|
||||||
return None
|
|
||||||
return convert_items_to_line(items)
|
|
||||||
|
|
||||||
def convert_items_to_line(items):
|
|
||||||
fields = ('required', 'default', 'count', 'name', 'value', 'type',
|
|
||||||
'description')
|
|
||||||
getfield = lambda(x): items[fields.index(x)].strip()
|
|
||||||
|
|
||||||
output = " ("
|
|
||||||
output += "%s, " % getfield('name')
|
|
||||||
value = getfield('value')
|
|
||||||
if value == '"off"':
|
|
||||||
type = "coreapi.CONF_DATA_TYPE_BOOL"
|
|
||||||
value = "0"
|
|
||||||
defaults = '"On,Off"'
|
|
||||||
elif value == '"on"':
|
|
||||||
type = "coreapi.CONF_DATA_TYPE_BOOL"
|
|
||||||
value = '"1"'
|
|
||||||
defaults = '"On,Off"'
|
|
||||||
else:
|
|
||||||
type = "coreapi.CONF_DATA_TYPE_STRING"
|
|
||||||
defaults = '""'
|
|
||||||
output += "%s, %s, %s, " % (type, value, defaults)
|
|
||||||
output += getfield('description')
|
|
||||||
output += "),\n"
|
|
||||||
return output
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
usagestr = "usage: %prog [-h] [options] -- <command> ..."
|
|
||||||
parser = optparse.OptionParser(usage = usagestr)
|
|
||||||
parser.set_defaults(infile = None, outfile = sys.stdout)
|
|
||||||
|
|
||||||
parser.add_option("-i", "--infile", dest = "infile",
|
|
||||||
help = "file to read (usually '*mac.cc')")
|
|
||||||
parser.add_option("-o", "--outfile", dest = "outfile",
|
|
||||||
help = "file to write (stdout is default)")
|
|
||||||
|
|
||||||
def usage(msg = None, err = 0):
|
|
||||||
sys.stdout.write("\n")
|
|
||||||
if msg:
|
|
||||||
sys.stdout.write(msg + "\n\n")
|
|
||||||
parser.print_help()
|
|
||||||
sys.exit(err)
|
|
||||||
|
|
||||||
# parse command line options
|
|
||||||
(options, args) = parser.parse_args()
|
|
||||||
|
|
||||||
if options.infile is None:
|
|
||||||
usage("please specify input file with the '-i' option", err=1)
|
|
||||||
|
|
||||||
emane_model_source_to_core(options.infile, options.outfile)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
|
@ -1,78 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
#
|
|
||||||
# Search for installed CORE library files and Python bindings.
|
|
||||||
#
|
|
||||||
|
|
||||||
import os, glob
|
|
||||||
|
|
||||||
pythondirs = [
|
|
||||||
"/usr/lib/python2.7/site-packages",
|
|
||||||
"/usr/lib/python2.7/dist-packages",
|
|
||||||
"/usr/lib64/python2.7/site-packages",
|
|
||||||
"/usr/lib64/python2.7/dist-packages",
|
|
||||||
"/usr/local/lib/python2.7/site-packages",
|
|
||||||
"/usr/local/lib/python2.7/dist-packages",
|
|
||||||
"/usr/local/lib64/python2.7/site-packages",
|
|
||||||
"/usr/local/lib64/python2.7/dist-packages",
|
|
||||||
"/usr/lib/python2.6/site-packages",
|
|
||||||
"/usr/lib/python2.6/dist-packages",
|
|
||||||
"/usr/lib64/python2.6/site-packages",
|
|
||||||
"/usr/lib64/python2.6/dist-packages",
|
|
||||||
"/usr/local/lib/python2.6/site-packages",
|
|
||||||
"/usr/local/lib/python2.6/dist-packages",
|
|
||||||
"/usr/local/lib64/python2.6/site-packages",
|
|
||||||
"/usr/local/lib64/python2.6/dist-packages",
|
|
||||||
]
|
|
||||||
|
|
||||||
tcldirs = [
|
|
||||||
"/usr/lib/core",
|
|
||||||
"/usr/local/lib/core",
|
|
||||||
]
|
|
||||||
|
|
||||||
def find_in_file(fn, search, column=None):
|
|
||||||
''' Find a line starting with 'search' in the file given by the filename
|
|
||||||
'fn'. Return True if found, False if not found, or the column text if
|
|
||||||
column is specified.
|
|
||||||
'''
|
|
||||||
r = False
|
|
||||||
if not os.path.exists(fn):
|
|
||||||
return r
|
|
||||||
f = open(fn, "r")
|
|
||||||
for line in f:
|
|
||||||
if line[:len(search)] != search:
|
|
||||||
continue
|
|
||||||
r = True
|
|
||||||
if column is not None:
|
|
||||||
r = line.split()[column]
|
|
||||||
break
|
|
||||||
f.close()
|
|
||||||
return r
|
|
||||||
|
|
||||||
def main():
|
|
||||||
versions = []
|
|
||||||
for d in pythondirs:
|
|
||||||
fn = "%s/core/constants.py" % d
|
|
||||||
ver = find_in_file(fn, 'COREDPY_VERSION', 2)
|
|
||||||
if ver:
|
|
||||||
ver = ver.strip('"')
|
|
||||||
versions.append((d, ver))
|
|
||||||
for e in glob.iglob("%s/core_python*egg-info" % d):
|
|
||||||
ver = find_in_file(e, 'Version:', 1)
|
|
||||||
if ver:
|
|
||||||
versions.append((e, ver))
|
|
||||||
for e in glob.iglob("%s/netns*egg-info" % d):
|
|
||||||
ver = find_in_file(e, 'Version:', 1)
|
|
||||||
if ver:
|
|
||||||
versions.append((e, ver))
|
|
||||||
for d in tcldirs:
|
|
||||||
fn = "%s/version.tcl" % d
|
|
||||||
ver = find_in_file(fn, 'set CORE_VERSION', 2)
|
|
||||||
if ver:
|
|
||||||
versions.append((d, ver))
|
|
||||||
|
|
||||||
for (d, ver) in versions:
|
|
||||||
print "%8s %s" % (ver, d)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue