cleaned up core.emane, core.services, core.xml, fixed bug introduced in coreobj.py
This commit is contained in:
parent
eb04e0a79f
commit
12cc40d3d3
11 changed files with 11 additions and 207 deletions
|
@ -213,7 +213,7 @@ class PyCoreObj(object):
|
|||
|
||||
services = self.services
|
||||
if services is not None:
|
||||
services = "|".join([x.name for x in services])
|
||||
services = "|".join([service.name for service in services])
|
||||
|
||||
node_data = NodeData(
|
||||
message_type=message_type,
|
||||
|
|
|
@ -25,7 +25,7 @@ def convert_none(x):
|
|||
"""
|
||||
Helper to use 0 for None values.
|
||||
"""
|
||||
if type(x) is str:
|
||||
if isinstance(x, basestring):
|
||||
x = float(x)
|
||||
if x is None:
|
||||
return 0
|
||||
|
|
|
@ -627,11 +627,11 @@ class EmaneManager(ModelManager):
|
|||
if realtime:
|
||||
emanecmd += "-r",
|
||||
|
||||
otagroup, otaport = self.get_config("otamanagergroup").split(":")
|
||||
otagroup, _otaport = self.get_config("otamanagergroup").split(":")
|
||||
otadev = self.get_config("otamanagerdevice")
|
||||
otanetidx = self.session.get_control_net_index(otadev)
|
||||
|
||||
eventgroup, eventport = self.get_config("eventservicegroup").split(":")
|
||||
eventgroup, _eventport = self.get_config("eventservicegroup").split(":")
|
||||
eventdev = self.get_config("eventservicedevice")
|
||||
eventservicenetidx = self.session.get_control_net_index(eventdev)
|
||||
|
||||
|
@ -781,7 +781,7 @@ class EmaneManager(ModelManager):
|
|||
return
|
||||
logger.info("subscribing to EMANE location events. (%s)", threading.currentThread().getName())
|
||||
while self.doeventloop is True:
|
||||
uuid, seq, events = self.service.nextEvent()
|
||||
_uuid, _seq, events = self.service.nextEvent()
|
||||
|
||||
# this occurs with 0.9.1 event service
|
||||
if not self.doeventloop:
|
||||
|
@ -820,7 +820,7 @@ class EmaneManager(ModelManager):
|
|||
Returns True if successfully parsed and a Node Message was sent.
|
||||
"""
|
||||
# convert nemid to node number
|
||||
emanenode, netif = self.nemlookup(nemid)
|
||||
_emanenode, netif = self.nemlookup(nemid)
|
||||
if netif is None:
|
||||
logger.info("location event for unknown NEM %s", nemid)
|
||||
return False
|
||||
|
|
|
@ -37,7 +37,7 @@ class EmaneNode(EmaneNet):
|
|||
"""
|
||||
|
||||
def __init__(self, session, objid=None, name=None, start=True):
|
||||
PyCoreNet.__init__(self, session, objid, name, start)
|
||||
super(EmaneNode, self).__init__(session, objid, name, start)
|
||||
self.conf = ""
|
||||
self.up = False
|
||||
self.nemidmap = {}
|
||||
|
|
|
@ -602,8 +602,7 @@ class MgenActor(NrlService):
|
|||
comments = ""
|
||||
cmd = "mgenBasicActor.py -n %s -a 0.0.0.0" % node.name
|
||||
|
||||
servicenames = map(lambda x: x.name, node.services)
|
||||
netifs = filter(lambda x: not getattr(x, 'control', False), node.netifs())
|
||||
netifs = [x for x in node.netifs() if not getattr(x, "control", False)]
|
||||
if len(netifs) == 0:
|
||||
return ""
|
||||
|
||||
|
|
|
@ -551,7 +551,6 @@ class Babel(QuaggaService):
|
|||
|
||||
@classmethod
|
||||
def generatequaggaifcconfig(cls, node, ifc):
|
||||
type = "wired"
|
||||
if ifc.net and ifc.net.linktype == LinkTypes.WIRELESS.value:
|
||||
return " babel wireless\n no babel split-horizon\n"
|
||||
else:
|
||||
|
|
|
@ -35,12 +35,6 @@ class OvsService(SdnService):
|
|||
if s.name == "zebra":
|
||||
has_zebra = 1
|
||||
|
||||
# Check whether the node is running an SDN controller
|
||||
has_sdn_ctrlr = 0
|
||||
for s in node.services:
|
||||
if s.name == "ryuService":
|
||||
has_sdn_ctrlr = 1
|
||||
|
||||
cfg = "#!/bin/sh\n"
|
||||
cfg += "# auto-generated by OvsService (OvsService.py)\n"
|
||||
cfg += "/etc/init.d/openvswitch-switch start < /dev/null\n"
|
||||
|
|
|
@ -107,11 +107,6 @@ ${UCARP_EXEC} -B ${UCARP_OPTS}
|
|||
"""
|
||||
Generate a shell script used to boot the Ucarp daemons.
|
||||
"""
|
||||
|
||||
try:
|
||||
ucarp_bin = node.session.cfg['ucarp_bin']
|
||||
except KeyError:
|
||||
ucarp_bin = "/usr/sbin/ucarp"
|
||||
return """\
|
||||
#!/bin/sh
|
||||
# Location of the UCARP config directory
|
||||
|
@ -129,11 +124,6 @@ ${UCARP_CFGDIR}/default.sh
|
|||
"""
|
||||
Generate a shell script used to start the virtual ip
|
||||
"""
|
||||
try:
|
||||
ucarp_bin = node.session.cfg['ucarp_bin']
|
||||
except KeyError:
|
||||
ucarp_bin = "/usr/sbin/ucarp"
|
||||
|
||||
return """\
|
||||
#!/bin/bash
|
||||
|
||||
|
@ -156,10 +146,6 @@ fi
|
|||
"""
|
||||
Generate a shell script used to stop the virtual ip
|
||||
"""
|
||||
try:
|
||||
ucarp_bin = node.session.cfg['ucarp_bin']
|
||||
except KeyError:
|
||||
ucarp_bin = "/usr/sbin/ucarp"
|
||||
return """\
|
||||
#!/bin/bash
|
||||
|
||||
|
|
|
@ -83,10 +83,8 @@ class DefaultRouteService(UtilService):
|
|||
def addrstr(x):
|
||||
if x.find(":") >= 0:
|
||||
net = Ipv6Prefix(x)
|
||||
fam = "inet6 ::"
|
||||
else:
|
||||
net = Ipv4Prefix(x)
|
||||
fam = "inet 0.0.0.0"
|
||||
if net.max_addr() == net.min_addr():
|
||||
return ""
|
||||
else:
|
||||
|
@ -145,11 +143,9 @@ class StaticRouteService(UtilService):
|
|||
def routestr(x):
|
||||
if x.find(":") >= 0:
|
||||
net = Ipv6Prefix(x)
|
||||
fam = "inet6"
|
||||
dst = "3ffe:4::/64"
|
||||
else:
|
||||
net = Ipv4Prefix(x)
|
||||
fam = "inet"
|
||||
dst = "10.9.8.0/24"
|
||||
if net.max_addr() == net.min_addr():
|
||||
return ""
|
||||
|
|
|
@ -98,79 +98,6 @@ def add_configuration(parent, name, value):
|
|||
add_attribute(config_element, "value", value)
|
||||
|
||||
|
||||
def get_endpoints(node):
|
||||
endpoints = []
|
||||
for interface in node.netifs(sort=True):
|
||||
endpoint = get_endpoint(node, interface)
|
||||
endpoints.append(endpoint)
|
||||
return endpoints
|
||||
|
||||
|
||||
def get_endpoint(node, interface):
|
||||
l2devport = None
|
||||
othernet = getattr(interface, "othernet", None)
|
||||
|
||||
# reference interface of node that is part of this network
|
||||
if interface.net.objid == node.objid and interface.node:
|
||||
params = interface.getparams()
|
||||
if nodeutils.is_node(interface.net, (NodeTypes.HUB, NodeTypes.SWITCH)):
|
||||
l2devport = "%s/e%s" % (interface.net.name, interface.netindex)
|
||||
endpoint_id = "%s/%s" % (interface.node.name, interface.name)
|
||||
endpoint = Endpoint(
|
||||
node,
|
||||
interface,
|
||||
"interface",
|
||||
endpoint_id,
|
||||
l2devport,
|
||||
params
|
||||
)
|
||||
# references another node connected to this network
|
||||
elif othernet and othernet.objid == node.objid:
|
||||
interface.swapparams("_params_up")
|
||||
params = interface.getparams()
|
||||
interface.swapparams("_params_up")
|
||||
l2devport = "%s/e%s" % (othernet.name, interface.netindex)
|
||||
endpoint_id = "%s/%s/%s" % (node.name, interface.node.name, interface.netindex)
|
||||
endpoint = Endpoint(
|
||||
interface.net,
|
||||
interface,
|
||||
"interface",
|
||||
endpoint_id,
|
||||
l2devport,
|
||||
params
|
||||
)
|
||||
else:
|
||||
endpoint = Endpoint(
|
||||
node,
|
||||
interface,
|
||||
)
|
||||
|
||||
return endpoint
|
||||
|
||||
|
||||
def get_downstream_l2_devices(node):
|
||||
all_endpoints = []
|
||||
l2_devices = [node]
|
||||
current_endpoint = get_endpoints(node)
|
||||
all_endpoints.extend(current_endpoint)
|
||||
for endpoint in current_endpoint:
|
||||
if endpoint.type and endpoint.network.objid != node.objid:
|
||||
new_l2_devices, new_endpoints = get_downstream_l2_devices(endpoint.network)
|
||||
l2_devices.extend(new_l2_devices)
|
||||
all_endpoints.extend(new_endpoints)
|
||||
return l2_devices, all_endpoints
|
||||
|
||||
|
||||
class Endpoint(object):
|
||||
def __init__(self, network, interface, _type=None, _id=None, l2devport=None, params=None):
|
||||
self.network = network
|
||||
self.interface = interface
|
||||
self.type = _type
|
||||
self.id = _id
|
||||
self.l2devport = l2devport
|
||||
self.params = params
|
||||
|
||||
|
||||
class NodeElement(object):
|
||||
def __init__(self, session, node, element_name):
|
||||
self.session = session
|
||||
|
@ -198,50 +125,6 @@ class NodeElement(object):
|
|||
add_attribute(position, "alt", alt)
|
||||
|
||||
|
||||
class InterfaceElement(object):
|
||||
def __init__(self, session, node, interface):
|
||||
self.session = session
|
||||
self.node = node
|
||||
self.interface = interface
|
||||
self.element = etree.Element("interface")
|
||||
add_attribute(self.element, "id", interface.netindex)
|
||||
add_attribute(self.element, "name", interface.name)
|
||||
mac = etree.SubElement(self.element, "mac")
|
||||
mac.text = str(interface.hwaddr)
|
||||
self.add_mtu()
|
||||
self.addresses = etree.SubElement(self.element, "addresses")
|
||||
self.add_addresses()
|
||||
self.add_model()
|
||||
|
||||
def add_mtu(self):
|
||||
# check to add mtu
|
||||
if self.interface.mtu and self.interface.mtu != 1500:
|
||||
add_attribute(self.element, "mtu", self.interface.mtu)
|
||||
|
||||
def add_model(self):
|
||||
# check for emane specific interface configuration
|
||||
net_model = None
|
||||
if self.interface.net and hasattr(self.interface.net, "model"):
|
||||
net_model = self.interface.net.model
|
||||
|
||||
if net_model and net_model.name.startswith("emane_"):
|
||||
config = self.session.emane.getifcconfig(self.node.objid, self.interface, net_model.name)
|
||||
if config:
|
||||
emane_element = create_emane_model_config(net_model, config)
|
||||
self.element.append(emane_element)
|
||||
|
||||
def add_addresses(self):
|
||||
for address in self.interface.addrlist:
|
||||
ip, mask = address.split("/")
|
||||
if ipaddress.is_ipv4_address(ip):
|
||||
address_type = "IPv4"
|
||||
else:
|
||||
address_type = "IPv6"
|
||||
address_element = etree.SubElement(self.addresses, "address")
|
||||
add_attribute(address_element, "type", address_type)
|
||||
address_element.text = str(address)
|
||||
|
||||
|
||||
class ServiceElement(object):
|
||||
def __init__(self, service):
|
||||
self.service = service
|
||||
|
@ -309,7 +192,6 @@ class DeviceElement(NodeElement):
|
|||
def __init__(self, session, node):
|
||||
super(DeviceElement, self).__init__(session, node, "device")
|
||||
add_attribute(self.element, "type", node.type)
|
||||
# self.add_interfaces()
|
||||
self.add_services()
|
||||
|
||||
def add_services(self):
|
||||
|
@ -320,15 +202,6 @@ class DeviceElement(NodeElement):
|
|||
if service_elements.getchildren():
|
||||
self.element.append(service_elements)
|
||||
|
||||
def add_interfaces(self):
|
||||
interfaces = etree.Element("interfaces")
|
||||
for interface in self.node.netifs(sort=True):
|
||||
interface_element = InterfaceElement(self.session, self.node, interface)
|
||||
interfaces.append(interface_element.element)
|
||||
|
||||
if interfaces.getchildren():
|
||||
self.element.append(interfaces)
|
||||
|
||||
|
||||
class NetworkElement(NodeElement):
|
||||
def __init__(self, session, node):
|
||||
|
@ -343,9 +216,6 @@ class NetworkElement(NodeElement):
|
|||
if grekey and grekey is not None:
|
||||
add_attribute(self.element, "grekey", grekey)
|
||||
self.add_type()
|
||||
# self.endpoints = get_endpoints(self.node)
|
||||
# self.l2_devices = self.get_l2_devices()
|
||||
# self.add_configs()
|
||||
|
||||
def add_type(self):
|
||||
if self.node.apitype:
|
||||
|
@ -354,35 +224,6 @@ class NetworkElement(NodeElement):
|
|||
node_type = self.node.__class__.__name__
|
||||
add_attribute(self.element, "type", node_type)
|
||||
|
||||
def get_l2_devices(self):
|
||||
l2_devices = []
|
||||
found_l2_devices = []
|
||||
found_endpoints = []
|
||||
if nodeutils.is_node(self.node, (NodeTypes.SWITCH, NodeTypes.HUB)):
|
||||
for endpoint in self.endpoints:
|
||||
if endpoint.type and endpoint.network.objid != self.node.objid:
|
||||
downstream_l2_devices, downstream_endpoints = get_downstream_l2_devices(endpoint.network)
|
||||
found_l2_devices.extend(downstream_l2_devices)
|
||||
found_endpoints.extend(downstream_endpoints)
|
||||
|
||||
for l2_device in found_l2_devices:
|
||||
pass
|
||||
|
||||
self.endpoints.extend(found_endpoints)
|
||||
return l2_devices
|
||||
|
||||
def add_peer_to_peer_config(self):
|
||||
pass
|
||||
|
||||
def add_switch_hub_tunnel_config(self):
|
||||
pass
|
||||
|
||||
def add_configs(self):
|
||||
if nodeutils.is_node(self.node, NodeTypes.PEER_TO_PEER):
|
||||
self.add_peer_to_peer_config()
|
||||
elif nodeutils.is_node(self.node, (NodeTypes.SWITCH, NodeTypes.HUB, NodeTypes.TUNNEL)):
|
||||
self.add_switch_hub_tunnel_config()
|
||||
|
||||
|
||||
class CoreXmlWriter(object):
|
||||
def __init__(self, session):
|
||||
|
|
|
@ -49,7 +49,7 @@ def add_emane_interface(host_element, netif, platform_name="p1", transport_name=
|
|||
|
||||
|
||||
def get_address_type(address):
|
||||
addr, slash, prefixlen = address.partition("/")
|
||||
addr, _slash, _prefixlen = address.partition("/")
|
||||
if ipaddress.is_ipv4_address(addr):
|
||||
address_type = "IPv4"
|
||||
elif ipaddress.is_ipv6_address(addr):
|
||||
|
@ -122,20 +122,13 @@ class CoreXmlDeployment(object):
|
|||
return host_element
|
||||
|
||||
def add_virtual_host(self, physical_host, node):
|
||||
assert isinstance(node, PyCoreNode)
|
||||
if not isinstance(node, PyCoreNode):
|
||||
raise TypeError("invalid node type: %s" % node)
|
||||
|
||||
# create virtual host element
|
||||
host_id = "%s/%s" % (physical_host.get("id"), node.name)
|
||||
host_element = etree.SubElement(physical_host, "testHost", id=host_id, name=node.name)
|
||||
|
||||
# TODO: need to inject mapping into device element?
|
||||
self.find_device(node.name)
|
||||
# device = self.find_device(self.root.base_element, obj.name)
|
||||
# if device is None:
|
||||
# logger.warn("corresponding XML device not found for %s", obj.name)
|
||||
# return
|
||||
# add_mapping(device, "testHost", host_id)
|
||||
|
||||
# add host type
|
||||
add_type(host_element, "virtual")
|
||||
|
||||
|
@ -151,7 +144,3 @@ class CoreXmlDeployment(object):
|
|||
for address in netif.addrlist:
|
||||
address_type = get_address_type(address)
|
||||
add_address(parent_element, address_type, address, netif.name)
|
||||
|
||||
# TODO: need to inject mapping in interface?
|
||||
# interface = self.find_interface(device, netif.name)
|
||||
# add_mapping(interface, "nem", nem.getAttribute("id"))
|
||||
|
|
Loading…
Reference in a new issue