int _tcpOutductId(struct sockaddr *socketName, char *protocolName, char *ductName) { static Lyst tcpOutductIds = NULL; LystElt elt; TcpOutductId *id = NULL; int idNotFound = 1; CHKERR(socketName); if (tcpOutductIds == NULL) { tcpOutductIds = lyst_create_using(getIonMemoryMgr()); CHKERR(tcpOutductIds); lyst_delete_set(tcpOutductIds, deleteOutductId, NULL); } for (elt = lyst_first(tcpOutductIds); elt; elt = lyst_next(elt)) { id = (TcpOutductId *) lyst_data(elt); idNotFound = memcmp(&(id->socketName), socketName, sizeof(struct sockaddr)); if (idNotFound < 0) { continue; } /* The result of memcmp is either 0, indicating * matching TcpOutductId was found (that is, * idNotFound is false), or greater than 0 * indicating that no matching TcpOutductId was * found (that is, idNotFound is true). */ break; } if (protocolName == NULL) /* Deleting outduct ID. */ { if (!idNotFound) /* Found it. */ { lyst_delete(elt); } return 0; } if (*protocolName == 0) /* Retrieving outduct ID. */ { if (!idNotFound) /* Found it. */ { istrcpy(protocolName, id->protocolName, MAX_CL_PROTOCOL_NAME_LEN); istrcpy(ductName, id->ductName, MAX_CL_DUCT_NAME_LEN); } return 0; } /* Recording new TCP Outduct ID. */ if (!idNotFound) { putErrmsg("[?] Socket address is already in TcpOutductSocket \ list.", ductName); return -1; }
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; }