def run(args): msg_count = int(args[0]) msg_size = int(args[1]) print('Hello from Python pipe_src: msg_count = %d, msg_size = %d' % ( msg_count, msg_size)) # Ins/outs matching with the the model yaml outq = CisOutput('output_pipe') print("pipe_src(P): Created I/O channels") # Send test message multiple times test_msg = '0' * msg_size count = 0 for i in range(msg_count): ret = outq.send(test_msg) if not ret: print('pipe_src(P): SEND ERROR ON MSG %d' % i) break count += 1 ret = outq.send_eof() if not ret: print('pipe_src(P): SEND ERROR ON EOF') print('Goodbye from Python source. Sent %d messages.' % count) return 0
def main(iterations, client_index): r"""Function to execute client communication with server that computes numbers in the Fibonacci sequence. Args: iterations (int): The number of Fibonacci numbers to log. client_index (int): Index of the client in total list of clients. Returns: int: Exit code. Negative if an error occurred. """ exit_code = 0 print('Hello from Python client%d: iterations = %d ' % (client_index, iterations)) # Set up connections matching yaml # RPC client-side connection will be $(server_name)_$(client_name) rpc = CisRpcClient("server_client%d" % client_index, "%d", "%d") log = CisOutput("output_log%d" % client_index, 'fib(%-2d) = %-2d\n') # Iterate over Fibonacci sequence for i in range(1, iterations + 1): # Call the server and receive response print('client%d(Python): Calling fib(%d)' % (client_index, i)) ret, result = rpc.call(i) if not ret: print('client%d(Python): RPC CALL ERROR' % client_index) exit_code = -1 break fib = result[0] print('client%d(Python): Response fib(%d) = %d' % (client_index, i, fib)) # Log result by sending it to the log connection ret = log.send(i, fib) if not ret: print('client%d(Python): SEND ERROR' % client_index) exit_code = -1 break print('Goodbye from Python client%d' % client_index) return exit_code
def run(): print('Hello from Python pipe_dst') # Ins/outs matching with the the model yaml inq = CisInput('input_pipe') outf = CisOutput('output_file') print("pipe_dst(P): Created I/O channels") # Continue receiving input from the queue count = 0 while True: ret, buf = inq.recv() if not ret: print("pipe_dst(P): Input channel closed") break ret = outf.send(buf) if not ret: print("pipe_dst(P): SEND ERROR ON MSG %d" % count) sys.exit(-1) count += 1 print('Goodbye from Python destination. Received %d messages.' % count)
def fibClient(args): iterations = int(args[0]) print('Hello from Python rpcFibCli: iterations = %d ' % iterations) # Set up connections matching yaml # RPC client-side connection will be $(server_name)_$(client_name) ymlfile = CisInput("yaml_in") rpc = CisRpcClient("rpcFibSrv_rpcFibCli", "%d", "%d %d") log = CisOutput("output_log") # Read entire contents of yaml ret, ycontent = ymlfile.recv() if not ret: print('rpcFibCli(P): RECV ERROR') sys.exit(-1) print('rpcFibCli: yaml has %d lines' % len(ycontent.split(backwards.unicode2bytes('\n')))) for i in range(1, iterations + 1): # Call the server and receive response print('rpcFibCli(P): fib(->%-2d) ::: ' % i, end='') ret, fib = rpc.rpcCall(i) if not ret: print('rpcFibCli(P): RPC CALL ERROR') sys.exit(-1) # Log result by sending it to the log connection s = 'fib(%2d<-) = %-2d<-\n' % fib print(s, end='') ret = log.send(s) if not ret: print('rpcFibCli(P): SEND ERROR') sys.exit(-1) print('Goodbye from Python rpcFibCli') sys.exit(0)
def runhello(): print('Hello from Python') # Ins/outs matching with the the model yaml inf = CisInput('inFile') outf = CisOutput('outFile') inq = CisInput('helloQueueIn') outq = CisOutput('helloQueueOut') print("hello(P): Created I/O channels") # Receive input from a local file ret, buf = inf.recv() if not ret: print('hello(P): ERROR FILE RECV') sys.exit(-1) print('hello(P): Received %d bytes from file: %s' % (len(buf), buf)) # Send output to the output queue ret = outq.send(buf) if not ret: print('hello(P): ERROR QUEUE SEND') sys.exit(-1) print('hello(P): Sent to outq') # Receive input form the input queue ret, buf = inq.recv() if not ret: print('hello(P): ERROR QUEUE RECV') sys.exit(-1) print('hello(P): Received %d bytes from queue: %s' % (len(buf), buf)) # Send output to a local file ret = outf.send(buf) if not ret: print('hello(P): ERROR FILE SEND') sys.exit(-1) print('hello(P): Sent to outf') print('Goodbye from Python')
# Import classes for input/output channels from cis_interface.interface.CisInterface import CisInput, CisOutput # Initialize input/output channels in_channel = CisInput('inputA') out_channel = CisOutput('outputA') # Loop until there is no longer input or the queues are closed while True: # Receive input from input channel # If there is an error, the flag will be False flag, msg = in_channel.recv() if not flag: print("Model A: No more input.") break # Print received message print('Model A: %s' % msg) # Send output to output channel # If there is an error, the flag will be False flag = out_channel.send(msg) if not flag: print("Model A: Error sending output.") break
# Import classes for input/output channels from cis_interface.interface.CisInterface import CisInput, CisOutput # Initialize input/output channels in_channel = CisInput('inputB', '%6s\t%d\t%f\n') out_channel = CisOutput('outputB', '%6s\t%d\t%f\n') # Loop until there is no longer input or the queues are closed while True: # Receive input from input channel # If there is an error, the flag will be False flag, msg = in_channel.recv() if not flag: print("Model B: No more input.") break name, count, size = msg # Print received message print('Model B: %s, %d, %f' % (name, count, size)) # Send output to output channel # If there is an error, the flag will be False flag = out_channel.send(name, count, size) if not flag: print("Model B: Error sending output.") break
#!/usr/bin/python import sys from cis_interface.interface.CisInterface import CisInput, CisOutput if __name__ == '__main__': # Get input and output channels matching yaml in1 = CisInput('input1_python') in2 = CisInput('static_python') out1 = CisOutput('output_python') print('SaM(P): Set up I/O channels') # Get input from input1 channel ret, adata = in1.recv() if not ret: print('SaM(P): ERROR RECV from input1') sys.exit(-1) a = int(adata) print('SaM(P): Received %d from input1' % a) # Get input from static channel ret, bdata = in2.recv() if not ret: print('SaM(P): ERROR RECV from static') sys.exit(-1) b = int(bdata) print('SaM(P): Received %d from static' % b) # Compute sum and send message to output channel sum = a + b outdata = '%d' % sum