📄 ixethacccodeletloopbacks.c
字号:
/** * @file IxEthAccCodeletLoopbacks.c * * @date 01 July 2005 * * @brief This file contains the implementation of the Ethernet Access * Codelet that implements the different loopback scenarios * * @li RxSink * @li Sw Loopback * @li TxGen RxSink * @li Phy Loopback * * @par * IXP400 SW Release version 2.1 * * -- Copyright Notice -- * * @par * Copyright (c) 2001-2005, Intel Corporation. * All rights reserved. * * @par * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the Intel Corporation nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * * @par * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * * @par * -- End of Copyright Notice --*//* * Put the system defined include files required. */#include "IxOsal.h"#include "IxEthDB.h"/* * Put the user defined include files required. */#include "IxEthAccCodelet.h"#include "IxEthAccCodelet_p.h"/* * Private data declarations. *//* Generated frames payload data */PRIVATE UINT8 compData[IX_ETHACC_CODELET_PCK_LEN];/** Macro to generate random payload data * (multicast|broadcast bits are masked in both source * and destination MAC addresses, typelength is set to IP) */#define IX_ETHACC_CODELET_DATAGEN(compPtr) \ { \ int i = 0; \ UINT8 random = (UINT8)ixOsalTimestampGet(); \ for(i=0; i<IX_ETHACC_CODELET_TXGEN_PCK_LEN; i++) \ { \ compPtr[i] = random++; \ } \ compPtr[0] &= 0xfe; \ compPtr[IX_IEEE803_MAC_ADDRESS_SIZE] &= 0xfe; \ compPtr[2 * IX_IEEE803_MAC_ADDRESS_SIZE] = 0x08; \ compPtr[2 * IX_IEEE803_MAC_ADDRESS_SIZE + 1] &= 0x00; \ }/** Macro to verify payload */#define IX_ETHACC_CODELET_DATA_VERIFY(m_data, compPtr) \ { \ if(memcmp(&compPtr[0], m_data, IX_ETHACC_CODELET_TXGEN_PCK_LEN) != 0) \ { \ ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, \ "Mbuf data verification failed\n", \ 0, 0, 0, 0, 0, 0); \ } \ }/* * SECTION I : Datapath callbacks * * The following callbacks are supposed to run under the QMgr dispatcher * context and are able to process the following options * - re-transmit received frames (Loopback) * - drop incoming traffic (RxSink) * - retransmit transmitted frames again (TxGen) * *//** * @fn void ixEthAccCodeletRxSinkRxCB() * * Recieve callback for Rx sink * * @return void */PRIVATE void ixEthAccCodeletRxSinkRxCB(UINT32 cbTag, IX_OSAL_MBUF** mBufPtr){ while (NULL != *mBufPtr) { ixEthAccCodeletStats[cbTag].rxCount++; #ifdef IX_ETHACC_CODELET_TXGENRXSINK_VERIFY IX_ETHACC_CODELET_DATA_VERIFY(IX_OSAL_MBUF_MDATA(*mBufPtr), compData); /* After reading the payload, invalidate it before replenish */ IX_OSAL_CACHE_INVALIDATE(IX_OSAL_MBUF_MDATA(*mBufPtr), IX_OSAL_MBUF_MLEN(*mBufPtr));#endif ixEthAccCodeletMbufChainSizeSet(*mBufPtr); /* Return mBuf to free queue on same port */ if(ixEthAccPortRxFreeReplenish(cbTag, *mBufPtr) != IX_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Error replenishing RX free q in TxGen-RxSink\n", 0, 0, 0, 0, 0, 0); } /* move to next buffer received */ mBufPtr++; }}/** * @fn void ixEthAccCodeletTxGenTxCB() * * Transmit callback for TxGen operation. Transmitted frames are re- * transmitted. * * @return void */PRIVATE void ixEthAccCodeletTxGenTxCB(UINT32 cbTag, IX_OSAL_MBUF* mBufPtr){ ixEthAccCodeletStats[cbTag].txCount++; /* Re-transmit the frame on same port */ if(ixEthAccPortTxFrameSubmit(cbTag, mBufPtr, IX_ETH_ACC_TX_DEFAULT_PRIORITY) != IX_ETH_ACC_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Tx Buffer submission failure in TxGen-RxSink\n", 0, 0, 0, 0, 0, 0); }}/** * @fn void ixEthAccCodeletLoopbackTxCB() * * Transmit callback for the Sw Loopback Operation. Transmitted frames * are placed in the receive free pool. * * @return void */PRIVATE void ixEthAccCodeletLoopbackTxCB(UINT32 cbTag, IX_OSAL_MBUF* mBufPtr){ /* Put the mbuf back in the rx free pool */ if(cbTag < IX_ETHACC_CODELET_MAX_PORT) { ixEthAccCodeletStats[cbTag].txCount++; /* reset the frame length to the length at pool setup */ ixEthAccCodeletMbufChainSizeSet(mBufPtr); if(ixEthAccPortRxFreeReplenish(cbTag, mBufPtr) != IX_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Error replenishing RX free queue on port %d\n", cbTag, 0, 0, 0, 0, 0); } } else { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Invalid Tx callback tag %d in RxSink Operation\n", cbTag, 0, 0, 0, 0, 0); }}/** * @fn void ixEthAccCodeletLoopbackRxCB() * * Receive callback for the Sw Loopback Operation. Any frames received * are transmitted back out on the same port. * * @return void */PRIVATE voidixEthAccCodeletLoopbackRxCB(UINT32 cbTag, IX_OSAL_MBUF** mBufPtr){ /* Transmit the buffer back on the port it was received on*/ if(cbTag < IX_ETHACC_CODELET_MAX_PORT ) { while (NULL != *mBufPtr) { ixEthAccCodeletStats[cbTag].rxCount++; /* transmit the frame on the same port */ if(ixEthAccPortTxFrameSubmit(cbTag, *mBufPtr, IX_ETH_ACC_TX_DEFAULT_PRIORITY) != IX_ETH_ACC_SUCCESS) { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Tx Buffer submission failure port %d\n", cbTag, 0, 0, 0, 0, 0); } /* move to next buffer received */ mBufPtr++; } } else { ixOsalLog(IX_OSAL_LOG_LVL_ERROR, IX_OSAL_LOG_DEV_STDOUT, "Invalid Rx callback tag %d in Sw Loopback Operation\n", cbTag, 0, 0, 0, 0, 0); }}/* * SECTION II : Control path * * the following functions register the different callbacks * to enable the following features * - Sink all rx traffic, silent on Tx * - sw loopback on one port (Rx frames are transmitted on the * same port) * - transmit as fast as possible on one port, sw loopback on * an other port, allows full traffic to be seen with a * crossover cable. * *//* * Function definition: ixEthAccCodeletTxGenRxSinkStart() * * Start datapath traffic for TxGen-RxSink demo. */PRIVATE IX_STATUS ixEthAccCodeletTxGenRxSinkStart(IxEthAccPortId portId){ IX_OSAL_MBUF *mBufPtr; UINT32 numBufs; IxEthDBStatus status; /* port transmits as fast as possible and drops rx traffic */ if (ixEthAccCodeletPortConfigure(portId, NULL, ixEthAccCodeletRxSinkRxCB, ixEthAccCodeletTxGenTxCB, portId)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -