int _extractSmallSdnv(unsigned int *into, unsigned char **from, int *remnant, int lineNbr) { int sdnvLength; uvast val; CHKZERO(into && from && remnant); if (*remnant < 1) { writeMemoNote("[?] Missing SDNV at line...", itoa(lineNbr)); return 0; } sdnvLength = decodeSdnv(&val, *from); if (sdnvLength < 1) { writeMemoNote("[?] Invalid SDNV at line...", itoa(lineNbr)); return 0; } *into = val; /* Truncate. */ (*from) += sdnvLength; (*remnant) -= sdnvLength; return sdnvLength; }
int dtn2_updateRule(char *nodeNm, char *demux, FwdDirective *directive) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; OBJ_POINTER(Dtn2Plan, plan); Object ruleAddr; Dtn2Rule ruleBuf; CHKERR(nodeNm && demux && directive); if (*demux == '\0') { writeMemo("[?] Zero-length DTN2 rule demux."); return 0; } if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] No plan defined for this node", nodeNm); return 0; } GET_OBJ_POINTER(sdr, Dtn2Plan, plan, sdr_list_data(sdr, elt)); dtn2_findRule(nodeName, demux, plan, &ruleAddr, &elt); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Unknown rule", demux); return 0; } /* All parameters validated, okay to update the rule. */ sdr_stage(sdr, (char *) &ruleBuf, ruleAddr, sizeof(Dtn2Rule)); dtn2_destroyDirective(&ruleBuf.directive); memcpy((char *) &ruleBuf.directive, (char *) directive, sizeof(FwdDirective)); sdr_write(sdr, ruleAddr, (char *) &ruleBuf, sizeof(Dtn2Rule)); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't update rule.", NULL); return -1; } return 1; }
int dtn2_removeRule(char *nodeNm, char *demux) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; OBJ_POINTER(Dtn2Plan, plan); Object ruleAddr; OBJ_POINTER(Dtn2Rule, rule); CHKERR(nodeNm && demux); if (*demux == '\0') { writeMemo("[?] Zero-length DTN2 rule demux."); return 0; } if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] No plan defined for this node", nodeNm); return 0; } GET_OBJ_POINTER(sdr, Dtn2Plan, plan, sdr_list_data(sdr, elt)); dtn2_findRule(nodeName, demux, plan, &ruleAddr, &elt); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Unknown rule", demux); return 0; } /* All parameters validated, okay to remove the rule. */ GET_OBJ_POINTER(sdr, Dtn2Rule, rule, ruleAddr); dtn2_destroyDirective(&(rule->directive)); sdr_free(sdr, ruleAddr); sdr_list_delete(sdr, elt, NULL, NULL); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't remove rule.", NULL); return -1; } return 1; }
Sdr getAcssdr(void) { static int haveTriedAcsSdr = 0; if (acsSdr || haveTriedAcsSdr) { return acsSdr; } if (ionAttach() < 0) { putErrmsg("Can't attach to ION.", NULL); return NULL; } haveTriedAcsSdr = 1; acsSdr = sdr_start_using(acssdrName); if (acsSdr == NULL) { writeMemoNote("[i] This task is unable to exercise ACS \ because the ACS SDR is not initialized, as noted in message above", itoa(sm_TaskIdSelf())); } return acsSdr; }
int dtn2_removePlan(char *nodeNm) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; Object planObj; OBJ_POINTER(Dtn2Plan, plan); CHKERR(nodeNm); if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Unknown plan", nodeNm); return 0; } planObj = sdr_list_data(sdr, elt); GET_OBJ_POINTER(sdr, Dtn2Plan, plan, planObj); if (sdr_list_length(sdr, plan->rules) > 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Can't remove plan; still has rules", nodeNm); return 0; } /* Okay to remove this plan from the database. */ sdr_list_delete(sdr, elt, NULL, NULL); dtn2_destroyDirective(&(plan->defaultDirective)); sdr_list_destroy(sdr, plan->rules, NULL, NULL); sdr_free(sdr, plan->nodeName); sdr_free(sdr, planObj); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't remove plan.", nodeNm); return -1; } return 1; }
void ionProd(unsigned long fromNode, unsigned long toNode, unsigned long xmitRate, unsigned int owlt) { Sdr ionsdr = _ionsdr(NULL); time_t fromTime; time_t toTime; Object elt; char textbuf[RFX_NOTE_LEN]; if (ionsdr == NULL) { if (ionAttach() < 0) { writeMemo("[?] ionProd: node not initialized yet."); return; } } fromTime = getUTCTime(); /* The current time. */ toTime = fromTime + 14400; /* Four hours later. */ elt = rfx_insert_range(fromTime, toTime, fromNode, toNode, owlt); if (elt == 0) { writeMemoNote("[?] ionProd: range insertion failed.", utoa(owlt)); return; } writeMemo("ionProd: range inserted."); writeMemo(rfx_print_range(sdr_list_data(ionsdr, elt), textbuf)); elt = rfx_insert_contact(fromTime, toTime, fromNode, toNode, xmitRate); if (elt == 0) { writeMemoNote("[?] ionProd: contact insertion failed.", utoa(xmitRate)); return; } writeMemo("ionProd: contact inserted."); writeMemo(rfx_print_contact(sdr_list_data(ionsdr, elt), textbuf)); }
int dtn2_addPlan(char *nodeNm, FwdDirective *defaultDir) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object nextPlan; Dtn2Plan plan; Object planObj; CHKERR(nodeNm && defaultDir); if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); if (locatePlan(nodeName, &nextPlan) != 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Duplicate plan", nodeNm); return 0; } /* Okay to add this plan to the database. */ plan.nodeName = sdr_string_create(sdr, nodeName); memcpy((char *) &plan.defaultDirective, (char *) defaultDir, sizeof(FwdDirective)); plan.rules = sdr_list_create(sdr); planObj = sdr_malloc(sdr, sizeof(Dtn2Plan)); if (planObj) { if (nextPlan) { oK(sdr_list_insert_before(sdr, nextPlan, planObj)); } else { oK(sdr_list_insert_last(sdr, (_dtn2Constants())->plans, planObj)); } sdr_write(sdr, planObj, (char *) &plan, sizeof(Dtn2Plan)); } if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't add plan.", nodeNm); return -1; } return 1; }
int _extractSdnv(unsigned long *into, unsigned char **from, int *remnant, int lineNbr) { int sdnvLength; CHKZERO(into && from && remnant); if (*remnant < 1) { writeMemoNote("[?] Missing SDNV at line...", itoa(lineNbr)); return 0; } sdnvLength = decodeSdnv(into, *from); if (sdnvLength < 1) { writeMemoNote("[?] Invalid SDNV at line...", itoa(lineNbr)); return 0; } (*from) += sdnvLength; (*remnant) -= sdnvLength; return sdnvLength; }
int dtn2_updatePlan(char *nodeNm, FwdDirective *defaultDir) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; Object planObj; Dtn2Plan plan; CHKERR(nodeNm && defaultDir); if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] No plan defined for this node", nodeNm); return 0; } /* Okay to update this plan. */ planObj = sdr_list_data(sdr, elt); sdr_stage(sdr, (char *) &plan, planObj, sizeof(Dtn2Plan)); dtn2_destroyDirective(&plan.defaultDirective); memcpy((char *) &plan.defaultDirective, (char *) defaultDir, sizeof(FwdDirective)); sdr_write(sdr, planObj, (char *) &plan, sizeof(Dtn2Plan)); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't update plan.", nodeNm); return -1; } return 1; }
int dtn2_addRule(char *nodeNm, char *demux, FwdDirective *directive) { Sdr sdr = getIonsdr(); char nodeName[SDRSTRING_BUFSZ]; Object elt; OBJ_POINTER(Dtn2Plan, plan); Object nextRule; Dtn2Rule ruleBuf; Object addr; CHKERR(nodeNm && demux && directive); if (*demux == '\0') { writeMemo("[?] Zero-length DTN2 rule demux."); return 0; } if (filterNodeName(nodeName, nodeNm) < 0) { return 0; } CHKERR(sdr_begin_xn(sdr)); elt = locatePlan(nodeName, NULL); if (elt == 0) { sdr_exit_xn(sdr); writeMemoNote("[?] No plan defined for this node", nodeNm); return 0; } GET_OBJ_POINTER(sdr, Dtn2Plan, plan, sdr_list_data(sdr, elt)); if (locateRule(plan, demux, &nextRule) != 0) { sdr_exit_xn(sdr); writeMemoNote("[?] Duplicate rule", demux); return 0; } /* All parameters validated, okay to add the rule. */ memset((char *) &ruleBuf, 0, sizeof(Dtn2Rule)); ruleBuf.demux = sdr_string_create(sdr, demux); memcpy((char *) &ruleBuf.directive, (char *) directive, sizeof(FwdDirective)); addr = sdr_malloc(sdr, sizeof(Dtn2Rule)); if (addr) { if (nextRule) { elt = sdr_list_insert_before(sdr, nextRule, addr); } else { elt = sdr_list_insert_last(sdr, plan->rules, addr); } sdr_write(sdr, addr, (char *) &ruleBuf, sizeof(Dtn2Rule)); } if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't add rule.", NULL); return -1; } return 1; }
static int checkNodeListParms(IonParms *parms, char *wdName, unsigned long nodeNbr) { char *nodeListDir; char nodeListFileName[265]; int nodeListFile; int lineNbr = 0; int lineLen; char lineBuf[256]; unsigned long lineNodeNbr; int lineWmKey; char lineSdrName[MAX_SDR_NAME + 1]; char lineWdName[256]; int result; nodeListDir = getenv("ION_NODE_LIST_DIR"); if (nodeListDir == NULL) /* Single node on machine. */ { if (parms->wmKey == 0) { parms->wmKey = ION_DEFAULT_SM_KEY; } if (parms->wmKey != ION_DEFAULT_SM_KEY) { putErrmsg("Config parms wmKey != default.", itoa(ION_DEFAULT_SM_KEY)); return -1; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME, sizeof parms->sdrName); } if (strcmp(parms->sdrName, ION_DEFAULT_SDR_NAME) != 0) { putErrmsg("Config parms sdrName != default.", ION_DEFAULT_SDR_NAME); return -1; } return 0; } /* Configured for multi-node operation. */ isprintf(nodeListFileName, sizeof nodeListFileName, "%.255s%cion_nodes", nodeListDir, ION_PATH_DELIMITER); if (nodeNbr == 0) /* Just attaching. */ { nodeListFile = open(nodeListFileName, O_RDONLY, 0); } else /* Initializing the node. */ { nodeListFile = open(nodeListFileName, O_RDWR | O_CREAT, 00666); } if (nodeListFile < 0) { putSysErrmsg("Can't open ion_nodes file", nodeListFileName); writeMemo("[?] Remove ION_NODE_LIST_DIR from env?"); return -1; } while (1) { if (igets(nodeListFile, lineBuf, sizeof lineBuf, &lineLen) == NULL) { if (lineLen < 0) { close(nodeListFile); putErrmsg("Failed reading ion_nodes file.", nodeListFileName); return -1; } break; /* End of file. */ } lineNbr++; if (sscanf(lineBuf, "%lu %d %31s %255s", &lineNodeNbr, &lineWmKey, lineSdrName, lineWdName) < 4) { close(nodeListFile); putErrmsg("Syntax error at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (lineNodeNbr == nodeNbr) /* Match. */ { /* lineNodeNbr can't be zero (we never * write such lines to the file), so this * must be matching non-zero node numbers. * So we are re-initializing this node. */ close(nodeListFile); if (strcmp(lineWdName, wdName) != 0) { putErrmsg("CWD conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (parms->wmKey == 0) { parms->wmKey = lineWmKey; } if (parms->wmKey != lineWmKey) { putErrmsg("WmKey conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, lineSdrName, sizeof parms->sdrName); } if (strcmp(parms->sdrName, lineSdrName) != 0) { putErrmsg("SdrName conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } return 0; } /* lineNodeNbr does not match nodeNbr (which may * be zero). */ if (strcmp(lineWdName, wdName) == 0) /* Match. */ { close(nodeListFile); if (nodeNbr == 0) /* Attaching. */ { parms->wmKey = lineWmKey; istrcpy(parms->sdrName, lineSdrName, MAX_SDR_NAME + 1); return 0; } /* Reinitialization conflict. */ putErrmsg("NodeNbr conflict at line#", itoa(lineNbr)); writeMemoNote("[?] Repair ion_nodes file.", nodeListFileName); return -1; } /* Haven't found matching line yet. Continue. */ } /* No matching lines in file. */ if (nodeNbr == 0) /* Attaching to existing node. */ { close(nodeListFile); putErrmsg("No node has been initialized in this directory.", wdName); return -1; } /* Initializing, so append line to the nodes list file. */ if (parms->wmKey == 0) { parms->wmKey = ION_DEFAULT_SM_KEY; } if (parms->sdrName[0] == '\0') { istrcpy(parms->sdrName, ION_DEFAULT_SDR_NAME, sizeof parms->sdrName); } isprintf(lineBuf, sizeof lineBuf, "%lu %d %.31s %.255s\n", nodeNbr, parms->wmKey, parms->sdrName, wdName); result = iputs(nodeListFile, lineBuf); close(nodeListFile); if (result < 0) { putErrmsg("Failed writing to ion_nodes file.", NULL); return -1; } return 0; }
static void *sendBundles(void *parm) { /* Main loop for single bundle transmission thread * serving all BRS sockets. */ SenderThreadParms *parms = (SenderThreadParms *) parm; unsigned char *buffer; Outduct outduct; Sdr sdr; Outflow outflows[3]; int i; Object bundleZco; BpExtendedCOS extendedCOS; char destDuctName[MAX_CL_DUCT_NAME_LEN + 1]; unsigned int bundleLength; int ductNbr; int bytesSent; int failedTransmissions = 0; buffer = MTAKE(TCPCLA_BUFSZ); if (buffer == NULL) { putErrmsg("No memory for TCP buffer in brsscla.", NULL); return terminateSenderThread(parms); } sdr = getIonsdr(); sdr_read(sdr, (char *) &outduct, sdr_list_data(sdr, parms->vduct->outductElt), sizeof(Outduct)); 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; } /* Can now begin transmitting to clients. */ iblock(SIGTERM); while (!(sm_SemEnded(parms->vduct->semaphore))) { if (bpDequeue(parms->vduct, outflows, &bundleZco, &extendedCOS, destDuctName) < 0) { break; } if (bundleZco == 0) /* Interrupted. */ { continue; } bundleLength = zco_length(sdr, bundleZco); ductNbr = atoi(destDuctName); if (ductNbr >= parms->baseDuctNbr && ductNbr <= parms->lastDuctNbr && parms->brsSockets[(i = ductNbr - parms->baseDuctNbr)] != -1) { bytesSent = sendBundleByTCP(NULL, parms->brsSockets + i, bundleLength, bundleZco, buffer); if (bytesSent < 0) { putErrmsg("Can't send bundle.", NULL); break; } if (bytesSent < bundleLength) { failedTransmissions++; } } else /* Can't send it; just discard it. */ { sdr_begin_xn(sdr); zco_destroy_reference(sdr, bundleZco); if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't destroy ZCO reference.", NULL); break; } } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); } pthread_kill(brssclaMainThread(0), SIGTERM); writeMemoNote("[i] brsscla outduct has ended", itoa(failedTransmissions)); MRELEASE(buffer); return terminateSenderThread(parms); }
static int rcParse(LoadMibState *state, char *buf, size_t length) { char *elementName; char *atts[MAX_ATTRIBUTES * 2]; int attNameIdx = 0; int attValueIdx = 1; char *cursor; char *attStart; int bytesRemaining; char *delimiter; char *token; if (length < 2) { writeMemoNote("[?] No element name in rc line", buf); return -1; } cursor = buf + 1; findToken(&cursor, &token); if (token == NULL) { writeMemo("Element name omitted."); return -1; } elementName = token; memset(atts, 0, sizeof atts); bytesRemaining = length - (cursor - buf); while (bytesRemaining > 0) { if (bytesRemaining < 2) { writeMemoNote("[?] Incomplete rc line attribute", cursor); return -1; } attStart = cursor; delimiter = strchr(cursor, '='); if (delimiter == NULL) { writeMemoNote("[?] Attribute name not terminated", cursor); return -1; } if (attValueIdx > MAX_ATTRIBUTES) { writeMemoNote("[?] Too many attributes", cursor); return -1; } atts[attNameIdx] = cursor; *delimiter = 0; cursor = delimiter + 1; findToken(&cursor, &token); if (token == NULL) { writeMemoNote("[?] Attribute value omitted", atts[attNameIdx]); return -1; } atts[attValueIdx] = token; attNameIdx += 2; attValueIdx += 2; bytesRemaining -= (cursor - attStart); } switch (buf[0]) { case '+': startElement(state, elementName, (const char **) atts); break; case '-': endElement(state, elementName); break; case '*': startElement(state, elementName, (const char **) atts); endElement(state, elementName); break; default: writeMemoNote("[?] Invalid rc line control character", buf); return -1; } return 0; }
PsmAddress rfx_insert_contact(time_t fromTime, time_t toTime, uvast fromNode, uvast toNode, unsigned int xmitRate, float prob) { Sdr sdr = getIonsdr(); PsmPartition ionwm = getIonwm(); IonVdb *vdb = getIonVdb(); IonCXref arg; PsmAddress cxelt; PsmAddress nextElt; PsmAddress cxaddr; IonCXref *cxref; PsmAddress prevElt; char contactIdString[128]; IonContact contact; Object iondbObj; IonDB iondb; Object obj; Object elt; CHKZERO(fromTime); CHKZERO(toTime > fromTime); CHKZERO(fromNode); CHKZERO(toNode); CHKZERO(prob > 0.0 && prob <= 1.0); CHKZERO(sdr_begin_xn(sdr)); /* Make sure contact doesn't overlap with any pre-existing * contacts. */ memset((char *) &arg, 0, sizeof(IonCXref)); arg.fromNode = fromNode; arg.toNode = toNode; arg.fromTime = fromTime; arg.toTime = toTime; arg.xmitRate = xmitRate; arg.routingObject = 0; cxelt = sm_rbt_search(ionwm, vdb->contactIndex, rfx_order_contacts, &arg, &nextElt); //cxelt = 0; if (cxelt) /* Contact is in database already. */ { cxaddr = sm_rbt_data(ionwm, cxelt); cxref = (IonCXref *) psp(ionwm, cxaddr); if (cxref->xmitRate == xmitRate) { sdr_exit_xn(sdr); return cxaddr; } isprintf(contactIdString, sizeof contactIdString, "at %lu, %llu->%llu", fromTime, fromNode, toNode); writeMemoNote("[?] Contact data rate not revised", contactIdString); sdr_exit_xn(sdr); return 0; } else /* Check for overlap, which is not allowed. */ { if (nextElt) { prevElt = sm_rbt_prev(ionwm, nextElt); cxref = (IonCXref *) psp(ionwm, sm_rbt_data(ionwm, nextElt)); if (fromNode == cxref->fromNode && toNode == cxref->toNode && toTime > cxref->fromTime) { writeMemoNote("[?] Overlapping contact", utoa(fromNode)); sdr_exit_xn(sdr); return 0; } } else { prevElt = sm_rbt_last(ionwm, vdb->contactIndex); } if (prevElt) { cxref = (IonCXref *) psp(ionwm, sm_rbt_data(ionwm, prevElt)); if (fromNode == cxref->fromNode && toNode == cxref->toNode && fromTime < cxref->toTime) { writeMemoNote("[?] Overlapping contact", utoa(fromNode)); sdr_exit_xn(sdr); return 0; } } } /* Contact isn't already in database; okay to add. */ cxaddr = 0; contact.fromTime = fromTime; contact.toTime = toTime; contact.fromNode = fromNode; contact.toNode = toNode; contact.xmitRate = xmitRate; contact.prob = prob; obj = sdr_malloc(sdr, sizeof(IonContact)); if (obj) { sdr_write(sdr, obj, (char *) &contact, sizeof(IonContact)); iondbObj = getIonDbObject(); sdr_read(sdr, (char *) &iondb, iondbObj, sizeof(IonDB)); elt = sdr_list_insert_last(sdr, iondb.contacts, obj); if (elt) { arg.contactElt = elt; cxaddr = insertCXref(&arg); if (cxaddr == 0) { sdr_cancel_xn(sdr); } } } if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't insert contact.", NULL); return 0; } return cxaddr; }
Object rfx_insert_range(time_t fromTime, time_t toTime, uvast fromNode, uvast toNode, unsigned int owlt) { Sdr sdr = getIonsdr(); PsmPartition ionwm = getIonwm(); IonVdb *vdb = getIonVdb(); IonRXref arg1; PsmAddress rxelt; PsmAddress nextElt; PsmAddress rxaddr; IonRXref *rxref; IonEvent arg2; PsmAddress prevElt; char rangeIdString[128]; IonRange range; Object iondbObj; IonDB iondb; Object obj; Object elt; /* Note that ranges are normally assumed to be symmetrical, * i.e., the signal propagation time from B to A is normally * assumed to be the same as the signal propagation time * from A to B. For this reason, normally only the A->B * range (where A is a node number that is less than node * number B) need be entered; when ranges are applied to * the IonNeighbor objects in the ION database, the A->B * range is stored as the OWLT for transmissions from A to * B and also as the OWLT for transmissions from B to A. * * However, it is possible to insert asymmetric ranges, as * would apply when the forward and return traffic between * some pair of nodes travels by different transmission * paths that introduce different latencies. When this is * the case, both the A->B and B->A ranges must be entered. * The A->B range is initially processed as a symmetric * range as described above, but when the B->A range is * subsequently noted it overrides the default OWLT for * transmissions from B to A. */ CHKZERO(fromTime); CHKZERO(toTime > fromTime); CHKZERO(fromNode); CHKZERO(toNode); CHKZERO(sdr_begin_xn(sdr)); /* Make sure range doesn't overlap with any pre-existing * ranges. */ memset((char *) &arg1, 0, sizeof(IonRXref)); arg1.fromNode = fromNode; arg1.toNode = toNode; arg1.fromTime = fromTime; arg1.toTime = toTime; arg1.owlt = owlt; rxelt = sm_rbt_search(ionwm, vdb->rangeIndex, rfx_order_ranges, &arg1, &nextElt); if (rxelt) /* Range is in database already. */ { rxaddr = sm_rbt_data(ionwm, rxelt); rxref = (IonRXref *) psp(ionwm, rxaddr); if (rxref->rangeElt == 0) /* Imputed. */ { /* The existing range for the same nodes * and time is merely an imputed range, * which is being overridden by a non- * canonical range assertion indicating * an override of the normal symmetry in * the owlt between nodes. Must delete * that imputed range, together with the * associated events, after which there * is no duplication. */ sm_rbt_delete(ionwm, vdb->rangeIndex, rfx_order_ranges, &arg1, rfx_erase_data, NULL); arg2.ref = rxaddr; arg2.time = rxref->fromTime; arg2.type = IonStartImputedRange; sm_rbt_delete(ionwm, vdb->timeline, rfx_order_events, &arg2, rfx_erase_data, NULL); arg2.time = rxref->toTime; arg2.type = IonStopImputedRange; sm_rbt_delete(ionwm, vdb->timeline, rfx_order_events, &arg2, rfx_erase_data, NULL); } else /* Overriding an asserted range. */ { /* This is an attempt to replace an * existing asserted range with another * asserted range, which is prohibited. */ if (rxref->owlt == owlt) { sdr_exit_xn(sdr); return rxaddr; /* Idempotent. */ } isprintf(rangeIdString, sizeof rangeIdString, "from %lu, %llu->%llu", fromTime, fromNode, toNode); writeMemoNote("[?] Range OWLT not revised", rangeIdString); sdr_exit_xn(sdr); return 0; } } /* Check for overlap, which is not allowed. */ if (nextElt) { prevElt = sm_rbt_prev(ionwm, nextElt); rxref = (IonRXref *) psp(ionwm, sm_rbt_data(ionwm, nextElt)); if (fromNode == rxref->fromNode && toNode == rxref->toNode && toTime > rxref->fromTime) { writeMemoNote("[?] Overlapping range", utoa(fromNode)); sdr_exit_xn(sdr); return 0; } } else { prevElt = sm_rbt_last(ionwm, vdb->rangeIndex); } if (prevElt) { rxref = (IonRXref *) psp(ionwm, sm_rbt_data(ionwm, prevElt)); if (fromNode == rxref->fromNode && toNode == rxref->toNode && fromTime < rxref->toTime) { writeMemoNote("[?] Overlapping range", utoa(fromNode)); sdr_exit_xn(sdr); return 0; } } /* Range isn't already in database; okay to add. */ rxaddr = 0; range.fromTime = fromTime; range.toTime = toTime; range.fromNode = fromNode; range.toNode = toNode; range.owlt = owlt; obj = sdr_malloc(sdr, sizeof(IonRange)); if (obj) { sdr_write(sdr, obj, (char *) &range, sizeof(IonRange)); iondbObj = getIonDbObject(); sdr_read(sdr, (char *) &iondb, iondbObj, sizeof(IonDB)); elt = sdr_list_insert_last(sdr, iondb.ranges, obj); if (elt) { arg1.rangeElt = elt; rxaddr = insertRXref(&arg1); if (rxaddr == 0) { sdr_cancel_xn(sdr); } } } if (sdr_end_xn(sdr) < 0) { putErrmsg("Can't insert range.", NULL); return 0; } return rxaddr; }
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; }