static void handleQuit() { int stop = 0; oK(_running(&stop)); ionPauseAttendant(_attendant(NULL)); }
static void handleQuit() { int stop = 0; oK(_running(&stop)); ltp_interrupt(_clientId(NULL)); }
static void handleQuit() { int stop = 0; PUTS("BP reception interrupted."); oK(_running(&stop)); bp_interrupt(_bpsap(NULL)); }
static void shutDown() /* Commands bpclock termination. */ { int stop = 0; oK(_running(&stop)); /* Terminates bpclock. */ }
int bpclock(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { #else int main(int argc, char *argv[]) { #endif Sdr sdr; BpDB *bpConstants; int state = 1; time_t currentTime; if (bpAttach() < 0) { putErrmsg("bpclock can't attach to BP.", NULL); return 1; } sdr = getIonsdr(); bpConstants = getBpConstants(); isignal(SIGTERM, shutDown); /* Main loop: wait for event occurrence time, then * execute applicable events. */ oK(_running(&state)); writeMemo("[i] bpclock is running."); while (_running(NULL)) { /* Sleep for 1 second, then dispatch all events * whose executions times have now been reached. */ snooze(1); currentTime = getUTCTime(); if (dispatchEvents(sdr, bpConstants->timeline, currentTime) < 0) { putErrmsg("Can't dispatch events.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } /* Also adjust throttles in response to rate * changes noted in the shared ION database. */ if (adjustThrottles() < 0) { putErrmsg("Can't adjust throttles.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } /* Then apply rate control. */ applyRateControl(sdr); } writeErrmsgMemos(); writeMemo("[i] bpclock has ended."); ionDetach(); return 0; }
int ltpclock(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { #else int main(int argc, char *argv[]) { #endif Sdr sdr; LtpDB *ltpConstants; int state = 1; time_t currentTime; if (ltpInit(0, 0) < 0) { putErrmsg("ltpclock can't initialize LTP.", NULL); return 1; } sdr = getIonsdr(); ltpConstants = getLtpConstants(); isignal(SIGTERM, shutDown); /* Main loop: wait for event occurrence time, then * execute applicable events. */ oK(_running(&state)); writeMemo("[i] ltpclock is running."); while (_running(NULL)) { /* Sleep for 1 second, then dispatch all events * whose executions times have now been reached. */ snooze(1); currentTime = getUTCTime(); /* Infer link state changes from rate changes * noted in the shared ION database. */ if (manageLinks(sdr, currentTime) < 0) { putErrmsg("Can't manage links.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } /* Then dispatch retransmission events, as * constrained by the new link state. */ if (dispatchEvents(sdr, ltpConstants->timeline, currentTime) < 0) { putErrmsg("Can't dispatch events.", NULL); state = 0; /* Terminate loop. */ oK(_running(&state)); continue; } } writeErrmsgMemos(); writeMemo("[i] ltpclock has ended."); ionDetach(); return 0; }
int ltpcounter(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { int clientId = a1; int maxBytes = a2; #else int main(int argc, char **argv) { int clientId = (argc > 1 ? strtol(argv[1], NULL, 0) : 0); int maxBytes = (argc > 2 ? strtol(argv[2], NULL, 0) : 0); #endif IonAlarm alarm = { 5, 0, showProgress, NULL }; pthread_t alarmThread; int state = 1; LtpNoticeType type; LtpSessionId sessionId; unsigned char reasonCode; unsigned char endOfBlock; unsigned int dataOffset; unsigned int dataLength; Object data; char buffer[255]; if (clientId < 1) { PUTS("Usage: ltpcounter <client ID> [<max nbr of bytes>]"); PUTS(" Max nbr of bytes defaults to 2 billion."); return 0; } oK(_clientId(&clientId)); if (maxBytes < 1) { maxBytes = 2000000000; } if (ltp_attach() < 0) { putErrmsg("ltpcounter can't initialize LTP.", NULL); return 1; } if (ltp_open(_clientId(NULL)) < 0) { putErrmsg("ltpcounter can't open client access.", itoa(_clientId(NULL))); return 1; } ionSetAlarm(&alarm, &alarmThread); isignal(SIGINT, handleQuit); oK((_running(&state))); while (_running(NULL)) { if (ltp_get_notice(_clientId(NULL), &type, &sessionId, &reasonCode, &endOfBlock, &dataOffset, &dataLength, &data) < 0) { putErrmsg("Can't get LTP notice.", NULL); state = 0; oK((_running(&state))); continue; } switch (type) { case LtpExportSessionCanceled: isprintf(buffer, sizeof buffer, "Transmission \ canceled: source engine " UVAST_FIELDSPEC ", session %u, reason code %d.", sessionId.sourceEngineId, sessionId.sessionNbr, reasonCode); writeMemo(buffer); if (data) { ltp_release_data(data); } break; case LtpImportSessionCanceled: oK(_sessionsCanceled(1)); isprintf(buffer, sizeof buffer, "Reception canceled: \ source engine " UVAST_FIELDSPEC ", session %u, reason code %d.", sessionId.sourceEngineId, sessionId.sessionNbr, reasonCode); writeMemo(buffer); break; case LtpRecvGreenSegment: isprintf(buffer, sizeof buffer, "Green segment \ received, discarded: source engine " UVAST_FIELDSPEC ", session %u, \ offset %u, length %u, eob=%d.", sessionId.sourceEngineId, sessionId.sessionNbr, dataOffset, dataLength, endOfBlock); writeMemo(buffer); ltp_release_data(data); break; case LtpRecvRedPart: oK(_blocksReceived(1)); oK(_bytesReceived(dataLength)); ltp_release_data(data); break; default: break; } if (_bytesReceived(0) >= maxBytes) { state = 0; oK((_running(&state))); } } ionCancelAlarm(alarmThread); writeErrmsgMemos(); printCount(); PUTS("Stopping ltpcounter."); ltp_close(_clientId(NULL)); ltp_detach(); return 0; }
int bpcounter(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { char *ownEid = (char *) a1; int maxCount = a2; #else int main(int argc, char **argv) { char *ownEid = (argc > 1 ? argv[1] : NULL); int maxCount = (argc > 2 ? atoi(argv[2]) : 0); #endif BpSAP sap; Sdr sdr; BpDelivery dlv; int stop = 0; time_t startTime = 0; int bytesReceived; int bundlesReceived = 0; time_t endTime; long interval; if (ownEid == NULL) { PUTS("Usage: bpcounter <own endpoint ID> [<max count>]"); return 0; } if (maxCount < 1) { maxCount = 2000000000; } if (bp_attach() < 0) { putErrmsg("Can't attach to BP.", NULL); return 0; } if (bp_open(ownEid, &sap) < 0) { putErrmsg("Can't open own endpoint.", ownEid); return 0; } oK(_bpsap(&sap)); sdr = bp_get_sdr(); bundlesReceived = 0; bytesReceived = 0; isignal(SIGALRM, printCount); alarm(5); isignal(SIGINT, handleQuit); while (_running(NULL)) { if (bp_receive(sap, &dlv, BP_BLOCKING) < 0) { putErrmsg("bpcounter bundle reception failed.", NULL); oK(_running(&stop)); continue; } if (dlv.result == BpPayloadPresent) { if ((bundlesReceived = _bundleCount(1)) == 1) { startTime = time(NULL); } bytesReceived += zco_length(sdr, dlv.adu); } bp_release_delivery(&dlv, 1); if (bundlesReceived == maxCount) { oK(_running(&stop)); } } if (bundlesReceived > 0) { endTime = time(NULL); interval = endTime - startTime; PUTMEMO("Time (seconds)", itoa(interval)); if (interval > 0) { PUTMEMO("Throughput (bytes per second)", itoa(bytesReceived / interval)); } } bp_close(sap); PUTMEMO("Stopping bpcounter; bundles received", itoa(bundlesReceived)); bp_detach(); return 0; }