int bpstats(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 if (bp_attach() < 0) { putErrmsg("bpstats can't attach to BP.", NULL); return 0; } writeMemo("[i] Start of statistics snapshot..."); reportAllStateStats(); writeMemo("[i] ...end of statistics snapshot."); bp_detach(); return 0; }
int acslist(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) { if(argc > 1) { if (strcmp(argv[1], "-s") == 0 || strcmp(argv[1], "--stdout") == 0) { printToStdout = 1; argc--; argv++; } } #endif Sdr acsSdr; /* Attach to ACS database. */ if (acsAttach() < 0) { putErrmsg("Can't attach to ACS.", NULL); return 1; } acsSdr = getAcssdr(); /* Lock SDR and check the database. */ CHKZERO(sdr_begin_xn(acsSdr)); printAndCheckByCids(acsSdr); checkByBids(acsSdr); sdr_exit_xn(acsSdr); /* Cleanup */ writeErrmsgMemos(); acsDetach(); bp_detach(); return errors == 0 ? 0 : 1; }
int main(int argc, char **argv) { Sdr sdr; Object txExtent; Object txBundleZco; Object txNewBundle; BpDelivery rxDlv; int rxContentLength; ZcoReader rxReader; int rxLen; char rxContent[sizeof(testLine)]; /* Start ION */ ionstart_default_config("loopback-ltp/loopback.ionrc", NULL, "loopback-ltp/loopback.ltprc", "loopback-ltp/loopback.bprc", "loopback-ltp/loopback.ipnrc", NULL); /* Attach to ION */ fail_unless(bp_attach() >= 0); sdr = bp_get_sdr(); /* Send the loopback bundle */ sdr_begin_xn(sdr); txExtent = sdr_malloc(sdr, sizeof(testLine) - 1); fail_unless(txExtent != 0); sdr_write(sdr, txExtent, testLine, sizeof(testLine) - 1); txBundleZco = zco_create(sdr, ZcoSdrSource, txExtent, 0, sizeof(testLine) - 1); fail_unless(sdr_end_xn(sdr) >= 0 && txBundleZco != 0); fail_unless(bp_send(NULL, testEid, NULL, 300, BP_STD_PRIORITY, NoCustodyRequested, 0, 0, NULL, txBundleZco, &txNewBundle) > 0); /* Receive the loopback bundle */ fail_unless(bp_open(testEid, &rxSap) >= 0); fail_unless(bp_receive(rxSap, &rxDlv, IONTEST_DEFAULT_RECEIVE_WAIT) >= 0); fail_unless(rxDlv.result == BpPayloadPresent); sdr_begin_xn(sdr); rxContentLength = zco_source_data_length(sdr, rxDlv.adu); fail_unless(rxContentLength == sizeof(testLine) - 1); zco_start_receiving(rxDlv.adu, &rxReader); rxLen = zco_receive_source(sdr, &rxReader, rxContentLength, rxContent); fail_unless(rxLen == rxContentLength); fail_unless(sdr_end_xn(sdr) >= 0); bp_release_delivery(&rxDlv, 1); bp_close(rxSap); /* Detach from ION */ writeErrmsgMemos(); bp_detach(); /* Compare the received data */ rxContent[sizeof(rxContent) - 1] = '\0'; fail_unless(strncmp(rxContent, testLine, sizeof(testLine)) == 0); /* Stop ION */ ionstop(); CHECK_FINISH; }
int tcpclo(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { char *ductName = (char *) a1; #else int main(int argc, char *argv[]) { char *ductName = (argc > 1 ? argv[1] : NULL); #endif unsigned char *buffer; VOutduct *vduct; PsmAddress vductElt; Sdr sdr; Outduct duct; ClProtocol protocol; Outflow outflows[3]; int i; char *hostName; unsigned short portNbr; unsigned int hostNbr; struct sockaddr socketName; struct sockaddr_in *inetName; int running = 1; pthread_mutex_t mutex; KeepaliveThreadParms parms; ReceiveThreadParms rparms; pthread_t keepaliveThread; pthread_t receiverThread; Object bundleZco; BpExtendedCOS extendedCOS; char destDuctName[MAX_CL_DUCT_NAME_LEN + 1]; unsigned int bundleLength; int ductSocket = -1; int bytesSent; int keepalivePeriod = 0; VInduct *viduct; if (ductName == NULL) { PUTS("Usage: tcpclo <remote host name>[:<port number>]"); return 0; } if (bpAttach() < 0) { putErrmsg("tcpclo can't attach to BP", NULL); return 1; } buffer = MTAKE(TCPCLA_BUFSZ); if (buffer == NULL) { putErrmsg("No memory for TCP buffer in tcpclo.", NULL); return 1; } findOutduct("tcp", ductName, &vduct, &vductElt); if (vductElt == 0) { putErrmsg("No such tcp duct.", ductName); MRELEASE(buffer); return 1; } if (vduct->cloPid != ERROR && vduct->cloPid != sm_TaskIdSelf()) { putErrmsg("CLO task is already started for this duct.", itoa(vduct->cloPid)); MRELEASE(buffer); return 1; } /* All command-line arguments are now validated. */ sdr = getIonsdr(); CHKERR(sdr_begin_xn(sdr)); sdr_read(sdr, (char *) &duct, sdr_list_data(sdr, vduct->outductElt), sizeof(Outduct)); sdr_read(sdr, (char *) &protocol, duct.protocol, sizeof(ClProtocol)); sdr_exit_xn(sdr); if (protocol.nominalRate == 0) { vduct->xmitThrottle.nominalRate = DEFAULT_TCP_RATE; } else { vduct->xmitThrottle.nominalRate = protocol.nominalRate; } memset((char *) outflows, 0, sizeof outflows); outflows[0].outboundBundles = duct.bulkQueue; outflows[1].outboundBundles = duct.stdQueue; outflows[2].outboundBundles = duct.urgentQueue; for (i = 0; i < 3; i++) { outflows[i].svcFactor = 1 << i; } hostName = ductName; parseSocketSpec(ductName, &portNbr, &hostNbr); if (portNbr == 0) { portNbr = BpTcpDefaultPortNbr; } portNbr = htons(portNbr); if (hostNbr == 0) { putErrmsg("Can't get IP address for host.", hostName); MRELEASE(buffer); return 1; } hostNbr = htonl(hostNbr); memset((char *) &socketName, 0, sizeof socketName); inetName = (struct sockaddr_in *) &socketName; inetName->sin_family = AF_INET; inetName->sin_port = portNbr; memcpy((char *) &(inetName->sin_addr.s_addr), (char *) &hostNbr, 4); if (_tcpOutductId(&socketName, "tcp", ductName) < 0) { putErrmsg("Can't record TCP Outduct ID for connection.", NULL); MRELEASE(buffer); return -1; } /* Set up signal handling. SIGTERM is shutdown signal. */ oK(tcpcloSemaphore(&(vduct->semaphore))); isignal(SIGTERM, shutDownClo); #ifndef mingw isignal(SIGPIPE, handleConnectionLoss); #endif /* Start the keepalive thread for the eventual connection. */ tcpDesiredKeepAlivePeriod = KEEPALIVE_PERIOD; parms.cloRunning = &running; pthread_mutex_init(&mutex, NULL); parms.mutex = &mutex; parms.socketName = &socketName; parms.ductSocket = &ductSocket; parms.keepalivePeriod = &keepalivePeriod; if (pthread_begin(&keepaliveThread, NULL, sendKeepalives, &parms)) { putSysErrmsg("tcpclo can't create keepalive thread", NULL); MRELEASE(buffer); pthread_mutex_destroy(&mutex); return 1; } // Returns the VInduct Object of first induct with same protocol // as the outduct. The VInduct is required to create an acq area. // The Acq Area inturn uses the throttle information from VInduct // object while receiving bundles. The throttle information // of all inducts of the same induct will be the same, so choosing // any induct will serve the purpose. findVInduct(&viduct,protocol.name); if(viduct == NULL) { putErrmsg("tcpclo can't get VInduct", NULL); MRELEASE(buffer); pthread_mutex_destroy(&mutex); return 1; } rparms.vduct = viduct; rparms.bundleSocket = &ductSocket; rparms.mutex = &mutex; rparms.cloRunning = &running; if (pthread_begin(&receiverThread, NULL, receiveBundles, &rparms)) { putSysErrmsg("tcpclo can't create receive thread", NULL); MRELEASE(buffer); pthread_mutex_destroy(&mutex); return 1; } /* Can now begin transmitting to remote duct. */ { char txt[500]; isprintf(txt, sizeof(txt), "[i] tcpclo is running, spec=[%s:%d].", inet_ntoa(inetName->sin_addr), ntohs(inetName->sin_port)); writeMemo(txt); } while (running && !(sm_SemEnded(tcpcloSemaphore(NULL)))) { if (bpDequeue(vduct, outflows, &bundleZco, &extendedCOS, destDuctName, 0, -1) < 0) { running = 0; /* Terminate CLO. */ continue; } if (bundleZco == 0) /* Interrupted. */ { continue; } CHKZERO(sdr_begin_xn(sdr)); bundleLength = zco_length(sdr, bundleZco); sdr_exit_xn(sdr); pthread_mutex_lock(&mutex); bytesSent = sendBundleByTCPCL(&socketName, &ductSocket, bundleLength, bundleZco, buffer, &keepalivePeriod); pthread_mutex_unlock(&mutex); if(bytesSent < 0) { running = 0; /* Terminate CLO. */ } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); } writeMemo("[i] tcpclo done sending"); if (sendShutDownMessage(&ductSocket, SHUT_DN_NO, -1, &socketName) < 0) { putErrmsg("Sending Shutdown message failed!!",NULL); } if (ductSocket != -1) { closesocket(ductSocket); ductSocket=-1; } running = 0; pthread_join(keepaliveThread, NULL); writeMemo("[i] tcpclo keepalive thread killed"); pthread_join(receiverThread, NULL); writeMemo("[i] tcpclo receiver thread killed"); writeErrmsgMemos(); writeMemo("[i] tcpclo duct has ended."); oK(_tcpOutductId(&socketName, NULL, NULL)); MRELEASE(buffer); pthread_mutex_destroy(&mutex); bp_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; }
int bpecho(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { char *ownEid = (char *) a1; #else int main(int argc, char **argv) { char *ownEid = (argc > 1 ? argv[1] : NULL); #endif /* Indication marks: "." for BpPayloadPresent (1), "*" for BpReceptionTimedOut (2). "!" for BpReceptionInterrupted (3). */ static char dlvmarks[] = "?.*!"; BpSAP sap; Sdr sdr; int running = 1; char dataToSend[ADU_LEN] = "x"; Object bundleZco; Object newBundle; Object extent; BpDelivery dlv; char sourceEid[1024]; if (ownEid == NULL) { PUTS("Usage: bpecho <own endpoint ID>"); return 0; } 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.", NULL); return 0; } oK(_bpsap(&sap)); sdr = bp_get_sdr(); isignal(SIGINT, handleQuit); while (1) { /* Wait for a bundle from the driver. */ while (running) { if (bp_receive(sap, &dlv, BP_BLOCKING) < 0) { bp_close(sap); putErrmsg("bpecho bundle reception failed.", NULL); return 1; } putchar(dlvmarks[dlv.result]); fflush(stdout); if (dlv.result == BpReceptionInterrupted) { running = 0; continue; } if (dlv.result == BpPayloadPresent) { istrcpy(sourceEid, dlv.bundleSourceEid, sizeof sourceEid); bp_release_delivery(&dlv, 1); break; /* Out of reception loop. */ } bp_release_delivery(&dlv, 1); } if (!running) /* Benchmark run terminated. */ { break; /* Out of main loop. */ } /* Now send acknowledgment bundle. */ sdr_begin_xn(sdr); extent = sdr_malloc(sdr, ADU_LEN); if (extent == 0) { sdr_cancel_xn(sdr); putErrmsg("No space for ZCO extent.", NULL); break; /* Out of main loop. */ } sdr_write(sdr, extent, dataToSend, ADU_LEN); bundleZco = zco_create(sdr, ZcoSdrSource, extent, 0, ADU_LEN); if (sdr_end_xn(sdr) < 0 || bundleZco == 0) { putErrmsg("Can't create ZCO.", NULL); break; /* Out of main loop. */ } if (bp_send(sap, BP_BLOCKING, sourceEid, NULL, 300, BP_STD_PRIORITY, NoCustodyRequested, 0, 0, NULL, bundleZco, &newBundle) < 1) { putErrmsg("bpecho can't send echo bundle.", NULL); break; /* Out of main loop. */ } } bp_close(sap); writeErrmsgMemos(); bp_detach(); return 0; }