diff options
author | fossee | 2019-09-18 17:25:18 +0530 |
---|---|---|
committer | fossee | 2019-09-18 17:25:18 +0530 |
commit | e43b6221138d30d9b2ea37c708c9521d4ba926af (patch) | |
tree | 67007cb0a3b4f004fe395fdfabbd6c7f64f3f6f6 /src | |
parent | 13b65c2e7ef066d2481e384352402de7cd9ff7fe (diff) | |
download | nghdl-e43b6221138d30d9b2ea37c708c9521d4ba926af.tar.gz nghdl-e43b6221138d30d9b2ea37c708c9521d4ba926af.tar.bz2 nghdl-e43b6221138d30d9b2ea37c708c9521d4ba926af.zip |
support for multiple ghdl models
Diffstat (limited to 'src')
-rw-r--r-- | src/ghdlserver/ghdlserver.c | 99 | ||||
-rw-r--r-- | src/model_generation.py | 87 |
2 files changed, 148 insertions, 38 deletions
diff --git a/src/ghdlserver/ghdlserver.c b/src/ghdlserver/ghdlserver.c index 5bf2e99..622c246 100644 --- a/src/ghdlserver/ghdlserver.c +++ b/src/ghdlserver/ghdlserver.c @@ -1,5 +1,20 @@ -/************************************************************************* - * <ghdlserver.c> FOSSEE, IIT-Mumbai +/******************************************************************************** + * <ghdlserver.c> FOSSEE, IIT-Bombay + * 18.Sept.2019 - Rahul Paknikar - Added reading of IP from a file to + * support multiple digital models + * - Reads the ip set by its client to map + * with the same socket with the name of file + * NGHDL_IP in the model's local directory + * - On exit, the test bench removes this file as + * well as the NGHDL_COMMON_IP file. It is created + * by its client (cfunc) and stored in /tmp + * directory. It tracks the used IPs for existing + * digital models in current simulation. + * 5.July.2019 - Rahul Paknikar - Added loop to send all port values for + * a given event. + * - Removed bug to terminate multiple testbench + * instances in ngpsice windows. + * * 24.Mar.2017 - Raj Mohan - Added signal handler for SIGUSR1, to handle an * orphan test bench process. * The test bench will now create a PID file in @@ -21,8 +36,8 @@ * Added the following functions: * o curtim() * o print_hash_table() - ************************************************************************* - */ + *********************************************************************************/ + #include <string.h> #include "ghdlserver.h" #include "uthash.h" @@ -33,7 +48,8 @@ #include <signal.h> #include <unistd.h> #include <sys/types.h> -#include <sys/socket.h> +#include <sys/socket.h> +#include <arpa/inet.h> #include <sys/time.h> #include <netinet/in.h> #include <netdb.h> @@ -105,11 +121,11 @@ static int get_ngspice_pid(void) sprintf(path, "/proc/%s/comm", dir_entry->d_name); if ((fp = fopen(path, "r")) != NULL) { - fscanf(fp, "%s", rd_buff); - if (strcmp(rd_buff, NGSPICE) == 0) - { - pid = (pid_t)tmp; - } + fscanf(fp, "%s", rd_buff); + if (strcmp(rd_buff, NGSPICE) == 0) + { + pid = (pid_t)tmp; // 5.July.2019 - RP - Kludge + } } } } @@ -127,24 +143,25 @@ static int get_ngspice_pid(void) static void create_pid_file(int sock_port) { pid_t my_pid = getpid(); - pid_t ngspice_pid = get_ngspice_pid(); + pid_t ngspice_pid = get_ngspice_pid(); if (ngspice_pid == -1) { - fprintf(stderr, "create_pid_file() Failed to get ngspice PID"); - syslog(LOG_ERR, "create_pid_file() Failed to get ngspice PID"); - exit(1); + fprintf(stderr, "create_pid_file() Failed to get ngspice PID"); + syslog(LOG_ERR, "create_pid_file() Failed to get ngspice PID"); + exit(1); } + sprintf(pid_filename, "/tmp/NGHDL_%d_%s_%d", ngspice_pid, __progname, sock_port); pid_file = fopen(pid_filename, "w"); if (pid_file) { - pid_file_created = 1; - fprintf(pid_file,"%d\n", my_pid); - fclose(pid_file); + pid_file_created = 1; + fprintf(pid_file,"%d\n", my_pid); + fclose(pid_file); } else { perror("fopen() - PID file"); - syslog(LOG_ERR, "create_pid_file(): Unable to open PID file in /tmp"); + syslog(LOG_ERR, "create_pid_file(): Unable to open PID file in /tmp"); exit(1); } @@ -218,7 +235,7 @@ static void parse_buffer(int sock_id, char* receive_buffer) // //Create Server and listen for client connections. // -static int create_server(int port_number,int max_connections) +static int create_server(int port_number, int max_connections) { int sockfd, reuse = 1; struct sockaddr_in serv_addr; @@ -236,12 +253,32 @@ static int create_server(int port_number,int max_connections) int ret = setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int)); if (ret < 0) { - syslog(LOG_ERR, "create_server:setsockopt() failed...."); + syslog(LOG_ERR, "create_server:setsockopt() failed...."); } +/* 18.Sept.2019 - RP - Read and set IP of server decided by its client */ + char ip_filename[80]; + sprintf(ip_filename, "NGHDL_IP.txt"); + + char lo_ip[20]; + + FILE* fp = fopen(ip_filename, "r"); + + if (fp) + { + if (fscanf(fp, "%s", lo_ip) != EOF) + { + fclose(fp); + } + } else { + perror("fopen() - NGHDL_IP file"); + syslog(LOG_ERR, "create_server(): Unable to open NGHDL_IP file in /tmp"); + exit(1); + } + bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; + serv_addr.sin_addr.s_addr = inet_addr(lo_ip); // 18.Sept.2019 - RP - Bind to specific IP only serv_addr.sin_port = htons(port_number); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) @@ -404,7 +441,7 @@ static void Data_Send(int sockid) out = calloc(1, 2048); - for (i=0; i<out_port_num; i++) + for (i=0; i<out_port_num; i++) // 5.July.2019 - RP - loop to send all ports { found = 0; @@ -482,7 +519,8 @@ void Vhpi_Initialize(int sock_port) while(try_limit > 0) { - server_socket_id = create_server(DEFAULT_SERVER_PORT,DEFAULT_MAX_CONNECTIONS); + // 18.Sept.2019 - RP + server_socket_id = create_server(DEFAULT_SERVER_PORT, DEFAULT_MAX_CONNECTIONS); if(server_socket_id > 0) { syslog(LOG_INFO,"Started the server on port %d SRV:%d", @@ -636,8 +674,8 @@ void Vhpi_Send() if (prev_sendto_sock != sendto_sock) { - Data_Send(sendto_sock); - prev_sendto_sock = sendto_sock; + Data_Send(sendto_sock); + prev_sendto_sock = sendto_sock; } // 22.Feb.2017 End kludge @@ -653,15 +691,16 @@ void Vhpi_Exit(int sig) { Vhpi_Close(); - // printf("\nVHPI EXIT\n"); - -// 10.Mar.2017 - RM + // 10.Mar.2017 - RM if (pid_file_created) { - // printf("%s\n", pid_filename); remove(pid_filename); } + // 18.Sept.2019 - RP + remove("NGHDL_IP.txt"); + remove("/tmp/NGHDL_COMMON_IP.txt"); + syslog(LOG_INFO, "*** Exiting ***"); exit(0); -} +}
\ No newline at end of file diff --git a/src/model_generation.py b/src/model_generation.py index 772cbb5..40a4b4a 100644 --- a/src/model_generation.py +++ b/src/model_generation.py @@ -143,7 +143,7 @@ cfunc=open('cfunc.mod','w') print "Building content for cfunc.mod file" comment='''/* This is cfunc.mod file auto generated by gen_con_info.py -Developed by Fahim at IIT Bombay */ \n +Developed by Fahim, Rahul at IIT Bombay */ \n ''' header=''' @@ -217,6 +217,8 @@ systime_info=''' fprintf(log_client,"Setup Client Server Connection at %s \\n",ctime(&systime)); ''' + + init_else=''' printf("Client-Inside else of INIT \\n"); fprintf(log_client,"Inside else of INIT \\n"); @@ -233,13 +235,80 @@ for item in output_port: els_evt_count1=els_evt_count1+1 -client_setup=''' - /* Client setup */ - //Default hostname assignment - host = gethostbyname("127.0.0.1"); +client_setup_ip=''' + /* Client Setup IP Addr */ + FILE *fptr; + int ip_count = 0; + char my_ip[20]; + + fptr = fopen("/tmp/NGHDL_COMMON_IP.txt", "r"); + if (fptr) + { + char line[20]; + while(fscanf(fptr, "%s", line) == 1) { + ip_count++; + } + + fclose(fptr); + } + + if (ip_count < 255) { + sprintf(my_ip, "127.0.0.%d", ip_count+1); + } else { + sprintf(my_ip, "127.0.%d.1", (ip_count+1)%256); + } + + fptr = fopen("/tmp/NGHDL_COMMON_IP.txt", "a"); + if (fptr) + { + fprintf(fptr, "%s\\n", my_ip); + fclose(fptr); + } else { + perror("fopen() - Common IP"); + exit(1); + } + + + char ip_filename[300]; +''' +client_setup_ip +='sprintf(ip_filename,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/NGHDL_IP.txt");' +client_setup_ip +=''' + fptr = fopen(ip_filename, "w"); + if(fptr) + { + fprintf(fptr, "%s\\n", my_ip); + fclose(fptr); + } else { + perror("fopen() - IP file"); + exit(1); + } +''' + +client_fetch_ip=''' + /* Client Fetch IP Addr */ + + char lo_ip[20]; + char ip_filename[300]; +''' +client_fetch_ip +='sprintf(ip_filename,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/NGHDL_IP.txt");\n' +client_fetch_ip +=''' + FILE* fp = fopen(ip_filename, "r"); + if (fp) + { + if (fscanf(fp, "%s", lo_ip) != EOF) + { + fclose(fp); + } + } else { + perror("fopen() - NGHDL_IP file"); + exit(1); + } + + host = gethostbyname(lo_ip); printf("Client-Creating Client Socket \\n"); fprintf(log_client,"Creating client socket \\n"); ''' + create_socket=''' //Creating socket for client if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) @@ -471,10 +540,12 @@ for item in cm_event_get_ptr: cfunc.write("\n") cfunc.write(systime_info) cfunc.write("\n") -cfunc.write("\t\tchar command[1024];") +cfunc.write(client_setup_ip) +cfunc.write("\n") +cfunc.write("\t\tchar command[1024];\n") cfunc.write('\t\tsnprintf(command,1024,"'+home+'/ngspice-nghdl/src/xspice/icm/ghdl/'+fname.split('.')[0]+'/DUTghdl/start_server.sh %d &",sock_port);\n') cfunc.write('\t\tsystem(command);') -cfunc.write("\t}") +cfunc.write("\n\t}") cfunc.write("\n") cfunc.write("\telse\n\t{\n") @@ -484,7 +555,7 @@ for item in els_evt_ptr: cfunc.write("\t}") cfunc.write("\n\n") cfunc.write("\tif(flag==0)\n\t{") -cfunc.write(client_setup) +cfunc.write(client_fetch_ip) cfunc.write(create_socket) cfunc.write(connect_server) cfunc.write(time_limit) |