bp_error_t bp_bundle_send(bp_handle_t handle, bp_reg_id_t regid, bp_bundle_object_t * bundle_object) { if (bundle_object == NULL) return BP_ENULLPNTR; memset(bundle_object->id, 0, sizeof(bp_bundle_id_t)); return bp_send(handle, regid, bundle_object->spec, bundle_object->payload, bundle_object->id); }
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 bputa(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 char ownEid[64]; BpSAP txSap; RxThreadParms parms; Sdr sdr; pthread_t rxThread; int haveRxThread = 0; Object pduZco; OutFdu fduBuffer; BpUtParms utParms; uvast destinationNodeNbr; char destEid[64]; char reportToEidBuf[64]; char *reportToEid; Object newBundle; Object pduElt; if (bp_attach() < 0) { putErrmsg("CFDP can't attach to BP.", NULL); return 0; } isprintf(ownEid, sizeof ownEid, "ipn:" UVAST_FIELDSPEC ".%u", getOwnNodeNbr(), CFDP_SEND_SVC_NBR); if (bp_open(ownEid, &txSap) < 0) { putErrmsg("CFDP can't open own 'send' endpoint.", ownEid); return 0; } if (txSap == NULL) { putErrmsg("bputa can't get Bundle Protocol SAP.", NULL); return 0; } if (cfdpAttach() < 0) { bp_close(txSap); putErrmsg("bputa can't attach to CFDP.", NULL); return 0; } sdr = bp_get_sdr(); parms.mainThread = pthread_self(); parms.running = 1; if (pthread_begin(&rxThread, NULL, receivePdus, &parms)) { bp_close(txSap); putSysErrmsg("bputa can't create receiver thread", NULL); return -1; } haveRxThread = 1; writeMemo("[i] bputa is running."); while (parms.running) { /* Get an outbound CFDP PDU for transmission. */ if (cfdpDequeueOutboundPdu(&pduZco, &fduBuffer) < 0) { writeMemo("[?] bputa can't dequeue outbound CFDP PDU; \ terminating."); parms.running = 0; continue; } /* Determine quality of service for transmission. */ if (fduBuffer.utParmsLength == sizeof(BpUtParms)) { memcpy((char *) &utParms, (char *) &fduBuffer.utParms, sizeof(BpUtParms)); } else { memset((char *) &utParms, 0, sizeof(BpUtParms)); utParms.reportToNodeNbr = 0; utParms.lifespan = 86400; /* 1 day. */ utParms.classOfService = BP_STD_PRIORITY; utParms.custodySwitch = NoCustodyRequested; utParms.srrFlags = 0; utParms.ackRequested = 0; utParms.extendedCOS.flowLabel = 0; utParms.extendedCOS.flags = 0; utParms.extendedCOS.ordinal = 0; } cfdp_decompress_number(&destinationNodeNbr, &fduBuffer.destinationEntityNbr); if (destinationNodeNbr == 0) { writeMemo("[?] bputa declining to send to node 0."); continue; } isprintf(destEid, sizeof destEid, "ipn:" UVAST_FIELDSPEC ".%u", destinationNodeNbr, CFDP_RECV_SVC_NBR); if (utParms.reportToNodeNbr == 0) { reportToEid = NULL; } else { isprintf(reportToEidBuf, sizeof reportToEidBuf, "ipn:" UVAST_FIELDSPEC ".%u", utParms.reportToNodeNbr, CFDP_RECV_SVC_NBR); reportToEid = reportToEidBuf; } /* Send PDU in a bundle. */ newBundle = 0; if (bp_send(txSap, destEid, reportToEid, utParms.lifespan, utParms.classOfService, utParms.custodySwitch, utParms.srrFlags, utParms.ackRequested, &utParms.extendedCOS, pduZco, &newBundle) <= 0) { putErrmsg("bputa can't send PDU in bundle; terminated.", NULL); parms.running = 0; } if (newBundle == 0) { continue; /* Must have stopped. */ } /* Enable cancellation of this PDU. */ if (sdr_begin_xn(sdr) == 0) { parms.running = 0; continue; } pduElt = sdr_list_insert_last(sdr, fduBuffer.extantPdus, newBundle); if (pduElt) { bp_track(newBundle, pduElt); } if (sdr_end_xn(sdr) < 0) { putErrmsg("bputa can't track PDU; terminated.", NULL); parms.running = 0; } /* Make sure other tasks have a chance to run. */ sm_TaskYield(); }
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; }