def test_link_delay(self, session, ip_prefixes): """ Test ptp node network with modifying link packet delay. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create link network node_one, node_two = create_ptp_network(session, ip_prefixes) # run ping for delay information stdout = ping_output(node_one, node_two, ip_prefixes) assert stdout rtt_line = stdout.split("\n")[-1] rtt_values = rtt_line.split("=")[1].split("ms")[0].strip() rtt_avg = float(rtt_values.split("/")[2]) assert 0 <= rtt_avg <= 0.2 # change delay in microseconds link_options = LinkOptions() link_options.delay = 1000000 session.update_link(node_one.objid, node_two.objid, link_options=link_options) # run ping for delay information again stdout = ping_output(node_one, node_two, ip_prefixes) assert stdout rtt_line = stdout.split("\n")[-1] rtt_values = rtt_line.split("=")[1].split("ms")[0].strip() rtt_avg = float(rtt_values.split("/")[2]) assert 1800 <= rtt_avg <= 2200
def test_link_loss(self, session, ip_prefixes): """ Test ptp node network with modifying link packet loss. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create link network node_one, node_two = create_ptp_network(session, ip_prefixes) # output csv index loss_index = -2 # run iperf, validate normal bandwidth stdout = iperf(node_one, node_two, ip_prefixes) assert stdout value = float(stdout.split(',')[loss_index]) assert 0 <= value <= 0.5 # change bandwidth in bits per second link_options = LinkOptions() link_options.per = 50 session.update_link(node_one.objid, node_two.objid, link_options=link_options) # run iperf again stdout = iperf(node_one, node_two, ip_prefixes) assert stdout value = float(stdout.split(',')[loss_index]) assert 40 <= value <= 60
def test_link_jitter(self, session, ip_prefixes): """ Test ptp node network with modifying link packet jitter. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create link network node_one, node_two = create_ptp_network(session, ip_prefixes) # output csv index jitter_index = 9 # run iperf stdout = iperf(node_one, node_two, ip_prefixes) assert stdout value = float(stdout.split(",")[jitter_index]) assert -0.5 <= value <= 0.05 # change jitter in microseconds link_options = LinkOptions() link_options.jitter = 1000000 session.update_link(node_one.objid, node_two.objid, link_options=link_options) # run iperf again stdout = iperf(node_one, node_two, ip_prefixes) assert stdout value = float(stdout.split(",")[jitter_index]) assert 200 <= value <= 500
def test_link_bandwidth(self, session, ip_prefixes): """ Test ptp node network with modifying link bandwidth. :param core.emulator.coreemu.EmuSession session: session for test :param ip_prefixes: generates ip addresses for nodes """ # create link network node_one, node_two = create_ptp_network(session, ip_prefixes) # output csv index bandwidth_index = 8 # run iperf, validate normal bandwidth stdout = iperf(node_one, node_two, ip_prefixes) assert stdout value = int(stdout.split(',')[bandwidth_index]) assert 900000 <= value <= 1100000 # change bandwidth in bits per second link_options = LinkOptions() link_options.bandwidth = 500000 session.update_link(node_one.id, node_two.id, link_options=link_options) # run iperf again stdout = iperf(node_one, node_two, ip_prefixes) assert stdout value = int(stdout.split(',')[bandwidth_index]) assert 400000 <= value <= 600000
def test_link_update(self, session, ip_prefixes): # given node_one = session.add_node() node_two = session.add_node(_type=NodeTypes.SWITCH) interface_one = ip_prefixes.create_interface(node_one) session.add_link(node_one.objid, node_two.objid, interface_one) interface = node_one.netif(interface_one.id) output = utils.check_cmd(["tc", "qdisc", "show", "dev", interface.localname]) assert "delay" not in output assert "rate" not in output assert "loss" not in output assert "duplicate" not in output # when link_options = LinkOptions() link_options.delay = 50 link_options.bandwidth = 5000000 link_options.per = 25 link_options.dup = 25 session.update_link(node_one.objid, node_two.objid, interface_one_id=interface_one.id, link_options=link_options) # then output = utils.check_cmd(["tc", "qdisc", "show", "dev", interface.localname]) assert "delay" in output assert "rate" in output assert "loss" in output assert "duplicate" in output
def get_LinkOptions(link_params): '''This class is used derive new LinkOptions() from the LinkEvent object. LinkOptions are used by CORE to specify delays, bandwidth etc for a specific link. :returns: linkOptions, a convenience object used by core to specify link values (delay, bandwidth, jitter etc.) :rtype: LinkOptions ''' linkOptions = LinkOptions() for param, value in link_params.items(): parameter = param.lower() if (value): newValue = float(value) else: newValue = value if (parameter == "session"): linkOptions.session = newValue elif (parameter == "delay"): linkOptions.delay = newValue elif (parameter == "bandwidth"): linkOptions.bandwidth = newValue # Packet Loss Rate elif (parameter == "loss"): linkOptions.per = newValue # Packet duplication rate elif (parameter == "duplication" or parameter == "dup"): linkOptions.dup = newValue elif (parameter == "jitter"): linkOptions.jitter = newValue return linkOptions
def test_link_update(self, session, ip_prefixes): # given node_one = session.add_node() node_two = session.add_node(_type=NodeTypes.SWITCH) interface_one = ip_prefixes.create_interface(node_one) session.add_link(node_one.objid, node_two.objid, interface_one) interface = node_one.netif(interface_one.id) output = utils.check_cmd( ["tc", "qdisc", "show", "dev", interface.localname]) assert "delay" not in output assert "rate" not in output assert "loss" not in output assert "duplicate" not in output # when link_options = LinkOptions() link_options.delay = 50 link_options.bandwidth = 5000000 link_options.per = 25 link_options.dup = 25 session.update_link(node_one.objid, node_two.objid, interface_one_id=interface_one.id, link_options=link_options) # then output = utils.check_cmd( ["tc", "qdisc", "show", "dev", interface.localname]) assert "delay" in output assert "rate" in output assert "loss" in output assert "duplicate" in output
def __init__(self, first_node, second_node): # first node and second are from InterNode type self.first_node = first_node self.first_interface = None self.second_node = second_node self.second_interface = None self.link_options = LinkOptions() self.is_in_CORE = False ## Flag gets set to true when the link is added to the actual underlying CORE session # This is useful later when adding new links from the API and having to update all of the physical connections. # Is used in the _set_up_physical_link method. # If either of the nodes is a physical node then set phyiscal flag of the node if (self.first_node.is_physical == True or self.second_node.is_physical == True): self.has_physical = True else: self.has_physical = False # Add each of the nodes to the others "neighbours" list first_node.neighbours.append(second_node) second_node.neighbours.append(first_node) ## create interface for FIRST node if (first_node.type == NodeTypes.RJ45): interface_data = InterfaceData(*[None] * 7) self.first_interface = interface_data elif (first_node.type == NodeTypes.SWITCH): self.first_interface = None second_node.has_switch_connection = True else: interface = Topology.prefixes.create_interface( first_node.CORE_node) self.first_interface = interface # Add interface to the nodes "interface" dictionary - This helps track which interface was used for which link first_node.interfaces[second_node] = self.first_interface # Repeat for SECOND node if (second_node.type == NodeTypes.RJ45): interface_data = InterfaceData(*[None] * 7) self.second_interface = interface_data elif (second_node.type == NodeTypes.SWITCH): first_node.has_switch_connection = True self.second_interface = None else: interface = Topology.prefixes.create_interface( second_node.CORE_node) self.second_interface = interface second_node.interfaces[first_node] = self.second_interface
def setlinkparams(self) -> None: """ Apply link parameters to all interfaces. This is invoked from WlanNode.setmodel() after the position callback has been set. """ with self._netifslock: for netif in self._netifs: options = LinkOptions( bandwidth=self.bw, delay=self.delay, per=self.loss, jitter=self.jitter, ) self.wlan.linkconfig(netif, options)
def get_LinkOptions(self): '''This method is used derive new LinkOptions() from the LinkEvent object. LinkOptions are used by CORE to specify delays, bandwidth etc for a specific link. :returns: linkOptions, a convenience object used by core to specify link values (delay, bandwidth, jitter etc.) :rtype: core.emulator.emudata.LinkOptions ''' linkOptions = LinkOptions() for param, value in self.link_params.items(): #print ("param = {} -- Value = {}".format(param, value)) parameter = param.lower() newValue = value if (parameter == "session"): linkOptions.session = newValue elif (parameter == "delay"): linkOptions.delay = newValue elif (parameter == "bandwidth"): linkOptions.bandwidth = float(newValue) # Packet Loss Rate elif (parameter == "loss"): linkOptions.per = newValue # Packet duplication rate elif (parameter == "duplication"): linkOptions.dup = newValue elif (parameter == "jitter"): linkOptions.jitter = newValue # elif (parameter == "mer"): # linkOptions.mer = newValue # elif (parameter == "burst"): # linkOptions.burst = newValue # elif (parameter == "mburst"): # linkOptions.mburst = newValue # elif (parameter == "gui_attributes"): # linkOptions.gui_attributes = newValue # elif (parameter == "unidirectional"): # linkOptions.unidirectional = newValue # elif (parameter == "emulation_id"): # linkOptions.emulation_id = newValue # elif (parameter == "network_id"): # linkOptions.network_id = newValue # elif (parameter == "key"): # linkOptions.key = newValue # elif (parameter == "opaque"): # linkOptions.opaque = newValue return linkOptions
def test_link_update(self, session: Session, ip_prefixes: IpPrefixes): # given delay = 50 bandwidth = 5000000 per = 25 dup = 25 jitter = 10 node_one = session.add_node(CoreNode) node_two = session.add_node(SwitchNode) interface_one_data = ip_prefixes.create_interface(node_one) session.add_link(node_one.id, node_two.id, interface_one_data) interface_one = node_one.netif(interface_one_data.id) assert interface_one.getparam("delay") != delay assert interface_one.getparam("bw") != bandwidth assert interface_one.getparam("loss") != per assert interface_one.getparam("duplicate") != dup assert interface_one.getparam("jitter") != jitter # when link_options = LinkOptions() link_options.delay = delay link_options.bandwidth = bandwidth link_options.per = per link_options.dup = dup link_options.jitter = jitter session.update_link( node_one.id, node_two.id, interface_one_id=interface_one_data.id, options=link_options, ) # then assert interface_one.getparam("delay") == delay assert interface_one.getparam("bw") == bandwidth assert interface_one.getparam("loss") == per assert interface_one.getparam("duplicate") == dup assert interface_one.getparam("jitter") == jitter
def read_links(self): link_elements = self.scenario.find("links") if link_elements is None: return node_sets = set() for link_element in link_elements.iterchildren(): node_one = get_int(link_element, "node_one") node_two = get_int(link_element, "node_two") node_set = frozenset((node_one, node_two)) interface_one_element = link_element.find("interface_one") interface_one = None if interface_one_element is not None: interface_one = create_interface_data(interface_one_element) interface_two_element = link_element.find("interface_two") interface_two = None if interface_two_element is not None: interface_two = create_interface_data(interface_two_element) options_element = link_element.find("options") link_options = LinkOptions() if options_element is not None: link_options.bandwidth = get_int(options_element, "bandwidth") link_options.burst = get_int(options_element, "burst") link_options.delay = get_int(options_element, "delay") link_options.dup = get_int(options_element, "dup") link_options.mer = get_int(options_element, "mer") link_options.mburst = get_int(options_element, "mburst") link_options.jitter = get_int(options_element, "jitter") link_options.key = get_int(options_element, "key") link_options.per = get_int(options_element, "per") link_options.unidirectional = get_int(options_element, "unidirectional") link_options.session = options_element.get("session") link_options.emulation_id = get_int(options_element, "emulation_id") link_options.network_id = get_int(options_element, "network_id") link_options.opaque = options_element.get("opaque") link_options.gui_attributes = options_element.get( "gui_attributes") if link_options.unidirectional == 1 and node_set in node_sets: logging.info("updating link node_one(%s) node_two(%s): %s", node_one, node_two, link_options) self.session.update_link(node_one, node_two, interface_one.id, interface_two.id, link_options) else: logging.info("adding link node_one(%s) node_two(%s): %s", node_one, node_two, link_options) self.session.add_link(node_one, node_two, interface_one, interface_two, link_options) node_sets.add(node_set)
def EditLink(self, request, context): logging.debug("edit link: %s", request) session = self.get_session(request.session_id, context) node_one_id = request.node_one_id node_two_id = request.node_two_id interface_one_id = request.interface_one_id interface_two_id = request.interface_two_id options_data = request.options link_options = LinkOptions() link_options.delay = options_data.delay link_options.bandwidth = options_data.bandwidth link_options.per = options_data.per link_options.dup = options_data.dup link_options.jitter = options_data.jitter link_options.mer = options_data.mer link_options.burst = options_data.burst link_options.mburst = options_data.mburst link_options.unidirectional = options_data.unidirectional link_options.key = options_data.key link_options.opaque = options_data.opaque session.update_link(node_one_id, node_two_id, interface_one_id, interface_two_id, link_options) return core_pb2.EditLinkResponse(result=True)
def AddLink(self, request, context): logging.debug("add link: %s", request) session = self.get_session(request.session_id, context) # validate node exist self.get_node(session, request.link.node_one_id, context) self.get_node(session, request.link.node_two_id, context) node_one_id = request.link.node_one_id node_two_id = request.link.node_two_id interface_one = None interface_one_data = request.link.interface_one if interface_one_data: name = interface_one_data.name if name == "": name = None mac = interface_one_data.mac if mac == "": mac = None else: mac = MacAddress.from_string(mac) interface_one = InterfaceData( _id=interface_one_data.id, name=name, mac=mac, ip4=interface_one_data.ip4, ip4_mask=interface_one_data.ip4mask, ip6=interface_one_data.ip6, ip6_mask=interface_one_data.ip6mask, ) interface_two = None interface_two_data = request.link.interface_two if interface_two_data: name = interface_two_data.name if name == "": name = None mac = interface_two_data.mac if mac == "": mac = None else: mac = MacAddress.from_string(mac) interface_two = InterfaceData( _id=interface_two_data.id, name=name, mac=mac, ip4=interface_two_data.ip4, ip4_mask=interface_two_data.ip4mask, ip6=interface_two_data.ip6, ip6_mask=interface_two_data.ip6mask, ) link_type = None link_type_value = request.link.type if link_type_value is not None: link_type = LinkTypes(link_type_value) options_data = request.link.options link_options = LinkOptions(_type=link_type) if options_data: link_options.delay = options_data.delay link_options.bandwidth = options_data.bandwidth link_options.per = options_data.per link_options.dup = options_data.dup link_options.jitter = options_data.jitter link_options.mer = options_data.mer link_options.burst = options_data.burst link_options.mburst = options_data.mburst link_options.unidirectional = options_data.unidirectional link_options.key = options_data.key link_options.opaque = options_data.opaque session.add_link(node_one_id, node_two_id, interface_one, interface_two, link_options=link_options) return core_pb2.AddLinkResponse(result=True)
def test_link_options_bidirectional(self, session, tmpdir, ip_prefixes): """ Test xml client methods for a ptp network. :param session: session for test :param tmpdir: tmpdir to create data in :param ip_prefixes: generates ip addresses for nodes """ # create nodes node_one = session.add_node() interface_one = ip_prefixes.create_interface(node_one) node_two = session.add_node() interface_two = ip_prefixes.create_interface(node_two) # create link link_options_one = LinkOptions() link_options_one.unidirectional = 1 link_options_one.bandwidth = 5000 link_options_one.delay = 10 link_options_one.per = 10.5 link_options_one.dup = 5 link_options_one.jitter = 5 session.add_link(node_one.id, node_two.id, interface_one, interface_two, link_options_one) link_options_two = LinkOptions() link_options_two.unidirectional = 1 link_options_two.bandwidth = 10000 link_options_two.delay = 20 link_options_two.per = 10 link_options_two.dup = 10 link_options_two.jitter = 10 session.update_link( node_two.id, node_one.id, interface_two.id, interface_one.id, link_options_two, ) # instantiate session session.instantiate() # get ids for nodes n1_id = node_one.id n2_id = node_two.id # save xml xml_file = tmpdir.join("session.xml") file_path = xml_file.strpath session.save_xml(file_path) # 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(CoreError): assert not session.get_node(n1_id) with pytest.raises(CoreError): assert not session.get_node(n2_id) # load saved xml session.open_xml(file_path, start=True) # verify nodes have been recreated assert session.get_node(n1_id) assert session.get_node(n2_id) links = [] for node_id in session.nodes: node = session.nodes[node_id] links += node.all_link_data(0) assert len(links) == 2 link_one = links[0] link_two = links[1] assert link_options_one.bandwidth == link_one.bandwidth assert link_options_one.delay == link_one.delay assert link_options_one.per == link_one.per assert link_options_one.dup == link_one.dup assert link_options_one.jitter == link_one.jitter assert link_options_two.bandwidth == link_two.bandwidth assert link_options_two.delay == link_two.delay assert link_options_two.per == link_two.per assert link_options_two.dup == link_two.dup assert link_options_two.jitter == link_two.jitter
def test_link_options(self, session, tmpdir, ip_prefixes): """ Test xml client methods for a ptp network. :param session: session for test :param tmpdir: tmpdir to create data in :param ip_prefixes: generates ip addresses for nodes """ # create nodes node_one = session.add_node() interface_one = ip_prefixes.create_interface(node_one) switch = session.add_node(_type=NodeTypes.SWITCH) # create link link_options = LinkOptions() link_options.per = 10.5 link_options.bandwidth = 50000 link_options.jitter = 10 link_options.delay = 30 link_options.dup = 5 session.add_link(node_one.id, switch.id, interface_one, link_options=link_options) # instantiate session session.instantiate() # get ids for nodes n1_id = node_one.id n2_id = switch.id # save xml xml_file = tmpdir.join("session.xml") file_path = xml_file.strpath session.save_xml(file_path) # 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(CoreError): assert not session.get_node(n1_id) with pytest.raises(CoreError): assert not session.get_node(n2_id) # load saved xml session.open_xml(file_path, start=True) # verify nodes have been recreated assert session.get_node(n1_id) assert session.get_node(n2_id) links = [] for node_id in session.nodes: node = session.nodes[node_id] links += node.all_link_data(0) link = links[0] assert link_options.per == link.per assert link_options.bandwidth == link.bandwidth assert link_options.jitter == link.jitter assert link_options.delay == link.delay assert link_options.dup == link.dup
def update_link(self, node_one_id, node_two_id, interface_one_id=None, interface_two_id=None, link_options=LinkOptions()): """ Update link information between nodes. :param int node_one_id: node one id :param int node_two_id: node two id :param int interface_one_id: interface id for node one :param int interface_two_id: interface id for node two :param core.emulator.emudata.LinkOptions link_options: data to update link with :return: nothing """ # get node objects identified by link data node_one, node_two, net_one, net_two, tunnel = self._link_nodes( node_one_id, node_two_id) if node_one: node_one.lock.acquire() if node_two: node_two.lock.acquire() try: # wireless link if link_options.type == LinkTypes.WIRELESS.value: raise ValueError("cannot update wireless link") else: if not node_one and not node_two: if net_one and net_two: # modify link between nets interface = net_one.getlinknetif(net_two) upstream = False if not interface: upstream = True interface = net_two.getlinknetif(net_one) if not interface: raise ValueError( "modify unknown link between nets") if upstream: interface.swapparams("_params_up") link_config(net_one, interface, link_options, devname=interface.name) interface.swapparams("_params_up") else: link_config(net_one, interface, link_options) if not link_options.unidirectional: if upstream: link_config(net_two, interface, link_options) else: interface.swapparams("_params_up") link_config(net_two, interface, link_options, devname=interface.name) interface.swapparams("_params_up") else: raise ValueError("modify link for unknown nodes") elif not node_one: # node1 = layer 2node, node2 = layer3 node interface = node_two.netif(interface_two_id, net_one) link_config(net_one, interface, link_options) elif not node_two: # node2 = layer 2node, node1 = layer3 node interface = node_one.netif(interface_one_id, net_one) link_config(net_one, interface, link_options) else: common_networks = node_one.commonnets(node_two) if not common_networks: raise ValueError("no common network found") for net_one, interface_one, interface_two in common_networks: if interface_one_id is not None and interface_one_id != node_one.getifindex( interface_one): continue link_config(net_one, interface_one, link_options, interface_two=interface_two) if not link_options.unidirectional: link_config(net_one, interface_two, link_options, interface_two=interface_one) finally: if node_one: node_one.lock.release() if node_two: node_two.lock.release()
def add_link(self, node_one_id, node_two_id, interface_one=None, interface_two=None, link_options=LinkOptions()): """ Add a link between nodes. :param int node_one_id: node one id :param int node_two_id: node two id :param core.emulator.emudata.InterfaceData interface_one: node one interface data, defaults to none :param core.emulator.emudata.InterfaceData interface_two: node two interface data, defaults to none :param core.emulator.emudata.LinkOptions link_options: data for creating link, defaults to no options :return: """ # get node objects identified by link data node_one, node_two, net_one, net_two, tunnel = self._link_nodes( node_one_id, node_two_id) if node_one: node_one.lock.acquire() if node_two: node_two.lock.acquire() try: # wireless link if link_options.type == LinkTypes.WIRELESS: objects = [node_one, node_two, net_one, net_two] self._link_wireless(objects, connect=True) # wired link else: # 2 nodes being linked, ptp network if all([node_one, node_two]) and not net_one: logger.info("adding link for peer to peer nodes: %s - %s", node_one.name, node_two.name) ptp_class = nodeutils.get_node_class( NodeTypes.PEER_TO_PEER) start = self.state > EventTypes.DEFINITION_STATE.value net_one = self.add_object(cls=ptp_class, start=start) # node to network if node_one and net_one: logger.info("adding link from node to network: %s - %s", node_one.name, net_one.name) interface = create_interface(node_one, net_one, interface_one) link_config(net_one, interface, link_options) # network to node if node_two and net_one: logger.info("adding link from network to node: %s - %s", node_two.name, net_one.name) interface = create_interface(node_two, net_one, interface_two) if not link_options.unidirectional: link_config(net_one, interface, link_options) # network to network if net_one and net_two: logger.info("adding link from network to network: %s", net_one.name, net_two.name) if nodeutils.is_node(net_two, NodeTypes.RJ45): interface = net_two.linknet(net_one) else: interface = net_one.linknet(net_two) link_config(net_one, interface, link_options) if not link_options.unidirectional: interface.swapparams("_params_up") link_config(net_two, interface, link_options, devname=interface.name) interface.swapparams("_params_up") # a tunnel node was found for the nodes addresses = [] if not node_one and all([net_one, interface_one]): addresses.extend(interface_one.get_addresses()) if not node_two and all([net_two, interface_two]): addresses.extend(interface_two.get_addresses()) # tunnel node logic key = link_options.key if key and nodeutils.is_node(net_one, NodeTypes.TUNNEL): logger.info("setting tunnel key for: %s", net_one.name) net_one.setkey(key) if addresses: net_one.addrconfig(addresses) if key and nodeutils.is_node(net_two, NodeTypes.TUNNEL): logger.info("setting tunnel key for: %s", net_two.name) net_two.setkey(key) if addresses: net_two.addrconfig(addresses) # physical node connected with tunnel if not net_one and not net_two and (node_one or node_two): if node_one and nodeutils.is_node(node_one, NodeTypes.PHYSICAL): logger.info("adding link for physical node: %s", node_one.name) addresses = interface_one.get_addresses() node_one.adoptnetif(tunnel, interface_one.id, interface_one.mac, addresses) link_config(node_one, tunnel, link_options) elif node_two and nodeutils.is_node( node_two, NodeTypes.PHYSICAL): logger.info("adding link for physical node: %s", node_two.name) addresses = interface_two.get_addresses() node_two.adoptnetif(tunnel, interface_two.id, interface_two.mac, addresses) link_config(node_two, tunnel, link_options) finally: if node_one: node_one.lock.release() if node_two: node_two.lock.release()
def add_link_data( link_proto: core_pb2.Link ) -> Tuple[InterfaceData, InterfaceData, LinkOptions]: """ Convert link proto to link interfaces and options data. :param link_proto: link proto :return: link interfaces and options """ interface_one = link_interface(link_proto.interface_one) interface_two = link_interface(link_proto.interface_two) link_type = None link_type_value = link_proto.type if link_type_value is not None: link_type = LinkTypes(link_type_value) options = LinkOptions(_type=link_type) options_data = link_proto.options if options_data: options.delay = options_data.delay options.bandwidth = options_data.bandwidth options.per = options_data.per options.dup = options_data.dup options.jitter = options_data.jitter options.mer = options_data.mer options.burst = options_data.burst options.mburst = options_data.mburst options.unidirectional = options_data.unidirectional options.key = options_data.key options.opaque = options_data.opaque return interface_one, interface_two, options
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 switch network node switch = session.add_node(_type=NodeTypes.SWITCH) print "Everything is set up now." # create nodes for _ in xrange(2): node = session.add_node() interface = prefixes.create_interface(node) link_opts = LinkOptions() link_opts.delay = {{delay}} link_opts.bandwidth = {{mean_bw}} session.add_link(node.objid, switch.objid, interface_one=interface, link_options=link_opts) print "Links are set up." # instantiate session session.instantiate() # get nodes to run example first_node = session.get_object(2) last_node = session.get_object(3)
def read_links(self): link_elements = self.scenario.find("links") if link_elements is None: return for link_element in link_elements.iterchildren(): node_one = get_int(link_element, "node_one") node_two = get_int(link_element, "node_two") interface_one_element = link_element.find("interface_one") interface_one = None if interface_one_element is not None: interface_one = create_interface_data(interface_one_element) interface_two_element = link_element.find("interface_two") interface_two = None if interface_two_element is not None: interface_two = create_interface_data(interface_two_element) options_element = link_element.find("options") link_options = LinkOptions() if options_element is not None: link_options.bandwidth = get_float(options_element, "bandwidth") link_options.burst = get_float(options_element, "burst") link_options.delay = get_float(options_element, "delay") link_options.dup = get_float(options_element, "dup") link_options.mer = get_float(options_element, "mer") link_options.mburst = get_float(options_element, "mburst") link_options.jitter = get_float(options_element, "jitter") link_options.key = get_float(options_element, "key") link_options.per = get_float(options_element, "per") link_options.unidirectional = get_int(options_element, "unidirectional") link_options.session = options_element.get("session") link_options.emulation_id = get_int(options_element, "emulation_id") link_options.network_id = get_int(options_element, "network_id") link_options.opaque = options_element.get("opaque") link_options.gui_attributes = options_element.get("gui_attributes") logger.info("reading link node_one(%s) node_two(%s)", node_one, node_two) self.session.add_link(node_one, node_two, interface_one, interface_two, link_options)