int main(int argc, char *argv[]) { if (argc < 4) { printf("Syntax: %s <TOP local IP> <BOT local IP> <forward IP>\n", argv[0]); return 1; } struct in_addr top_ip; struct in_addr bot_ip; struct in_addr fwd_ip; struct in_addr netmask; inet_aton(argv[1], &top_ip); inet_aton(argv[2], &bot_ip); inet_aton(argv[3], &fwd_ip); inet_aton("255.255.255.0", &netmask); uint16_t port = 7653; printf("EthFwd: TOP IP '%s', BOT IP '%s', Forward IP '%s', port %u\n", argv[1], argv[2], argv[3], port); max_file_t *maxfile = EthFwd_init(); max_engine_t * engine = max_load(maxfile, "*"); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &top_ip, &netmask); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &bot_ip, &netmask); struct ether_addr local_mac2, remote_mac2; max_arp_lookup_entry(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &fwd_ip, &remote_mac2); max_eth_get_default_mac_address(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &local_mac2); uint64_t localMac = 0, forwardMac = 0; memcpy(&localMac, &local_mac2, 6); memcpy(&forwardMac, &remote_mac2, 6); max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); max_actions_t *action = max_actions_init(maxfile, NULL); max_set_uint64t(action, "fwdKernel", "localIp", bot_ip.s_addr); max_set_uint64t(action, "fwdKernel", "forwardIp", fwd_ip.s_addr); max_set_uint64t(action, "fwdKernel", "localMac", localMac); max_set_uint64t(action, "fwdKernel", "forwardMac", forwardMac); max_set_uint64t(action, "fwdKernel", "port", port); max_run(engine, action); printf("JDFE Running.\n"); getchar(); max_unload(engine); max_file_free(maxfile); printf("Done.\n"); return 0; }
int main(int argc, char *argv[]) { if (argc != 3) { printf("Usage: %s <dfe_ip> <netmask>\n", argv[0]); return 1; } uint16_t Nsockets = 1; const int port = 80; struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr netmask; inet_aton(argv[2], &netmask); // initialization files for crcIndex table, generated by init_code char fileCrcIndex1[] = "./results/romCrcIndex1_init.html"; char fileCrcIndex2[] = "./results/romCrcIndex2_init.html"; // LMEM initialization file location, generated by init_code char fileLmem[] = "./results/lmem_generated_file.html"; uint64_t *arrCrc1; uint64_t *arrCrc2; long Lcrc; FILE *fpCrc1 = fopen(fileCrcIndex1, "rb"); FILE *fpCrc2 = fopen(fileCrcIndex2, "rb"); FILE *fpLmem = fopen(fileLmem, "rb"); if (!(fpCrc1 && fpCrc2 && fpLmem)) { printf("Error with file\n"); exit(0); } // obtain file size fseek(fpCrc1, 0, SEEK_END); Lcrc = ftell(fpCrc1); rewind(fpCrc1); fillRomCrcIndex(fpCrc1, &arrCrc1, Lcrc); fillRomCrcIndex(fpCrc2, &arrCrc2, Lcrc); printf("Preparing for init() and max_load()\n"); max_file_t *maxfile = httpserver_init(); max_engine_t * engine = max_load(maxfile, "*"); printf("Done\n"); max_actions_t *actions = max_actions_init(maxfile, NULL); int romDepthCrc = Lcrc / 8; for (uint32_t i = 0; i < romDepthCrc; i++) { max_set_mem_uint64t(actions, "CrcIndexTable", "romCrcIndex1", i, arrCrc1[i]); max_set_mem_uint64t(actions, "CrcIndexTable", "romCrcIndex2", i, arrCrc2[i]); } max_run(engine, actions); max_actions_free(actions); long L; size_t result; uint64_t* arrLmem; // obtain file size fseek(fpLmem, 0, SEEK_END); L = ftell(fpLmem); rewind(fpLmem); double diff = ceil(L / 8.0) - L / 8.0; // NULL character padding if (diff != 0) { L = (int) ceil(L / 8.0) * 8; } // allocate memory to contain the whole file size_t Nelem = sizeof(uint64_t) * (L / 8); arrLmem = (uint64_t*) malloc(Nelem); result = fread(arrLmem, 1, L, fpLmem); int romDepth = L / 8; int burstLengthInBytes = max_get_burst_size(maxfile, "cmd_tolmem"); inline int max(int a, int b) { return a > b ? a : b; } ; const int size = romDepth; int sizeBytes = size * sizeof(uint64_t); uint64_t *inData; printf("Writing to DFE memory.\n"); inData = arrLmem; writeDataToLMem(inData, size, sizeBytes, burstLengthInBytes, engine, maxfile); printf("Done\n"); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &dfe_ip, &netmask); //all sockets MUST be created before first call to max_tcp_connect or max_tcp_listen max_tcp_socket_t *(dfe_socket[Nsockets]); uint16_t socketNumber[Nsockets]; for (int i = 0; i < Nsockets; i++) { //dfe_socket[i] = max_tcp_create_socket(engine, "tcp_ISCA_QSFP_BOT_10G_PORT1"); dfe_socket[i] = max_tcp_create_socket_with_number(engine, "tcp_ISCA_QSFP_BOT_10G_PORT1", i); socketNumber[i] = max_tcp_get_socket_number(dfe_socket[i]); printf("Socket %d was assigned socket number %u\n", i, socketNumber[i]); } for (int i = 0; i < Nsockets; i++) { max_tcp_listen(dfe_socket[i], port + i); max_tcp_await_state(dfe_socket[i], MAX_TCP_STATE_LISTEN, NULL); } printf("CPU code: Total %u socket(s), listening on the port(s) %u-%u\n\n", Nsockets, port, port + Nsockets - 1); void *read_ptr; uint8_t *read_buffer; max_llstream_t *read_llstream; uint64_t *byteNumber; printf("CPU code: Setting up 'toCpuByteNumber' stream.\n"); int Nslots_byteNumber = 512; size_t tCBN_buffer_size = Nslots_byteNumber * 16; posix_memalign((void *) &read_buffer, 4096, tCBN_buffer_size); read_llstream = max_llstream_setup(engine, "toCpuFileSizeBytes", Nslots_byteNumber, 16, read_buffer); uint8_t *read_buffer_socket; max_llstream_t *read_llstream_socket; printf("CPU code: Setting up 'toCpuSocketNumber' stream.\n"); int Nslots_socketNumber = 512; size_t tCSB_buffer_size = Nslots_socketNumber * 16; posix_memalign((void *) &read_buffer_socket, 4096, tCSB_buffer_size); read_llstream_socket = max_llstream_setup(engine, "toCpuSocketNumber", Nslots_socketNumber, 16, read_buffer_socket); void *read_ptr_socket_slot; uint16_t ti = 10; while(ti > 0) { printf("CPU code: time=%u, waiting file size and socket numbers stream data to be sent to CPU\n", ti); usleep(1000*1000*1); ti--; } //while(1); uint64_t num_rx_bytes; uint64_t num_tx_bytes; uint8_t session_id; while (1) { //part 1: first wait to receive LengthBytes number printf("CPU code: PART 1 - waiting to receive LengthBytes number\n"); int FoundByteNumber = 0; ti=0; while (FoundByteNumber != 1) //first wait to receive LengthBytes number { usleep(1000*1000*1); for (int i = 0; i < Nsockets; i++) { max_tcp_get_num_bytes_received(dfe_socket[i], &num_rx_bytes); max_tcp_get_num_bytes_transmitted(dfe_socket[i], &num_tx_bytes, &session_id); printf("CPU code: waiting, time=%u, port=%u, socket=%i, max_tcp_get_num_bytes_received=%llu, max_tcp_get_num_bytes_transmitted=%llu\n", ti, port + i, i, (long long unsigned int) num_rx_bytes, (long long unsigned int) num_tx_bytes); } ti++; uint8_t ii = max_llstream_read(read_llstream, 1, &read_ptr); if (ii) { byteNumber = (uint64_t*) read_ptr; printf("CPU code: number of slots found to contain new data=%u, fileSizeBytes=%u\n", ii, (unsigned int) *byteNumber); max_llstream_read_discard(read_llstream, 1); FoundByteNumber = 1; } } //part 2: receive total number of data transfered printf("CPU code: PART 2 - receive socket number\n"); while (max_llstream_read(read_llstream_socket, 1, &read_ptr_socket_slot) == 0) ; uint16_t socket_returned = (uint16_t) *((uint16_t*) read_ptr_socket_slot); //event->socketID; unsigned int fileBytes = (unsigned int) *byteNumber; printf("CPU code: fileBytes=%u, socket_returned=%u\n", fileBytes, socket_returned); ti = 0; while (1) { { for (int i = 0; i < Nsockets; i++) { max_tcp_get_num_bytes_received(dfe_socket[i], &num_rx_bytes); max_tcp_get_num_bytes_transmitted(dfe_socket[i], &num_tx_bytes, &session_id); printf("CPU code: time=%i, port=%u, socket=%i, max_tcp_get_num_bytes_received=%llu, max_tcp_get_num_bytes_transmitted=%llu\n", ti, port + i, i, (long long unsigned int) num_rx_bytes, (long long unsigned int) num_tx_bytes); } ti++; printf("\n"); max_tcp_get_num_bytes_transmitted(dfe_socket[socket_returned], &num_tx_bytes, &session_id); printf("CPU code: fileSizeBytes=%u, socketReturned=%u, num_tx_bytes=%llu\n", fileBytes, socket_returned, (long long unsigned int) num_tx_bytes); } //usleep(1000*100); //printf("CPU code: While LOOP, socket_returned=%u, fileBytes=%u, num_tx_bytes(max_tcp_get_num_bytes_transmitted)=%llu\n", socket_returned, fileBytes, (long long unsigned int) num_tx_bytes); if (num_tx_bytes == fileBytes) { //usleep(1000*1000*3); printf("CPU code: MATCH num_tx_bytes==fileBytes, socket_returned=%u, fileBytes=%u, num_tx_bytes(max_tcp_get_num_bytes_transmitted)=%llu\n", socket_returned, fileBytes, (long long unsigned int) num_tx_bytes); printf("CPU code: Closing socket=%u\n", socket_returned); max_tcp_close(dfe_socket[socket_returned]); //max_tcp_close_mode_t close_mode=MAX_TCP_CLOSE_ABORT_RESET; //max_tcp_close_advanced(dfe_socket[socket_returned],close_mode); printf("CPU code: Waiting for MAX_TCP_STATE_CLOSED\n"); max_tcp_await_state(dfe_socket[socket_returned], MAX_TCP_STATE_CLOSED, NULL); printf("CPU code: Set LISTEN state\n"); max_tcp_listen(dfe_socket[socket_returned], port); printf("CPU code: Waiting for MAX_TCP_STATE_LISTEN\n"); max_tcp_await_state(dfe_socket[socket_returned], MAX_TCP_STATE_LISTEN, NULL); printf("CPU code: Again opened socket=%u\n", socket_returned); printf("\nCPU code: State of rx/tx after socket closing\n"); break; } usleep(1000*1000*1); } } for (int i = 0; i < Nsockets; i++) { max_tcp_close(dfe_socket[i]); printf("max_tcp_close(dfe_socket[i])"); } max_unload(engine); printf("max_unload(engine)"); max_file_free(maxfile); printf("max_file_free(maxfile)"); printf("The end\n"); return 0; }
int main(int argc, char *argv[]) { if(argc != 4) { printf("Usage: %s <dfe_ip> <cpu_ip> <netmask>\n", argv[0]); return 1; } struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr cpu_ip; inet_aton(argv[2], &cpu_ip); struct in_addr netmask; inet_aton(argv[3], &netmask); const int port = 5008; /* Create DFE Socket, then listen */ max_file_t *maxfile = FieldAccumulatorTCP_init(); max_engine_t *engine = max_load(maxfile, "*"); max_ip_config(engine, MAX_NET_CONNECTION_CH2_SFP1, &dfe_ip, &netmask); max_udp_socket_t *dfe_socket = max_udp_create_socket(engine, "udp_ch2_sfp1"); max_udp_bind(dfe_socket, port); max_udp_connect(dfe_socket, &cpu_ip, port); int cpu_socket = create_cpu_udp_socket(&cpu_ip, &dfe_ip, port); FILE *stream = fopen("source_data1.csv", "r"); char line[BUFFERSIZE]; // char *to_be_free = line; /* Ignore Header File */ fgets(line, BUFFERSIZE, stream); printf(line); while (fgets(line, BUFFERSIZE, stream)) { struct input_data data; parse(line,&data); printf("\n Instrument id = %d \n level = %d \n side = %d \n Quantity = %d \n Price = %d",data.instrument_id,data.level,data.side,data.quantity,data.price); calculateDeltas(cpu_socket, &data); } // /* Set Value A */ // data.instrument_id = 0; // data.level = 0; // data.side = 0; // data.quantity = 5; // data.price = 10; // calculateDeltas(cpu_socket, &data); // // /* Set B*/ // data.instrument_id = 1; // data.level = 0; // data.side = 1; // data.quantity = 3; // data.price = 4; // calculateDeltas(cpu_socket, &data); // // /* Hold */ // data.instrument_id = 1; // data.level = 0; // data.side = 1; // data.quantity = 5; // data.price = 6; // calculateDeltas(cpu_socket, &data); // // /* Set AB */ // data.instrument_id = 2; // data.level = 0; // data.side = 1; // data.quantity = 7; // data.price = 8; // calculateDeltas(cpu_socket, &data); max_udp_close(dfe_socket); max_unload(engine); max_file_free(maxfile); return 0; }
int main(int argc, char *argv[]) { if(argc < 3) { printf("Usage: $0 dfe_ip cpu_ip\n"); return 1; } struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr cpu_ip; inet_aton(argv[2], &cpu_ip); struct in_addr netmask; inet_aton("255.255.255.0", &netmask); const int port = 5007; max_file_t *maxfile = Tracker_init(); max_engine_t * engine = max_load(maxfile, "*"); max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); max_actions_t *actions = max_actions_init(maxfile, NULL); char regName[32]; for (int i=0; i < 1024; i++) { sprintf(regName, "filter_%d", i); if (i == 150) { max_set_uint64t(actions, "filteringKernel", regName, 0xCC /* a value to match... */); } else { max_set_uint64t(actions, "filteringKernel", regName, 0x4D1B /* or any value you want */); } } max_run(engine, actions); max_actions_free(actions); void *buffer; size_t bufferSize = 4096 * 512; posix_memalign(&buffer, 4096, bufferSize); max_framed_stream_t *toCpu = max_framed_stream_setup(engine, "toCPU", buffer, bufferSize, -1); /* * This executable both creates a normal Linux UDP socket as well as a DFE UDP Socket. * We then exchange data between the two. */ // DFE Socket max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &dfe_ip, &netmask); max_udp_socket_t *dfe_socket = max_udp_create_socket(engine, "udpTopPort1"); max_udp_bind(dfe_socket, port); max_udp_connect(dfe_socket, &cpu_ip, port); // Linux Socket int cpu_socket = create_cpu_udp_socket(&cpu_ip, &dfe_ip, port); printf("Sending test frame...\n"); sendTestFrame(cpu_socket); printf("Waiting for kernel response...\n"); fflush(stdout); void *f; size_t fsz; size_t numMessageRx = 0; uint8_t received_data[512]; while (numMessageRx < NUM_MESSAGES_EXPECTED) { if (max_framed_stream_read(toCpu, 1, &f, &fsz) == 1) { printf("CPU: Got output frame - size %zd - NumMsg = %zd!\n", fsz, numMessageRx); // Frame size would be rounded up to the next 8 bytes. memcpy(received_data, f, fsz); numMessageRx++; max_framed_stream_discard(toCpu, 1); } else usleep(10); } max_udp_close(dfe_socket); max_unload(engine); max_file_free(maxfile); printf("Done.\n"); fflush(stdout); return 0; }
int main(int argc, char *argv[]) { if(argc < 3) { printf("Usage: $0 dfe_ip remote_ip\n"); return 1; } struct in_addr dfe_ip; inet_aton(argv[1], &dfe_ip); struct in_addr remote_ip; inet_aton(argv[2], &remote_ip); struct in_addr netmask; inet_aton("255.255.255.0", &netmask); const int in_port = 2000; const int out_port = 2000; // struct in_addr mcastaddr; // inet_aton("224.0.0.1", &mcastaddr); max_file_t *maxfile = SignExtWithPatternMatching_init(); max_engine_t * engine = max_load(maxfile, "*"); max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true); max_actions_t *actions = max_actions_init(maxfile, NULL); max_run(engine, actions); max_actions_free(actions); void *buffer; size_t bufferSize = 4096 * 512; posix_memalign(&buffer, 4096, bufferSize); max_framed_stream_t *toCpu = max_framed_stream_setup(engine, "toCPU", buffer, bufferSize, -1); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &dfe_ip, &netmask); max_udp_socket_t *dfe_socket = max_udp_create_socket(engine, "udpTopPort1"); // max_ip_multicast_join_group(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &mcastaddr); // max_udp_bind_ip(dfe_socket, &mcastaddr, in_port); max_udp_bind(dfe_socket, in_port); max_udp_connect(dfe_socket, &remote_ip, out_port); printf("Listening on %s in_port %d\n", argv[1], in_port); printf("Waiting for kernel response...\n"); fflush(stdout); void *f; size_t fsz; size_t numMessageRx = 0; while (1) { if (max_framed_stream_read(toCpu, 1, &f, &fsz) == 1) { numMessageRx++; printf("CPU: Got output frame %zd - size %zd bytes\n", numMessageRx, fsz); uint64_t *w = f; for (size_t i=0; i < 3; i++) { printf("Frame [%zd] Word[%zd]: 0x%lx\n", numMessageRx, i, w[i]); } max_framed_stream_discard(toCpu, 1); } else usleep(10); } // max_ip_multicast_leave_group(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &mcastaddr); max_udp_close(dfe_socket); max_unload(engine); max_file_free(maxfile); printf("Done.\n"); fflush(stdout); return 0; }
int main(int argc, char *argv[]) { if(argc != 4) { printf("Usage: %s <topIp>:<topNetmask> <botIp>:<botNetmask> <remoteIp>:<remotePort>\n", argv[0]); return 1; } char top_ip_str[16]; char top_netmask_str[16]; char bot_ip_str[16]; char bot_netmask_str[16]; char remote_ip_str[16]; uint remote_port; if (sscanf(argv[1], "%15[0-9.]:%15[0-9.]", top_ip_str, top_netmask_str) != 2) { printf("Failed to parse top port IP and netmask"); return 1; } if (sscanf(argv[2], "%15[0-9.]:%15[0-9.]", bot_ip_str, bot_netmask_str) != 2) { printf("Failed to parse bot port IP and netmask"); return 1; } if (sscanf(argv[3], "%15[0-9.]:%u", remote_ip_str, &remote_port) != 2) { printf("Failed to parse remote IP and port"); return 1; } struct in_addr top_ip = { inet_addr(top_ip_str) }; struct in_addr top_netmask = { inet_addr(top_netmask_str) }; struct in_addr bot_ip = { inet_addr(bot_ip_str) }; struct in_addr bot_netmask = { inet_addr(bot_netmask_str) }; struct in_addr remote_ip = { inet_addr(remote_ip_str) }; max_file_t* maxfile = CmeTrading_init(); max_engine_t* engine = max_load(maxfile, "*"); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &top_ip, &top_netmask); max_ip_config(engine, MAX_NET_CONNECTION_QSFP_BOT_10G_PORT1, &bot_ip, &bot_netmask); max_cme_mdp_handle_t* mdp; if (max_cme_mdp_open_handler(engine, &mdp, "md", "templates_FixBinary.xml", "config.xml")) { printf("Failed to open market data handler.\nError trace: %s\n", max_cme_mdp_get_error_trace(mdp)); return 1; } max_cme_ilink_handle_t* ilink; // The NULL arguments here are the iLink output folders. Passing NULL disables iLink logging and session persistence. if (max_cme_ilink_open_handler(&ilink, engine, "orderEntry", NULL, NULL)) { printf("Failed to open iLink handler.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } struct timeval timeout = {5, 0}; // 5 seconds max_cme_ilink_session_t* session = max_cme_ilink_session_connect(ilink, &remote_ip, remote_port, &timeout); if (!session) { printf("Failed to connect iLink session.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } const char* session_id = "ABC"; const char* sender_sub_id = "subID"; const char* firm_id = "123"; const char* location_id = "GB"; const char* password = "******"; const int heartbeat_interval = 30; if (max_cme_ilink_session_login( session, session_id, sender_sub_id, firm_id, MAXCMEILINK_CUSTOMERORFIRM_CUSTOMER, MAXCMEILINK_CTICODE_1, location_id, password, MAXELER_APPLICATION_SYSTEM_NAME, MAXELER_TRADING_SYSTEM_VERSION, MAXELER_APPLICATION_SYSTEM_VENDOR, heartbeat_interval, &timeout)) { printf("Failed to login iLink session.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } // allow iLink to send some orders from the hardware if (max_cme_ilink_alloc_orders(session, 512)) { printf("Failed to alloc orders.\nError trace: %s\n", max_cme_ilink_get_error_trace(ilink)); return 1; } const uint channel_id = 342; const uint security_id = 295722; const uint market_depth = 10; const max_cme_mdp_channel_t* channel = max_cme_mdp_get_channel_by_id(mdp, channel_id); if (!channel) { printf("Failed to find channel with id '%d'.\nError trace: %s\n", channel_id, max_cme_mdp_get_error_trace(mdp)); return 1; } max_cme_mdp_instrument_t* instrument = max_cme_mdp_new_instrument(mdp, channel, security_id, market_depth); if (!instrument) { printf("Failed to create new instrument.\nError trace: %s\n", max_cme_mdp_get_error_trace(mdp)); return 1; } if (max_cme_mdp_add_instrument(mdp, instrument) < 0) { printf("Failed to add instrument.\nError trace: %s\n", max_cme_mdp_get_error_trace(mdp)); return 1; } // Don't wait for iLink events here as market data events might pile up. struct timeval no_wait = {0}; while (1) { int activity = 0; max_cme_mdp_event_t* md_event; while (max_cme_mdp_get_next_event(mdp, &md_event) == 1) { max_cme_mdp_print_event(md_event); max_cme_mdp_destroy_event(md_event); activity = 1; } max_cme_ilink_session_event_t session_event; while (max_cme_ilink_get_next_session_event(session, &session_event, &no_wait) == 1) { max_cme_ilink_display_session_event(&session_event); activity = 1; } max_cme_ilink_order_event_t order_event; while (max_cme_ilink_get_next_order_event(session, &order_event, &no_wait) == 1) { max_cme_ilink_display_order_event(&order_event); activity = 1; } if (!activity) usleep(1000); } return 0; }