static int run_sdatest(uvast destEngineId) { SenderThreadParms parms; pthread_t senderThread; isignal(SIGTERM, interruptThread); if (destEngineId) { /* Must start sender thread. */ parms.destEngineId = destEngineId; parms.running = 1; if (pthread_begin(&senderThread, NULL, sendItems, &parms)) { putSysErrmsg("sdatest can't create send thread", NULL); return 1; } } if (sda_run(getLengthOfItem, handleItem) < 0) { putErrmsg("sdatest sda_run failed.", NULL); } if (destEngineId) { parms.running = 0; pthread_join(senderThread, NULL); } writeErrmsgMemos(); writeMemo("[i] sdatest main thread has ended."); ionDetach(); return 0; }
void bp_detach() { ionDetach(); }
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 udplsi(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { char *endpointSpec = (char *) a1; #else int main(int argc, char *argv[]) { char *endpointSpec = (argc > 1 ? argv[1] : NULL); #endif LtpVdb *vdb; unsigned short portNbr = 0; unsigned int ipAddress = INADDR_ANY; struct sockaddr socketName; struct sockaddr_in *inetName; ReceiverThreadParms rtp; socklen_t nameLength; pthread_t receiverThread; int fd; char quit = '\0'; /* Note that ltpadmin must be run before the first * invocation of ltplsi, to initialize the LTP database * (as necessary) and dynamic database. */ if (ltpInit(0) < 0) { putErrmsg("udplsi can't initialize LTP.", NULL); return 1; } vdb = getLtpVdb(); if (vdb->lsiPid != ERROR && vdb->lsiPid != sm_TaskIdSelf()) { putErrmsg("LSI task is already started.", itoa(vdb->lsiPid)); return 1; } /* All command-line arguments are now validated. */ if (endpointSpec) { if(parseSocketSpec(endpointSpec, &portNbr, &ipAddress) != 0) { putErrmsg("Can't get IP/port for endpointSpec.", endpointSpec); return -1; } } if (portNbr == 0) { portNbr = LtpUdpDefaultPortNbr; } portNbr = htons(portNbr); ipAddress = htonl(ipAddress); 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 *) &ipAddress, 4); rtp.linkSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (rtp.linkSocket < 0) { putSysErrmsg("LSI can't open UDP socket", NULL); return -1; } nameLength = sizeof(struct sockaddr); if (reUseAddress(rtp.linkSocket) || bind(rtp.linkSocket, &socketName, nameLength) < 0 || getsockname(rtp.linkSocket, &socketName, &nameLength) < 0) { closesocket(rtp.linkSocket); putSysErrmsg("Can't initialize socket", NULL); return 1; } /* Set up signal handling; SIGTERM is shutdown signal. */ ionNoteMainThread("udplsi"); isignal(SIGTERM, interruptThread); /* Start the receiver thread. */ rtp.running = 1; if (pthread_begin(&receiverThread, NULL, handleDatagrams, &rtp)) { closesocket(rtp.linkSocket); putSysErrmsg("udplsi can't create receiver thread", NULL); return 1; } /* Now sleep until interrupted by SIGTERM, at which point * it's time to stop the link service. */ { char txt[500]; isprintf(txt, sizeof(txt), "[i] udplsi is running, spec=[%s:%d].", inet_ntoa(inetName->sin_addr), ntohs(portNbr)); writeMemo(txt); } ionPauseMainThread(-1); /* Time to shut down. */ rtp.running = 0; /* Wake up the receiver thread by sending it a 1-byte * datagram. */ fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd >= 0) { isendto(fd, &quit, 1, 0, &socketName, sizeof(struct sockaddr)); closesocket(fd); } pthread_join(receiverThread, NULL); closesocket(rtp.linkSocket); writeErrmsgMemos(); writeMemo("[i] udplsi 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 ltpcli(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 VInduct *vduct; PsmAddress vductElt; ReceiverThreadParms rtp; pthread_t receiverThread; if (ductName == NULL) { PUTS("Usage: ltpcli <local engine number>]"); return 0; } if (bpAttach() < 0) { putErrmsg("ltpcli can't attach to BP.", NULL); return -1; } findInduct("ltp", ductName, &vduct, &vductElt); if (vductElt == 0) { putErrmsg("No such ltp duct.", ductName); return -1; } if (vduct->cliPid != ERROR && vduct->cliPid != sm_TaskIdSelf()) { putErrmsg("CLI task is already started for this duct.", itoa(vduct->cliPid)); return -1; } /* All command-line arguments are now validated. */ if (ltp_attach() < 0) { putErrmsg("ltpcli can't initialize LTP.", NULL); return -1; } /* Set up signal handling; SIGTERM is shutdown signal. */ ionNoteMainThread("ltpcli"); isignal(SIGTERM, interruptThread); /* Start the receiver thread. */ rtp.vduct = vduct; rtp.running = 1; if (pthread_begin(&receiverThread, NULL, handleNotices, &rtp)) { putSysErrmsg("ltpcli can't create receiver thread", NULL); return 1; } /* Now sleep until interrupted by SIGTERM, at which point * it's time to stop the induct. */ writeMemo("[i] ltpcli is running."); ionPauseMainThread(-1); /* Time to shut down. */ rtp.running = 0; /* Stop the receiver thread by interrupting client access. */ ltp_interrupt(BpLtpClientId); pthread_join(receiverThread, NULL); writeErrmsgMemos(); writeMemo("[i] ltpcli duct has ended."); ionDetach(); return 0; }
int dtn2fw(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 int running = 1; Sdr sdr; VScheme *vscheme; PsmAddress vschemeElt; Scheme scheme; Object elt; Object bundleAddr; Bundle bundle; if (bpAttach() < 0) { putErrmsg("dtn2fw can't attach to BP.", NULL); return 1; } if (dtn2Init(NULL) < 0) { putErrmsg("dtn2fw can't load routing database.", NULL); return 1; } sdr = getIonsdr(); findScheme("dtn", &vscheme, &vschemeElt); if (vschemeElt == 0) { putErrmsg("Scheme name for dtn2 is unknown.", "dtn"); return 1; } CHKZERO(sdr_begin_xn(sdr)); sdr_read(sdr, (char *) &scheme, sdr_list_data(sdr, vscheme->schemeElt), sizeof(Scheme)); sdr_exit_xn(sdr); oK(_dtn2fwSemaphore(&vscheme->semaphore)); isignal(SIGTERM, shutDown); /* Main loop: wait until forwarding queue is non-empty, * then drain it. */ writeMemo("[i] dtn2fw is running."); while (running && !(sm_SemEnded(vscheme->semaphore))) { /* We wrap forwarding in an SDR transaction to * prevent race condition with bpclock (which * is destroying bundles as their TTLs expire). */ CHKZERO(sdr_begin_xn(sdr)); elt = sdr_list_first(sdr, scheme.forwardQueue); if (elt == 0) /* Wait for forwarding notice. */ { sdr_exit_xn(sdr); if (sm_SemTake(vscheme->semaphore) < 0) { putErrmsg("Can't take forwarder semaphore.", NULL); running = 0; } continue; } bundleAddr = (Object) sdr_list_data(sdr, elt); sdr_stage(sdr, (char *) &bundle, bundleAddr, sizeof(Bundle)); sdr_list_delete(sdr, elt, NULL, NULL); bundle.fwdQueueElt = 0; /* Must rewrite bundle to note removal of * fwdQueueElt, in case the bundle is abandoned * and bpDestroyBundle re-reads it from the * database. */ sdr_write(sdr, bundleAddr, (char *) &bundle, sizeof(Bundle)); if (enqueueBundle(&bundle, bundleAddr) < 0) { sdr_cancel_xn(sdr); putErrmsg("Can't enqueue bundle.", NULL); running = 0; /* Terminate loop. */ continue; } if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't enqueue bundle.", NULL); running = 0; /* Terminate loop. */ } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); } writeErrmsgMemos(); writeMemo("[i] dtn2fw forwarder has ended."); ionDetach(); return 0; }
int stcpclo(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; pthread_t keepaliveThread; Object bundleZco; BpExtendedCOS extendedCOS; char destDuctName[MAX_CL_DUCT_NAME_LEN + 1]; unsigned int bundleLength; int ductSocket = -1; int bytesSent; if (ductName == NULL) { PUTS("Usage: stcpclo <remote host name>[:<port number>]"); return 0; } if (bpAttach() < 0) { putErrmsg("stcpclo can't attach to BP.", NULL); return -1; } buffer = MTAKE(TCPCLA_BUFSZ); if (buffer == NULL) { putErrmsg("No memory for TCP buffer in stcpclo.", NULL); return -1; } findOutduct("stcp", ductName, &vduct, &vductElt); if (vductElt == 0) { putErrmsg("No such stcp duct.", ductName); MRELEASE(buffer); return -1; } if (vduct->cloPid > 0 && 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(); sdr_read(sdr, (char *) &duct, sdr_list_data(sdr, vduct->outductElt), sizeof(Outduct)); sdr_read(sdr, (char *) &protocol, duct.protocol, sizeof(ClProtocol)); 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); /* Set up signal handling. SIGTERM is shutdown signal. */ oK(stcpcloSemaphore(&(vduct->semaphore))); isignal(SIGTERM, shutDownClo); isignal(SIGPIPE, handleConnectionLoss); /* Start the keepalive thread for the eventual connection. */ parms.cloRunning = &running; pthread_mutex_init(&mutex, NULL); parms.mutex = &mutex; parms.socketName = &socketName; parms.ductSocket = &ductSocket; if (pthread_create(&keepaliveThread, NULL, sendKeepalives, &parms)) { putSysErrmsg("stcpclo can't create keepalive thread", NULL); MRELEASE(buffer); pthread_mutex_destroy(&mutex); return 1; } /* Can now begin transmitting to remote duct. */ writeMemo("[i] stcpclo is running."); while (!(sm_SemEnded(stcpcloSemaphore(NULL)))) { if (bpDequeue(vduct, outflows, &bundleZco, &extendedCOS, destDuctName) < 0) { sm_SemEnd(stcpcloSemaphore(NULL));/* Stop. */ continue; } if (bundleZco == 0) /* Interrupted. */ { continue; } bundleLength = zco_length(sdr, bundleZco); pthread_mutex_lock(&mutex); bytesSent = sendBundleByTCP(&socketName, &ductSocket, bundleLength, bundleZco, buffer); pthread_mutex_unlock(&mutex); if (bytesSent < bundleLength) { sm_SemEnd(stcpcloSemaphore(NULL));/* Stop. */ continue; } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); } running = 0; /* Terminate keepalive. */ pthread_join(keepaliveThread, NULL); if (ductSocket != -1) { close(ductSocket); } pthread_mutex_destroy(&mutex); writeErrmsgMemos(); writeMemo("[i] stcpclo duct has ended."); MRELEASE(buffer); ionDetach(); return 0; }
static int run_imcadmin(char *cmdFileName) { int cmdFile; char line[256]; int len; if (bpAttach() < 0) { putErrmsg("imcadmin can't attach to BP.", NULL); return -1; } if (imcInit() < 0) { putErrmsg("imcadmin can't initialize IMC database.", NULL); return -1; } if (cmdFileName == NULL) /* Interactive. */ { #ifdef FSWLOGGER return 0; #else cmdFile = fileno(stdin); isignal(SIGINT, handleQuit); while (1) { printf(": "); fflush(stdout); if (igets(cmdFile, line, sizeof line, &len) == NULL) { if (len == 0) { break; } putErrmsg("igets failed.", NULL); break; /* Out of loop. */ } if (len == 0) { continue; } if (processLine(line, len)) { break; /* Out of loop. */ } } #endif } else /* Scripted. */ { cmdFile = iopen(cmdFileName, O_RDONLY, 0777); if (cmdFile < 0) { PERROR("Can't open command file"); } else { while (1) { if (igets(cmdFile, line, sizeof line, &len) == NULL) { if (len == 0) { break; /* Loop. */ } putErrmsg("igets failed.", NULL); break; /* Loop. */ } if (len == 0 || line[0] == '#') /* Comment.*/ { continue; } if (processLine(line, len)) { break; /* Out of loop. */ } } close(cmdFile); } } writeErrmsgMemos(); printText("Stopping imcadmin."); ionDetach(); return 0; }
int pmqlso(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10) { char *mqName = (char *) a1; uvast remoteEngineId = a2 != 0 ? strtouvast((char *) a2) : 0; #else int main(int argc, char *argv[]) { char *mqName = argc > 1 ? argv[1] : NULL; uvast remoteEngineId = argc > 2 ? strtouvast(argv[2]) : 0; #endif Sdr sdr; LtpVspan *vspan; PsmAddress vspanElt; struct mq_attr mqAttributes = { 0, PMQLSA_MAXMSG, PMQLSA_MSGSIZE, 0 }; mqd_t mq; int running; int segmentLength; char *segment; if (remoteEngineId == 0 || mqName == NULL) { puts("Usage: pmqlso <message queue name> <remote engine ID>"); return 0; } /* Note that ltpadmin must be run before the first * invocation of ltplso, to initialize the LTP database * (as necessary) and dynamic database. */ if (ltpInit(0) < 0) { putErrmsg("pmqlso can't initialize LTP.", NULL); return 1; } sdr = getIonsdr(); CHKERR(sdr_begin_xn(sdr)); /* Just to lock memory. */ findSpan(remoteEngineId, &vspan, &vspanElt); if (vspanElt == 0) { sdr_exit_xn(sdr); putErrmsg("No such engine in database.", itoa(remoteEngineId)); return 1; } if (vspan->lsoPid > 0 && vspan->lsoPid != sm_TaskIdSelf()) { sdr_exit_xn(sdr); putErrmsg("LSO task is already started for this span.", itoa(vspan->lsoPid)); return 1; } /* All command-line arguments are now validated. */ sdr_exit_xn(sdr); mq = mq_open(mqName, O_RDWR | O_CREAT, 0777, &mqAttributes); if (mq == (mqd_t) -1) { putSysErrmsg("pmqlso can't open message queue", mqName); return 1; } oK(_pmqlsoSemaphore(&vspan->segSemaphore)); isignal(SIGTERM, interruptThread); /* Can now begin transmitting to remote engine. */ writeMemo("[i] pmqlso is running."); running = 1; while (running && !(sm_SemEnded(_pmqlsoSemaphore(NULL)))) { segmentLength = ltpDequeueOutboundSegment(vspan, &segment); if (segmentLength < 0) { running = 0; /* Terminate LSO. */ continue; } if (segmentLength == 0) /* Interrupted. */ { continue; } if (segmentLength > PMQLSA_MSGSIZE) { putErrmsg("Segment is too big for PMQ LSO.", itoa(segmentLength)); running = 0; /* Terminate LSO. */ continue; } if (sendSegmentByPMQ(mq, segment, segmentLength) < 0) { putSysErrmsg("pmqlso failed sending segment", mqName); running = 0; /* Terminate LSO. */ continue; } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); } mq_close(mq); writeErrmsgMemos(); writeMemo("[i] pmqlso duct has ended."); ionDetach(); return 0; }
int bsspclo(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 Sdr sdr; VOutduct *vduct; PsmAddress vductElt; vast destEngineNbr; Outduct outduct; ClProtocol protocol; Outflow outflows[3]; int i; int running = 1; Object bundleZco; BpExtendedCOS extendedCOS; char destDuctName[MAX_CL_DUCT_NAME_LEN + 1]; BsspSessionId sessionId; unsigned char *buffer; Lyst streams; Bundle bundleImage; char *dictionary = 0; unsigned int bundleLength; if (ductName == NULL) { PUTS("Usage: bsspclo [-]<destination engine number>"); return 0; } if (bpAttach() < 0) { putErrmsg("bsspclo can't attach to BP.", NULL); return -1; } sdr = getIonsdr(); findOutduct("bssp", ductName, &vduct, &vductElt); if (vductElt == 0) { putErrmsg("No such bssp duct.", ductName); return -1; } if (vduct->cloPid != ERROR && vduct->cloPid != sm_TaskIdSelf()) { putErrmsg("BSSPCLO task is already started for this duct.", itoa(vduct->cloPid)); return -1; } /* All command-line arguments are now validated. */ buffer = (unsigned char *) MTAKE(BP_MAX_BLOCK_SIZE); if (buffer == NULL) { putErrmsg("Can't get buffer for decoding bundle ZCOs.", NULL); return -1; } streams = lyst_create_using(getIonMemoryMgr()); if (streams == NULL) { putErrmsg("Can't create lyst of streams.", NULL); MRELEASE(buffer); return -1; } lyst_delete_set(streams, eraseStream, NULL); CHKERR(sdr_begin_xn(sdr)); sdr_read(sdr, (char *) &outduct, sdr_list_data(sdr, vduct->outductElt), sizeof(Outduct)); sdr_read(sdr, (char *) &protocol, outduct.protocol, sizeof(ClProtocol)); sdr_exit_xn(sdr); destEngineNbr = strtovast(ductName); if (protocol.nominalRate == 0) { vduct->xmitThrottle.nominalRate = DEFAULT_BSSP_RATE; } else { vduct->xmitThrottle.nominalRate = protocol.nominalRate; } memset((char *) outflows, 0, sizeof outflows); outflows[0].outboundBundles = outduct.bulkQueue; outflows[1].outboundBundles = outduct.stdQueue; outflows[2].outboundBundles = outduct.urgentQueue; for (i = 0; i < 3; i++) { outflows[i].svcFactor = 1 << i; } if (bssp_attach() < 0) { putErrmsg("bsspclo can't initialize BSSP.", NULL); lyst_destroy(streams); MRELEASE(buffer); return -1; } /* Set up signal handling. SIGTERM is shutdown signal. */ oK(bsspcloSemaphore(&(vduct->semaphore))); isignal(SIGTERM, shutDownClo); /* Can now begin transmitting to remote duct. */ writeMemo("[i] bsspclo is running."); while (running && !(sm_SemEnded(bsspcloSemaphore(NULL)))) { if (bpDequeue(vduct, outflows, &bundleZco, &extendedCOS, destDuctName, 0, -1) < 0) { running = 0; /* Terminate CLO. */ continue; } if (bundleZco == 0) /* Interrupted. */ { continue; } if (decodeBundle(sdr, bundleZco, buffer, &bundleImage, &dictionary, &bundleLength) < 0) { putErrmsg("Can't decode bundle ZCO.", NULL); CHKERR(sdr_begin_xn(sdr)); zco_destroy(sdr, bundleZco); if (sdr_end_xn(sdr) < 0) { putErrmsg("Failed destroying ZCO.", NULL); break; } continue; } switch (bssp_send(destEngineNbr, BpBsspClientId, bundleZco, isInOrder(streams, &bundleImage), &sessionId)) { case 0: putErrmsg("Unable to send this bundle via BSSP.", NULL); break; case -1: putErrmsg("BsspSend failed.", NULL); running = 0; /* Terminate CLO. */ } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); /* Note: bundleZco is destroyed later, when BSSP's * ExportSession is closed following transmission * of bundle ZCOs as aggregated into a block. */ } writeErrmsgMemos(); writeMemo("[i] bsspclo duct has ended."); lyst_destroy(streams); MRELEASE(buffer); ionDetach(); return 0; }
int udpclo(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 unsigned char *buffer; VOutduct *vduct; PsmAddress vductElt; Sdr sdr; Outduct outduct; ClProtocol protocol; Outflow outflows[3]; int i; char *hostName; unsigned short portNbr; unsigned int hostNbr; struct sockaddr socketName; struct sockaddr_in *inetName; Object bundleZco; BpExtendedCOS extendedCOS; char destDuctName[MAX_CL_DUCT_NAME_LEN + 1]; unsigned int bundleLength; int ductSocket = -1; int bytesSent; if (bpAttach() < 0) { putErrmsg("udpclo can't attach to BP.", NULL); return -1; } buffer = MTAKE(UDPCLA_BUFSZ); if (buffer == NULL) { putErrmsg("No memory for UDP buffer in udpclo.", NULL); return -1; } findOutduct("udp", "*", &vduct, &vductElt); if (vductElt == 0) { putErrmsg("No such udp duct.", "*"); MRELEASE(buffer); return -1; } if (vduct->cloPid > 0 && 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(); sdr_read(sdr, (char *) &outduct, sdr_list_data(sdr, vduct->outductElt), sizeof(Outduct)); sdr_read(sdr, (char *) &protocol, outduct.protocol, sizeof(ClProtocol)); if (protocol.nominalRate <= 0) { vduct->xmitThrottle.nominalRate = DEFAULT_UDP_RATE; } else { vduct->xmitThrottle.nominalRate = protocol.nominalRate; } memset((char *) outflows, 0, sizeof outflows); outflows[0].outboundBundles = outduct.bulkQueue; outflows[1].outboundBundles = outduct.stdQueue; outflows[2].outboundBundles = outduct.urgentQueue; for (i = 0; i < 3; i++) { outflows[i].svcFactor = 1 << i; } /* Set up signal handling. SIGTERM is shutdown signal. */ oK(udpcloSemaphore(&(vduct->semaphore))); isignal(SIGTERM, shutDownClo); /* Can now begin transmitting to remote duct. */ writeMemo("[i] udpclo is running."); while (!(sm_SemEnded(vduct->semaphore))) { if (bpDequeue(vduct, outflows, &bundleZco, &extendedCOS, destDuctName) < 0) { sm_SemEnd(udpcloSemaphore(NULL));/* Stop. */ continue; } if (bundleZco == 0) /* Interrupted. */ { continue; } hostName = destDuctName; parseSocketSpec(destDuctName, &portNbr, &hostNbr); if (portNbr == 0) { portNbr = BpUdpDefaultPortNbr; } portNbr = htons(portNbr); if (hostNbr == 0) { writeMemoNote("[?] Can't get IP address for host", hostName); } 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); bundleLength = zco_length(sdr, bundleZco); bytesSent = sendBundleByUDP(&socketName, &ductSocket, bundleLength, bundleZco, buffer); if (bytesSent < bundleLength) { sm_SemEnd(udpcloSemaphore(NULL));/* Stop. */ continue; } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); } if (ductSocket != -1) { close(ductSocket); } writeErrmsgMemos(); writeMemo("[i] udpclo duct has ended."); MRELEASE(buffer); ionDetach(); return 0; }