Luận văn Xây dựng dịch vụ tính toán phân bố

LUẬN VĂN TỐT NGHỆP Đề tài XÂY DỰNG DỊCH VỤ TÍNH TOÁN PHÂN BỐ (Distributed Computing Environment-DCE MỤC LỤC 1 Giới thiệu 5 1.1 Sự hình thành bài toán 6 1.2 Bài toán 7 1.3 Các giả thuyết của bài toán: 8 1.4 Mô hình 8 1.5 Sơ lược về hoạt động hệ thống 10 2 Cơ sở lý thuyết 12 2.1 TCP/IP 13 2.1.1 Tổng quan về TCP/IP 14 2.1.2 Các lớp trong TCP/IP 16 2.1.3 Internet Protocol (IP) 19 2.1.4 Transmission Control Protocol (TCP) 22 2.1.5 User Datagram Protocol (UDP) 25 2.2 Berkeley sockets 26 2.2.1 Sự trừu tượng hóa socket 27 2.2.2 Các hàm hệ thống liên quan đến dịch vụ của cấp transport 28 2.3 Mô hình Client – Server 31 2.3.1 Xây dựng chương trình Client 32 2.3.2 Các loại Server 33 2.3.3 Xây dựng chương trình Server 34 2.4 Multicast 38 2.4.1 Giới thiệu 38 2.4.2 Broadcasting 40 2.4.3 Multicasting 41 2.4.4 IGMP : Internet Group Management Protocol 47 2.4.5 Quá trình Multicast 50 2.4.6 Làm sao viết một ứng dụng dùng Multicast trong Unix 53 2.4.7 Vấn đề tìm đường trong multicast: 56 2.5 Mô hình Group Communicatons 56 2.6 XDR (eXternal Data Representation) 59 2.6.1 Tại sao lại phải sử dụng XDR 59 2.6.2 Các kiểu dữ liệu chuẩn của XDR 60 2.6.3 Các thủ tục chuyển đổi 61 3 Phân tích ,thiết kế và hiện thực 62 3.1 Tổng kết phần cơ sở lý thuyết 62 3.2 Phân tích 64 3.2.1 Bài toán 64 3.2.2 Các giả thuyết của bài toán: 65 3.2.3 Phân tích bài toán và các giả thuyết 65 3.3 Các mô hình và lựa chọn mô hình 67 3.3.1 Chỉ dùng mô hình Client –Server 67 3.3.2 Dùng Client –Server kết hợp với Peer Group 68 3.3.3 Dùng Client –Server kết hợp với Hierarchical Group 69 3.4 Cấu trúc của hệ thống 69 3.5 Lưa chọn protocol và hoạt đọng của hệ thống 71 3.6 Phân tích chức năng 73 3.6.1 Admin 73 3.6.2 Agent 74 3.6.3 Server 74 3.6.4 Service 74 3.6.5 Client 75 3.6.6 Tools 75 3.7 Các giải thuật 75 3.7.1 Admin 75 3.7.2 Agent 75 3.7.3 Server 77 3.7.4 Giải thuật bầu chọn 78 3.7.5 Client 78 3.8 Hiện thực 80 3.8.1 Tổ chức dữ liệu 80 3.8.2 Quản lý timer 83 3.8.3 Socket giao tiếp 86 3.8.4 Tìm tất cả các host và user trên mạng 86 3.8.5 Tải trên hệ thống Sun-solaris , chọn Server tốt nhất 87 3.8.6 Hướng dẫn chương trình demo 89 3.9 Tổng kết 93 4 Phụ lục 94 4.1 Tài liệu tham khảo 94 4.2 Chương trình nguồn 96 4.2.1 _project 96

doc151 trang | Chia sẻ: lvcdongnoi | Lượt xem: 2397 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Luận văn Xây dựng dịch vụ tính toán phân bố, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
dce_admin_getcommand () { char *p = buf; int i; fprintf (stdout, "DCE >"); fgets (buf, MAXBUF, stdin); strstandard (buf); if (!buf[0]) return 0; strcpy (_buf, buf); argc = 0; argv[argc] = buf; while (*p) { if (*p == ' ') { argc++; argv[argc] = p + 1; (*p) = '\0'; } p++; } argc++; argv[argc] = NULL; return argc; } /****************************************/ int dce_admin_treat () { pfunct_t p = f; while (p->function) { if (strcmp (p->functname, argv[0]) == 0) { return p->function (argc, argv); } p++; } fprintf (stderr, "Bad command : %s\n", _buf); return 0; } /****************************************/ int dce_admin_quit (int argc, char **argv) { Admin.bExit = 1; Admin.Msg.type = DCE_MSG_ADMIN_EXIT; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); return 1; } /****************************************/ int dce_admin_help (int argc, char **argv) { pfunct_t p = f; while (p->function) { fprintf (stderr, "%13s %s\n", p->functname, p->functhelp); p++; } return 1; } /****************************************/ int dce_admin_accept () { int n = -1; set_timeout (); while (wait_timeout ()) if ((n = dce_socketaccept (Admin.nSocket)) > 0) { alarm (0); return n; } return -1; } /****************************************/ int dce_admin_mcastsend (char *buf, int len) { return dce_mcastsendsend (Admin.nMSockSend, Admin.maddr, Admin.mport, buf, len); } /****************************************/ int dce_admin_listhostuser (int argc, char **argv) { dce_admin_listhost (1); return 1; } /****************************************/ int dce_admin_killall (int argc, char **argv) { Admin.Msg.type = DCE_MSG_KILLALL; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); return dce_admin_quit (argc, argv); } /****************************************/ int dce_admin_findagent (int argc, char **argv) { int n; fprintf (stderr, "Searching Agent ..... "); Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_EXIST; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_EXIST) { fprintf (stderr, "Agent found at %s\n", ascaddr (msg.saddr)); close (n); return 1; } close (n); fprintf (stderr, "Error in read message \n"); return 0; } /****************************************/ int dce_admin_startagent (int argc, char **argv) { char cmd[256]; char host[20]; char ssport[20]; char smport[20]; char *p = argv[1]; int n, code; u_long u = gethostaddr (argv[1]); if (dce_admin_findagent (argc, argv)) return 0; if (u == -1) { fprintf (stderr, "Illegal hostname %s\n", argv[1]); return 0; } if (u != getmyaddr ()) { dce_admin_listhost (0); if (!dce_admin_findhost (u)) { fprintf (stderr, "%s is not on subnet\n", ascaddr (u)); return 0; } } else p = host; sprintf (cmd, "%s/bin/%s/dceagent", Admin.szDCE_ROOT, gethostarch (argv[1])); strcpy (host, (char *) ascaddrip (getmyaddr ())); sprintf (smport, "%d", Admin.mport); sprintf (ssport, "%d", Admin.Msg.sport); if (!IsFileExist (cmd)) { fprintf (stderr, "%s not found\n", cmd); return 0; } if ((code = fork ()) < 0) { fprintf (stderr, "Can not fork process for agent\n"); return 0; } if (!code) { code = execlp ("/usr/bin/rsh", "rsh", p, cmd, Admin.szDCE_ROOT, ascaddrip (Admin.maddr), smport, host, ssport, "0", NULL); if (code < 0) fprintf (stderr, "Can not execlp %s\n", cmd); exit (-1); } if ((n = dce_admin_accept ()) <= 0) return 0; if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_FORK_SUCCESS) fprintf (stderr, "Agent start successfully at %s\n", ascaddr (msg.saddr)); close (n); return dce_admin_connectagent (argc, argv); } /****************************************/ int dce_admin_connectagent (int argc, char **argv) { int n; char buf[30]; if (Admin.bConnect) return; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_CONNECT; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_ACCEPT_CONNECT) { strcpy (buf, ascaddr (msg.saddr)); fprintf (stderr, "Agent at %s accept connect with %s\n", buf, ascaddrip (getmyaddr ())); close (n); Admin.bConnect = 1; return 1; } if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_REFUSE_CONNECT) { strcpy (buf, ascaddr (msg.saddr)); fprintf (stderr, "Agent at %s has connected with %s time %d s\n", buf, ascaddr (msg.aaddr), msg.nextra); close (n); Admin.bExit = 1; return 0; } close (n); fprintf (stderr, "Error in read message \n"); return 0; } int dce_admin_disconnect (int argc, char **argv) { if (!Admin.bConnect) return; Admin.bConnect = 0; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_DISCONNECT; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); } int dce_admin_maxorder (int argc, char **argv) { int n; if (!Admin.bConnect) return; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_MAXORDER; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_MAXORDER) { fprintf (stderr, "Max order of Server List is %d\n", msg.nextra); close (n); return 1; } close (n); fprintf (stderr, "Error in read message \n"); return 0; } int dce_admin_server_is_running_on_host (int argc, char **argv) { int n; u_long u = gethostaddr (argv[1]); if (!Admin.bConnect) return 0; if (u == -1) { fprintf (stderr, "Illegal hostname %s\n", argv[1]); return 0; } Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_SERONHOST; Admin.Msg.aaddr = u; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_SERVERREADYRUN) { fprintf (stderr, "Server is running at %s\n", ascaddr (u)); close (n); return 1; } else if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_NOSERVERONHOST) { fprintf (stderr, "No Server run at %s\n", ascaddr (u)); close (n); return 0; } close (n); fprintf (stderr, "Error in read message \n"); return 0; } int dce_admin_startserver (int argc, char **argv) { char cmd[256]; char host[20]; char ssport[20]; char smport[20]; char smax[10]; char *p = argv[1]; int n, code; u_long u = gethostaddr (argv[1]); if (!Admin.bConnect) return 0; if (u == -1) { fprintf (stderr, "Illegal hostname %s\n", argv[1]); return 0; } if (dce_admin_server_is_running_on_host (argc, argv)) return 0; if (!dce_admin_maxorder (argc, argv)) return 0; sprintf (smax, "%d", msg.nextra + 1); if (u != getmyaddr ()) { dce_admin_listhost (0); if (!dce_admin_findhost (u)) { fprintf (stderr, "%s is not on subnet\n", ascaddr (u)); return 0; } } else p = host; sprintf (cmd, "%s/bin/%s/dceserver", Admin.szDCE_ROOT, gethostarch (argv[1])); strcpy (host, (char *) ascaddrip (getmyaddr ())); sprintf (smport, "%d", Admin.mport); sprintf (ssport, "%d", Admin.Msg.sport); if (!IsFileExist (cmd)) { fprintf (stderr, "%s not found\n", cmd); return 0; } if ((code = fork ()) < 0) { fprintf (stderr, "Can not fork process for agent\n"); return 0; } if (!code) { code = execlp ("/usr/bin/rsh", "rsh", p, cmd, Admin.szDCE_ROOT, ascaddrip (Admin.maddr), smport, host, ssport, smax, NULL); if (code < 0) fprintf (stderr, "Can not execlp %s\n", cmd); exit (-1); } if ((n = dce_admin_accept ()) <= 0) return 0; if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_SERVER_REPLY_ADMIN_FORK_SUCCESS) fprintf (stderr, "Server start successfully at %s\n", ascaddr (msg.saddr)); close (n); return 1; } int dce_admin_listserver (int argc, char **argv) { int n; SINFO s; if (!Admin.bConnect) return; dce_admin_howmanyserver (argc, argv); Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_LISTSERVER; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } while (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) { if (msg.type == DCE_MSG_END_OF_TRANSACTION) { fprintf (stderr, "End of transaction\n"); close (n); return 1; } if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_SERVERINFO) { if (read (n, (void *) &s, sizeof (s)) == sizeof (s)) fprintf (stderr, "Server %s order %d status %d load %6.5f\n", ascaddr (s.addr), s.order, s.status, s.load); } } close (n); return 1; } int dce_admin_killserver (int argc, char **argv) { u_long u = gethostaddr (argv[1]); if (!Admin.bConnect) return 0; if (u == -1) { fprintf (stderr, "Illegal hostname %s\n", argv[1]); return 0; } Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_ALL_KILLSERVER; Admin.Msg.aaddr = u; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); } int dce_admin_killagent (int argc, char **argv) { if (!Admin.bConnect) return 0; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_KILLAGENT; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); Admin.bConnect = 0; } int dce_admin_restart (int argc, char **argv) { char cmd[256]; char host[20]; char ssport[20]; char smport[20]; char *p = argv[1]; int n, code; u_long u = gethostaddr (argv[1]); if (!Admin.bConnect) return 0; if (!dce_admin_findagent (argc, argv)) return 0; if (!dce_admin_countnumaliveserver (argc, argv)) return 0; if (!msg.nextra) return 0; if (u == -1) { fprintf (stderr, "Illegal hostname %s\n", argv[1]); return 0; } if (u == msg.saddr) return 0; if (u != getmyaddr ()) { dce_admin_listhost (0); if (!dce_admin_findhost (u)) { fprintf (stderr, "%s is not on subnet\n", ascaddr (u)); return 0; } } else p = host; dce_admin_killagent (argc, argv); sprintf (cmd, "%s/bin/%s/dceagent", Admin.szDCE_ROOT, gethostarch (argv[1])); strcpy (host, (char *) ascaddrip (getmyaddr ())); sprintf (smport, "%d", Admin.mport); sprintf (ssport, "%d", Admin.Msg.sport); if (!IsFileExist (cmd)) { fprintf (stderr, "%s not found\n", cmd); return 0; } if ((code = fork ()) < 0) { fprintf (stderr, "Can not fork process for agent\n"); return 0; } if (!code) { code = execlp ("/usr/bin/rsh", "rsh", p, cmd, Admin.szDCE_ROOT, ascaddrip (Admin.maddr), smport, host, ssport, "0", NULL); if (code < 0) fprintf (stderr, "Can not execlp %s\n", cmd); exit (-1); } if ((n = dce_admin_accept ()) <= 0) return 0; if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_FORK_SUCCESS) fprintf (stderr, "Agent restart successfully at %s\n", ascaddr (msg.saddr)); close (n); return dce_admin_connectagent (argc, argv); } int dce_admin_howmanyserver (int argc, char **argv) { int n; if (!Admin.bConnect) return; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_HOWSERVER; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_HOWSERVER) { fprintf (stderr, "Total servers: %2d on DCE system \n", msg.nextra); close (n); return 1; } close (n); fprintf (stderr, "Error in read message \n"); return 0; } int dce_admin_adduser (int argc, char **argv) { uid_t uid; if (!Admin.bConnect) return; if (argc == 1) return 0; if ((uid = getuserid (argv[1])) < 0) { fprintf (stderr, "Illegal username %s\n", argv[1]); return 0; } Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_ALL_ADDUSER; Admin.Msg.lextra = uid; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); return dce_admin_listperuser (argc, argv); } int dce_admin_listperuser (int argc, char **argv) { int n; if (!Admin.bConnect) return; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_LISTUSER; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } while (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) { if (msg.type == DCE_MSG_END_OF_TRANSACTION) { fprintf (stderr, "End of transaction\n"); close (n); return 1; } if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_USERINFO) fprintf (stderr, "User :%s\n", ascuserid (msg.lextra)); } close (n); return 1; } int dce_admin_deluser (int argc, char **argv) { uid_t uid; if (!Admin.bConnect) return; if (argc == 1) return 0; if ((uid = getuserid (argv[1])) < 0) { fprintf (stderr, "Illegal username %s\n", argv[1]); return 0; } Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_ALL_DELUSER; Admin.Msg.lextra = uid; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); return dce_admin_listperuser (argc, argv); } int dce_admin_countnumaliveserver (int argc, char **argv) { int n; if (!Admin.bConnect) return; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_HOWMANYSERVERALIVE; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_HOWMANYSERVERALIVE) { fprintf (stderr, "Total alive servers: %2d on DCE system \n", msg.nextra); close (n); return 1; } close (n); fprintf (stderr, "Error in read message \n"); return 0; } int dce_admin_add_service (int argc, char **argv) { int i; char cmd[256]; if (!Admin.bConnect) return; if (argc < 3) { fprintf (stderr, "%s servicename numparams\n", argv[0]); return 0; } if (strlen (argv[1]) > MAXSERVICENAMELEN) { fprintf (stderr, "Service length too long :%s\n", argv[1]); return 0; } sprintf (cmd, "%s/bin/%s/%s", Admin.szDCE_ROOT, sysinfo_hostarch (), argv[1]); if (!IsFileExist (cmd)) { fprintf (stderr, "File %s not found \n", cmd); return 0; } i = atoi (argv[2]); if (i < 0) { fprintf (stderr, "Parameter negative: %d\n", i); return 0; } Admin.Msg.nextra = i; strcpy (Admin.Msg.sername, argv[1]); Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_ADDSERVICE; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); return dce_admin_listservice (argc, argv); } int dce_admin_listservice (int argc, char **argv) { int n; if (!Admin.bConnect) return; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_LISTSERVICE; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } while (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) { if (msg.type == DCE_MSG_END_OF_TRANSACTION) { fprintf (stderr, "End of transaction\n"); close (n); return 1; } if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_SERVICEINFO) fprintf (stderr, "SERVICECODE %3d NAME %25s %d params\n", msg.pid, msg.sername, msg.nextra); } close (n); return 1; } int dce_admin_listcurusage (int argc, char **argv) { int n; USERSERVICE us; if (!Admin.bConnect) return 0; if (!dce_admin_listservice (argc, argv)) return 0; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_LISTCURUSERSERVICE; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } while (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) { if (msg.type == DCE_MSG_END_OF_TRANSACTION) { fprintf (stderr, "End of transaction\n"); close (n); return 1; } if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_LISTCURUSERSERVICE) if (read (n, (void *) &us, sizeof (us)) == sizeof (us)) { fprintf (stderr, "\nUser %s from %s\n", ascuserid (us.uid), ascaddr (us.clientaddr)); fprintf (stderr, "using serive %d at server %s with pid %d\n", us.sernum, ascaddr (us.serveraddr), us.pid); fprintf (stderr, "Begin time :%s", ctime (&us.tStart)); if (us.tEnd) { fprintf (stderr, "End time :%s", ctime (&us.tEnd)); fprintf (stderr, "Total of excutable time : %d (s)\n", us.tEnd - us.tStart); } else { fprintf (stderr, "Running with Status :%d\n", us.status); fprintf (stderr, "Excuting time : %d (s)\n", time (NULL) - us.tStart); } } } close (n); return 1; } int dce_admin_load (int argc, char **argv) { double y, y1, y2, y3; kstat_ctl_t *kc; kstat_t *ksp; void *vp; if ((kc = kstat_open ()) == (void *) NULL) return y; if ((ksp = kstat_lookup (kc, "unix", 0, "system_misc")) == (void *) NULL) return 0; if (kstat_read (kc, ksp, NULL) == (kid_t) - 1) return y; if ((vp = kstat_data_lookup (ksp, "avenrun_1min")) == (void *) NULL) return 0; y = y3 = (double) (((kstat_named_t *) vp)->value.l) / (double) (FSCALE); if ((vp = kstat_data_lookup (ksp, "avenrun_5min")) == (void *) NULL) return 0; y = y2 = (double) (((kstat_named_t *) vp)->value.l) / (double) (FSCALE); if ((vp = kstat_data_lookup (ksp, "avenrun_15min")) == (void *) NULL) return 0; y = y1 = (double) (((kstat_named_t *) vp)->value.l) / (double) (FSCALE); fprintf (stderr, "1 minute load average: %.2f\n", y3); fprintf (stderr, "5 minute load average: %.2f\n", y2); fprintf (stderr, "15 minute load average: %.2f\n", y1); y = (y1 * 15 + y2 * 5 + y3) / 21; fprintf (stderr, "Future value %.2f\n", y); return 1; } int dce_admin_listonusage (int argc, char **argv) { int n; USERSERVICE us; if (!Admin.bConnect) return 0; if (!dce_admin_listservice (argc, argv)) return 0; Admin.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_LISTCURUSERSERVICE; dce_admin_mcastsend ((char *) &Admin.Msg, sizeof (MSG)); if ((n = dce_admin_accept ()) <= 0) { fprintf (stderr, "Time out ! Agent not found !\n"); return 0; } while (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) { if (msg.type == DCE_MSG_END_OF_TRANSACTION) { fprintf (stderr, "End of transaction\n"); close (n); return 1; } if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_LISTCURUSERSERVICE) if (read (n, (void *) &us, sizeof (us)) == sizeof (us)) { if (!us.tEnd) { fprintf (stderr, "\nUser %s from %s\n", ascuserid (us.uid), ascaddr (us.clientaddr)); fprintf (stderr, "using serive %d at server %s with pid %d\n", us.sernum, ascaddr (us.serveraddr), us.pid); fprintf (stderr, "Begin time :%s", ctime (&us.tStart)); fprintf (stderr, "Running with Status :%d\n", us.status); fprintf (stderr, "Excuting time : %d\n", time (NULL) - us.tStart); } } } close (n); return 1; } int dce_admin_brstart (int argc, char **argv) { int i; if (argc == 2) i = atoi (argv[1]); dce_netstat (i); return 1; } int dce_admin_listhoste (int argc, char **argv) { travelprinthost (); } Client dce_matrix.c on Tue Nov 17 18:31:12 1998 #include #include "dcec.h" int readn (register int, register char *, register); int writen (register int, register char *, register); pmatrix initmatrix (int type, int row, int col, void **ppvoid, mf_t f) { int i, j; pmatrix pm = (pmatrix) malloc (sizeof (matrix)); if (!pm) return NULL; pm->type = type; pm->row = row; pm->col = col; pm->_ppvoid = ppvoid; if (f) { for (i = 0; i < row; i++) for (j = 0; j < col; j++) f (pm, i, j); } return pm; } pmatrix newmatrix (int type, int row, int col, mf_t f) { int i, j; pmatrix pm = (pmatrix) malloc (sizeof (matrix)); if (!pm) return NULL; pm->type = type; pm->row = row; pm->col = col; pm->_ppvoid = NULL; if (!(pm->_ppvoid = (void **) malloc (sizeof (void *) * row))) { free (pm); return NULL; } for (i = 0; i < row; i++) pm->_ppvoid[i] = NULL; for (i = 0; i < row; i++) if (!(pm->_ppvoid[i] = (void *) malloc (type * col))) { freematrix (pm); return NULL; } if (f) { for (i = 0; i row; i++) for (j = 0; j col; j++) f (pm, i, j); } return pm; } void freematrix (pmatrix pm) { int i; if (pm->_ppvoid) { for (i = 0; i row; i++) if (pm->_ppvoid[i]) free (pm->_ppvoid[i]); } free (pm); } int writematrix (int fd, pmatrix pm) { int i; if (writen (fd, (char *) &(pm->type), sizeof (pm->type)) < 0) return -1; if (writen (fd, (char *) &(pm->row), sizeof (pm->row)) < 0) return -1; if (writen (fd, (char *) &(pm->col), sizeof (pm->col)) < 0) return -1; for (i = 0; i row; i++) if (writen (fd, (char *) (pm->_ppvoid[i]), pm->type * pm->col) < 0) return -1; return pm->row * pm->col; } pmatrix readmatrix (int fd) { int i, type, row, col; pmatrix pm; if (readn (fd, (char *) &type, sizeof (type)) < 0) return NULL; if (readn (fd, (char *) &row, sizeof (row)) < 0) return NULL; if (readn (fd, (char *) &col, sizeof (col)) < 0) return NULL; if (!(pm = newmatrix (type, row, col, NULL))) return NULL; for (i = 0; i < row; i++) if (readn (fd, (char *) (pm->_ppvoid[i]), type * col) < 0) { freematrix (pm); return NULL; } return pm; } void printmatrix (pmatrix pm, FILE * fo, mf_t fm) { int i, j; FILE *f = (fo) ? fo : stderr; fprintf (f, "\nSize of 1 element : %d bytes.Dim : %d row %d col\n", pm->type, pm->row, pm->col); for (i = 0; i row; i++) { for (j = 0; j col; j++) if (fm) fm (pm, i, j); fprintf (f, "\n"); } } int readn (register int fd, register char *ptr, register nbytes) { int nread, nleft = nbytes; while (nleft > 0) { nread = read (fd, ptr, nleft); if (nread < 0) return nread; else if (nread == 0) break; nleft -= nread; ptr += nread; } return nbytes - nleft; } int writen (register int fd, register char *ptr, register nbytes) { int nwritten, nleft = nbytes; while (nleft > 0) { nwritten = write (fd, ptr, nleft); if (nwritten <= 0) return nwritten; nleft -= nwritten; ptr += nwritten; } return nbytes - nleft; } dce_client.c on Thu Dec 24 03:12:34 1998 #include #include "dce_client.h" #define MAXCLIENTARGV 20 #define MAXREQUEST 3 #define CLIENTTIMEOUT 10*TIMEOUT_IAMALIVE+1 pmatrix dce_service (const char *servicename, pmatrix pm,...) { pmatrix _pm[MAXCLIENTARGV], pt = pm; ClientDes Client; MSG msg; int nParam = 0, nTimes = MAXREQUEST, nTimeOut = CLIENTTIMEOUT, fd; va_list ap; static char *_szwho[] = {"ADMIN", "AGENT", "SERVER", "SERVICE", "CLIENT", "UNKNOWN", NULL}; static int i; if (!i) if (!dce_timer_init ()) return NULL; else i++; if (!servicename) { #ifdef VIEW fprintf (stderr, "Service name must not be NULL\n"); #endif return NULL; } if (strlen (servicename) > MAXSERVICENAMELEN) { #ifdef VIEW fprintf (stderr, "Length of Servicename %s very long \n", servicename); #endif return NULL; } Client.Msg.who = CLIENT; Client.Msg.saddr = getmyaddr (); Client.Msg.uid = getuid (); Client.Msg.order = 0; if (!dce_readconf (&Client.maddr, &Client.mport)) return NULL; if ((Client.nMSockSend = dce_mcastsocksend ()) < 0) return NULL; if ((Client.nSocket = dce_socket (&Client.Msg.sport)) < 0) return NULL; va_start (ap, pm); while (pt) { _pm[nParam] = pt; nParam++; if (nParam > MAXCLIENTARGV) break; pt = va_arg (ap, pmatrix); } va_end (ap); #ifdef VIEW fprintf (stderr, "Number of param %d \nUsername %s\n", nParam, ascuserid (Client.Msg.uid)); #endif pt = NULL; Client.Msg.type = DCE_MSG_CLIENT_REQUEST_AGENT_SERVICE; Client.Msg.nextra = nParam; strcpy (Client.Msg.sername, servicename); while (nTimes--) { dce_mcastsendsend (Client.nMSockSend, Client.maddr, Client.mport, (char *) &Client.Msg, sizeof (MSG)); nTimeOut = CLIENTTIMEOUT; Client.TimerId = dce_settimer (nTimeOut, dce_timerzero, (void *) &nTimeOut); while (nTimeOut) { if ((fd = dce_socketaccept (Client.nSocket)) < 0) continue; dce_killtimer (Client.TimerId); read (fd, &msg, sizeof (msg)); switch (msg.type) { /************************************************/ case DCE_MSG_AGENT_REPLY_CLIENT_NOSERVER: #ifdef VIEW fprintf (stderr, "Reply from %s %s :No server running on DCE system\n", _szwho[msg.who], ascaddr (msg.saddr)); #endif close (fd); close (Client.nMSockSend); close (Client.nSocket); return NULL; break; /************************************************/ case DCE_MSG_AGENT_REPLY_CLIENT_USERNOTFOUND: #ifdef VIEW fprintf (stderr, "Reply from %s %s :User %s not allowed on DCE system\n", _szwho[msg.who], ascaddr (msg.saddr), ascuserid (Client.Msg.uid)); #endif close (fd); close (Client.nMSockSend); close (Client.nSocket); return NULL; break; /************************************************/ case DCE_MSG_AGENT_REPLY_CLIENT_NOSERVICE: #ifdef VIEW fprintf (stderr, "Reply from %s %s :Service : %s not found on DCE system\n", _szwho[msg.who], ascaddr (msg.saddr), servicename); #endif close (fd); close (Client.nMSockSend); close (Client.nSocket); return NULL; break; /************************************************/ case DCE_MSG_ALL_REPLY_CLIENT_ERROR: #ifdef VIEW fprintf (stderr, "Reply from %s %s :Error in data transfered to service : %s\n", _szwho[msg.who], ascaddr (msg.saddr), servicename); #endif close (fd); close (Client.nMSockSend); close (Client.nSocket); return NULL; break; /************************************************/ case DCE_MSG_ALL_REPLY_CLIENT_PLEASEWAIT: #ifdef VIEW fprintf (stderr, "Reply from %s %s :Please wait the result of : %s\n", _szwho[msg.who], ascaddr (msg.saddr), servicename); #endif break; /************************************************/ case DCE_MSG_SERVICE_REQUEST_CLIENT_DATA: #ifdef VIEW fprintf (stderr, "Request from %s %s : Transfer data : matrix %d\n", _szwho[msg.who], ascaddr (msg.saddr), msg.sport); #endif writematrix (fd, _pm[msg.sport]); break; /************************************************/ case DCE_MSG_SERVICE_REPLY_CLIENT_DATA: sleep (1); pt = readmatrix (fd); #ifdef VIEW fprintf (stderr, "Reply from %s %s : Receive result matrix ....", _szwho[msg.who], ascaddr (msg.saddr)); if (pt) fprintf (stderr, "Successfully\n"); else fprintf (stderr, "Error with failure!\n"); #endif close (fd); close (Client.nMSockSend); close (Client.nSocket); return pt; break; } close (fd); nTimeOut = CLIENTTIMEOUT; Client.TimerId = dce_settimer (nTimeOut, dce_timerzero, (void *) &nTimeOut); } #ifdef VIEW fprintf (stderr, "Request timeout .Retry !\n"); #endif } #ifdef VIEW fprintf (stderr, "End of request with failure !\n"); #endif close (Client.nMSockSend); close (Client.nSocket); return NULL; } Server dce_server.c on Mon Dec 21 18:36:20 1998 #include #include #include "dce_server.h" ServerDes Server; MSG msg; int dce_server_init (int, char **); void dce_server_exit (); int dce_agent_mcastrecv (char *buf, int len); int dce_server_mcastsend (char *buf, int len); void dce_server_alive (void *p); void dce_server_election_agent (void *p); void dce_server_fork_agent (); void dce_msg_admin_request_all_killserver (); void dce_msg_agent_request_server_broadcastdata (); void dce_msg_admin_reqeust_agent_addservice (); void dce_msg_client_request_agent_service (); void dce_msg_agent_request_server_serve_client (); void dce_msg_all_reply_client_pleasewait (); void dce_msg_service_reply_all_finish (); void dce_msg_all_reply_alluserservice (); void dce_server_treat_for_electionagent (); double dce_server_getload (); void main (int argc, char *argv[]) { if (!dce_diamon ()) exit (-1); if (!dce_server_init (argc, argv)) exit (-2); while (!Server.bExit) { if (dce_server_mcastrecv ((char *) &msg, sizeof (MSG)) != sizeof (MSG)) continue; switch (msg.who) { case ADMIN: break; case AGENT: Server.AgentTime = 2 * TIMEOUT_IAMALIVE + 1; dce_killtimer (Server.TimerIdElection); break; case SERVER: dce_agent_update_newmsg (); break; case SERVICE: break; } switch (msg.type) { case DCE_MSG_SERVER_ELECTION_AGENT: case DCE_MSG_SERVER_ELECTED_AGENT: dce_server_treat_for_electionagent (); break; case DCE_MSG_ALL_REPLY_ALL_USERSERVICE: dce_msg_all_reply_alluserservice (); break; case DCE_MSG_ALL_REPLY_CLIENT_PLEASEWAIT: dce_msg_all_reply_client_pleasewait (); break; case DCE_MSG_SERVICE_REPLY_ALL_FINISH: dce_msg_service_reply_all_finish (); break; case DCE_MSG_AGENT_REQUEST_SERVER_SERVE_CLIENT: dce_msg_agent_request_server_serve_client (); break; case DCE_MSG_AGENT_REQUEST_SERVER_BROADCASTDATA: dce_msg_agent_request_server_broadcastdata (); break; case DCE_MSG_CLIENT_REQUEST_AGENT_SERVICE: dce_msg_client_request_agent_service (); break; case DCE_MSG_ADMIN_REQUEST_AGENT_ADDSERVICE: dce_msg_admin_reqeust_agent_addservice (); break; case DCE_MSG_ADMIN_REQUEST_ALL_ADDUSER: AddUid (Server.pUserList, msg.lextra); break; case DCE_MSG_ADMIN_REQUEST_ALL_KILLSERVER: dce_msg_admin_request_all_killserver (); break; case DCE_MSG_KILLALL: Server.bExit = 1; break; } } } int dce_server_init (int argc, char **argv) { int i, n; u_long u; if (argc < 7) return 0; atexit (dce_server_exit); Server.Msg.order = atoi (argv[6]); Server.szDCE_ROOT = argv[1]; Server.maddr = gethostaddr (argv[2]); Server.mport = atoi (argv[3]); u = gethostaddr (argv[4]); i = atoi (argv[5]); Server.Msg.who = SERVER; Server.Msg.saddr = getmyaddr (); if (!(Server.pList = NewList ())) return 0; if (!(Server.pUserList = NewList ())) return 0; if (!(Server.pService = NewList ())) return 0; if (!(Server.pCurUserService = NewList ())) return 0; if ((Server.nMSockSend = dce_mcastsocksend ()) < 0) return 0; if ((Server.nMSockRecv = dce_mcastsockrecv (Server.maddr, Server.mport)) < 0) return 0; if ((Server.nSocket = dce_socket (&Server.Msg.sport)) < 0) return 0; if ((n = dce_connect (u, i)) > 0) { Server.Msg.type = DCE_MSG_SERVER_REPLY_ADMIN_FORK_SUCCESS; write (n, (void *) &Server.Msg, sizeof (MSG)); close (n); } else return 0; dce_signal (); if (!dce_timer_init ()) return 0; Server.Msg.load = dce_server_getload (); dce_server_alive (NULL); Server.Msg.type = DCE_MSG_SERVER_REQUEST_AGENT_BROADCASTDATA; dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); return 1; } void dce_server_exit () { FreeList (Server.pList, NULL); FreeList (Server.pUserList, NULL); FreeList (Server.pService, NULL); FreeList (Server.pCurUserService, NULL); dce_timer_free (); dce_mcastcloserecv (Server.nMSockRecv, Server.maddr); close (Server.nSocket); close (Server.nMSockSend); _cleanup (); _exit (); } int dce_server_mcastsend (char *buf, int len) { return dce_mcastsendsend (Server.nMSockSend, Server.maddr, Server.mport, buf, len); } int dce_server_mcastrecv (char *buf, int len) { return dce_mcastrecvrecv (Server.nMSockRecv, Server.maddr, Server.mport, buf, len); } void dce_server_alive (void *p) { char c = Server.Msg.type; Server.Msg.type = DCE_MSG_IAMALIVE; dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); dce_settimer (TIMEOUT_IAMALIVE, dce_server_alive, NULL); dce_server_dcetime (); DecTimeUserService (Server.pCurUserService); if (Server.AgentTime > 0) Server.AgentTime -= TIMEOUT_IAMALIVE; else { Server.Msg.type = DCE_MSG_SERVER_ELECTION_AGENT; dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); Server.TimerIdElection = dce_settimer ((Server.Msg.order - 1) * TIMEOUT_IAMALIVE, dce_server_election_agent, NULL); } Server.Msg.type = c; } void dce_server_election_agent (void *p) { char c = Server.Msg.type; if (dce_server_minorder () != Server.Msg.order) return; Server.Msg.type = DCE_MSG_SERVER_ELECTED_AGENT; dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); Server.Msg.type = c; dce_server_fork_agent (); } int dce_server_accept () { int n = -1; int timeout = TIMEOUT; int tid = dce_settimer (timeout, dce_timerzero, (char *) &timeout); while (timeout) { if ((n = dce_socketaccept (Server.nSocket)) > 0) { dce_killtimer (tid); return n; } } return -1; } void dce_server_fork_agent () { char cmd[256]; char host[20]; char ssport[20]; char smport[20]; char smax[10]; int n, code; MSG msg; sprintf (cmd, "%s/bin/%s/dceagent", Server.szDCE_ROOT, sysinfo_hostarch ()); strcpy (host, (char *) ascaddrip (getmyaddr ())); sprintf (smport, "%d", Server.mport); sprintf (ssport, "%d", Server.Msg.sport); sprintf (smax, "%d", Server.Msg.order); if (!IsFileExist (cmd)) return; if ((code = fork ()) < 0) return; if (!code) { code = execlp (cmd, cmd, Server.szDCE_ROOT, ascaddrip (Server.maddr), smport, host, ssport, smax, NULL); exit (-1); } if ((n = dce_server_accept ()) <= 0) return; if (read (n, (void *) &msg, sizeof (msg)) == sizeof (msg)) if (msg.type == DCE_MSG_AGENT_REPLY_ADMIN_FORK_SUCCESS) close (n); } void dce_msg_admin_request_all_killserver () { if (msg.aaddr == Server.Msg.saddr) Server.bExit = 1; else dce_server_delete_server (msg.aaddr); } void dce_msg_agent_request_server_broadcastdata () { Server.Msg.type = DCE_MSG_ADMIN_REQUEST_ALL_ADDUSER; dce_server_userbroadcast (); Server.Msg.type = DCE_MSG_ADMIN_REQUEST_AGENT_ADDSERVICE; dce_server_servicebroadcast (); dce_server_userservicebroadcast (); } void dce_msg_admin_reqeust_agent_addservice () { AddService (Server.pService, msg.nextra, msg.sername); } void dce_msg_client_request_agent_service () { Server.Msg.type = DCE_MSG_IAMALIVE; Server.Msg.load = dce_server_getload (); dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); } void dce_msg_agent_request_server_serve_client () { static char cmd[256]; static char smaddr[20]; static char smport[10]; static char seaddr[20]; static char seport[10]; static char suserid[10]; static char snparam[10]; static char sorder[10]; static char ssernum[10]; int n, code; PSERVICEINFO p; if (msg.aaddr != Server.Msg.saddr) return; sprintf (cmd, "%s/bin/%s/%s", Server.szDCE_ROOT, sysinfo_hostarch (), msg.sername); if ((!IsFileExist (cmd)) || (!(p = (PSERVICEINFO) FindService (Server.pService, msg.sername)))) Server.Msg.type = DCE_MSG_ALL_REPLY_CLIENT_ERROR; else Server.Msg.type = DCE_MSG_ALL_REPLY_CLIENT_PLEASEWAIT; if ((n = dce_connect (msg.saddr, msg.sport)) <= 0) return; write (n, (void *) &Server.Msg, sizeof (MSG)); close (n); if (Server.Msg.type != DCE_MSG_ALL_REPLY_CLIENT_PLEASEWAIT) return; strcpy (smaddr, ascaddrip (Server.maddr)); sprintf (smport, "%d", Server.mport); strcpy (seaddr, ascaddrip (msg.saddr)); sprintf (seport, "%d", msg.sport); sprintf (suserid, "%d", msg.uid); sprintf (snparam, "%d", msg.nextra); sprintf (sorder, "%d", Server.Msg.order); sprintf (ssernum, "%d", p->num); if (!(code = fork ())) { code = execlp (cmd, cmd, smaddr, smport, seaddr, seport, suserid, snparam, sorder, ssernum, NULL); exit (-1); } } void dce_msg_all_reply_client_pleasewait () { PUSERSERVICE p = (PUSERSERVICE) FindUserService (Server.pCurUserService, msg.pid, msg.saddr); if (p) { p->time = 2 * TIMEOUT_IAMALIVE + 1; p->status = 1; return; } if (p = (PUSERSERVICE) NewUserService (msg.pid, msg.saddr, msg.uid, msg.nextra, msg.aaddr, msg.lextra)) InsertList (Server.pCurUserService, (void *) p); } void dce_msg_service_reply_all_finish () { PUSERSERVICE p = (PUSERSERVICE) FindUserService (Server.pCurUserService, msg.pid, msg.saddr); if (p) { p->tEnd = msg.lextra1; p->time = -1; p->status = 0; return; } } void dce_msg_all_reply_alluserservice () { PUSERSERVICE p = (PUSERSERVICE) FindUserService (Server.pCurUserService, msg.pid, msg.saddr); if (p) return; if (!(p = (PUSERSERVICE) NewUserService (msg.pid, msg.saddr, msg.uid, msg.nextra, msg.aaddr, msg.lextra))) return; p->tEnd = msg.lextra1; p->time = msg.sport; p->status = (p->time > 0); InsertList (Server.pCurUserService, (void *) p); } double dce_server_getload () { static double y; double y1, y2, y3; kstat_ctl_t *kc; kstat_t *ksp; void *vp; if ((kc = kstat_open ()) == (void *) NULL) return y; if ((ksp = kstat_lookup (kc, "unix", 0, "system_misc")) == (void *) NULL) return y; if (kstat_read (kc, ksp, NULL) == (kid_t) - 1) return y; if ((vp = kstat_data_lookup (ksp, "avenrun_1min")) == (void *) NULL) return y; y = y3 = (double) (((kstat_named_t *) vp)->value.l) / (double) (FSCALE); if ((vp = kstat_data_lookup (ksp, "avenrun_5min")) == (void *) NULL) return y; y = y2 = (double) (((kstat_named_t *) vp)->value.l) / (double) (FSCALE); if ((vp = kstat_data_lookup (ksp, "avenrun_15min")) == (void *) NULL) return y; y = y1 = (double) (((kstat_named_t *) vp)->value.l) / (double) (FSCALE); y = y3; return y; } void dce_server_treat_for_electionagent () { char c = Server.Msg.type; if (msg.order == Server.Msg.order) return; dce_killtimer (Server.TimerIdElection); Server.Msg.type = DCE_MSG_IAMALIVE; dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); Server.Msg.type = c; } dce_hinfo.c on Tue Dec 22 13:30:40 1998 #include #include "dce_server.h" PHINFO NewHinfo (int order, u_long addr) { PHINFO p = (PHINFO) malloc (sizeof (HINFO)); if (!p) return NULL; p->order = order; p->addr = addr; p->status = 1; p->time = 2 * TIMEOUT_IAMALIVE + 1; return p; } void DecTime (void *pt) { PHINFO p = (PHINFO) pt; if (p->time >= 0) p->time -= TIMEOUT_IAMALIVE; else p->status = 0; } void dce_server_dcetime () { TravelList (Server.pList, DecTime); } int _MinOrder; void MinOrder (void *pt) { PHINFO p = (PHINFO) pt; if ((p->status == 1) && (_MinOrder > p->order)) _MinOrder = p->order; } int dce_server_minorder () { _MinOrder = MAXINT; TravelList (Server.pList, MinOrder); return _MinOrder; } int cmpsinfo (void *p1, void *p2) { PHINFO p = (PHINFO) p1; u_long *pu = (u_long *) p2; if (*pu == p->addr) { p->status = 1; p->time = 2 * TIMEOUT_IAMALIVE + 1; return 1; } return 0; } void dce_agent_update_newmsg () { PHINFO p; void **pr = ItemLookup (Server.pList, (void *) &msg.saddr, cmpsinfo); if (pr) { free (pr); return; } p = NewHinfo (msg.order, msg.saddr); if (!p) return; InsertList (Server.pList, (void *) p); } int cmppp (void *p1, void *p2) { PHINFO p = (PHINFO) p1; u_long *pu = (u_long *) p2; if (*pu == p->addr) return 1; return 0; } void dce_server_delete_server (u_long u) { DeleteItem (Server.pList, (void *) &u, cmppp, NULL); } void userbroadcast (void *p) { long *pl = (long *) p; Server.Msg.lextra = *pl; dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); } void dce_server_userbroadcast () { TravelList (Server.pUserList, userbroadcast); } void servicebroadcast (void *pt) { PSERVICEINFO p = (PSERVICEINFO) pt; Server.Msg.nextra = p->param; strcpy (Server.Msg.sername, p->sername); dce_server_mcastsend ((char *) &Server.Msg, sizeof (MSG)); } void dce_server_servicebroadcast () { TravelList (Server.pService, servicebroadcast); } void userservicebroadcast (void *pt) { PUSERSERVICE p = (PUSERSERVICE) pt; msg.type = DCE_MSG_ALL_REPLY_ALL_USERSERVICE; msg.who = UNKNOWN; msg.pid = p->pid; msg.saddr = p->serveraddr; msg.uid = p->uid; msg.nextra = p->sernum; msg.aaddr = p->clientaddr; msg.lextra = p->tStart; msg.lextra1 = p->tEnd; msg.sport = p->time; dce_server_mcastsend ((char *) &msg, sizeof (MSG)); } void dce_server_userservicebroadcast () { TravelList (Server.pCurUserService, userservicebroadcast); } Service dce_service1.c on Thu Dec 24 16:43:19 1998 #include "dce_service.h" void main (int argc, char *argv[]) { pmatrix p1; int i, j; if (!dce_service_init (argc, argv)) exit (-1); p1 = dce_get_matrix (0); sleep (500); dce_service_sendmatrix (p1); } dce_sum.c on Tue Jan 5 14:15:16 1999 #include #include "dce_service.h" #define MAXPARM 1 void main (int argc, char *argv[]) { int i, j; pmatrix pm, p[MAXPARM]; if (!dce_service_init (argc, argv)) exit (-1); if (Service.nParam < MAXPARM) exit (-2); for (i = 0; i < MAXPARM; i++) if (!(p[i] = dce_get_matrix (i))) dce_service_senderr (); pm = newmatrix (sizeof (int), 1, 1, NULL); pm->_ppint[0][0] = 0; for (i = 0; i row; i++) for (j = 0; j col; j++) pm->_ppint[0][0] += p[0]->_ppint[i][j]; dce_service_sendmatrix (pm); for (i = 0; i < MAXPARM; i++) freematrix (p[i]); freematrix (pm); } dce_addmatrix.c on Fri Jan 8 20:41:43 1999 #include #include "dce_service.h" #define MAXPARM 2 void main (int argc, char *argv[]) { int i, j; pmatrix pm, p[MAXPARM]; if (!dce_service_init (argc, argv)) exit (-1); if (Service.nParam < MAXPARM) exit (-2); for (i = 0; i < MAXPARM; i++) if (!(p[i] = dce_get_matrix (i))) dce_service_senderr (); if ((p[0]->type != p[1]->type) || (p[0]->col != p[1]->col) || (p[0]->row != p[1]->row)) dce_service_senderr (); if (!(pm = newmatrix (p[0]->type, p[0]->row, p[0]->col, NULL))) dce_service_senderr ();; for (i = 0; i row; i++) for (j = 0; j col; j++) pm->_ppint[i][j] = p[0]->_ppint[i][j] + p[1]->_ppint[i][j]; dce_service_sendmatrix (pm); for (i = 0; i < MAXPARM; i++) freematrix (p[i]); freematrix (pm); } dce_revmatrix.c on Fri Jan 8 21:26:15 1999 #include #include "dce_service.h" #define MAXPARM 1 void main (int argc, char *argv[]) { int i, j; pmatrix pm, p[MAXPARM]; if (!dce_service_init (argc, argv)) exit (-1); if (Service.nParam < MAXPARM) exit (-2); for (i = 0; i < MAXPARM; i++) if (!(p[i] = dce_get_matrix (i))) dce_service_senderr (); if (!(pm = newmatrix (p[0]->type, p[0]->col, p[0]->row, NULL))) dce_service_senderr (); for (i = 0; i row; i++) for (j = 0; j col; j++) pm->_ppint[i][j] = p[0]->_ppint[j][i]; dce_service_sendmatrix (pm); for (i = 0; i < MAXPARM; i++) freematrix (p[i]); freematrix (pm); } dce_mulmatrix.c on Fri Jan 8 20:42:38 1999 #include #include "dce_service.h" #define MAXPARM 2 void main (int argc, char *argv[]) { int i, j, k; pmatrix pm, p[MAXPARM]; if (!dce_service_init (argc, argv)) exit (-1); if (Service.nParam < MAXPARM) exit (-2); for (i = 0; i < MAXPARM; i++) if (!(p[i] = dce_get_matrix (i))) dce_service_senderr (); if ((p[0]->type != p[1]->type) || (p[0]->col != p[1]->row)) dce_service_senderr (); if (!(pm = newmatrix (p[0]->type, p[0]->row, p[1]->col, NULL))) dce_service_senderr ();; for (i = 0; i row; i++) for (j = 0; j col; j++) { pm->_ppint[i][j] = 0; for (k = 0; k col; k++) pm->_ppint[i][j] += p[0]->_ppint[i][k] * p[1]->_ppint[k][j]; } dce_service_sendmatrix (pm); for (i = 0; i < MAXPARM; i++) freematrix (p[i]); freematrix (pm); } Test test1.c on Thu Dec 24 05:13:55 1998 #include #include "dcec.h" #define SIZE 10 #define SERVICENAME "service1" void main (int argc, char *argv[]) { int i, j; pmatrix p, p1 = newmatrix (sizeof (int), SIZE, SIZE, NULL); printf ("Testing program at Client for %s service \n", SERVICENAME); for (i = 0; i row; i++) { for (j = 0; j col; j++) { p1->_ppint[i][j] = i + j; printf ("%4d ", p1->_ppint[i][j]); } printf ("\n"); } if (!(p = dce_service (SERVICENAME, p1, NULL))) exit (-1); for (i = 0; i row; i++) { for (j = 0; j col; j++) { printf ("%4d ", p->_ppint[i][j]); } printf ("\n"); } freematrix (p1); freematrix (p); } test2.c on Tue Jan 5 14:25:35 1999 #include #include "dcec.h" #define SIZE 10 #define SERVICENAME "sum" void main (int argc, char *argv[]) { int i, j; pmatrix p, p1 = newmatrix (sizeof (int), SIZE, SIZE, NULL); printf ("Testing program at Client for %s service \n", SERVICENAME); for (i = 0; i row; i++) { for (j = 0; j col; j++) { p1->_ppint[i][j] = 1; printf ("%4d ", p1->_ppint[i][j]); } printf ("\n"); } if (!(p = dce_service (SERVICENAME, p1, NULL))) exit (-1); printf ("sum %4d\n", p->_ppint[0][0]); freematrix (p1); freematrix (p); } testaddmatrix.c on Fri Jan 8 21:05:09 1999 #include #include "dcec.h" #define SIZE 10 #define SERVICENAME "addmatrix" void main (int argc, char *argv[]) { int i, j; pmatrix p, p1 = newmatrix (sizeof (int), SIZE, SIZE, NULL), p2 = newmatrix (sizeof (int), SIZE, SIZE, NULL); printf ("Testing program at Client for %s service \n", SERVICENAME); printf ("Matrix 1\n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { p1->_ppint[i][j] = 1; printf ("%4d ", p1->_ppint[i][j]); } printf ("\n"); } printf ("Matrix 2\n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { p2->_ppint[i][j] = 2; printf ("%4d ", p2->_ppint[i][j]); } printf ("\n"); } if (!(p = dce_service (SERVICENAME, p1, p2, NULL))) exit (-1); printf ("Add matrix\n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { printf ("%4d ", p->_ppint[i][j]); } printf ("\n"); } freematrix (p1); freematrix (p2); freematrix (p); } testrevmatrix.c on Fri Jan 8 21:37:10 1999 #include #include "dcec.h" #define SIZE 10 #define SERVICENAME "revmatrix" void main (int argc, char *argv[]) { int i, j; pmatrix p, p1 = newmatrix (sizeof (int), SIZE, SIZE, NULL); printf ("Testing program at Client for %s service \n", SERVICENAME); printf ("Matrix \n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { p1->_ppint[i][j] = j; printf ("%4d ", p1->_ppint[i][j]); } printf ("\n"); } if (!(p = dce_service (SERVICENAME, p1, NULL))) exit (-1); printf ("rev matrix\n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { printf ("%4d ", p->_ppint[i][j]); } printf ("\n"); } freematrix (p1); freematrix (p); } testmulmatrix.c on Fri Jan 8 21:51:47 1999 #include #include "dcec.h" #define SIZE 10 #define SERVICENAME "mulmatrix" void main (int argc, char *argv[]) { int i, j; pmatrix p, p1 = newmatrix (sizeof (int), SIZE, SIZE, NULL), p2 = newmatrix (sizeof (int), SIZE, SIZE, NULL); printf ("Testing program at Client for %s service \n", SERVICENAME); printf ("Matrix 1\n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { p1->_ppint[i][j] = 1; printf ("%4d ", p1->_ppint[i][j]); } printf ("\n"); } printf ("Matrix 2\n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { p2->_ppint[i][j] = 2; printf ("%4d ", p2->_ppint[i][j]); } printf ("\n"); } if (!(p = dce_service (SERVICENAME, p1, p2, NULL))) exit (-1); printf ("Mul matrix\n"); for (i = 0; i row; i++) { for (j = 0; j col; j++) { printf ("%4d ", p->_ppint[i][j]); } printf ("\n"); } freematrix (p1); freematrix (p2); freematrix (p); } Tools dce_monitor.c on Thu Dec 17 15:18:57 1998 #include #include "dce_core.h" u_long maddr; int mport; MSG msg; int bExit; int nMSockRecv; static char * s[]={"ADMIN","AGENT","SERVER","SERVICE","CLIENT","UNKNOWN",NULL}; void main() { if (!(dce_readconf(&maddr,&mport))) exit(-1); if ((nMSockRecv=dce_mcastsockrecv(maddr,mport))<0) exit(-2); while (!bExit) if (dce_mcastrecvrecv(nMSockRecv,maddr,mport,(char*)&msg,sizeof(MSG))!=sizeof(MSG)) continue; else { fprintf(stderr,"%7s order %2d at %s %4d uid %5d Msg %2d Load %6.5f\n",s[msg.who],msg.order,ascaddrip(msg.saddr),msg.sport,msg.uid,msg.type,msg.load); bExit=(msg.type==DCE_MSG_KILLALL); } dce_mcastcloserecv(nMSockRecv,maddr);} dce_gencode.c on Thu Dec 31 13:22:49 1998 #include #include #include void main (int argc, char *argv[]) { static char *s = "File % s on % s ****************************************/ #include #include \"dce_service.h\" #define MAXPARM %s void main (int argc, char *argv[]) { int i, j; pmatrix pm, p[MAXPARM]; if (!dce_service_init (argc, argv)) exit (-1); if (Service.nParam < MAXPARM) exit (-2); for (i = 0; i < MAXPARM; i++) if (!(p[i] = dce_get_matrix (i))) dce_service_senderr (); /*pm= */ dce_service_sendmatrix (pm); for (i = 0; i < MAXPARM; i++) freematrix (p[i]); freematrix (pm); }"; time_t t; FILE * f; if (argc < 3) { fprintf (stderr, "%s filename numparam\n", argv[0]); exit (-1); } if (!(f = fopen (argv[1], "wt"))) return; time (&t); fprintf (f, s, argv[1], ctime (&t), argv[2]); fclose (f); }

Các file đính kèm theo tài liệu này:

  • docXÂY DỰNG DỊCH VỤ TÍNH TOÁN PHÂN BỐ (Distributed Computing Environment-DCE).doc
Luận văn liên quan