📄 ixethdbnpeadaptor.c
字号:
(UINT32) baseAddress, FULL_ELT_BYTE_SIZE); IX_ETH_DB_NPE_DUMP_ELT(baseAddress, FULL_ELT_BYTE_SIZE); /* compute number of 64-byte blocks */ if (blocks != NULL) { *blocks = maxOffset != 0 ? 1 + maxOffset / 8 : 0; IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Wrote %d 64-byte blocks\n", *blocks); } /* compute epDelta - start index for binary search */ if (epDelta != NULL) { UINT32 deltaIndex = 0; *epDelta = 0; for (; deltaIndex < IX_ETH_DB_MAX_DELTA_ZONES ; deltaIndex ++) { if (ixEthDBEPDeltaOffset[type][deltaIndex] >= maxOffset) { *epDelta = ixEthDBEPDelta[type][deltaIndex]; break; } } IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Computed epDelta %d (based on maxOffset %d)\n", *epDelta, maxOffset); } ixOsalCacheDmaFree(stack);}/** * @brief implements a dummy node serialization function * * @param address address of where the node is to be serialized (unused) * @param node tree node to be serialized (unused) * * This function is registered for safety reasons and should * never be called. It will display an error message if this * function is called. * * @return none * * @internal */IX_ETH_DB_PRIVATEvoid ixEthDBNullSerialize(void *address, MacTreeNode *node){ IX_ETH_DB_NPE_TRACE("DB: (NPEAdaptor) Warning, the NullSerialize function was called, wrong record type?\n");}/** * @brief writes a filtering entry in NPE linear format * * @param address memory address to write node to * @param node node to be written * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PRIVATEvoid ixEthDBNPELearningNodeWrite(void *address, MacTreeNode *node){ /* copy mac address */ memcpy(address, node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE); /* copy port ID */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_ELT_PORT_ID_OFFSET) = IX_ETH_DB_PORT_ID_TO_NPE_LOGICAL_ID(node->descriptor->portID); /* copy flags (valid and not active, as the NPE sets it to active) and clear reserved section (bits 2-7) */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_ELT_FLAGS_OFFSET) = (UINT8) IX_EDB_FLAGS_INACTIVE_VALID; IX_ETH_DB_NPE_VERBOSE_TRACE("DB: (NPEAdaptor) writing ELT node 0x%08x:0x%08x\n", * (UINT32 *) address, * (((UINT32 *) (address)) + 1));}/** * @brief writes a WiFi header conversion record in * NPE linear format * * @param address memory address to write node to * @param node node to be written * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PRIVATEvoid ixEthDBNPEWiFiNodeWrite(void *address, MacTreeNode *node){ /* copy mac address */ memcpy(address, node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE); /* copy index */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_WIFI_INDEX_OFFSET) = node->descriptor->recordData.wifiData.gwAddressIndex; /* copy flags (type and valid) */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_WIFI_FLAGS_OFFSET) = node->descriptor->recordData.wifiData.type << 1 | IX_EDB_FLAGS_VALID;}/** * @brief writes a WiFi gateway header conversion record in * NPE linear format * * @param address memory address to write node to * @param node node to be written * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PUBLICvoid ixEthDBNPEGatewayNodeWrite(void *address, MacTreeNode *node){ /* copy mac address */ memcpy(address, node->descriptor->recordData.wifiData.gwMacAddress, IX_IEEE803_MAC_ADDRESS_SIZE); /* set reserved field, two bytes */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET) = 0; NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET + 1) = 0;}/** * @brief writes a firewall record in * NPE linear format * * @param address memory address to write node to * @param node node to be written * * Used by @ref ixEthDBNPETreeWrite to liniarize a search tree * in NPE-readable format. * * @internal */IX_ETH_DB_PRIVATEvoid ixEthDBNPEFirewallNodeWrite(void *address, MacTreeNode *node){ /* set reserved field */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_RESERVED_OFFSET) = 0; /* set flags */ NPE_NODE_BYTE(address, IX_EDB_NPE_NODE_FW_FLAGS_OFFSET) = IX_EDB_FLAGS_VALID; /* copy mac address */ memcpy((void *) ((UINT32) address + IX_EDB_NPE_NODE_FW_ADDR_OFFSET), node->descriptor->macAddress, IX_IEEE803_MAC_ADDRESS_SIZE);}/** * @brief registers the NPE serialization methods * * This functions registers NPE serialization methods * for writing the following types of records in NPE * readable linear format: * - filtering records * - WiFi header conversion records * - WiFi gateway header conversion records * - firewall records * * Note that this function should be called by the * component initialization function. * * @return number of registered record types * * @internal */IX_ETH_DB_PUBLICUINT32 ixEthDBRecordSerializeMethodsRegister(){ int i; /* safety - register a blank method for everybody first */ for ( i = 0 ; i < IX_ETH_DB_MAX_RECORD_TYPE_INDEX + 1 ; i++) { ixEthDBNPENodeWrite[i] = ixEthDBNullSerialize; } /* register real methods */ ixEthDBNPENodeWrite[IX_ETH_DB_FILTERING_RECORD] = ixEthDBNPELearningNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_FILTERING_VLAN_RECORD] = ixEthDBNPELearningNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_WIFI_RECORD] = ixEthDBNPEWiFiNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_FIREWALL_RECORD] = ixEthDBNPEFirewallNodeWrite; ixEthDBNPENodeWrite[IX_ETH_DB_GATEWAY_RECORD] = ixEthDBNPEGatewayNodeWrite; /* EP Delta arrays */ memset(ixEthDBEPDeltaOffset, 0, sizeof (ixEthDBEPDeltaOffset)); memset(ixEthDBEPDelta, 0, sizeof (ixEthDBEPDelta)); /* filtering records */ ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][0] = 1; ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][0] = 0; ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][1] = 3; ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][1] = 7; ixEthDBEPDeltaOffset[IX_ETH_DB_FILTERING_RECORD][2] = 511; ixEthDBEPDelta[IX_ETH_DB_FILTERING_RECORD][2] = 14; /* wifi records */ ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][0] = 1; ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][0] = 0; ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][1] = 3; ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][1] = 7; ixEthDBEPDeltaOffset[IX_ETH_DB_WIFI_RECORD][2] = 511; ixEthDBEPDelta[IX_ETH_DB_WIFI_RECORD][2] = 14; /* firewall records */ ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][0] = 0; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][0] = 0; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][1] = 1; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][1] = 5; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][2] = 3; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][2] = 13; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][3] = 7; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][3] = 21; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][4] = 15; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][4] = 29; ixEthDBEPDeltaOffset[IX_ETH_DB_FIREWALL_RECORD][5] = 31; ixEthDBEPDelta[IX_ETH_DB_FIREWALL_RECORD][5] = 37; return 5; /* 5 methods registered */}#ifndef IX_NDEBUGIX_ETH_DB_PUBLIC UINT32 npeMsgHistory[IX_ETH_DB_NPE_MSG_HISTORY_DEPTH][2];IX_ETH_DB_PUBLIC UINT32 npeMsgHistoryLen = 0;/** * When compiled in DEBUG mode, this function can be used to display * the history of messages sent to the NPEs (up to 100). */IX_ETH_DB_PUBLICvoid ixEthDBShowNpeMsgHistory(){ UINT32 i = 0; UINT32 base, len; if (npeMsgHistoryLen <= IX_ETH_DB_NPE_MSG_HISTORY_DEPTH) { base = 0; len = npeMsgHistoryLen; } else { base = npeMsgHistoryLen % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; len = IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; } printf("NPE message history [last %d messages, from least to most recent]:\n", len); for (; i < len ; i++) { UINT32 pos = (base + i) % IX_ETH_DB_NPE_MSG_HISTORY_DEPTH; printf("msg[%d]: 0x%08x:0x%08x\n", i, npeMsgHistory[pos][0], npeMsgHistory[pos][1]); }}IX_ETH_DB_PUBLICvoid ixEthDBELTShow(IxEthDBPortId portID){ IxNpeMhMessage message; IX_STATUS result; /* send EDB_GetMACAddressDatabase message */ FILL_GETMACADDRESSDATABASE(message, 0 /* reserved */, IX_OSAL_MMU_VIRT_TO_PHYS(ixEthDBPortInfo[portID].updateMethod.npeUpdateZone)); IX_ETHDB_SEND_NPE_MSG(IX_ETH_DB_PORT_ID_TO_NPE(portID), message, result); if (result == IX_SUCCESS) { /* analyze NPE copy */ UINT32 eltEntryOffset; UINT32 entryPortID; UINT32 eltBaseAddress = (UINT32) ixEthDBPortInfo[portID].updateMethod.npeUpdateZone; UINT32 eltSize = FULL_ELT_BYTE_SIZE; /* invalidate cache */ IX_OSAL_CACHE_INVALIDATE((void *) eltBaseAddress, eltSize); printf("Listing records in main learning tree for port %d\n", portID); for (eltEntryOffset = ELT_ROOT_OFFSET ; eltEntryOffset < eltSize ; eltEntryOffset += ELT_ENTRY_SIZE) { /* (eltBaseAddress + eltEntryOffset) points to a valid NPE tree node * * the format of the node is MAC[6 bytes]:PortID[1 byte]:Reserved[6 bits]:Active[1 bit]:Valid[1 bit] * therefore we can just use the pointer for database searches as only the first 6 bytes are checked */ void *eltNodeAddress = (void *) ((UINT32) eltBaseAddress + eltEntryOffset); if (IX_EDB_NPE_NODE_VALID(eltNodeAddress)) { HashNode *node; entryPortID = IX_ETH_DB_NPE_LOGICAL_ID_TO_PORT_ID(IX_EDB_NPE_NODE_PORT_ID(eltNodeAddress)); /* search record */ node = ixEthDBSearch((IxEthDBMacAddr *) eltNodeAddress, IX_ETH_DB_ALL_RECORD_TYPES); printf("%s - port %d - %s ", mac2string((unsigned char *) eltNodeAddress), entryPortID, IX_EDB_NPE_NODE_ACTIVE(eltNodeAddress) ? "active" : "inactive"); /* safety check, maybe user deleted record right before sync? */ if (node != NULL) { /* found record */ MacDescriptor *descriptor = (MacDescriptor *) node->data; printf("- %s ", descriptor->type == IX_ETH_DB_FILTERING_RECORD ? "filtering" : descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD ? "vlan" : descriptor->type == IX_ETH_DB_WIFI_RECORD ? "wifi" : "other (check main DB)"); if (descriptor->type == IX_ETH_DB_FILTERING_RECORD) printf("- age %d - %s ", descriptor->recordData.filteringData.age, descriptor->recordData.filteringData.staticEntry ? "static" : "dynamic"); if (descriptor->type == IX_ETH_DB_FILTERING_VLAN_RECORD) printf("- age %d - %s - tci %d ", descriptor->recordData.filteringVlanData.age, descriptor->recordData.filteringVlanData.staticEntry ? "static" : "dynamic", descriptor->recordData.filteringVlanData.ieee802_1qTag); /* end transaction */ ixEthDBReleaseHashNode(node); } else { printf("- not synced"); } printf("\n"); } } } else { ixOsalLog(IX_OSAL_LOG_LVL_FATAL, IX_OSAL_LOG_DEV_STDOUT, "EthDB: (ShowELT) Could not complete action (communication failure)\n", portID, 0, 0, 0, 0, 0); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -