def test_junction_run(): port1 = next(port) port2 = next(port) line1 = ns.TcpLine(port=port1) line2 = ns.TcpLine(port=port2) ns.junction.route(line1, line2) ns.junction.loop.call_later(1, stop_loop, ns.junction.loop) ns.junction.run()
async def init_tcp_junction_impl(expect_json=False, src_to_dst=None): port1 = next(port) port2 = next(port) line1 = ns.TcpLine(port=port1) line2 = ns.TcpLine(port=port2) ns.junction.route(line1, line2, src_to_dst=src_to_dst) await ns.junction.init() await asyncio.sleep(0.1) return (port1, port2)
async def init_tcp2_junction_impl(expect_json=False): port1 = next(port) port2 = next(port) line1 = ns.TcpLine(port=port1, expect_json=expect_json) line2 = ns.TcpLine(port=port2) ns.junction.route(line1, line2) await ns.junction.init() await asyncio.sleep(0.1) return (port1, port2)
async def not_working_for_python_362_test_junction_run(event_loop): port1 = next(port) port2 = next(port) line1 = ns.TcpLine(port=port1) line2 = ns.TcpLine(port=port2) ns.junction.route(line1, line2) ns.junction.loop.call_later(1, stop_loop, ns.junction.loop) ns.junction.run() await ns.junction.shutdown() cancel_tasks()
async def test_name_not_known(event_loop): port1 = 7000 port2 = 4001 line1 = ns.TcpLine(port=port1) line2 = ns.TcpLine(host='no-one', port=port2, remote_is_server=True) ns.junction.route(line1, line2) await ns.junction.init() await asyncio.sleep(30) await ns.junction.shutdown() cancel_tasks()
async def test_remote_is_server(event_loop): # remember to terminate the ascii string message with a newline ('\n') ascii_msg = b"ciao pippo\n" port1 = 7000 port2 = 4001 loop = asyncio.get_event_loop() factory = asyncio.start_server(myserver, 'localhost', port2, family=socket.AF_INET) server = await factory await asyncio.sleep(1) line1 = ns.TcpLine(port=port1) line2 = ns.TcpLine(port=port2, remote_is_server=True) ns.junction.route(line1, line2) await ns.junction.init() #await asyncio.sleep(0.5) #start the clients #reader1, writer1 = await asyncio.open_connection('0.0.0.0', port1) channel = await ns.connect('0.0.0.0', port1) channel.writer.write(ascii_msg) await asyncio.sleep(1) #recv_msg = await ns.msg_receive(reader2) #LOG.debug("msg delivered!: %s", recv_msg) #assert recv_msg == ascii_msg # print("CLOSING") # server.close() # await server.wait_closed() # print("CLOSED") # await asyncio.sleep(5) await ns.junction.shutdown() cancel_tasks()
async def test_tcp_to_ws(event_loop): p1 = next(port) p2 = next(port) start_server = websockets.serve(my_server, 'localhost', p2) x = await start_server line1 = ns.TcpLine(port=p1) line2 = ns.WSLine(port=p2, remote_is_server=True) ns.junction.route(line1, line2) await ns.junction.init() profile = ns.msg.Profile(uid='uid', pwd='pwd') sock = await ns.connect('0.0.0.0', p1) await ns.proto_send(sock, profile) #await sock.close() await asyncio.sleep(3) await ns.junction.shutdown() x.close() await x.wait_closed() cancel_tasks()
async def test_connection_refused(event_loop): port1 = 7000 port2 = 4001 line1 = ns.TcpLine(port=port1) line2 = ns.TcpLine(port=port2, remote_is_server=True) ns.junction.route(line1, line2) await ns.junction.init() await asyncio.sleep(2.5) await ns.junction.shutdown() cancel_tasks()
async def test_mqtt(event_loop): """ mqtt line linked to tcp and ws lines """ topic = "a/b" # start broker broker = hbmqtt.broker.Broker(CONFIG) await broker.start() # start the junction port1 = 1883 port2 = 3001 port3 = 9000 line1 = ns.MqttLine(topic=topic, port=port1) line2 = ns.TcpLine(port=port2) line3 = ns.WSLine(port=port3) ns.junction.route(line1, line2) ns.junction.route(line1, line3) await ns.junction.init() await asyncio.sleep(0.1) #start tcp client channel = await ns.connect('0.0.0.0', port2) #start ws client ws_socket = await ns.wsconnect('0.0.0.0', port3) #start mqtt client mqtt_client = hbmqtt.client.MQTTClient() await mqtt_client.connect('mqtt://127.0.0.1') await mqtt_client.subscribe([('hb/' + topic, QOS_1)]) #send a message from tcp client ascii_msg = b'pippo\n' await ns.msg_send(channel, ascii_msg) json_msg = "'JSON_MSG'" await ws_socket.send(json_msg) #wait for a mqtt packet message = await mqtt_client.deliver_message() LOG.debug("received mqtt message: %s", message.publish_packet.payload.data) await mqtt_client.publish(topic, b'PLUTO\n', QOS_1) response = await ns.msg_receive(channel) #print the response from mqtt LOG.debug("response from mqtt client: %s", response) await mqtt_client.disconnect() await ns.junction.shutdown() await broker.shutdown() cancel_tasks()
def main(serial): """Configure the junction endpoints """ web_page = ns.WSLine(port=3000) if serial: # the real board board = ns.SerialLine() else: # a software simulator or a tcp connected cc3200 board board = ns.TcpLine(port=3001) script = ns.TcpLine(port=3002) # scripting endpoint, eg provisioning # ns.junction.route(src=web_page, dst=board, src_to_dst=to_protobuf, dst_to_src=to_json) ns.junction.route(src=web_page, dst=board, src_to_dst=to_protobuf, dst_to_src=to_json) ns.junction.route(src=board, dst=script) ns.junction.run()
def main(serial): web_page = ns.WSLine(port=3000) if (serial): # the real board board = ns.SerialLine() else: # a software simulator board = ns.TcpLine(port=2001) ns.junction.route(src=web_page, dst=board, src_to_dst=to_protobuf, dst_to_src=to_json) ns.junction.run()
async def test_junction_tcp_init(event_loop, shutdown): board = ns.TcpLine(port=next(port)) await ns.junction.init() await shutdown()