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;
}
示例#2
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 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;
}