/*****************************************************************//** * \brief Send a packet on the specified port * * \param unit [IN] Unit number. * \param port [IN] Port number. * \param data [IN] Pointer to packet data. * \param len [IN] Size of the packet data. * * \return OPENNSL_E_XXX OpenNSL API return code ********************************************************************/ int example_pkt_send(int unit, int port, char *data, int len) { opennsl_pkt_t *pkt; int rv; rv = opennsl_pkt_alloc(unit, len, 0, &pkt); if (OPENNSL_SUCCESS(rv)) { rv = opennsl_pkt_memcpy(pkt, 0, data, len); if (!OPENNSL_SUCCESS(rv)) { opennsl_pkt_free(unit, pkt); return rv; } OPENNSL_PBMP_PORT_SET(pkt->tx_pbmp, port); rv = opennsl_tx(unit, pkt, NULL); if (!OPENNSL_SUCCESS(rv)) { opennsl_pkt_free(unit, pkt); return rv; } } opennsl_pkt_free(unit, pkt); return rv; }
/*****************************************************************//** * \brief Form a packet and send multiple packets from the specified port * * \param unit [IN] Unit number. * \param port [IN] Port number. * \param count [IN] Number of packets to be transmitted. * * \return OPENNSL_E_XXX OpenNSL API return code ********************************************************************/ void example_multi_pkt_send(int unit, int port, int count) { int i; int rv; char data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x82, 0x2f, 0x2e, 0x42, 0x46, 0x74, 0x08, 0x06, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x82, 0x2f, 0x2e, 0x42, 0x46, 0x74, 0x0a, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 }; for (i = 0; i < count; i++) { rv = example_pkt_send(unit, port, data, (int) sizeof(data)); if (!OPENNSL_SUCCESS(rv)) { printf("Error Sending Packet: %d. Error: %s\n", i + 1, opennsl_errmsg(rv)); } else { printf("Transmitted Packet %d of size %zu\n", i + 1, sizeof(data)); } } }
BcmUnit::~BcmUnit() { if (attached_.load(std::memory_order_acquire)) { auto rv = opennsl_detach(unit_); CHECK(OPENNSL_SUCCESS(rv)) << "failed to detach BCM unit " << unit_ << ": " << opennsl_errmsg(rv); } // Unregister ourselves from BcmAPI. BcmAPI::unitDestroyed(this); }