How to use rebalancing_enabled method in locust

Best Python code snippet using locust

runners.py

Source:runners.py Github

copy

Full Screen

...574 # register listener that sends quit message to worker nodes575 def on_quitting(environment: "Environment", **kw):576 self.quit()577 self.environment.events.quitting.add_listener(on_quitting)578 def rebalancing_enabled(self) -> bool:579 return self.environment.parsed_options is not None and cast(580 bool, self.environment.parsed_options.enable_rebalancing581 )582 @property583 def user_count(self) -> int:584 return sum([c.user_count for c in self.clients.values()])585 def cpu_log_warning(self) -> bool:586 warning_emitted = Runner.cpu_log_warning(self)587 if self.worker_cpu_warning_emitted:588 logger.warning("CPU usage threshold was exceeded on workers during the test!")589 warning_emitted = True590 return warning_emitted591 def start(self, user_count: int, spawn_rate: float, wait=False) -> None:592 self.spawning_completed = False593 self.target_user_count = user_count594 num_workers = len(self.clients.ready) + len(self.clients.running) + len(self.clients.spawning)595 if not num_workers:596 logger.warning("You can't start a distributed test before at least one worker processes has connected")597 return598 for user_class in self.user_classes:599 if self.environment.host:600 user_class.host = self.environment.host601 self.spawn_rate = spawn_rate602 if self._users_dispatcher is None:603 self._users_dispatcher = UsersDispatcher(604 worker_nodes=list(self.clients.values()), user_classes=self.user_classes605 )606 logger.info(607 "Sending spawn jobs of %d users at %.2f spawn rate to %d ready clients"608 % (user_count, spawn_rate, num_workers)609 )610 worker_spawn_rate = float(spawn_rate) / (num_workers or 1)611 if worker_spawn_rate > 100:612 logger.warning(613 "Your selected spawn rate is very high (>100/worker), and this is known to sometimes cause issues. Do you really need to ramp up that fast?"614 )615 if self.state != STATE_RUNNING and self.state != STATE_SPAWNING:616 self.stats.clear_all()617 self.exceptions = {}618 self.environment._filter_tasks_by_tags()619 self.environment.events.test_start.fire(environment=self.environment)620 if self.environment.shape_class:621 self.environment.shape_class.reset_time()622 self.update_state(STATE_SPAWNING)623 self._users_dispatcher.new_dispatch(target_user_count=user_count, spawn_rate=spawn_rate)624 try:625 for dispatched_users in self._users_dispatcher:626 dispatch_greenlets = Group()627 for worker_node_id, worker_user_classes_count in dispatched_users.items():628 data = {629 "timestamp": time.time(),630 "user_classes_count": worker_user_classes_count,631 "host": self.environment.host,632 "stop_timeout": self.environment.stop_timeout,633 "parsed_options": vars(self.environment.parsed_options)634 if self.environment.parsed_options635 else {},636 }637 dispatch_greenlets.add(638 gevent.spawn_later(639 0,640 self.server.send_to_client,641 Message("spawn", data, worker_node_id),642 )643 )644 dispatched_user_count = sum(map(sum, map(methodcaller("values"), dispatched_users.values())))645 logger.debug(646 "Sending spawn messages for %g total users to %i client(s)",647 dispatched_user_count,648 len(dispatch_greenlets),649 )650 dispatch_greenlets.join()651 logger.debug(652 f"Currently spawned users: {_format_user_classes_count_for_log(self.reported_user_classes_count)}"653 )654 self.target_user_classes_count = _aggregate_dispatched_users(dispatched_users)655 except KeyboardInterrupt:656 # TODO: Find a cleaner way to handle that657 # We need to catch keyboard interrupt. Otherwise, if KeyboardInterrupt is received while in658 # a gevent.sleep inside the dispatch_users function, locust won't gracefully shutdown.659 self.quit()660 # Wait a little for workers to report their users to the master661 # so that we can give an accurate log message below and fire the `spawning_complete` event662 # when the user count is really at the desired value.663 timeout = gevent.Timeout(self._wait_for_workers_report_after_ramp_up())664 timeout.start()665 msg_prefix = "All users spawned"666 try:667 while self.user_count != self.target_user_count:668 gevent.sleep(0.01)669 except gevent.Timeout:670 msg_prefix = (671 "Spawning is complete and report waittime is expired, but not all reports received from workers"672 )673 finally:674 timeout.cancel()675 self.environment.events.spawning_complete.fire(user_count=sum(self.target_user_classes_count.values()))676 self.spawning_completed = True677 logger.info(f"{msg_prefix}: {_format_user_classes_count_for_log(self.reported_user_classes_count)}")678 @functools.lru_cache()679 def _wait_for_workers_report_after_ramp_up(self) -> float:680 """681 The amount of time to wait after a ramp-up in order for all the workers to report their state682 to the master. If not supplied by the user, it is 1000ms by default. If the supplied value is a number,683 it is taken as-is. If the supplied value is a pattern like "some_number * WORKER_REPORT_INTERVAL",684 the value will be "some_number * WORKER_REPORT_INTERVAL". The most sensible value would be something685 like "1.25 * WORKER_REPORT_INTERVAL". However, some users might find it too high, so it is left686 to a relatively small value of 1000ms by default.687 """688 locust_wait_for_workers_report_after_ramp_up = os.getenv("LOCUST_WAIT_FOR_WORKERS_REPORT_AFTER_RAMP_UP")689 if locust_wait_for_workers_report_after_ramp_up is None:690 return 1.0691 match = re.search(692 r"^(?P<coeff>(\d+)|(\d+\.\d+))[ ]*\*[ ]*WORKER_REPORT_INTERVAL$",693 locust_wait_for_workers_report_after_ramp_up,694 )695 if match is None:696 assert float(locust_wait_for_workers_report_after_ramp_up) >= 0697 return float(locust_wait_for_workers_report_after_ramp_up)698 else:699 return float(match.group("coeff")) * WORKER_REPORT_INTERVAL700 def stop(self, send_stop_to_client: bool = True) -> None:701 if self.state not in [STATE_INIT, STATE_STOPPED, STATE_STOPPING]:702 logger.debug("Stopping...")703 self.environment.events.test_stopping.fire(environment=self.environment)704 self.final_user_classes_count = {**self.reported_user_classes_count}705 self.update_state(STATE_STOPPING)706 if (707 self.environment.shape_class is not None708 and self.shape_greenlet is not None709 and self.shape_greenlet is not greenlet.getcurrent()710 ):711 self.shape_greenlet.kill(block=True)712 self.shape_greenlet = None713 self.shape_last_state = None714 self._users_dispatcher = None715 if send_stop_to_client:716 for client in self.clients.all:717 logger.debug(f"Sending stop message to client {client.id}")718 self.server.send_to_client(Message("stop", None, client.id))719 # Give an additional 60s for all workers to stop720 timeout = gevent.Timeout(self.environment.stop_timeout or 0 + 60)721 timeout.start()722 try:723 while self.user_count != 0:724 gevent.sleep(1)725 except gevent.Timeout:726 logger.error("Timeout waiting for all workers to stop")727 finally:728 timeout.cancel()729 self.environment.events.test_stop.fire(environment=self.environment)730 def quit(self) -> None:731 self.stop(send_stop_to_client=False)732 logger.debug("Quitting...")733 for client in self.clients.all:734 logger.debug(f"Sending quit message to client {client.id}")735 self.server.send_to_client(Message("quit", None, client.id))736 gevent.sleep(0.5) # wait for final stats report from all workers737 self.greenlet.kill(block=True)738 def check_stopped(self) -> None:739 if (740 not self.state == STATE_INIT741 and not self.state == STATE_STOPPED742 and (743 (744 self.state == STATE_STOPPING745 and all(746 map(747 lambda x: x.state == STATE_INIT,748 self.clients.all,749 )750 )751 )752 )753 or all(754 map(755 lambda x: x.state not in (STATE_RUNNING, STATE_SPAWNING, STATE_INIT),756 self.clients.all,757 )758 )759 ):760 self.update_state(STATE_STOPPED)761 def heartbeat_worker(self) -> NoReturn:762 while True:763 gevent.sleep(HEARTBEAT_INTERVAL)764 if self.connection_broken:765 self.reset_connection()766 continue767 missing_clients_to_be_removed = []768 for client in self.clients.all:769 # if clients goes missing for more than HEARTBEAT_DEAD_INTERNAL then add them to be removed list770 if client.state == STATE_MISSING and client.heartbeat <= HEARTBEAT_DEAD_INTERNAL:771 missing_clients_to_be_removed.append(client.id)772 if client.heartbeat < 0 and client.state != STATE_MISSING:773 logger.info(f"Worker {str(client.id)} failed to send heartbeat, setting state to missing.")774 client.state = STATE_MISSING775 client.user_classes_count = {}776 if self._users_dispatcher is not None:777 self._users_dispatcher.remove_worker(client)778 if self.rebalancing_enabled() and self.state == STATE_RUNNING and self.spawning_completed:779 self.start(self.target_user_count, self.spawn_rate)780 if self.worker_count <= 0:781 logger.info("The last worker went missing, stopping test.")782 self.stop()783 self.check_stopped()784 else:785 client.heartbeat -= 1786 # if there are any missing clients to be removed then remove them and trigger rebalance.787 if len(missing_clients_to_be_removed) > 0:788 for to_remove_client_id in missing_clients_to_be_removed:789 if self.clients.get(to_remove_client_id) is not None:790 del self.clients[to_remove_client_id]791 if self.state == STATE_RUNNING or self.state == STATE_SPAWNING:792 # _users_dispatcher is set to none so that during redistribution the dead clients are not picked, alternative is to call self.stop() before start793 self._users_dispatcher = None794 # trigger redistribution after missing cclient removal795 self.start(user_count=self.target_user_count, spawn_rate=self.spawn_rate)796 def reset_connection(self) -> None:797 logger.info("Resetting RPC server and all client connections.")798 try:799 self.server.close(linger=0)800 self.server = rpc.Server(self.master_bind_host, self.master_bind_port)801 self.connection_broken = False802 except RPCError as e:803 logger.error(f"Temporary failure when resetting connection: {e}, will retry later.")804 def client_listener(self) -> NoReturn:805 while True:806 try:807 client_id, msg = self.server.recv_from_client()808 except RPCReceiveError as e:809 logger.error(f"RPCError when receiving from client: {e}. Will reset client {client_id}.")810 try:811 self.server.send_to_client(Message("reconnect", None, client_id))812 except Exception as e:813 logger.error(f"Error sending reconnect message to client: {e}. Will reset RPC server.")814 self.connection_broken = True815 gevent.sleep(FALLBACK_INTERVAL)816 continue817 except RPCSendError as e:818 logger.error(f"Error sending reconnect message to client: {e}. Will reset RPC server.")819 self.connection_broken = True820 gevent.sleep(FALLBACK_INTERVAL)821 continue822 except RPCError as e:823 if self.clients.ready or self.clients.spawning or self.clients.running:824 logger.error(f"RPCError: {e}. Will reset RPC server.")825 else:826 logger.debug(827 "RPCError when receiving from client: %s (but no clients were expected to be connected anyway)"828 % (e)829 )830 self.connection_broken = True831 gevent.sleep(FALLBACK_INTERVAL)832 continue833 msg.node_id = client_id834 if msg.type == "client_ready":835 if not msg.data:836 logger.error(f"An old (pre 2.0) worker tried to connect ({client_id}). That's not going to work.")837 continue838 elif msg.data != __version__ and msg.data != -1:839 if msg.data[0:4] == __version__[0:4]:840 logger.debug(841 f"A worker ({client_id}) running a different patch version ({msg.data}) connected, master version is {__version__}"842 )843 else:844 logger.warning(845 f"A worker ({client_id}) running a different version ({msg.data}) connected, master version is {__version__}"846 )847 self.send_message("ack", client_id=client_id)848 worker_node_id = msg.node_id849 self.clients[worker_node_id] = WorkerNode(worker_node_id, heartbeat_liveness=HEARTBEAT_LIVENESS)850 if self._users_dispatcher is not None:851 self._users_dispatcher.add_worker(worker_node=self.clients[worker_node_id])852 if not self._users_dispatcher.dispatch_in_progress and self.state == STATE_RUNNING:853 # TODO: Test this situation854 self.start(self.target_user_count, self.spawn_rate)855 logger.info(856 "Client %r reported as ready. Currently %i clients ready to swarm."857 % (worker_node_id, len(self.clients.ready + self.clients.running + self.clients.spawning))858 )859 if self.rebalancing_enabled() and self.state == STATE_RUNNING and self.spawning_completed:860 self.start(self.target_user_count, self.spawn_rate)861 # emit a warning if the worker's clock seem to be out of sync with our clock862 # if abs(time() - msg.data["time"]) > 5.0:863 # warnings.warn("The worker node's clock seem to be out of sync. For the statistics to be correct the different locust servers need to have synchronized clocks.")864 elif msg.type == "client_stopped":865 if msg.node_id not in self.clients:866 logger.warning(f"Received {msg.type} message from an unknown client: {msg.node_id}.")867 continue868 client = self.clients[msg.node_id]869 del self.clients[msg.node_id]870 if self._users_dispatcher is not None:871 self._users_dispatcher.remove_worker(client)872 if not self._users_dispatcher.dispatch_in_progress and self.state == STATE_RUNNING:873 # TODO: Test this situation...

Full Screen

Full Screen

create_topo_ned_file.py

Source:create_topo_ned_file.py Github

copy

Full Screen

1import sys2import textwrap3import argparse4import networkx as nx5from config import *6import re7import os8import math9import random10import numpy as np11def parse_node_name(node_name, max_router, max_host):12 try:13 val = int(node_name[:-1])14 if(node_name[-1] == 'r'):15 if(val > max_router):16 max_router = val17 return ("router[" + str(val) + "]", max_router, max_host)18 if(node_name[-1] == 'e'):19 if(val > max_host):20 max_host = val21 return ("host[" + str(val) + "]", max_router, max_host)22 return -123 except:24 return -125# take the topology file in a specific format and write it to a ned file26def write_ned_file(topo_filename, output_filename, network_name, routing_alg):27 # topo_filename must be a text file where each line contains the ids of two neighbouring nodes that 28 # have a payment channel between them, relative delays in each direction, initial balance on each 29 # end (see sample-topology.txt)30 # each line is of form:31 # [node1] [node2] [1->2 delay] [2->1 delay] [balance @ 1] [balance @ 2]32 topo_file = open(topo_filename).readlines() 33 outfile = open(output_filename, "w")34 # metadata used for forwarding table35 neighbor_interfaces = dict()36 node_interface_count = dict()37 node_used_interface = dict()38 linklist = list()39 max_val = -1 #used to find number of nodes, assume nodes start at 0 and number consecutively40 max_router = -141 max_host = -142 line_num = 043 for line in topo_file:44 line_num += 145 # landmark line46 if line_num == 1:47 continue48 if line == "\n":49 continue50 n1 = parse_node_name(line.split()[0], max_router, max_host)51 if(n1 == -1):52 print("Bad line " + line)53 continue54 max_router = n1[1]55 max_host = n1[2]56 n2 = parse_node_name(line.split()[1], max_router, max_host)57 if(n2 == -1):58 print("Bad line " + line)59 continue60 max_router = n2[1]61 max_host = n2[2]62 n3 = float(line.split()[2]) # delay going from n1 to n263 n4 = float(line.split()[3]) # delay going from n2 to n164 linklist.append((n1[0], n2[0], n3, n4))65 max_router = max_router + 166 max_host = max_host + 167 # generic routerNode and hostNode definition that every network will have68 print(routing_alg)69 if (routing_alg == 'shortestPath'):70 host_node_type = 'hostNodeBase'71 router_node_type = 'routerNodeBase'72 else:73 if routing_alg == 'DCTCPBal' or routing_alg == 'DCTCPQ' or routing_alg == 'TCP' or routing_alg == 'TCPCubic':74 host_node_type = 'hostNodeDCTCP'75 elif routing_alg == 'DCTCPRate':76 host_node_type = 'hostNodePropFairPriceScheme'77 else:78 host_node_type = 'hostNode' + routing_alg[0].upper() + routing_alg[1:]79 80 if routing_alg == 'landmarkRouting':81 router_node_type = 'routerNodeWaterfilling'82 elif routing_alg == 'DCTCPRate' or routing_alg == 'DCTCPQ' or routing_alg == 'TCP' or routing_alg == 'TCPCubic':83 router_node_type = 'routerNodeDCTCP'84 else:85 router_node_type = 'routerNode' + routing_alg[0].upper() + routing_alg[1:]86 print(router_node_type)87 outfile.write("import " + router_node_type + ";\n")88 outfile.write("import " + host_node_type + ";\n\n")89 outfile.write("network " + network_name + "_" + routing_alg + "\n")90 outfile.write("{\n")91 # This script (meant for a simpler datacenter topology) just assigns the same link delay to all links.92 # You need to change this such that the parameter values are instead assigned on a per node basis and 93 # are read from an additional 'delay' column and 'channel balance' columns in the text file.94 outfile.write('\tparameters:\n\t\tdouble linkDelay @unit("s") = default(100us);\n')95 outfile.write('\t\tdouble linkDataRate @unit("Gbps") = default(1Gbps);\n')96 outfile.write('\tsubmodules:\n')97 outfile.write('\t\thost['+str(max_host)+']: ' + host_node_type + ' {} \n')98 outfile.write('\t\trouter['+str(max_router)+']: ' + router_node_type + ' {} \n')99 outfile.write('\tconnections: \n')100 for link in linklist:101 a = link[0]102 b = link[1]103 abDelay = link[2]104 baDelay = link[3]105 outfile.write('\t\t' + a + '.out++ --> {delay = ' + str(abDelay) +'ms; }')106 outfile.write(' --> ' + b + '.in++; \n')107 outfile.write('\t\t' + a + '.in++ <-- {delay = ' + str(baDelay) +'ms; }')108 outfile.write(' <-- ' + b + '.out++; \n')109 outfile.write('}\n')110# generate either a small world or scale free graph111def generate_graph(size, graph_type):112 if graph_type == 'random':113 G = nx.dense_gnm_random_graph(size, size * 5,seed=SEED)114 elif graph_type == 'small_world':115 G = nx.watts_strogatz_graph(size, 8, 0.25, seed=SEED)116 elif graph_type == 'small_world_sparse':117 G = nx.watts_strogatz_graph(size, size/8, 0.25, seed=SEED)118 elif graph_type == 'scale_free':119 # regular expts120 G = nx.barabasi_albert_graph(size, 8, seed=SEED) 121 # implementation, celer expts - 10 node graph122 # G = nx.barabasi_albert_graph(size, 5, seed=12)123 elif graph_type == 'scale_free_sparse':124 G = nx.barabasi_albert_graph(size, size/8, seed=SEED)125 elif graph_type == 'tree':126 G = nx.random_tree(size, seed=SEED)127 # remove self loops and parallel edges128 G.remove_edges_from(G.selfloop_edges())129 G = nx.Graph(G)130 print('Generated a ', graph_type, ' graph')131 print('number of nodes: ', G.number_of_nodes())132 print('Number of Edges: ', G.number_of_edges())133 print('Number of connected components: ', nx.number_connected_components(G))134 return G135# print the output in the desired format for write_ned_file to read136# generate extra end host nodes if need be137# make the first line list of landmarks for this topology138def print_topology_in_format(G, balance_per_channel, delay_per_channel, output_filename, separate_end_hosts,\139 randomize_init_bal=False, random_channel_capacity=False, lnd_capacity=False, is_lnd=False, rebalancing_enabled=False):140 f1 = open(output_filename, "w+")141 end_host_delay = delay_per_channel142 offset = G.number_of_nodes()143 if (separate_end_hosts == False):144 offset = 0145 nodes_sorted_by_degree = sorted(G.degree, key=lambda x: x[1], reverse=True)146 # generate landmarks based on degree147 i = 0148 landmarks, current_list = [], []149 max_degree = -1150 while len(landmarks) < NUM_LANDMARKS and i < len(nodes_sorted_by_degree):151 num_remaining = NUM_LANDMARKS - len(landmarks)152 if nodes_sorted_by_degree[i][1] == max_degree:153 current_list.append(nodes_sorted_by_degree[i][0])154 else:155 spaced_indices = np.round(np.linspace(0, len(current_list)-1, \156 min(num_remaining, len(current_list)))).astype(int)157 if max_degree != -1:158 landmarks.extend([current_list[x] for x in spaced_indices])159 current_list = [nodes_sorted_by_degree[i][0]]160 max_degree = nodes_sorted_by_degree[i][1]161 i += 1162 if len(landmarks) < NUM_LANDMARKS:163 spaced_indices = np.round(np.linspace(0, len(current_list)-1, \164 min(num_remaining, len(current_list)))).astype(int)165 landmarks.extend([current_list[x] for x in spaced_indices])166 167 # make the first line the landmarks and make them all router nodes168 for l in landmarks[:NUM_LANDMARKS]:169 f1.write(str(l) + "r ")170 f1.write("\n")171 total_budget = balance_per_channel * len(G.edges())172 weights = {e: min(G.degree(e[0]), G.degree(e[1])) for e in G.edges()}173 sum_weights = sum(weights.values())174 capacity_dict = dict()175 # get lnd capacity data176 lnd_capacities_graph = nx.read_edgelist(LND_FILE_PATH + 'lnd_july15_2019_reducedsize' + '.edgelist')177 lnd_capacities = list(nx.get_edge_attributes(lnd_capacities_graph, 'capacity').values()) 178 # write rest of topology179 real_rtts = np.loadtxt(LND_FILE_PATH + "ping_times_data")180 for e in G.edges():181 f1.write(str(e[0]) + "r " + str(e[1]) + "r ")182 183 if not random_channel_capacity and is_lnd and "uniform" not in output_filename:184 delay_per_channel = np.random.choice(real_rtts) / 2.0185 f1.write(str(delay_per_channel) + " " + str(delay_per_channel) + " ")186 else:187 f1.write(str(delay_per_channel) + " " + str(delay_per_channel) + " ")188 189 if random_channel_capacity:190 balance_for_this_channel = -1191 while balance_for_this_channel < 2:192 balance_for_this_channel = round(np.random.normal(balance_per_channel, \193 0.75 * balance_per_channel))194 195 elif lnd_capacity:196 balance_for_this_channel = -1197 while balance_for_this_channel < 40:198 balance_for_this_channel = round(np.random.choice(lnd_capacities) * \199 (balance_per_channel / np.mean(lnd_capacities)))200 201 elif is_lnd and "uniform" not in output_filename:202 if "lessScale" in output_filename:203 balance_for_this_channel = int(round(G[e[0]][e[1]]['capacity'] *10 * balance_per_channel))204 else:205 balance_for_this_channel = int(round(G[e[0]][e[1]]['capacity'] * balance_per_channel))206 207 else:208 balance_for_this_channel = balance_per_channel209 capacity_dict[e] = balance_for_this_channel210 if randomize_init_bal:211 one_end_bal = random.randint(1, balance_for_this_channel)212 other_end_bal = balance_for_this_channel - one_end_bal213 f1.write(str(one_end_bal) + " " + str(other_end_bal) + "\n")214 else:215 f1.write(str(round(balance_for_this_channel/2)) + " " + \216 str(round(balance_for_this_channel/2)) + "\n")217 # generate extra end host nodes218 if separate_end_hosts : 219 for n in G.nodes():220 f1.write(str(n) + "e " + str(n) + "r ")221 f1.write(str(end_host_delay) + " " + str(end_host_delay) + " ")222 if rebalancing_enabled:223 f1.write(str(REASONABLE_BALANCE) + " " + str(REASONABLE_ROUTER_BALANCE) + "\n")224 else:225 f1.write(str(LARGE_BALANCE/2) + " " + str(LARGE_BALANCE/2) + "\n")226 if args.graph_type == "parallel_graph":227 for (e,r) in zip([1,3], [0, 2]):228 f1.write(str(e) + "e " + str(r) + "r ")229 f1.write(str(end_host_delay) + " " + str(end_host_delay) + " ")230 f1.write(str(LARGE_BALANCE/2) + " " + str(LARGE_BALANCE/2) + "\n")231 f1.close()232 nx.set_edge_attributes(G, capacity_dict, 'capacity')233# parse arguments234parser = argparse.ArgumentParser(description="Create arbitrary topologies to run the omnet simulator on")235parser.add_argument('--num-nodes', type=int, dest='num_nodes', help='number of nodes in the graph', default=20)236parser.add_argument('--delay-per-channel', type=int, dest='delay_per_channel', \237 help='delay between nodes (ms)', default=30)238parser.add_argument('graph_type', choices=['small_world', 'scale_free', 'hotnets_topo', 'simple_line', 'toy_dctcp', \239 'simple_deadlock', 'simple_topologies', 'parallel_graph', 'dag_example', 'lnd_dec4_2018','lnd_dec4_2018lessScale', \240 'lnd_dec4_2018_randomCap', 'lnd_dec4_2018_modified', 'lnd_uniform', 'tree', 'random', \241 'lnd_july15_2019'], \242 help='type of graph (Small world or scale free or custom topology list)', default='small_world')243parser.add_argument('--balance-per-channel', type=int, dest='balance_per_channel', default=100)244parser.add_argument('--topo-filename', dest='topo_filename', type=str, \245 help='name of intermediate output file', default="topo.txt")246parser.add_argument('--network-name', type=str, dest='network_name', \247 help='name of the output ned filename', default='simpleNet')248parser.add_argument('--separate-end-hosts', action='store_true', \249 help='do you need separate end hosts that only send transactions')250parser.add_argument('--randomize-start-bal', type=str, dest='randomize_start_bal', \251 help='Do not start from pergect balance, but rather randomize it', default='False')252parser.add_argument('--random-channel-capacity', type=str, dest='random_channel_capacity', \253 help='Give channels a random balance between bal/2 and bal', default='False')254parser.add_argument('--lnd-channel-capacity', type=str, dest='lnd_capacity', \255 help='Give channels a random balance sampled from lnd', default='False')256parser.add_argument('--rebalancing-enabled', type=str, dest="rebalancing_enabled",\257 help="should the end host router channel be reasonably sized", default="false")258routing_alg_list = ['shortestPath', 'priceScheme', 'waterfilling', 'landmarkRouting', 'lndBaseline', \259 'DCTCP', 'DCTCPBal', 'DCTCPRate', 'DCTCPQ', 'TCP', 'TCPCubic', 'celer']260args = parser.parse_args()261np.random.seed(SEED)262random.seed(SEED)263# generate graph and print topology and ned file264if args.num_nodes <= 5 and args.graph_type == 'simple_topologies':265 if args.num_nodes == 2:266 G = two_node_graph267 elif args.num_nodes == 3:268 G = three_node_graph269 elif args.num_nodes == 4:270 G = four_node_graph271 elif 'line' in args.network_name:272 G = five_line_graph273 else:274 G = five_node_graph275elif args.graph_type in ['small_world', 'scale_free', 'tree', 'random']:276 if "sparse" in args.topo_filename:277 args.graph_type = args.graph_type + "_sparse"278 G = generate_graph(args.num_nodes, args.graph_type)279elif args.graph_type == 'toy_dctcp':280 G = toy_dctcp_graph281elif args.graph_type == 'dag_example':282 print("generating dag example")283 G = dag_example_graph284elif args.graph_type == 'parallel_graph':285 G = parallel_graph286elif args.graph_type == 'hotnets_topo':287 G = hotnets_topo_graph288elif args.graph_type == 'simple_deadlock':289 G = simple_deadlock_graph290 args.separate_end_hosts = False291elif args.graph_type.startswith('lnd_'):292 G = nx.read_edgelist(LND_FILE_PATH + 'lnd_july15_2019_reducedsize' + '.edgelist')293else:294 G = simple_line_graph295 args.separate_end_hosts = False296args.randomize_start_bal = args.randomize_start_bal == 'true'297args.random_channel_capacity = args.random_channel_capacity == 'true'298args.lnd_capacity = args.lnd_capacity == 'true'299print_topology_in_format(G, args.balance_per_channel, args.delay_per_channel, args.topo_filename, \300 args.separate_end_hosts, args.randomize_start_bal, args.random_channel_capacity,\301 args.lnd_capacity, args.graph_type.startswith('lnd_'), args.rebalancing_enabled == "true")302network_base = os.path.basename(args.network_name)303for routing_alg in routing_alg_list:304 write_ned_file(args.topo_filename, args.network_name + '_' + routing_alg + '.ned', \...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful