static int startDTN() { uvast nodenbr = ION_NODE_NBR; char cmd[80]; int count; sm_ipc_init(); isprintf(cmd, sizeof cmd, "ionadmin /ion/node" UVAST_FIELDSPEC ".ionrc", nodenbr); pseudoshell(cmd); count = 5; while (rfx_system_is_started() == 0) { snooze(1); count--; if (count == 0) { writeMemo("[?] RFX start hung up, abandoned."); return -1; } } pseudoshell("ionadmin /ion/global.ionrc"); snooze(1); isprintf(cmd, sizeof cmd, "ionsecadmin /ion/node" UVAST_FIELDSPEC ".ionsecrc", nodenbr); pseudoshell(cmd); snooze(1); /* Now start the higher layers of the DTN stack. */ isprintf(cmd, sizeof cmd, "ltpadmin /ion/node" UVAST_FIELDSPEC ".ltprc", nodenbr); pseudoshell(cmd); count = 5; while (ltp_engine_is_started() == 0) { snooze(1); count--; if (count == 0) { writeMemo("[?] LTP start hung up, abandoned."); return -1; } } isprintf(cmd, sizeof cmd, "bpadmin /ion/node" UVAST_FIELDSPEC ".bprc", nodenbr); pseudoshell(cmd); count = 5; while (bp_agent_is_started() == 0) { snooze(1); count--; if (count == 0) { writeMemo("[?] BP start hung up, abandoned."); return -1; } } isprintf(cmd, sizeof cmd, "lgagent ipn:" UVAST_FIELDSPEC ".127", nodenbr); pseudoshell(cmd); snooze(1); #ifndef NASA_PROTECTED_FLIGHT_CODE /* Now start CFDP. */ isprintf(cmd, sizeof cmd, "cfdpadmin /ion/node" UVAST_FIELDSPEC ".cfdprc", nodenbr); pseudoshell(cmd); count = 5; while (cfdp_entity_is_started() == 0) { snooze(1); count--; if (count == 0) { writeMemo("[?] CFDP start hung up, abandoned."); return -1; } } #endif return 0; }
static int run_file2dgr(char *remoteHostName, char *fileName) { int cyclesLeft; char ownHostName[MAXHOSTNAMELEN + 1]; unsigned int ownIpAddress; unsigned int remoteIpAddress; unsigned short remotePortNbr = TEST_PORT_NBR; PsmMgtOutcome outcome; DgrRC rc; FILE *inputFile; char line[256]; int lineLen; struct timeval startTime; unsigned long bytesSent; cyclesLeft = cyclesRequested; getNameOfHost(ownHostName, sizeof ownHostName); ownIpAddress = getInternetAddress(ownHostName); remoteIpAddress = getInternetAddress(remoteHostName); sm_ipc_init(); wmPtr = malloc(wmSize); if (wmPtr == NULL || psm_manage(wmPtr, wmSize, "dgr", &dgrwm, &outcome) < 0 || outcome == Refused) { putErrmsg("Can't acquire DGR working memory.", NULL); writeErrmsgMemos(); return 0; } #if 0 psm_start_trace(dgrwm, 10000000, NULL); #endif memmgr_add("dgr", allocFromDgrMemory, releaseToDgrMemory, dgrAtoP, dgrPtoA); if (dgr_open(ownIpAddress, 2, 0, ownIpAddress, "dgr", &dgr, &rc) < 0 || rc != DgrOpened) { putErrmsg("Can't open dgr service.", NULL); writeErrmsgMemos(); return 0; } inputFile = fopen(fileName, "r"); if (inputFile == NULL) { putSysErrmsg("Can't open input file", fileName); writeErrmsgMemos(); return 0; } eofLineLen = strlen(eofLine); getCurrentTime(&startTime); bytesSent = 0; /* Copy text lines from file to SDR. */ while (cyclesLeft > 0) { if (fgets(line, 256, inputFile) == NULL) { if (feof(inputFile)) { if (dgr_send(dgr, remotePortNbr, remoteIpAddress, DGR_NOTE_FAILED, eofLine, eofLineLen, &rc) < 0) { putErrmsg("dgr_send failed.", NULL); writeErrmsgMemos(); fclose(inputFile); return 0; } bytesSent += eofLineLen; fclose(inputFile); cyclesLeft--; if (cyclesLeft == 0) { inputFile = NULL; break; } inputFile = fopen(fileName, "r"); if (inputFile == NULL) { putSysErrmsg("Can't reopen input file", NULL); writeErrmsgMemos(); return 0; } continue; } else { putSysErrmsg("Can't read from input file", NULL); writeErrmsgMemos(); fclose(inputFile); return 0; } } lineLen = strlen(line); if (dgr_send(dgr, remotePortNbr, remoteIpAddress, DGR_NOTE_FAILED, line, lineLen, &rc) < 0) { putErrmsg("dgr_send failed", NULL); writeErrmsgMemos(); fclose(inputFile); return 0; } bytesSent += lineLen; } report(&startTime, bytesSent); writeMemo("[i] file2dgr waiting 10 sec for retransmission to stop."); snooze(10); dgr_close(dgr); #if 0 psm_print_trace(dgrwm, 0); psm_stop_trace(dgrwm); #endif if (inputFile) { fclose(inputFile); } return 0; }
int main(int argc, char **argv) #endif { char *wmspace; int wmid; PsmPartition wm = NULL; PsmMgtOutcome outcome; PsmAddress testlist; sm_SemId semaphore; int cycleNbr = 1; char fileName[256]; int outputFile; PsmAddress lineListElt; PsmAddress lineAddress; char *line; if (sm_ipc_init() < 0) { return 0; } if (sm_ShmAttach(0x1108, 10000000, &wmspace, &wmid) < 0) { PERROR("can't attach to shared memory"); return 0; } if (psm_manage(wmspace, 10000000, "file2sm", &wm, &outcome) < 0 || outcome == Refused) { PUTS("can't manage shared memory"); return 0; } testlist = psm_get_root(wm); if (testlist == 0) { testlist = sm_list_create(wm); if (testlist == 0) { PUTS("can't create shared memory list"); return 0; } psm_set_root(wm, testlist); } semaphore = sm_SemCreate(0x1101, SM_SEM_FIFO); if (semaphore < 0) { PUTS("can't create semaphore"); return 0; } PUTMEMO("Working on cycle", utoa(cycleNbr)); isprintf(fileName, sizeof fileName, "file_copy_%d", cycleNbr); outputFile = iopen(fileName, O_WRONLY | O_APPEND, 0666); if (outputFile < 0) { PERROR("can't open output file"); return 0; } while (1) { while (sm_list_length(wm, testlist) == 0) { sm_SemTake(semaphore); /* Wait for line. */ } lineListElt = sm_list_first(wm, testlist); lineAddress = sm_list_data(wm, lineListElt); line = psp(wm, lineAddress); /* Process text of line. */ if (strcmp(line, "*** End of the file ***\n") == 0) { /* Close file, open next one. */ close(outputFile); cycleNbr++; PUTMEMO("Working on cycle", utoa(cycleNbr)); isprintf(fileName, sizeof fileName, "file_copy_%d", cycleNbr); outputFile = iopen(fileName, O_WRONLY | O_APPEND, 0666); if (outputFile < 0) { PERROR("Can't open output file"); return 0; } } else /* Just write line to output file. */ { if (iputs(outputFile, line) < 0) { close(outputFile); PERROR("Can't write to output file"); return 0; } } /* Delete line from shared memory list. */ psm_free(wm, lineAddress); CHKZERO(sm_list_delete(wm, lineListElt, (SmListDeleteFn) NULL, NULL) == 0); } }