cleanup of files in root core module
This commit is contained in:
parent
0fc40cd96b
commit
aa91bb67a1
7 changed files with 67 additions and 73 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -20,6 +20,9 @@ stamp-h1
|
||||||
# python build directory
|
# python build directory
|
||||||
dist
|
dist
|
||||||
|
|
||||||
|
# vscode
|
||||||
|
.vscode
|
||||||
|
|
||||||
# intellij
|
# intellij
|
||||||
*.iml
|
*.iml
|
||||||
.idea
|
.idea
|
||||||
|
|
|
@ -1005,17 +1005,17 @@ class CoreHandler(SocketServer.BaseRequestHandler):
|
||||||
if not config_data.data_values:
|
if not config_data.data_values:
|
||||||
logger.warn("location data missing")
|
logger.warn("location data missing")
|
||||||
else:
|
else:
|
||||||
values = config_data.data_values.split("|")
|
values = [float(x) for x in config_data.data_values.split("|")]
|
||||||
|
|
||||||
# Cartesian coordinate reference point
|
# Cartesian coordinate reference point
|
||||||
refx, refy = map(lambda x: float(x), values[0:2])
|
refx, refy = values[0], values[1]
|
||||||
refz = 0.0
|
refz = 0.0
|
||||||
lat, lon, alt = map(lambda x: float(x), values[2:5])
|
lat, lon, alt = values[2], values[3], values[4]
|
||||||
# xyz point
|
# xyz point
|
||||||
self.session.location.refxyz = (refx, refy, refz)
|
self.session.location.refxyz = (refx, refy, refz)
|
||||||
# geographic reference point
|
# geographic reference point
|
||||||
self.session.location.setrefgeo(lat, lon, alt)
|
self.session.location.setrefgeo(lat, lon, alt)
|
||||||
self.session.location.refscale = float(values[5])
|
self.session.location.refscale = values[5]
|
||||||
logger.info("location configured: %s = %s scale=%s", self.session.location.refxyz,
|
logger.info("location configured: %s = %s scale=%s", self.session.location.refxyz,
|
||||||
self.session.location.refgeo, self.session.location.refscale)
|
self.session.location.refgeo, self.session.location.refscale)
|
||||||
logger.info("location configured: UTM%s", self.session.location.refutm)
|
logger.info("location configured: UTM%s", self.session.location.refutm)
|
||||||
|
|
|
@ -85,6 +85,9 @@ class PyCoreObj(object):
|
||||||
if name is None:
|
if name is None:
|
||||||
name = "o%s" % self.objid
|
name = "o%s" % self.objid
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.type = None
|
||||||
|
self.server = None
|
||||||
|
self.services = None
|
||||||
# ifindex is key, PyCoreNetIf instance is value
|
# ifindex is key, PyCoreNetIf instance is value
|
||||||
self._netif = {}
|
self._netif = {}
|
||||||
self.ifindex = 0
|
self.ifindex = 0
|
||||||
|
@ -205,21 +208,12 @@ class PyCoreObj(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
x, y, _ = self.getposition()
|
x, y, _ = self.getposition()
|
||||||
|
|
||||||
model = None
|
|
||||||
if hasattr(self, "type"):
|
|
||||||
model = self.type
|
model = self.type
|
||||||
|
|
||||||
emulation_server = None
|
|
||||||
if hasattr(self, "server"):
|
|
||||||
emulation_server = self.server
|
emulation_server = self.server
|
||||||
|
|
||||||
services = None
|
services = self.services
|
||||||
if hasattr(self, "services") and len(self.services) != 0:
|
if services is not None:
|
||||||
nodeservices = []
|
services = "|".join([x.name for x in services])
|
||||||
for s in self.services:
|
|
||||||
nodeservices.append(s.name)
|
|
||||||
services = "|".join(nodeservices)
|
|
||||||
|
|
||||||
node_data = NodeData(
|
node_data = NodeData(
|
||||||
message_type=message_type,
|
message_type=message_type,
|
||||||
|
@ -269,10 +263,8 @@ class PyCoreNode(PyCoreObj):
|
||||||
:param str name: object name
|
:param str name: object name
|
||||||
:param bool start: boolean for starting
|
:param bool start: boolean for starting
|
||||||
"""
|
"""
|
||||||
PyCoreObj.__init__(self, session, objid, name, start=start)
|
super(PyCoreNode, self).__init__(session, objid, name, start=start)
|
||||||
self.services = []
|
self.services = []
|
||||||
if not hasattr(self, "type"):
|
|
||||||
self.type = None
|
|
||||||
self.nodedir = None
|
self.nodedir = None
|
||||||
self.tmpnodedir = False
|
self.tmpnodedir = False
|
||||||
|
|
||||||
|
@ -460,6 +452,19 @@ class PyCoreNet(PyCoreObj):
|
||||||
"""
|
"""
|
||||||
linktype = LinkTypes.WIRED.value
|
linktype = LinkTypes.WIRED.value
|
||||||
|
|
||||||
|
def __init__(self, session, objid, name, start=True):
|
||||||
|
"""
|
||||||
|
Create a PyCoreNet instance.
|
||||||
|
|
||||||
|
:param core.session.Session session: CORE session object
|
||||||
|
:param int objid: object id
|
||||||
|
:param str name: object name
|
||||||
|
:param bool start: should object start
|
||||||
|
"""
|
||||||
|
super(PyCoreNet, self).__init__(session, objid, name, start=start)
|
||||||
|
self._linked = {}
|
||||||
|
self._linked_lock = threading.Lock()
|
||||||
|
|
||||||
def startup(self):
|
def startup(self):
|
||||||
"""
|
"""
|
||||||
Each object implements its own startup method.
|
Each object implements its own startup method.
|
||||||
|
@ -476,19 +481,6 @@ class PyCoreNet(PyCoreObj):
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def __init__(self, session, objid, name, start=True):
|
|
||||||
"""
|
|
||||||
Create a PyCoreNet instance.
|
|
||||||
|
|
||||||
:param core.session.Session session: CORE session object
|
|
||||||
:param int objid: object id
|
|
||||||
:param str name: object name
|
|
||||||
:param bool start: should object start
|
|
||||||
"""
|
|
||||||
PyCoreObj.__init__(self, session, objid, name, start=start)
|
|
||||||
self._linked = {}
|
|
||||||
self._linked_lock = threading.Lock()
|
|
||||||
|
|
||||||
def attach(self, netif):
|
def attach(self, netif):
|
||||||
"""
|
"""
|
||||||
Attach network interface.
|
Attach network interface.
|
||||||
|
@ -550,7 +542,7 @@ class PyCoreNet(PyCoreObj):
|
||||||
interface2_ip6 = None
|
interface2_ip6 = None
|
||||||
interface2_ip6_mask = None
|
interface2_ip6_mask = None
|
||||||
for address in netif.addrlist:
|
for address in netif.addrlist:
|
||||||
ip, sep, mask = address.partition('/')
|
ip, _sep, mask = address.partition("/")
|
||||||
mask = int(mask)
|
mask = int(mask)
|
||||||
if ipaddress.is_ipv4_address(ip):
|
if ipaddress.is_ipv4_address(ip):
|
||||||
family = AF_INET
|
family = AF_INET
|
||||||
|
@ -627,7 +619,8 @@ class PyCoreNetIf(object):
|
||||||
self._params = {}
|
self._params = {}
|
||||||
self.addrlist = []
|
self.addrlist = []
|
||||||
self.hwaddr = None
|
self.hwaddr = None
|
||||||
self.poshook = None
|
# placeholder position hook
|
||||||
|
self.poshook = lambda a, b, c, d: None
|
||||||
# used with EMANE
|
# used with EMANE
|
||||||
self.transport_type = None
|
self.transport_type = None
|
||||||
# interface index on the network
|
# interface index on the network
|
||||||
|
@ -760,5 +753,4 @@ class PyCoreNetIf(object):
|
||||||
:param z: z position
|
:param z: z position
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
if self.poshook is not None:
|
|
||||||
self.poshook(self, x, y, z)
|
self.poshook(self, x, y, z)
|
||||||
|
|
|
@ -139,7 +139,7 @@ class CoreLocation(object):
|
||||||
"""
|
"""
|
||||||
# convert lat/lon to UTM coordinates in meters
|
# convert lat/lon to UTM coordinates in meters
|
||||||
e, n, zonen, zonel = utm.from_latlon(lat, lon)
|
e, n, zonen, zonel = utm.from_latlon(lat, lon)
|
||||||
rlat, rlon, ralt = self.refgeo
|
_rlat, _rlon, ralt = self.refgeo
|
||||||
xshift = self.geteastingshift(zonen, zonel)
|
xshift = self.geteastingshift(zonen, zonel)
|
||||||
if xshift is None:
|
if xshift is None:
|
||||||
xm = e - self.refutm[1]
|
xm = e - self.refutm[1]
|
||||||
|
@ -180,11 +180,11 @@ class CoreLocation(object):
|
||||||
if z in self.zoneshifts and self.zoneshifts[z][0] is not None:
|
if z in self.zoneshifts and self.zoneshifts[z][0] is not None:
|
||||||
return self.zoneshifts[z][0]
|
return self.zoneshifts[z][0]
|
||||||
|
|
||||||
rlat, rlon, ralt = self.refgeo
|
rlat, rlon, _ralt = self.refgeo
|
||||||
# ea. zone is 6deg band
|
# ea. zone is 6deg band
|
||||||
lon2 = rlon + 6 * (zonen - rzonen)
|
lon2 = rlon + 6 * (zonen - rzonen)
|
||||||
# ignore northing
|
# ignore northing
|
||||||
e2, n2, zonen2, zonel2 = utm.from_latlon(rlat, lon2)
|
e2, _n2, _zonen2, _zonel2 = utm.from_latlon(rlat, lon2)
|
||||||
# NOTE: great circle distance used here, not reference ellipsoid!
|
# NOTE: great circle distance used here, not reference ellipsoid!
|
||||||
xshift = utm.haversine(rlon, rlat, lon2, rlat) - e2
|
xshift = utm.haversine(rlon, rlat, lon2, rlat) - e2
|
||||||
# cache the return value
|
# cache the return value
|
||||||
|
@ -216,12 +216,12 @@ class CoreLocation(object):
|
||||||
if z in self.zoneshifts and self.zoneshifts[z][1] is not None:
|
if z in self.zoneshifts and self.zoneshifts[z][1] is not None:
|
||||||
return self.zoneshifts[z][1]
|
return self.zoneshifts[z][1]
|
||||||
|
|
||||||
rlat, rlon, ralt = self.refgeo
|
rlat, rlon, _ralt = self.refgeo
|
||||||
# zonemap is used to calculate degrees difference between zone letters
|
# zonemap is used to calculate degrees difference between zone letters
|
||||||
latshift = self.zonemap[zonel] - self.zonemap[rzonel]
|
latshift = self.zonemap[zonel] - self.zonemap[rzonel]
|
||||||
# ea. latitude band is 8deg high
|
# ea. latitude band is 8deg high
|
||||||
lat2 = rlat + latshift
|
lat2 = rlat + latshift
|
||||||
e2, n2, zonen2, zonel2 = utm.from_latlon(lat2, rlon)
|
_e2, n2, _zonen2, _zonel2 = utm.from_latlon(lat2, rlon)
|
||||||
# NOTE: great circle distance used here, not reference ellipsoid
|
# NOTE: great circle distance used here, not reference ellipsoid
|
||||||
yshift = -(utm.haversine(rlon, rlat, rlon, lat2) + n2)
|
yshift = -(utm.haversine(rlon, rlat, rlon, lat2) + n2)
|
||||||
# cache the return value
|
# cache the return value
|
||||||
|
@ -244,12 +244,12 @@ class CoreLocation(object):
|
||||||
:rtype: tuple
|
:rtype: tuple
|
||||||
"""
|
"""
|
||||||
zone = self.refutm[0]
|
zone = self.refutm[0]
|
||||||
rlat, rlon, ralt = self.refgeo
|
rlat, rlon, _ralt = self.refgeo
|
||||||
if e > 834000 or e < 166000:
|
if e > 834000 or e < 166000:
|
||||||
num_zones = (int(e) - 166000) / (utm.R / 10)
|
num_zones = (int(e) - 166000) / (utm.R / 10)
|
||||||
# estimate number of zones to shift, E (positive) or W (negative)
|
# estimate number of zones to shift, E (positive) or W (negative)
|
||||||
rlon2 = self.refgeo[1] + (num_zones * 6)
|
rlon2 = self.refgeo[1] + (num_zones * 6)
|
||||||
e2, n2, zonen2, zonel2 = utm.from_latlon(rlat, rlon2)
|
_e2, _n2, zonen2, zonel2 = utm.from_latlon(rlat, rlon2)
|
||||||
xshift = utm.haversine(rlon, rlat, rlon2, rlat)
|
xshift = utm.haversine(rlon, rlat, rlon2, rlat)
|
||||||
# after >3 zones away from refpt, the above estimate won't work
|
# after >3 zones away from refpt, the above estimate won't work
|
||||||
# (the above estimate could be improved)
|
# (the above estimate could be improved)
|
||||||
|
@ -257,7 +257,7 @@ class CoreLocation(object):
|
||||||
# move one more zone away
|
# move one more zone away
|
||||||
num_zones = (abs(num_zones) + 1) * (abs(num_zones) / num_zones)
|
num_zones = (abs(num_zones) + 1) * (abs(num_zones) / num_zones)
|
||||||
rlon2 = self.refgeo[1] + (num_zones * 6)
|
rlon2 = self.refgeo[1] + (num_zones * 6)
|
||||||
e2, n2, zonen2, zonel2 = utm.from_latlon(rlat, rlon2)
|
_e2, _n2, zonen2, zonel2 = utm.from_latlon(rlat, rlon2)
|
||||||
xshift = utm.haversine(rlon, rlat, rlon2, rlat)
|
xshift = utm.haversine(rlon, rlat, rlon2, rlat)
|
||||||
e = e - xshift
|
e = e - xshift
|
||||||
zone = (zonen2, zonel2)
|
zone = (zonen2, zonel2)
|
||||||
|
|
|
@ -183,10 +183,10 @@ class Sdt(object):
|
||||||
if not self.cmd("path \"%s/icons/normal\"" % constants.CORE_DATA_DIR):
|
if not self.cmd("path \"%s/icons/normal\"" % constants.CORE_DATA_DIR):
|
||||||
return False
|
return False
|
||||||
# send node type to icon mappings
|
# send node type to icon mappings
|
||||||
for type, icon in self.DEFAULT_SPRITES:
|
for node_type, icon in self.DEFAULT_SPRITES:
|
||||||
if not self.cmd("sprite %s image %s" % (type, icon)):
|
if not self.cmd("sprite %s image %s" % (node_type, icon)):
|
||||||
return False
|
return False
|
||||||
(lat, long) = self.session.location.refgeo[:2]
|
lat, long = self.session.location.refgeo[:2]
|
||||||
return self.cmd("flyto %.6f,%.6f,%d" % (long, lat, self.DEFAULT_ALT))
|
return self.cmd("flyto %.6f,%.6f,%d" % (long, lat, self.DEFAULT_ALT))
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
|
@ -238,7 +238,7 @@ class Sdt(object):
|
||||||
self.connected = False
|
self.connected = False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def updatenode(self, nodenum, flags, x, y, z, name=None, type=None, icon=None):
|
def updatenode(self, nodenum, flags, x, y, z, name=None, node_type=None, icon=None):
|
||||||
"""
|
"""
|
||||||
Node is updated from a Node Message or mobility script.
|
Node is updated from a Node Message or mobility script.
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ class Sdt(object):
|
||||||
:param y: y position
|
:param y: y position
|
||||||
:param z: z position
|
:param z: z position
|
||||||
:param str name: node name
|
:param str name: node name
|
||||||
:param type: node type
|
:param node_type: node type
|
||||||
:param icon: node icon
|
:param icon: node icon
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
|
@ -263,11 +263,11 @@ class Sdt(object):
|
||||||
pos = "pos %.6f,%.6f,%.6f" % (lon, lat, alt)
|
pos = "pos %.6f,%.6f,%.6f" % (lon, lat, alt)
|
||||||
if flags & MessageFlags.ADD.value:
|
if flags & MessageFlags.ADD.value:
|
||||||
if icon is not None:
|
if icon is not None:
|
||||||
type = name
|
node_type = name
|
||||||
icon = icon.replace("$CORE_DATA_DIR", constants.CORE_DATA_DIR)
|
icon = icon.replace("$CORE_DATA_DIR", constants.CORE_DATA_DIR)
|
||||||
icon = icon.replace("$CORE_CONF_DIR", constants.CORE_CONF_DIR)
|
icon = icon.replace("$CORE_CONF_DIR", constants.CORE_CONF_DIR)
|
||||||
self.cmd("sprite %s image %s" % (type, icon))
|
self.cmd("sprite %s image %s" % (type, icon))
|
||||||
self.cmd("node %d type %s label on,\"%s\" %s" % (nodenum, type, name, pos))
|
self.cmd("node %d type %s label on,\"%s\" %s" % (nodenum, node_type, name, pos))
|
||||||
else:
|
else:
|
||||||
self.cmd("node %d %s" % (nodenum, pos))
|
self.cmd("node %d %s" % (nodenum, pos))
|
||||||
|
|
||||||
|
@ -403,12 +403,12 @@ class Sdt(object):
|
||||||
nodetype == NodeTypes.PHYSICAL.value:
|
nodetype == NodeTypes.PHYSICAL.value:
|
||||||
if model is None:
|
if model is None:
|
||||||
model = "router"
|
model = "router"
|
||||||
type = model
|
nodetype = model
|
||||||
elif nodetype is not None:
|
elif nodetype is not None:
|
||||||
type = nodeutils.get_node_class(NodeTypes(nodetype)).type
|
nodetype = nodeutils.get_node_class(NodeTypes(nodetype)).type
|
||||||
net = True
|
net = True
|
||||||
else:
|
else:
|
||||||
type = None
|
nodetype = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
node = self.session.get_object(nodenum)
|
node = self.session.get_object(nodenum)
|
||||||
|
@ -421,15 +421,15 @@ class Sdt(object):
|
||||||
remote = self.remotes[nodenum]
|
remote = self.remotes[nodenum]
|
||||||
if name is None:
|
if name is None:
|
||||||
name = remote.name
|
name = remote.name
|
||||||
if type is None:
|
if nodetype is None:
|
||||||
type = remote.type
|
nodetype = remote.type
|
||||||
if icon is None:
|
if icon is None:
|
||||||
icon = remote.icon
|
icon = remote.icon
|
||||||
else:
|
else:
|
||||||
remote = Bunch(objid=nodenum, type=type, icon=icon, name=name, net=net, links=set())
|
remote = Bunch(objid=nodenum, type=nodetype, icon=icon, name=name, net=net, links=set())
|
||||||
self.remotes[nodenum] = remote
|
self.remotes[nodenum] = remote
|
||||||
remote.pos = (x, y, z)
|
remote.pos = (x, y, z)
|
||||||
self.updatenode(nodenum, msg.flags, x, y, z, name, type, icon)
|
self.updatenode(nodenum, msg.flags, x, y, z, name, nodetype, icon)
|
||||||
|
|
||||||
def handlelinkmsg(self, msg):
|
def handlelinkmsg(self, msg):
|
||||||
"""
|
"""
|
||||||
|
@ -467,8 +467,8 @@ class Sdt(object):
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
if nodenum in self.remotes:
|
if nodenum in self.remotes:
|
||||||
type = self.remotes[nodenum].type
|
node_type = self.remotes[nodenum].type
|
||||||
if type in ("wlan", "emane"):
|
if node_type in ("wlan", "emane"):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -138,7 +138,7 @@ class ServiceShim(object):
|
||||||
if not service.custom:
|
if not service.custom:
|
||||||
valmap[1] = service.get_configs(node)
|
valmap[1] = service.get_configs(node)
|
||||||
valmap[3] = service.get_startup(node)
|
valmap[3] = service.get_startup(node)
|
||||||
vals = map(lambda a, b: "%s=%s" % (a, str(b)), cls.keys, valmap)
|
vals = ["%s=%s" % (x, y) for x, y in zip(cls.keys, valmap)]
|
||||||
return "|".join(vals)
|
return "|".join(vals)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -252,6 +252,7 @@ class Session(object):
|
||||||
hooks = self._hooks.get(state, [])
|
hooks = self._hooks.get(state, [])
|
||||||
|
|
||||||
# execute all state hooks
|
# execute all state hooks
|
||||||
|
if hooks:
|
||||||
for hook in hooks:
|
for hook in hooks:
|
||||||
self.run_hook(hook)
|
self.run_hook(hook)
|
||||||
else:
|
else:
|
||||||
|
@ -269,7 +270,7 @@ class Session(object):
|
||||||
"""
|
"""
|
||||||
logger.info("setting state hook: %s - %s from %s", hook_type, file_name, source_name)
|
logger.info("setting state hook: %s - %s from %s", hook_type, file_name, source_name)
|
||||||
|
|
||||||
hook_id, state = hook_type.split(':')[:2]
|
_hook_id, state = hook_type.split(':')[:2]
|
||||||
if not state.isdigit():
|
if not state.isdigit():
|
||||||
logger.error("error setting hook having state '%s'", state)
|
logger.error("error setting hook having state '%s'", state)
|
||||||
return
|
return
|
||||||
|
@ -352,7 +353,8 @@ class Session(object):
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
hooks = self._state_hooks.setdefault(state, [])
|
hooks = self._state_hooks.setdefault(state, [])
|
||||||
assert hook not in hooks
|
if hook in hooks:
|
||||||
|
raise ValueError("attempting to add duplicate state hook")
|
||||||
hooks.append(hook)
|
hooks.append(hook)
|
||||||
|
|
||||||
if self.state == state:
|
if self.state == state:
|
||||||
|
@ -629,13 +631,10 @@ class Session(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with self._objects_lock:
|
with self._objects_lock:
|
||||||
count = len(filter(lambda x: not nodeutils.is_node(x, (NodeTypes.PEER_TO_PEER, NodeTypes.CONTROL_NET)),
|
count = len([x for x in self.objects if not nodeutils.is_node(x, (NodeTypes.PEER_TO_PEER, NodeTypes.CONTROL_NET))])
|
||||||
self.objects))
|
|
||||||
|
|
||||||
# on Linux, GreTapBridges are auto-created, not part of GUI's node count
|
# on Linux, GreTapBridges are auto-created, not part of GUI's node count
|
||||||
count -= len(filter(
|
count -= len([x for x in self.objects if nodeutils.is_node(x, NodeTypes.TAP_BRIDGE) and not nodeutils.is_node(x, NodeTypes.TUNNEL)])
|
||||||
lambda (x): nodeutils.is_node(x, NodeTypes.TAP_BRIDGE) and not nodeutils.is_node(x, NodeTypes.TUNNEL),
|
|
||||||
self.objects))
|
|
||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue