def probe_hardware_map(): # import here so depend on socketIO_client only if needed from r2lab import SidecarSyncClient import ssl ssl_context = ssl.SSLContext() ssl_context.verify_mode = ssl.CERT_NONE with SidecarSyncClient(ssl=ssl_context) as sidecar: nodes_hash = sidecar.nodes_status() if not nodes_hash: print("Could not probe testbed status - exiting") exit(1) # debug #for id in sorted(nodes_hash.keys()): # print(f"node[{id}] = {nodes_hash[id]}") # we search for the nodes that have usrp_type == 'e3372' e3372_ids = [ id for id, node in nodes_hash.items() if node['usrp_type'] == 'e3372' ] # and here the ones that have a b210 with a 'for UE' duplexer oaiue_ids = [ id for id, node in nodes_hash.items() if node['usrp_type'] == 'b210' and 'ue' in node['usrp_duplexer'].lower() ] return { 'E3372-UE': e3372_ids, 'OAI-UE': oaiue_ids, }
def test_nodes(self): client = SidecarSyncClient(LOCAL_SERVER) client.connect() nodes = client.nodes_status() start = nodes[1]['available'] not_start = not_status(start) # invert client.set_node_attribute(1, 'available', not_start) nodes1 = client.nodes_status() self.assertEqual(nodes1[1]['available'], not_start) # put back client.set_node_attribute(1, 'available', not_start) client.close()
def main(): parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter) parser.add_argument('-c', '--cycle', dest='cycle', default=default_cycle, type=float, help="Cycle duration in seconds") parser.add_argument('-r', '--runs', dest='runs', default=default_runs, type=int, help="How many runs - means forever") parser.add_argument('-n', '--nodes', dest='max_nodes_impacted', default=default_max_nodes_impacted, type=int, help="Maximum number of nodes impacted by each cycle") parser.add_argument('-l', '--live', dest='live', action='store_true', default=False, help="If set, only rx/tx data are animated") parser.add_argument('-p', '--phone-cycle', default=5, type=int, help='send a random phone status every n cycles') parser.add_argument("-u", "--sidecar-url", dest="sidecar_url", default=default_sidecar_url, help="url for the sidecar server") parser.add_argument('-v', '--verbose', action='store_true', default=False) args = parser.parse_args() cycle = args.cycle if args.live: to_remove = [ k for k in field_possible_values if 'rx' not in k and 'tx' not in k] for k in to_remove: del field_possible_values[k] if args.verbose: print("Using cycle {}s".format(cycle)) url = args.sidecar_url print("Connecting to sidecar at {}".format(url)) # for connecting to a https endpoint # because by default openssl has no CA installed # - contrary to the browser model - # we turn off server authentication import websockets secure, *_ = websockets.uri.parse_uri(url) kwds = {} if secure: import ssl # kwds.update(dict(ssl=ssl.create_default_context())) kwds.update(dict(ssl=ssl.SSLContext())) with SidecarSyncClient(url, **kwds) as sidecar: counter = 0 payload = SidecarPayload() while True: news_infos = [ random_node_status(id, index) for index, id in enumerate(random_ids(args.max_nodes_impacted)) ] if args.verbose: print("{} -- on {} nodes (id, len(fields)) : {}" .format(counter, len(news_infos), [ (info['id'], len(info)-1) for info in news_infos])) print(news_infos[0]) payload.fill_from_infos(news_infos, category='nodes') sidecar.send_payload(payload) # only one phone if counter % args.phone_cycle == 0: phone_infos = [ random_phone_status(id) for id in [1]] if args.verbose: print("phone: emitting {}".format(phone_infos[0])) payload.fill_from_infos(phone_infos, 'phones') sidecar.send_payload(payload) leases = get_leases() print(f"leases {leases}") if leases: payload.fill_from_infos(leases, 'leases') sidecar.send_payload(payload) counter += 1 if args.runs and counter >= args.runs: break time.sleep(cycle)
def send_infos(infos, sidecar_url): print(f"connecting to {sidecar_url}") with SidecarSyncClient(sidecar_url) as sidecar: payload = SidecarPayload() payload.fill_from_infos(infos, category='nodes') sidecar.send_payload(payload)
def test_ping_with(self): with SidecarSyncClient(LOCAL_SERVER) as client: nodes = client.nodes_status() self.assertIn(nodes[1]['available'], {'ok', 'ko'})
def test_ping_iter(self): client = SidecarSyncClient(LOCAL_SERVER) client.connect() nodes = client.nodes_status() self.assertIn(nodes[1]['available'], {'ok', 'ko'}) client.close()
if args.devel: url = devel_sidecar_url else: url = args.sidecar_url def check_valid(node): return 1 <= node <= 37 invalid_nodes = [node for node in args.nodes if not check_valid(node)] if invalid_nodes: print("Invalid inputs {} - exiting".format(invalid_nodes)) exit(1) triples = [(node, 'available', available_value) for node in args.nodes] import websockets secure, *_ = websockets.uri.parse_uri(url) kwds = {} if secure: import ssl # kwds.update(dict(ssl=ssl.create_default_context())) kwds.update(dict(ssl=ssl.SSLContext())) print("Connecting to sidecar at {}".format(url)) with SidecarSyncClient(url, **kwds) as sidecar: sidecar.set_nodes_triples(*triples)