allowed = None, flags = NoFlags, validation_function = None):
if not type in Attribute.types:
raise AttributeError("invalid type %s " % type)
- self.name = name
+ self._name = name
self._type = type
self._help = help
self._value = value
self._validation_function = validation_function
self._modified = False
+ @property
+ def name(self):
+ return self._name
+
@property
def type(self):
return self._type
from nepi.core.attributes import AttributesMap, Attribute
from nepi.core.metadata import Metadata
from nepi.util import validation
-from nepi.util.constants import AF_INET, AF_INET6
from nepi.util.guid import GuidGenerator
from nepi.util.graphical_info import GraphicalInfo
from nepi.util.parser._xml import XmlExperimentParser
return self._help
class Address(AttributesMap):
- def __init__(self, family):
+ def __init__(self):
super(Address, self).__init__()
self.add_attribute(name = "AutoConfigure",
help = "If set, this address will automatically be assigned",
value = False,
flags = Attribute.DesignOnly,
validation_function = validation.is_bool)
- self.add_attribute(name = "Family",
- help = "Address family type: AF_INET, AFT_INET6",
- type = Attribute.INTEGER,
- value = family,
- flags = Attribute.ReadOnly | Attribute.HasNoDefaultValue,
- validation_function = validation.is_integer)
- address_validation = validation.is_ip4_address if family == AF_INET \
- else validation.is_ip6_address
self.add_attribute(name = "Address",
help = "Address number",
type = Attribute.STRING,
flags = Attribute.HasNoDefaultValue,
- validation_function = address_validation)
- prefix_range = (0, 32) if family == AF_INET else (0, 128)
+ validation_function = validation.is_ip_address)
self.add_attribute(name = "NetPrefix",
help = "Network prefix for the address",
type = Attribute.INTEGER,
- range = prefix_range,
- value = 24 if family == AF_INET else 64,
+ range = (0, 128),
+ value = 24,
flags = Attribute.HasNoDefaultValue,
validation_function = validation.is_integer)
- if family == AF_INET:
- self.add_attribute(name = "Broadcast",
- help = "Broadcast address",
- type = Attribute.STRING,
- validation_function = validation.is_ip4_address)
+ self.add_attribute(name = "Broadcast",
+ help = "Broadcast address",
+ type = Attribute.STRING,
+ validation_function = validation.is_ip4_address)
class Route(AttributesMap):
- def __init__(self, family):
+ def __init__(self):
super(Route, self).__init__()
- self.add_attribute(name = "Family",
- help = "Address family type: AF_INET, AFT_INET6",
- type = Attribute.INTEGER,
- value = family,
- flags = Attribute.ReadOnly | Attribute.HasNoDefaultValue,
- validation_function = validation.is_integer)
- address_validation = validation.is_ip4_address if family == AF_INET \
- else validation.is_ip6_address
self.add_attribute(name = "Destination",
help = "Network destintation",
type = Attribute.STRING,
- validation_function = address_validation)
- prefix_range = (0, 32) if family == AF_INET else (0, 128)
+ validation_function = validation.is_ip_address)
self.add_attribute(name = "NetPrefix",
help = "Network destination prefix",
type = Attribute.INTEGER,
+ prefix_range = (0,128),
+ value = 24,
flags = Attribute.HasNoDefaultValue,
- prefix_range = prefix_range,
validation_function = validation.is_integer)
self.add_attribute(name = "NextHop",
help = "Address for the next hop",
type = Attribute.STRING,
flags = Attribute.HasNoDefaultValue,
- validation_function = address_validation)
+ validation_function = validation.is_ip_address)
class Box(AttributesMap):
def __init__(self, guid, factory, testbed_guid, container = None):
def __init__(self, guid, factory, testbed_guid, container = None):
super(AddressableBox, self).__init__(guid, factory, testbed_guid,
container)
- self._family = factory.get_attribute_value("Family")
- # maximum number of addresses this box can have
- self._max_addresses = factory.get_attribute_value("MaxAddresses")
+ self._max_addresses = 1 # TODO: How to make this configurable!
self._addresses = list()
@property
def add_address(self):
if len(self._addresses) == self.max_addresses:
raise RuntimeError("Maximun number of addresses for this box reached.")
- address = Address(family = self._family)
+ address = Address()
self._addresses.append(address)
return address
def routes(self):
return self._routes
- def add_route(self, family):
- route = Route(family = family)
+ def add_route(self):
+ route = Route()
self._routes.append(route)
return route
def add_trace(self, guid, trace_id):
raise NotImplementedError
- def add_address(self, guid, family, address, netprefix, broadcast):
+ def add_address(self, guid, address, netprefix, broadcast):
raise NotImplementedError
def add_route(self, guid, destination, netprefix, nexthop):
other_testbed_id, other_factory_id, other_connector_type_name)
for trace_id in data.get_trace_data(guid):
testbed.add_trace(guid, trace_id)
- for (autoconf, address, family, netprefix, broadcast) in \
+ for (autoconf, address, netprefix, broadcast) in \
data.get_address_data(guid):
if address != None:
- testbed.add_address(guid, family, address, netprefix,
- broadcast)
- for (family, destination, netprefix, nexthop) in \
- data.get_route_data(guid):
+ testbed.add_address(guid, address, netprefix, broadcast)
+ for (destination, netprefix, nexthop) in data.get_route_data(guid):
testbed.add_route(guid, destination, netprefix, nexthop)
value = attribute_info["value"]
range = attribute_info["range"]
allowed = attribute_info["allowed"]
- flags = attribute_info["flags"] if "flags" in attribute_info \
- else Attribute.NoFlags
+ flags = attribute_info["flags"] if "flags" in attribute_info \
+ and attribute_info["flags"] != None \
+ else Attribute.NoFlags
validation_function = attribute_info["validation_function"]
if box_attributes:
factory.add_box_attribute(name, help, type, value, range,
self._add_trace[guid] = list()
self._add_trace[guid].append(trace_id)
- def add_address(self, guid, family, address, netprefix, broadcast):
+ def add_address(self, guid, address, netprefix, broadcast):
if not guid in self._create:
raise RuntimeError("Element guid %d doesn't exist" % guid)
factory_id = self._create[guid]
if not factory.allow_addresses:
raise RuntimeError("Element type '%s' doesn't support addresses" %
factory_id)
- max_addresses = factory.get_attribute_value("MaxAddresses")
+ max_addresses = 1 # TODO: MAKE THIS PARAMETRIZABLE
if guid in self._add_address:
count_addresses = len(self._add_address[guid])
if max_addresses == count_addresses:
raise RuntimeError("Element guid %d of type '%s' can't accept \
- more addresses" % (guid, family_id))
+ more addresses" % (guid, factory_id))
else:
self._add_address[guid] = list()
- self._add_address[guid].append((family, address, netprefix, broadcast))
+ self._add_address[guid].append((address, netprefix, broadcast))
def add_route(self, guid, destination, netprefix, nexthop):
if not guid in self._create:
from constants import TESTBED_ID
from nepi.core import testbed_impl
-from nepi.util.constants import AF_INET, AF_INET6
import os
class TestbedInstance(testbed_impl.TestbedInstance):
for guid, addresses in self._add_address.iteritems():
element = self._elements[guid]
for address in addresses:
- (family, address, netprefix, broadcast) = address
- if family == AF_INET:
- element.add_v4_address(address, netprefix)
+ (address, netprefix, broadcast) = address
+ # TODO: Decide if we should add a ipv4 or ipv6 address
+ element.add_v4_address(address, netprefix)
# configure routes
for guid, routes in self._add_route.iteritems():
element = self._elements[guid]
from nepi.core import metadata
from nepi.core.attributes import Attribute
from nepi.util import validation
-from nepi.util.constants import AF_INET, STATUS_NOT_STARTED, STATUS_RUNNING, \
+from nepi.util.constants import STATUS_NOT_STARTED, STATUS_RUNNING, \
STATUS_FINISHED
NODE = "Node"
"flags": Attribute.DesignOnly,
"validation_function": validation.is_string
}),
- "max_addresses": dict({
- "name": "MaxAddresses",
- "help": "Maximum number of addresses allowed by the device",
- "type": Attribute.INTEGER,
- "value": None,
- "range": None,
- "allowed": None,
- "flags": Attribute.Invisible,
- "validation_function": validation.is_integer
- }),
- "family": dict({
- "name": "Family",
- "help": "IP address family",
- "type": Attribute.INTEGER,
- "value": AF_INET,
- "range": None,
- "allowed": None,
- "flags": Attribute.Invisible,
- "validation_function": validation.is_integer
- }),
})
traces = dict({
"start_function": None,
"stop_function": None,
"status_function": None,
- "factory_attributes": ["family", "max_addresses"],
+ "factory_attributes": [],
"box_attributes": ["lladdr", "up", "device_name", "mtu",
"multicast", "broadcast", "arp"],
"connector_types": ["node", "p2p"]
"start_function": None,
"stop_function": None,
"status_function": None,
- "factory_attributes": ["family", "max_addresses"],
+ "factory_attributes": [],
"box_attributes": ["lladdr", "up", "device_name", "mtu",
"multicast", "broadcast", "arp"],
"connector_types": ["node", "fd"]
"start_function": None,
"stop_function": None,
"status_function": None,
- "factory_attributes": ["family", "max_addresses"],
+ "factory_attributes": [],
"box_attributes": ["lladdr", "up", "device_name", "mtu",
"multicast", "broadcast", "arp"],
"connector_types": ["node", "switch"]
"type": Attribute.STRING,
"help": "When this timeout expires, the RTS/CTS handshake has failed."
}),
- "max_addresses": dict({
- "name": "MaxAddresses",
- "help": "Maximum number of addresses allowed by the device",
- "type": Attribute.INTEGER,
- "value": None,
- "range": None,
- "allowed": None,
- "flags": Attribute.Invisible,
- "validation_function": validation.is_integer
- }),
- "family": dict({
- "name": "Family",
- "help": "IP address family",
- "type": Attribute.INTEGER,
- "value": AF_INET,
- "range": None,
- "allowed": None,
- "flags": Attribute.Invisible,
- "validation_function": validation.is_integer
- }),
})
from constants import TESTBED_ID
from nepi.core import testbed_impl
from nepi.core.attributes import Attribute
-from nepi.util.constants import AF_INET, AF_INET6
import os
class TestbedInstance(testbed_impl.TestbedInstance):
for guid, addresses in self._add_address.iteritems():
element = self._elements[guid]
for address in addresses:
- (family, address, netprefix, broadcast) = address
- if family == AF_INET:
- pass
- # TODO!!!
+ (address, netprefix, broadcast) = address
+ # TODO!!!
# configure routes
for guid, routes in self._add_route.iteritems():
element = self._elements[guid]
def addresses_data_to_xml(self, doc, parent_tag, guid, data):
addresses_tag = doc.createElement("addresses")
- for (autoconfigure, address, family, netprefix, broadcast) \
+ for (autoconfigure, address, netprefix, broadcast) \
in data.get_address_data(guid):
address_tag = doc.createElement("address")
addresses_tag.appendChild(address_tag)
address_tag.setAttribute("AutoConfigure", str(autoconf))
if address:
address_tag.setAttribute("Address", str(address))
- address_tag.setAttribute("Family", str(family))
address_tag.setAttribute("NetPrefix", str(netprefix))
if broadcast:
address_tag.setAttribute("Broadcast", str(broadcast))
def routes_data_to_xml(self, doc, parent_tag, guid, data):
routes_tag = doc.createElement("routes")
- for (family, destination, netprefix, nexthop) \
+ for (destination, netprefix, nexthop) \
in data.get_route_data(guid):
route_tag = doc.createElement("route")
routes_tag.appendChild(route_tag)
- route_tag.setAttribute("Family", str(family))
route_tag.setAttribute("Destination", str(destination))
route_tag.setAttribute("NetPrefix", str(netprefix))
route_tag.setAttribute("NextHop", str(nexthop))
if address_tag.hasAttribute("AutoConfigure") else None
address = str(address_tag.getAttribute("Address")) \
if address_tag.hasAttribute("Address") else None
- family = int(address_tag.getAttribute("Family")) \
- if address_tag.hasAttribute("Family") else None
netprefix = int(address_tag.getAttribute("NetPrefix")) \
if address_tag.hasAttribute("NetPrefix") else None
broadcast = str(address_tag.getAttribute("Broadcast")) \
if address_tag.hasAttribute("Broadcast") else None
- data.add_address_data(guid, autoconf, address, family,
- netprefix, broadcast)
+ data.add_address_data(guid, autoconf, address, netprefix,
+ broadcast)
def routes_data_from_xml(self, tag, guid, data):
routes_tag_list = tag.getElementsByTagName("routes")
route_tag_list = routes_tag_list[0].getElementsByTagName("route")
for route_tag in route_tag_list:
if route_tag.nodeType == tag.ELEMENT_NODE:
- family = int(route_tag.getAttribute("Family"))
destination = str(route_tag.getAttribute("Destination"))
netprefix = int(route_tag.getAttribute("NetPrefix"))
nexthop = str(route_tag.getAttribute("NextHop"))
- data.add_route_data(guid, family, destination, netprefix,
+ data.add_route_data(guid, destination, netprefix,
nexthop)
def connections_data_from_xml(self, tag, guid, data):
connection_data = connections_data[connector_type_name]
connection_data[other_guid] = other_connector_type_name
- def add_address_data(self, guid, autoconf, address, family, netprefix,
+ def add_address_data(self, guid, autoconf, address, netprefix,
broadcast):
data = self.data[guid]
if not "addresses" in data:
address_data["AutoConfigure"] = autoconf
if address:
address_data["Address"] = address
- address_data["Family"] = family
address_data["NetPrefix"] = netprefix
if broadcast:
address_data["Broadcast"] = broadcast
addresses_data.append(address_data)
- def add_route_data(self, guid, family, destination, netprefix, nexthop):
+ def add_route_data(self, guid, destination, netprefix, nexthop):
data = self.data[guid]
if not "routes" in data:
data["routes"] = list()
routes_data = data["routes"]
route_data = dict({
- "Family": family,
"Destination": destination,
"NetPrefix": netprefix,
"NextHop": nexthop
addresses_data = data["addresses"]
return [(data["AutoConfigure"] if "AutoConfigure" in data else None,
data["Address"] if "Address" in data else None,
- data["Family"] if "Family" in data else None,
data["NetPrefix"] if "NetPrefix" in data else None,
data["Broadcast"] if "Broadcast" in data else None) \
for data in addresses_data]
if not "routes" in data:
return []
routes_data = data["routes"]
- return [(data["Family"],
- data["Destination"],
+ return [(data["Destination"],
data["NetPrefix"],
data["NextHop"]) \
for data in routes_data]
autoconf = addr.get_attribute_value("AutoConfigure")
address = addr.get_attribute_value("Address")
netprefix = addr.get_attribute_value("NetPrefix")
- family = addr.get_attribute_value("Family")
broadcast = addr.get_attribute_value("Broadcast") \
if addr.has_attribute("Broadcast") and \
addr.is_attribute_modified("Broadcast") else None
- data.add_address_data(guid, autoconf, address, family, netprefix,
+ data.add_address_data(guid, autoconf, address, netprefix,
broadcast)
def routes_to_data(self, data, guid, routes):
for route in routes:
- family = route.get_attribute_value("Family")
destination = route.get_attribute_value("Destination")
netprefix = route.get_attribute_value("NetPrefix")
nexthop = route.get_attribute_value("NextHop")
- data.add_route_data(guid, family, destination, netprefix, nexthop)
+ data.add_route_data(guid, destination, netprefix, nexthop)
def from_data(self, experiment_description, data):
box_guids = list()
box.enable_trace(name)
def addresses_from_data(self, box, data):
- for (autoconf, address, family, netprefix, broadcast) \
+ for (autoconf, address, netprefix, broadcast) \
in data.get_address_data(box.guid):
addr = box.add_address()
if autoconf:
addr.set_attribute_value("AutoConfigure", autoconf)
if address:
addr.set_attribute_value("Address", address)
- if family != None:
- addr.set_attribute_value("Family", family)
if netprefix != None:
addr.set_attribute_value("NetPrefix", netprefix)
if broadcast:
addr.set_attribute_value("Broadcast", broadcast)
def routes_from_data(self, box, data):
- for (family, destination, netprefix, nexthop) \
+ for (destination, netprefix, nexthop) \
in data.get_route_data(box.guid):
- addr = box.add_route(family)
+ addr = box.add_route()
addr.set_attribute_value("Destination", destination)
addr.set_attribute_value("NetPrefix", netprefix)
addr.set_attribute_value("NextHop", nexthop)
CONNECT: "%d|%s" % (CONNECT, "%d|%s|%d|%s"),
CROSS_CONNECT: "%d|%s" % (CROSS_CONNECT, "%d|%s|%d|%d|%s|%s"),
ADD_TRACE: "%d|%s" % (ADD_TRACE, "%d|%s"),
- ADD_ADDRESS: "%d|%s" % (ADD_ADDRESS, "%d|%d|%s|%d|%s"),
+ ADD_ADDRESS: "%d|%s" % (ADD_ADDRESS, "%d|%s|%d|%s"),
ADD_ROUTE: "%d|%s" % (ADD_ROUTE, "%d|%s|%d|%s"),
DO_SETUP: "%d" % DO_SETUP,
DO_CREATE: "%d" % DO_CREATE,
def add_address(self, params):
guid = int(params[1])
- family = int(params[2])
- address = params[3]
- netprefix = int(params[4])
- broadcast = params[5]
- self._testbed.add_address(guid, family, address, netprefix,
+ address = params[2]
+ netprefix = int(params[3])
+ broadcast = params[4]
+ self._testbed.add_address(guid, address, netprefix,
broadcast)
return "%d|%s" % (OK, "")
if code == ERROR:
raise RuntimeError(text)
- def add_address(self, guid, family, address, netprefix, broadcast):
+ def add_address(self, guid, address, netprefix, broadcast):
msg = testbed_messages[ADD_ADDRESS]
- msg = msg % (guid, family, address, netprefix, broadcast)
+ msg = msg % (guid, address, netprefix, broadcast)
self._client.send_msg(msg)
reply = self._client.read_reply()
result = reply.split("|")
def is_time(attribute, value):
return isinstance(value, str) # TODO: Missing validation!
-# TODO: Allow netrefs!
def is_ip4_address(attribute, value):
try:
ipaddr.IPv4Address(value)
return False
return True
-# TODO: Allow netrefs!
def is_ip6_address(attribute, value):
try:
ipaddr.IPv6Address(value)
return False
return True
+# TODO: Allow netrefs!
+def is_ip_address(attribute, value):
+ if not is_ip4_address(attribute, value) and \
+ not is_ip6_address(attribute, value):
+ return False
+ return True
+
def is_mac_address(attribute, value):
regex = r'^([0-9a-zA-Z]{0,2}:)*[0-9a-zA-Z]{0,2}'
found = re.search(regex, value)
# -*- coding: utf-8 -*-
from nepi.core.design import ExperimentDescription, FactoriesProvider
-from nepi.core.design import AF_INET
import os
import shutil
import test_util
# -*- coding: utf-8 -*-
import getpass
-from nepi.util.constants import AF_INET, STATUS_FINISHED
+from nepi.util.constants import STATUS_FINISHED
from nepi.testbeds import netns
import os
import shutil
instance.create(4, "NodeInterface")
instance.create_set(4, "up", True)
instance.connect(2, "devs", 4, "node")
- instance.add_address(4, AF_INET, "10.0.0.1", 24, None)
+ instance.add_address(4, "10.0.0.1", 24, None)
instance.create(5, "NodeInterface")
instance.create_set(5, "up", True)
instance.connect(3, "devs", 5, "node")
- instance.add_address(5, AF_INET, "10.0.0.2", 24, None)
+ instance.add_address(5, "10.0.0.2", 24, None)
instance.create(6, "Switch")
instance.create_set(6, "up", True)
instance.connect(4, "switch", 6, "devs")
instance.create(4, "P2PNodeInterface")
instance.create_set(4, "up", True)
instance.connect(2, "devs", 4, "node")
- instance.add_address(4, AF_INET, "10.0.0.1", 24, None)
+ instance.add_address(4, "10.0.0.1", 24, None)
instance.create(5, "P2PNodeInterface")
instance.create_set(5, "up", True)
instance.connect(3, "devs", 5, "node")
- instance.add_address(5, AF_INET, "10.0.0.2", 24, None)
+ instance.add_address(5, "10.0.0.2", 24, None)
instance.connect(4, "p2p", 5, "p2p")
instance.create(6, "Application")
instance.create_set(6, "command", "ping -qc1 10.0.0.2")
instance.create(5, "NodeInterface")
instance.create_set(5, "up", True)
instance.connect(2, "devs", 5, "node")
- instance.add_address(5, AF_INET, "10.0.0.1", 24, None)
+ instance.add_address(5, "10.0.0.1", 24, None)
instance.create(6, "NodeInterface")
instance.create_set(6, "up", True)
instance.connect(3, "devs", 6, "node")
- instance.add_address(6, AF_INET, "10.0.0.2", 24, None)
+ instance.add_address(6, "10.0.0.2", 24, None)
instance.create(7, "NodeInterface")
instance.create_set(7, "up", True)
instance.connect(3, "devs", 7, "node")
- instance.add_address(7, AF_INET, "10.0.1.1", 24, None)
+ instance.add_address(7, "10.0.1.1", 24, None)
instance.create(8, "NodeInterface")
instance.create_set(8, "up", True)
instance.connect(4, "devs", 8, "node")
- instance.add_address(8, AF_INET, "10.0.1.2", 24, None)
+ instance.add_address(8, "10.0.1.2", 24, None)
instance.create(9, "Switch")
instance.create_set(9, "up", True)
instance.connect(5, "switch", 9, "devs")
# -*- coding: utf-8 -*-
from nepi.core.design import ExperimentDescription, FactoriesProvider
-from nepi.core.design import AF_INET
import os
import shutil
import test_util
node2.connector("devs").connect(iface2.connector("node"))
iface2.connector("queue").connect(queue2.connector("dev"))
trace2 = iface2.enable_trace("P2PPcapTrace")
- ip2 = iface1.add_address()
+ ip2 = iface2.add_address()
ip2.set_attribute_value("Address", "10.0.0.2")
chan = tstbd_desc.create("ns3::PointToPointChannel")