static Object newSdrAcsCustodian(Object custodians, const char *eid) { Object newCustodianAddr; SdrAcsPendingCust newCustodian; memset(&newCustodian, 0, sizeof(newCustodian)); strncpy(newCustodian.eid, eid, MAX_EID_LEN); newCustodian.eid[MAX_EID_LEN] = '\0'; /* Set default ACS size and delay. */ newCustodian.acsDelay = 2; newCustodian.acsSize = 300; CHKZERO(sdr_begin_xn(acsSdr)); newCustodianAddr = sdr_malloc(acsSdr, sizeof(newCustodian)); newCustodian.signals = sdr_list_create(acsSdr); sdr_poke(acsSdr, newCustodianAddr, newCustodian); sdr_list_insert_last(acsSdr, custodians, newCustodianAddr); if(sdr_end_xn(acsSdr) < 0) { ACSLOG_WARN("Couldn't create new custodian info for %s", eid); return 0; } return newCustodianAddr; }
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 dtn2Init() { Sdr sdr = getIonsdr(); Object dtn2dbObject; DtnDB dtn2dbBuf; /* Recover the DTN database, creating it if necessary. */ CHKERR(sdr_begin_xn(sdr)); dtn2dbObject = sdr_find(sdr, DTN_DBNAME, NULL); switch (dtn2dbObject) { case -1: /* SDR error. */ sdr_cancel_xn(sdr); putErrmsg("Failed seeking DTN database in SDR.", NULL); return -1; case 0: /* Not found; must create new DB. */ dtn2dbObject = sdr_malloc(sdr, sizeof(DtnDB)); if (dtn2dbObject == 0) { sdr_cancel_xn(sdr); putErrmsg("No space for DTN database.", NULL); return -1; } memset((char *) &dtn2dbBuf, 0, sizeof(DtnDB)); dtn2dbBuf.plans = sdr_list_create(sdr); sdr_write(sdr, dtn2dbObject, (char *) &dtn2dbBuf, sizeof(DtnDB)); sdr_catlg(sdr, DTN_DBNAME, 0, dtn2dbObject); if (sdr_end_xn(sdr)) { putErrmsg("Can't create DTN database.", NULL); return -1; } break; default: /* Found DB in the SDR. */ sdr_exit_xn(sdr); } oK(_dtn2dbObject(&dtn2dbObject)); oK(_dtn2Constants()); return 0; }
int acsInitialize(long heapWords, int logLevel) { AcsDB acsdbBuf; unsigned long zero = 0; /* sdr_stow() wants this */ if (heapWords == 0) { /* Caller wants us to supply a default. */ heapWords = ACS_SDR_DEFAULT_HEAPWORDS; } if (ionAttach() < 0) { putErrmsg("Can't attach to ION.", NULL); return -1; } { Sdr sdr = getIonsdr(); IonDB iondb; char *pathname = iondb.parmcopy.pathName; CHKERR(sdr_begin_xn(sdr)); sdr_read(sdr, (char *) &iondb, getIonDbObject(), sizeof(IonDB)); sdr_exit_xn(sdr); #if 0 { char text[100]; sprintf( text, "ION parms pathname : %s", pathname ); writeMemo( text ); } #endif if (sdr_load_profile(acssdrName, SDR_IN_DRAM, heapWords, SM_NO_KEY, pathname, NULL) < 0) { putErrmsg("Unable to load SDR profile for ACS.", NULL); return -1; } else { writeMemo("ACS SDR profile loaded."); } } acsSdr = sdr_start_using(acssdrName); if (acsSdr == NULL) { putErrmsg("Can't start using SDR for ACS.", NULL); return -1; } if (getAcssdr() < 0) { putErrmsg("ACS can't find ACS SDR.", NULL); return -1; } CHKERR(sdr_begin_xn(acsSdr)); acsdbObject = sdr_find(acsSdr, acsDbName, NULL); switch (acsdbObject) { case -1: /* SDR error. */ sdr_cancel_xn(acsSdr); putErrmsg("Can't seek ACS database in SDR.", NULL); return -1; case 0: /* Not found must create new DB. */ memset((char *) &acsdbBuf, 0, sizeof(AcsDB)); acsdbBuf.pendingCusts = sdr_list_create(acsSdr); acsdbBuf.logLevel = logLevel; acsdbBuf.cidHash = sdr_hash_create(acsSdr, sizeof(AcsCustodyId), ACS_CIDHASH_ROWCOUNT, 1); acsdbBuf.bidHash = sdr_hash_create(acsSdr, sizeof(AcsBundleId), ACS_BIDHASH_ROWCOUNT, 1); acsdbBuf.id = sdr_stow(acsSdr, zero); acsdbObject = sdr_malloc(acsSdr, sizeof(AcsDB)); if (acsdbObject == 0) { sdr_cancel_xn(acsSdr); putErrmsg("No space for ACS database.", NULL); return -1; } sdr_write(acsSdr, acsdbObject, (char *) &acsdbBuf, sizeof(AcsDB)); sdr_catlg(acsSdr, acsDbName, 0, acsdbObject); if (sdr_end_xn(acsSdr)) { putErrmsg("Can't create ACS database.", NULL); return -1; } break; default: sdr_exit_xn(acsSdr); } acsConstants = &acsConstantsBuf; CHKERR(sdr_begin_xn(acsSdr)); sdr_read(acsSdr, (char *) acsConstants, acsdbObject, sizeof(AcsDB)); sdr_exit_xn(acsSdr); return 0; }
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 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; }
int ionInitialize(IonParms *parms, unsigned long ownNodeNbr) { char wdname[256]; Sdr ionsdr; Object iondbObject; IonDB iondbBuf; sm_WmParms ionwmParms; char *ionvdbName = _ionvdbName(); CHKERR(parms); CHKERR(ownNodeNbr); if (sdr_initialize(0, NULL, SM_NO_KEY, NULL) < 0) { putErrmsg("Can't initialize the SDR system.", NULL); return -1; } if (igetcwd(wdname, 256) == NULL) { putErrmsg("Can't get cwd name.", NULL); return -1; } if (checkNodeListParms(parms, wdname, ownNodeNbr) < 0) { putErrmsg("Failed checking node list parms.", NULL); return -1; } if (sdr_load_profile(parms->sdrName, parms->configFlags, parms->heapWords, parms->heapKey, parms->pathName) < 0) { putErrmsg("Unable to load SDR profile for ION.", NULL); return -1; } ionsdr = sdr_start_using(parms->sdrName); if (ionsdr == NULL) { putErrmsg("Can't start using SDR for ION.", NULL); return -1; } ionsdr = _ionsdr(&ionsdr); /* Recover the ION database, creating it if necessary. */ sdr_begin_xn(ionsdr); iondbObject = sdr_find(ionsdr, _iondbName(), NULL); switch (iondbObject) { case -1: /* SDR error. */ sdr_cancel_xn(ionsdr); putErrmsg("Can't seek ION database in SDR.", NULL); return -1; case 0: /* Not found; must create new DB. */ if (ownNodeNbr == 0) { sdr_cancel_xn(ionsdr); putErrmsg("Must supply non-zero node number.", NULL); return -1; } memset((char *) &iondbBuf, 0, sizeof(IonDB)); memcpy(iondbBuf.workingDirectoryName, wdname, 256); iondbBuf.ownNodeNbr = ownNodeNbr; iondbBuf.occupancyCeiling = ((sdr_heap_size(ionsdr) / 100) * (100 - ION_SEQUESTERED)); iondbBuf.receptionSpikeReserve = iondbBuf.occupancyCeiling / 16; if (iondbBuf.receptionSpikeReserve < MIN_SPIKE_RSRV) { iondbBuf.receptionSpikeReserve = MIN_SPIKE_RSRV; } iondbBuf.contacts = sdr_list_create(ionsdr); iondbBuf.ranges = sdr_list_create(ionsdr); iondbBuf.maxClockError = 0; iondbObject = sdr_malloc(ionsdr, sizeof(IonDB)); if (iondbObject == 0) { sdr_cancel_xn(ionsdr); putErrmsg("No space for database.", NULL); return -1; } sdr_write(ionsdr, iondbObject, (char *) &iondbBuf, sizeof(IonDB)); sdr_catlg(ionsdr, _iondbName(), 0, iondbObject); if (sdr_end_xn(ionsdr)) { putErrmsg("Can't create ION database.", NULL); return -1; } break; default: /* Found DB in the SDR. */ sdr_exit_xn(ionsdr); } oK(_iondbObject(&iondbObject)); oK(_ionConstants()); /* Open ION shared-memory partition. */ ionwmParms.wmKey = parms->wmKey; ionwmParms.wmSize = parms->wmSize; ionwmParms.wmAddress = parms->wmAddress; ionwmParms.wmName = ION_SM_NAME; if (_ionwm(&ionwmParms) == NULL) { putErrmsg("ION memory configuration failed.", NULL); return -1; } if (_ionvdb(&ionvdbName) == NULL) { putErrmsg("ION can't initialize vdb.", NULL); return -1; } ionRedirectMemos(); return 0; }
/* * This function writes an item and its associated descriptor into the SDR, * allocating space for each, and adding the SDR descriptor pointer to a * given SDR list. * * item : The serialized item to store in the SDR. * item_len: The size of the serialized item. * *itemObj: The SDR pointer to the serialized item in the SDR. * desc : The item descriptor being written to the SDR. * desc_len: The size of the item descriptor. * *descObj: The SDR pointer to the item's descriptor object in the SDR. * list : The SDR list holding the item descriptor (at *descrObj). */ int db_persist(uint8_t *item, uint32_t item_len, Object *itemObj, void *desc, uint32_t desc_len, Object *descObj, Object list) { Sdr sdr = getIonsdr(); CHKERR(sdr_begin_xn(sdr)); /* Step 1: Allocate a descriptor object for this item in the SDR. */ if((*descObj = sdr_malloc(sdr, desc_len)) == 0) { sdr_cancel_xn(sdr); AMP_DEBUG_ERR("db_persist", "Can't allocate descriptor of size %d.", desc_len); return -1; } /* Step 2: Allocate space for the serialized rule in the SDR. */ if((*itemObj = sdr_malloc(sdr, item_len)) == 0) { sdr_free(sdr, *descObj); sdr_cancel_xn(sdr); *descObj = 0; AMP_DEBUG_ERR("db_persist", "Unable to allocate Item in SDR. Size %d.", item_len); return -1; } /* Step 3: Write the item to the SDR. */ sdr_write(sdr, *itemObj, (char *) item, item_len); /* Step 4: Write the item descriptor to the SDR. */ sdr_write(sdr, *descObj, (char *) desc, desc_len); /* Step 5: Save the descriptor in the AgentDB active rules list. */ if (sdr_list_insert_last(sdr, list, *descObj) == 0) { sdr_free(sdr, *itemObj); sdr_free(sdr, *descObj); sdr_cancel_xn(sdr); *itemObj = 0; *descObj = 0; AMP_DEBUG_ERR("db_persist", "Unable to insert item Descr. in SDR.", NULL); return -1; } if(sdr_end_xn(sdr)) { AMP_DEBUG_ERR("db_persist", "Can't create Agent database.", NULL); return -1; } return 1; }
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 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; }
int ionInitialize(IonParms *parms, uvast ownNodeNbr) { char wdname[256]; Sdr ionsdr; Object iondbObject; IonDB iondbBuf; vast limit; sm_WmParms ionwmParms; char *ionvdbName = _ionvdbName(); ZcoCallback notify = ionOfferZcoSpace; CHKERR(parms); CHKERR(ownNodeNbr); #ifdef mingw if (_winsock(0) < 0) { return -1; } #endif if (sdr_initialize(0, NULL, SM_NO_KEY, NULL) < 0) { putErrmsg("Can't initialize the SDR system.", NULL); return -1; } if (igetcwd(wdname, 256) == NULL) { putErrmsg("Can't get cwd name.", NULL); return -1; } if (checkNodeListParms(parms, wdname, ownNodeNbr) < 0) { putErrmsg("Failed checking node list parms.", NULL); return -1; } if (sdr_load_profile(parms->sdrName, parms->configFlags, parms->heapWords, parms->heapKey, parms->pathName, "ionrestart") < 0) { putErrmsg("Unable to load SDR profile for ION.", NULL); return -1; } ionsdr = sdr_start_using(parms->sdrName); if (ionsdr == NULL) { putErrmsg("Can't start using SDR for ION.", NULL); return -1; } ionsdr = _ionsdr(&ionsdr); /* Recover the ION database, creating it if necessary. */ CHKERR(sdr_begin_xn(ionsdr)); iondbObject = sdr_find(ionsdr, _iondbName(), NULL); switch (iondbObject) { case -1: /* SDR error. */ sdr_cancel_xn(ionsdr); putErrmsg("Can't seek ION database in SDR.", NULL); return -1; case 0: /* Not found; must create new DB. */ if (ownNodeNbr == 0) { sdr_cancel_xn(ionsdr); putErrmsg("Must supply non-zero node number.", NULL); return -1; } memset((char *) &iondbBuf, 0, sizeof(IonDB)); memcpy(iondbBuf.workingDirectoryName, wdname, 256); iondbBuf.ownNodeNbr = ownNodeNbr; iondbBuf.productionRate = -1; /* Unknown. */ iondbBuf.consumptionRate = -1; /* Unknown. */ limit = (sdr_heap_size(ionsdr) / 100) * (100 - ION_SEQUESTERED); zco_set_max_heap_occupancy(ionsdr, limit); iondbBuf.occupancyCeiling = zco_get_max_file_occupancy(ionsdr); iondbBuf.occupancyCeiling += limit; iondbBuf.contacts = sdr_list_create(ionsdr); iondbBuf.ranges = sdr_list_create(ionsdr); iondbBuf.maxClockError = 0; iondbBuf.clockIsSynchronized = 1; memcpy(&iondbBuf.parmcopy, parms, sizeof(IonParms)); iondbObject = sdr_malloc(ionsdr, sizeof(IonDB)); if (iondbObject == 0) { sdr_cancel_xn(ionsdr); putErrmsg("No space for database.", NULL); return -1; } sdr_write(ionsdr, iondbObject, (char *) &iondbBuf, sizeof(IonDB)); sdr_catlg(ionsdr, _iondbName(), 0, iondbObject); if (sdr_end_xn(ionsdr)) { putErrmsg("Can't create ION database.", NULL); return -1; } break; default: /* Found DB in the SDR. */ sdr_exit_xn(ionsdr); } oK(_iondbObject(&iondbObject)); oK(_ionConstants()); /* Open ION shared-memory partition. */ ionwmParms.wmKey = parms->wmKey; ionwmParms.wmSize = parms->wmSize; ionwmParms.wmAddress = parms->wmAddress; ionwmParms.wmName = ION_SM_NAME; if (_ionwm(&ionwmParms) == NULL) { putErrmsg("ION memory configuration failed.", NULL); return -1; } if (_ionvdb(&ionvdbName) == NULL) { putErrmsg("ION can't initialize vdb.", NULL); return -1; } zco_register_callback(notify); ionRedirectMemos(); #ifdef mingw DWORD threadId; HANDLE thread = CreateThread(NULL, 0, waitForSigterm, NULL, 0, &threadId); if (thread == NULL) { putErrmsg("Can't create sigterm thread.", utoa(GetLastError())); } else { CloseHandle(thread); } #endif return 0; }