def test_wlan_ping(self, session, ip_prefixes): """ Test basic wlan network. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create wlan wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.mobility.set_model(wlan_node, BasicRangeModel) # create nodes node_options = NodeOptions() node_options.set_position(0, 0) node_one = session.create_wireless_node(node_options=node_options) node_two = session.create_wireless_node(node_options=node_options) # link nodes for node in [node_one, node_two]: interface = ip_prefixes.create_interface(node) session.add_link(node.objid, wlan_node.objid, interface_one=interface) # link nodes in wlan session.wireless_link_all(wlan_node, [node_one, node_two]) # instantiate session session.instantiate() # ping n2 from n1 and assert success status = ping(node_one, node_two, ip_prefixes) assert not status
def main(args): # ip generator for example prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16") # create emulator instance for creating sessions and utility methods coreemu = CoreEmu({"distributed_address": args.address}) session = coreemu.create_session() # initialize distributed server_name = "core2" session.distributed.add_server(server_name, args.server) # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create local node, switch, and remote nodes options = NodeOptions(image="ubuntu:18.04") node_one = session.add_node(_type=NodeTypes.LXC, options=options) options.server = server_name node_two = session.add_node(_type=NodeTypes.LXC, options=options) # create node interfaces and link interface_one = prefixes.create_interface(node_one) interface_two = prefixes.create_interface(node_two) session.add_link(node_one.id, node_two.id, interface_one, interface_two) # instantiate session session.instantiate() # pause script for verification input("press enter for shutdown") # shutdown session coreemu.shutdown()
def test_wlan_ping(self, session: Session, ip_prefixes: IpPrefixes): """ Test basic wlan network. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create wlan wlan_node = session.add_node(WlanNode) session.mobility.set_model(wlan_node, BasicRangeModel) # create nodes options = NodeOptions(model="mdr") options.set_position(0, 0) node_one = session.add_node(CoreNode, options=options) node_two = session.add_node(CoreNode, options=options) # link nodes for node in [node_one, node_two]: interface = ip_prefixes.create_interface(node) session.add_link(node.id, wlan_node.id, interface_one=interface) # instantiate session session.instantiate() # ping n2 from n1 and assert success status = ping(node_one, node_two, ip_prefixes) assert not status
def example(nodes): # ip generator for example prefixes = IpPrefixes("192.168.10.0/24") node_list = [] # create emulator instance for creating sessions and utility methods coreemu = globals().get("coreemu", CoreEmu()) session = coreemu.create_session() # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create nodes node_options = NodeOptions() x = 0 for i in range(nodes): node_options.set_position(x, 100) x = x+70 session.add_node(node_options=node_options) node_list.append(node) # create switch network node wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.mobility.set_model(wlan, BasicRangeModel) for node in node_list: interface = prefixes.create_interface(node) session.add_link(node.id, wlan.id, interface_one=interface) # instantiate session session.instantiate()
def test_set_emane_model_config(self, grpc_server): # given client = CoreGrpcClient() session = grpc_server.coreemu.create_session() session.set_location(47.57917, -122.13232, 2.00000, 1.0) options = NodeOptions() options.emane = EmaneIeee80211abgModel.name emane_network = session.add_node(_type=NodeTypes.EMANE, options=options) session.emane.set_model(emane_network, EmaneIeee80211abgModel) config_key = "bandwidth" config_value = "900000" # then with client.context_connect(): response = client.set_emane_model_config( session.id, emane_network.id, EmaneIeee80211abgModel.name, {config_key: config_value}, ) # then assert response.result is True config = session.emane.get_model_config(emane_network.id, EmaneIeee80211abgModel.name) assert config[config_key] == config_value
def test_get_emane_model_configs(self, grpc_server): # given client = CoreGrpcClient() session = grpc_server.coreemu.create_session() session.set_location(47.57917, -122.13232, 2.00000, 1.0) options = NodeOptions() options.emane = EmaneIeee80211abgModel.name emane_network = session.add_node(_type=NodeTypes.EMANE, options=options) session.emane.set_model(emane_network, EmaneIeee80211abgModel) config_key = "platform_id_start" config_value = "2" session.emane.set_model_config(emane_network.id, EmaneIeee80211abgModel.name, {config_key: config_value}) # then with client.context_connect(): response = client.get_emane_model_configs(session.id) # then assert len(response.configs) == 1 model_config = response.configs[0] assert emane_network.id == model_config.node_id assert model_config.model == EmaneIeee80211abgModel.name assert len(model_config.config) > 0 assert model_config.interface == -1
def AddNode(self, request, context): logging.debug("add node: %s", request) session = self.get_session(request.session_id, context) node_proto = request.node node_id = node_proto.id node_type = node_proto.type if node_type is None: node_type = NodeTypes.DEFAULT.value node_type = NodeTypes(node_type) node_options = NodeOptions(name=node_proto.name, model=node_proto.model) node_options.icon = node_proto.icon node_options.opaque = node_proto.opaque node_options.services = node_proto.services position = node_proto.position node_options.set_position(position.x, position.y) node_options.set_location(position.lat, position.lon, position.alt) node = session.add_node(_type=node_type, _id=node_id, node_options=node_options) # configure emane if provided emane_model = node_proto.emane if emane_model: session.emane.set_model_config(node_id, emane_model) return core_pb2.AddNodeResponse(node_id=node.id)
def test_mobility(self, session, ip_prefixes): """ Test basic wlan network. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create wlan wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.mobility.set_model(wlan_node, BasicRangeModel) # create nodes node_options = NodeOptions() node_options.set_position(0, 0) node_one = session.create_wireless_node(node_options=node_options) node_two = session.create_wireless_node(node_options=node_options) # link nodes for node in [node_one, node_two]: interface = ip_prefixes.create_interface(node) session.add_link(node.objid, wlan_node.objid, interface_one=interface) # link nodes in wlan session.wireless_link_all(wlan_node, [node_one, node_two]) # configure mobility script for session config = { "file": _MOBILITY_FILE, "refresh_ms": "50", "loop": "1", "autostart": "0.0", "map": "", "script_start": "", "script_pause": "", "script_stop": "", } session.mobility.set_model(wlan_node, Ns2ScriptedMobility, config) # add handler for receiving node updates event = threading.Event() def node_update(_): event.set() session.node_handlers.append(node_update) # instantiate session session.instantiate() # validate we receive a node message for updating its location assert event.wait(5)
def test_node_update(self, session): # given node = session.add_node() position_value = 100 update_options = NodeOptions() update_options.set_position(x=position_value, y=position_value) # when session.update_node(node.objid, update_options) # then assert node.position.x == position_value assert node.position.y == position_value
def test_node_update(self, session): # given node = session.add_node() position_value = 100 update_options = NodeOptions() update_options.set_position(x=position_value, y=position_value) # when session.edit_node(node.id, update_options) # then assert node.position.x == position_value assert node.position.y == position_value
def test_mobility(self, session, ip_prefixes): """ Test basic wlan network. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create wlan wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.set_wireless_model(wlan_node, BasicRangeModel) # create nodes node_options = NodeOptions() node_options.set_position(0, 0) node_one = session.create_wireless_node(node_options=node_options) node_two = session.create_wireless_node(node_options=node_options) # link nodes for node in [node_one, node_two]: interface = ip_prefixes.create_interface(node) session.add_link(node.objid, wlan_node.objid, interface_one=interface) # link nodes in wlan session.wireless_link_all(wlan_node, [node_one, node_two]) # configure mobility script for session config = ConfigData( node=wlan_node.objid, object="ns2script", type=0, data_types=(10, 3, 11, 10, 10, 10, 10, 10, 0), data_values="file=%s|refresh_ms=50|loop=1|autostart=0.0|" "map=|script_start=|script_pause=|script_stop=" % _MOBILITY_FILE) session.config_object(config) # add handler for receiving node updates event = threading.Event() def node_update(_): event.set() session.node_handlers.append(node_update) # instantiate session session.instantiate() # validate we receive a node message for updating its location assert event.wait(5)
def add_node_data( node_proto: core_pb2.Node) -> Tuple[NodeTypes, int, NodeOptions]: """ Convert node protobuf message to data for creating a node. :param node_proto: node proto message :return: node type, id, and options """ _id = node_proto.id _type = NodeTypes(node_proto.type) options = NodeOptions( name=node_proto.name, model=node_proto.model, icon=node_proto.icon, opaque=node_proto.opaque, image=node_proto.image, services=node_proto.services, config_services=node_proto.config_services, ) if node_proto.emane: options.emane = node_proto.emane if node_proto.server: options.server = node_proto.server position = node_proto.position options.set_position(position.x, position.y) if node_proto.HasField("geo"): geo = node_proto.geo options.set_location(geo.lat, geo.lon, geo.alt) return _type, _id, options
def test_remote_node(self, session): # given server_name = "core2" host = "127.0.0.1" # when session.distributed.add_server(server_name, host) options = NodeOptions() options.server = server_name node = session.add_node(options=options) # then assert node.server is not None assert node.server.name == server_name assert node.server.host == host
def test_models(self, session, model, ip_prefixes): """ Test emane models within a basic network. :param core.emulator.coreemu.EmuSession session: session for test :param model: emane model to test :param ip_prefixes: generates ip addresses for nodes """ # create emane node for networking the core nodes session.set_location(47.57917, -122.13232, 2.00000, 1.0) options = NodeOptions() options.set_position(80, 50) emane_network = session.add_node(_type=NodeTypes.EMANE, options=options) session.emane.set_model(emane_network, model) # configure tdma if model == EmaneTdmaModel: session.emane.set_model_config( emane_network.id, EmaneTdmaModel.name, { "schedule": os.path.join(_DIR, "../../examples/tdma/schedule.xml") }, ) # create nodes options = NodeOptions(model="mdr") options.set_position(150, 150) node_one = session.add_node(options=options) options.set_position(300, 150) node_two = session.add_node(options=options) for i, node in enumerate([node_one, node_two]): node.setposition(x=150 * (i + 1), y=150) interface = ip_prefixes.create_interface(node) session.add_link(node.id, emane_network.id, interface_one=interface) # instantiate session session.instantiate() # ping n2 from n1 and assert success status = ping(node_one, node_two, ip_prefixes, count=5) assert not status
def create_emane_network(self, model, geo_reference, geo_scale=None, node_options=NodeOptions(), config=None): """ Convenience method for creating an emane network. :param model: emane model to use for emane network :param geo_reference: geo reference point to use for emane node locations :param geo_scale: geo scale to use for emane node locations, defaults to 1.0 :param core.emulator.emudata.NodeOptions node_options: options for emane node being created :param dict config: emane model configuration :return: create emane network """ # required to be set for emane to function properly self.location.setrefgeo(*geo_reference) if geo_scale: self.location.refscale = geo_scale # create and return network emane_network = self.add_node(_type=NodeTypes.EMANE, node_options=node_options) self.emane.set_model(emane_network, model, config) return emane_network
def read_network(self, network_element: etree.Element) -> None: node_id = get_int(network_element, "id") name = network_element.get("name") node_type = NodeTypes[network_element.get("type")] icon = network_element.get("icon") options = NodeOptions(name) options.icon = icon self.save_ntwk_node_attributes(node_id, str(name), str(node_type).strip("NodeTypes.")) position_element = network_element.find("position") if position_element is not None: x = get_float(position_element, "x") y = get_float(position_element, "y") if all([x, y]): options.set_position(x, y) lat = get_float(position_element, "lat") lon = get_float(position_element, "lon") alt = get_float(position_element, "alt") if all([lat, lon, alt]): options.set_location(lat, lon, alt) logging.info("reading node id(%s) node_type(%s) name(%s)", node_id, node_type, name) self.session.add_node(_type=node_type, _id=node_id, options=options)
def read_device(self, device_element): node_id = get_int(device_element, "id") name = device_element.get("name") model = device_element.get("type") node_options = NodeOptions(name, model) service_elements = device_element.find("services") if service_elements is not None: node_options.services = [ x.get("name") for x in service_elements.iterchildren() ] position_element = device_element.find("position") if position_element is not None: x = get_int(position_element, "x") y = get_int(position_element, "y") if all([x, y]): node_options.set_position(x, y) lat = get_float(position_element, "lat") lon = get_float(position_element, "lon") alt = get_float(position_element, "alt") if all([lat, lon, alt]): node_options.set_location(lat, lon, alt) logging.info("reading node id(%s) model(%s) name(%s)", node_id, model, name) self.session.add_node(_id=node_id, node_options=node_options)
def test_get_emane_model_config(self, grpc_server): # given client = CoreGrpcClient() session = grpc_server.coreemu.create_session() session.set_location(47.57917, -122.13232, 2.00000, 1.0) options = NodeOptions() options.emane = EmaneIeee80211abgModel.name emane_network = session.add_node(_type=NodeTypes.EMANE, options=options) session.emane.set_model(emane_network, EmaneIeee80211abgModel) # then with client.context_connect(): response = client.get_emane_model_config( session.id, emane_network.id, EmaneIeee80211abgModel.name) # then assert len(response.config) > 0
def test_remote_bridge(self, session): # given server_name = "core2" host = "127.0.0.1" session.distributed.address = host # when session.distributed.add_server(server_name, host) options = NodeOptions() options.server = server_name node = session.add_node(_type=NodeTypes.HUB, options=options) session.instantiate() # then assert node.server is not None assert node.server.name == server_name assert node.server.host == host assert len(session.distributed.tunnels) > 0
def main(args): # ip generator for example prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16") # create emulator instance for creating sessions and utility methods coreemu = CoreEmu( { "controlnet": "core1:172.16.1.0/24 core2:172.16.2.0/24 core3:172.16.3.0/24 " "core4:172.16.4.0/24 core5:172.16.5.0/24", "distributed_address": args.address, } ) session = coreemu.create_session() # initialize distributed server_name = "core2" session.distributed.add_server(server_name, args.server) # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create local node, switch, and remote nodes options = NodeOptions(model="mdr") options.set_position(0, 0) node_one = session.add_node(options=options) emane_net = session.add_node(_type=NodeTypes.EMANE) session.emane.set_model(emane_net, EmaneIeee80211abgModel) options.server = server_name node_two = session.add_node(options=options) # create node interfaces and link interface_one = prefixes.create_interface(node_one) interface_two = prefixes.create_interface(node_two) session.add_link(node_one.id, emane_net.id, interface_one=interface_one) session.add_link(node_two.id, emane_net.id, interface_one=interface_two) # instantiate session session.instantiate() # pause script for verification input("press enter for shutdown") # shutdown session coreemu.shutdown()
def create_wireless_node(self, _id=None, node_options=NodeOptions()): """ Create a wireless node for use within an wireless/EMANE networks. :param int _id: int for node, defaults to None and will be generated :param core.emulator.emudata.NodeOptions node_options: options for emane node, model will always be "mdr" :return: new emane node :rtype: core.netns.nodes.CoreNode """ node_options.model = "mdr" return self.add_node(_type=NodeTypes.DEFAULT, _id=_id, node_options=node_options)
def test_node_add(self, session, model): # given options = NodeOptions(model=model) # when node = session.add_node(options=options) # then assert node assert node.alive() assert node.up
def read_device(self, device_element: etree.Element) -> None: node_id = get_int(device_element, "id") name = device_element.get("name") model = device_element.get("type") icon = device_element.get("icon") clazz = device_element.get("class") image = device_element.get("image") options = NodeOptions(name, model, image) options.icon = icon self.save_ntwk_node_attributes(node_id, str(name), str(model)) node_type = NodeTypes.DEFAULT if clazz == "docker": node_type = NodeTypes.DOCKER elif clazz == "lxc": node_type = NodeTypes.LXC service_elements = device_element.find("services") if service_elements is not None: options.services = [ x.get("name") for x in service_elements.iterchildren() ] config_service_elements = device_element.find("configservices") if config_service_elements is not None: options.config_services = [ x.get("name") for x in config_service_elements.iterchildren() ] position_element = device_element.find("position") if position_element is not None: x = get_float(position_element, "x") y = get_float(position_element, "y") if all([x, y]): options.set_position(x, y) lat = get_float(position_element, "lat") lon = get_float(position_element, "lon") alt = get_float(position_element, "alt") if all([lat, lon, alt]): options.set_location(lat, lon, alt) logging.info("reading node id(%s) model(%s) name(%s)", node_id, model, name) self.session.add_node(_type=node_type, _id=node_id, options=options)
def read_network(self, network_element): node_id = get_int(network_element, "id") name = network_element.get("name") node_type = NodeTypes[network_element.get("type")] node_options = NodeOptions(name) position_element = network_element.find("position") if position_element is not None: x = get_float(position_element, "x") y = get_float(position_element, "y") if all([x, y]): node_options.set_position(x, y) lat = get_float(position_element, "lat") lon = get_float(position_element, "lon") alt = get_float(position_element, "alt") if all([lat, lon, alt]): node_options.set_location(lat, lon, alt) logger.info("reading node id(%s) node_type(%s) name(%s)", node_id, node_type, name) self.session.add_node(_type=node_type, _id=node_id, node_options=node_options)
def example(args): # ip generator for example prefixes = IpPrefixes("10.83.0.0/16") # create emulator instance for creating sessions and utility methods coreemu = CoreEmu() session = coreemu.create_session() # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create wlan network node wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.mobility.set_model(wlan, BasicRangeModel) # create nodes, must set a position for wlan basic range model options = NodeOptions(model="mdr") options.set_position(0, 0) for _ in range(args.nodes): node = session.add_node(options=options) interface = prefixes.create_interface(node) session.add_link(node.id, wlan.id, interface_one=interface) # instantiate session session.instantiate() # get nodes for example run first_node = session.get_node(2) last_node = session.get_node(args.nodes + 1) logging.info("starting iperf server on node: %s", first_node.name) first_node.cmd("iperf -s -D") address = prefixes.ip4_address(first_node) logging.info("node %s connecting to %s", last_node.name, address) output = last_node.cmd(f"iperf -t {args.time} -c {address}") logging.info(output) first_node.cmd("killall -9 iperf") # shutdown session coreemu.shutdown()
def example(args): # ip generator for example prefixes = IpPrefixes(ip4_prefix="10.83.0.0/16") # create emulator instance for creating sessions and utility methods coreemu = CoreEmu() session = coreemu.create_session() # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create emane network node session.set_location(47.57917, -122.13232, 2.00000, 1.0) options = NodeOptions() options.set_position(80, 50) emane_network = session.add_node(_type=NodeTypes.EMANE, options=options) session.emane.set_model(emane_network, EmaneIeee80211abgModel) # create nodes options = NodeOptions(model="mdr") for i in range(args.nodes): node = session.add_node(options=options) node.setposition(x=150 * (i + 1), y=150) interface = prefixes.create_interface(node) session.add_link(node.id, emane_network.id, interface_one=interface) # instantiate session session.instantiate() # shutdown session input("press enter to exit...") coreemu.shutdown()
def test_models(self, session, model, ip_prefixes): """ Test emane models within a basic network. :param core.emulator.coreemu.EmuSession session: session for test :param model: emane model to test :param ip_prefixes: generates ip addresses for nodes """ # create emane node for networking the core nodes emane_network = session.create_emane_network( model, geo_reference=(47.57917, -122.13232, 2.00000) ) emane_network.setposition(x=80, y=50) # create nodes node_options = NodeOptions() node_options.set_position(150, 150) node_one = session.create_wireless_node(node_options=node_options) node_options.set_position(300, 150) node_two = session.create_wireless_node(node_options=node_options) for i, node in enumerate([node_one, node_two]): node.setposition(x=150 * (i + 1), y=150) interface = ip_prefixes.create_interface(node) session.add_link(node.objid, emane_network.objid, interface_one=interface) # instantiate session session.instantiate() # ping n2 from n1 and assert success status = ping(node_one, node_two, ip_prefixes, count=5) assert not status
def read_device(self, device_element): node_id = get_int(device_element, "id") name = device_element.get("name") model = device_element.get("type") node_options = NodeOptions(name, model) service_elements = device_element.find("services") if service_elements is not None: node_options.services = [x.get("name") for x in service_elements.iterchildren()] position_element = device_element.find("position") if position_element is not None: x = get_float(position_element, "x") y = get_float(position_element, "y") if all([x, y]): node_options.set_position(x, y) lat = get_float(position_element, "lat") lon = get_float(position_element, "lon") alt = get_float(position_element, "alt") if all([lat, lon, alt]): node_options.set_location(lat, lon, alt) logger.info("reading node id(%s) model(%s) name(%s)", node_id, model, name) self.session.add_node(_id=node_id, node_options=node_options)
def example(options): # ip generator for example prefixes = IpPrefixes("10.83.0.0/16") # create emulator instance for creating sessions and utility methods coreemu = CoreEmu() session = coreemu.create_session() # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create wlan network node wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.mobility.set_model(wlan, BasicRangeModel) # create nodes, must set a position for wlan basic range model node_options = NodeOptions() node_options.set_position(0, 0) for _ in range(options.nodes): node = session.add_node(node_options=node_options) interface = prefixes.create_interface(node) session.add_link(node.id, wlan.id, interface_one=interface) # instantiate session session.instantiate() # get nodes for example run first_node = session.get_node(2) last_node = session.get_node(options.nodes + 1) print("starting iperf server on node: %s" % first_node.name) first_node.cmd(["iperf", "-s", "-D"]) address = prefixes.ip4_address(first_node) print("node %s connecting to %s" % (last_node.name, address)) last_node.client.icmd(["iperf", "-t", str(options.time), "-c", address]) first_node.cmd(["killall", "-9", "iperf"]) # shutdown session coreemu.shutdown()
def example(nodes): # ip generator for example prefixes = IpPrefixes("192.168.10.0/24") node_list = [] # create emulator instance for creating sessions and utility methods core_emu = globals().get("coreemu", CoreEmu()) session = core_emu.create_session() # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create nodes node_options = NodeOptions() x = 0 for i in range(nodes): y = 200 x = x + 100 if (i - 1) % 2 == 0: #node id starts at 1 y = 400 node_options.set_position(x, y) node = session.add_node(node_options=node_options) node_list.append(node) # create switch network node wlan = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.mobility.set_model(wlan, BasicRangeModel) for node in node_list: interface = prefixes.create_interface(node) session.add_link(node.id, wlan.id, interface_one=interface) # instantiate session session.instantiate() for node_num in range(2, 2 + nodes - 1): n = session.get_node(node_num) print("starting swarmdag on node: %s" % n.name) n.cmd([swarmdag_path, ">", "swarmdag.txt"])
def test_get_node_terminal(self, grpc_server): # given client = CoreGrpcClient() session = grpc_server.coreemu.create_session() session.set_state(EventTypes.CONFIGURATION_STATE) node_options = NodeOptions(model="Host") node = session.add_node(node_options=node_options) session.instantiate() # then with client.context_connect(): response = client.get_node_terminal(session.id, node.id) # then assert response.terminal is not None
def main(): # ip generator for example prefixes = IpPrefixes("10.83.0.0/16") # create emulator instance for creating sessions and utility methods coreemu = CoreEmu() session = coreemu.create_session() # must be in configuration state for nodes to start, when using "node_add" below session.set_state(EventTypes.CONFIGURATION_STATE) # create wlan network node wlan = session.add_node(WlanNode, _id=100) session.mobility.set_model(wlan, BasicRangeModel) # create nodes, must set a position for wlan basic range model options = NodeOptions(model="mdr") options.set_position(0, 0) for _ in range(NODES): node = session.add_node(CoreNode, options=options) interface = prefixes.create_interface(node) session.add_link(node.id, wlan.id, interface_one=interface) # instantiate session session.instantiate() # get nodes for example run first_node = session.get_node(1, CoreNode) last_node = session.get_node(NODES, CoreNode) address = prefixes.ip4_address(first_node) logging.info("node %s pinging %s", last_node.name, address) output = last_node.cmd(f"ping -c 3 {address}") logging.info(output) # shutdown session coreemu.shutdown()
def test_remote_node(self, session: Session): # given server_name = "core2" host = "127.0.0.1" # when session.distributed.add_server(server_name, host) options = NodeOptions(server=server_name) node = session.add_node(CoreNode, options=options) session.instantiate() # then assert node.server is not None assert node.server.name == server_name assert node.server.host == host
def test_node_add(self, session, model): # given node_options = NodeOptions(model=model) # when node = session.add_node(node_options=node_options) # give time for node services to boot time.sleep(1) # then assert node assert os.path.exists(node.nodedir) assert node.alive() assert node.up assert node.check_cmd(["ip", "addr", "show", "lo"])
def test_xml_mobility(self, session, tmpdir, version, ip_prefixes): """ Test xml client methods for mobility. :param session: session for test :param tmpdir: tmpdir to create data in :param str version: xml version to write and parse :param ip_prefixes: generates ip addresses for nodes """ # create wlan wlan_node = session.add_node(_type=NodeTypes.WIRELESS_LAN) session.mobility.set_model(wlan_node, BasicRangeModel, {"test": "1"}) # create nodes node_options = NodeOptions() node_options.set_position(0, 0) node_one = session.create_wireless_node(node_options=node_options) node_two = session.create_wireless_node(node_options=node_options) # link nodes for node in [node_one, node_two]: interface = ip_prefixes.create_interface(node) session.add_link(node.objid, wlan_node.objid, interface_one=interface) # link nodes in wlan session.wireless_link_all(wlan_node, [node_one, node_two]) # instantiate session session.instantiate() # get ids for nodes wlan_id = wlan_node.objid n1_id = node_one.objid n2_id = node_two.objid # save xml xml_file = tmpdir.join("session.xml") file_path = xml_file.strpath session.save_xml(file_path, version) # verify xml file was created and can be parsed assert xml_file.isfile() assert ElementTree.parse(file_path) # stop current session, clearing data session.shutdown() # verify nodes have been removed from session with pytest.raises(KeyError): assert not session.get_object(n1_id) with pytest.raises(KeyError): assert not session.get_object(n2_id) # load saved xml session.open_xml(file_path, start=True) # retrieve configuration we set originally value = str(session.mobility.get_config("test", wlan_id, BasicRangeModel.name)) # verify nodes and configuration were restored assert session.get_object(n1_id) assert session.get_object(n2_id) assert session.get_object(wlan_id) assert value == "1"
def test_xml_emane(self, session, tmpdir, version, ip_prefixes): """ Test xml client methods for emane. :param session: session for test :param tmpdir: tmpdir to create data in :param str version: xml version to write and parse :param ip_prefixes: generates ip addresses for nodes """ # create emane node for networking the core nodes emane_network = session.create_emane_network( EmaneIeee80211abgModel, geo_reference=(47.57917, -122.13232, 2.00000), config={"test": "1"} ) emane_network.setposition(x=80, y=50) # create nodes node_options = NodeOptions() node_options.set_position(150, 150) node_one = session.create_wireless_node(node_options=node_options) node_options.set_position(300, 150) node_two = session.create_wireless_node(node_options=node_options) for i, node in enumerate([node_one, node_two]): node.setposition(x=150 * (i + 1), y=150) interface = ip_prefixes.create_interface(node) session.add_link(node.objid, emane_network.objid, interface_one=interface) # instantiate session session.instantiate() # get ids for nodes emane_id = emane_network.objid n1_id = node_one.objid n2_id = node_two.objid # save xml xml_file = tmpdir.join("session.xml") file_path = xml_file.strpath session.save_xml(file_path, version) # verify xml file was created and can be parsed assert xml_file.isfile() assert ElementTree.parse(file_path) # stop current session, clearing data session.shutdown() # verify nodes have been removed from session with pytest.raises(KeyError): assert not session.get_object(n1_id) with pytest.raises(KeyError): assert not session.get_object(n2_id) # load saved xml session.open_xml(file_path, start=True) # retrieve configuration we set originally value = str(session.emane.get_config("test", emane_id, EmaneIeee80211abgModel.name)) # verify nodes and configuration were restored assert session.get_object(n1_id) assert session.get_object(n2_id) assert session.get_object(emane_id) assert value == "1"