Skip to content

Commit

Permalink
[TE6] Read Ethernet Network Diagnostic attributes from platform at ru…
Browse files Browse the repository at this point in the history
…n-time (#9587)

* Read ethernet network diagnostic attributes from platform at run-time

* Update zap file for lighting-app

* Update gen folder
  • Loading branch information
yufengwangca authored Sep 10, 2021
1 parent 735dbb0 commit eda07d5
Show file tree
Hide file tree
Showing 9 changed files with 339 additions and 14 deletions.
13 changes: 7 additions & 6 deletions examples/lighting-app/lighting-common/lighting-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0000000000000000",
Expand All @@ -2825,7 +2825,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0000000000000000",
Expand All @@ -2840,7 +2840,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0000000000000000",
Expand All @@ -2855,7 +2855,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0000000000000000",
Expand All @@ -2870,7 +2870,7 @@
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0000000000000000",
Expand Down Expand Up @@ -5490,5 +5490,6 @@
"endpointVersion": 1,
"deviceIdentifier": 259
}
]
],
"log": []
}
99 changes: 99 additions & 0 deletions examples/lighting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <platform/CHIPDeviceLayer.h>
#include <platform/PlatformManager.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/chip-zcl-zpro-codec.h>
Expand Down Expand Up @@ -87,6 +89,103 @@ void emberAfOnOffClusterInitCallback(EndpointId endpoint)
// TODO: implement any additional Cluster Server init actions
}

EmberAfStatus HandleReadEthernetNetworkDiagnosticsAttribute(chip::AttributeId attributeId, uint8_t * buffer, uint16_t maxReadLength)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_FAILURE;

switch (attributeId)
{
case ZCL_PACKET_RX_COUNT_ATTRIBUTE_ID:
if (maxReadLength == sizeof(uint64_t))
{
uint64_t packetRxCount;

if (ConnectivityMgr().GetEthPacketRxCount(packetRxCount) == CHIP_NO_ERROR)
{
memcpy(buffer, &packetRxCount, maxReadLength);
ret = EMBER_ZCL_STATUS_SUCCESS;
}
}
break;
case ZCL_PACKET_TX_COUNT_ATTRIBUTE_ID:
if (maxReadLength == sizeof(uint64_t))
{
uint64_t packetTxCount;

if (ConnectivityMgr().GetEthPacketTxCount(packetTxCount) == CHIP_NO_ERROR)
{
memcpy(buffer, &packetTxCount, maxReadLength);
ret = EMBER_ZCL_STATUS_SUCCESS;
}
}
break;
case ZCL_TX_ERR_COUNT_ATTRIBUTE_ID:
if (maxReadLength == sizeof(uint64_t))
{
uint64_t txErrCount;

if (ConnectivityMgr().GetEthTxErrCount(txErrCount) == CHIP_NO_ERROR)
{
memcpy(buffer, &txErrCount, maxReadLength);
ret = EMBER_ZCL_STATUS_SUCCESS;
}
}
break;
case ZCL_COLLISION_COUNT_ATTRIBUTE_ID:
if (maxReadLength == sizeof(uint64_t))
{
uint64_t collisionCount;

if (ConnectivityMgr().GetEthCollisionCount(collisionCount) == CHIP_NO_ERROR)
{
memcpy(buffer, &collisionCount, maxReadLength);
ret = EMBER_ZCL_STATUS_SUCCESS;
}
}
break;
case ZCL_ETHERNET_OVERRUN_COUNT_ATTRIBUTE_ID:
if (maxReadLength == sizeof(uint64_t))
{
uint64_t overrunCount;

if (ConnectivityMgr().GetEthOverrunCount(overrunCount) == CHIP_NO_ERROR)
{
memcpy(buffer, &overrunCount, maxReadLength);
ret = EMBER_ZCL_STATUS_SUCCESS;
}
}
break;
default:
ChipLogProgress(Zcl, "Unhandled attribute ID: %d", attributeId);
break;
}

return ret;
}

EmberAfStatus emberAfExternalAttributeReadCallback(EndpointId endpoint, ClusterId clusterId,
EmberAfAttributeMetadata * attributeMetadata, uint16_t manufacturerCode,
uint8_t * buffer, uint16_t maxReadLength, int32_t index)
{
EmberAfStatus ret = EMBER_ZCL_STATUS_FAILURE;

ChipLogProgress(Zcl,
"emberAfExternalAttributeReadCallback - Cluster ID: '0x%04x', EndPoint ID: '0x%02x', Attribute ID: '0x%04x'",
clusterId, endpoint, attributeMetadata->attributeId);

switch (clusterId)
{
case ZCL_ETHERNET_NETWORK_DIAGNOSTICS_CLUSTER_ID:
ret = HandleReadEthernetNetworkDiagnosticsAttribute(attributeMetadata->attributeId, buffer, maxReadLength);
break;
default:
ChipLogError(Zcl, "Unhandled cluster ID: %d", clusterId);
break;
}

return ret;
}

int main(int argc, char * argv[])
{
if (ChipLinuxAppInit(argc, argv) != 0)
Expand Down
12 changes: 12 additions & 0 deletions src/include/platform/CHIPDeviceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,18 @@
#define CHIP_DEVICE_CONFIG_DEFAULT_TELEMETRY_INTERVAL_MS 90000
#endif

/**
* @def CHIP_DEVICE_CONFIG_ETHERNET_IF_NAME
*
* @brief
* Default ethernet network interface name used to centralize all metrics that are
* relevant to a potential Ethernet connection to a Node.
*
*/
#ifndef CHIP_DEVICE_CONFIG_ETHERNET_IF_NAME
#define CHIP_DEVICE_CONFIG_ETHERNET_IF_NAME "enp0s25"
#endif

// -------------------- Event Logging Configuration --------------------

/**
Expand Down
32 changes: 32 additions & 0 deletions src/include/platform/ConnectivityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ class ConnectivityManager
// Service connectivity methods
bool HaveServiceConnectivity();

// Ethernet network diagnostics methods
CHIP_ERROR GetEthPacketRxCount(uint64_t & packetRxCount);
CHIP_ERROR GetEthPacketTxCount(uint64_t & packetTxCount);
CHIP_ERROR GetEthTxErrCount(uint64_t & txErrCount);
CHIP_ERROR GetEthCollisionCount(uint64_t & collisionCount);
CHIP_ERROR GetEthOverrunCount(uint64_t & overrunCount);

// CHIPoBLE service methods
Ble::BleLayer * GetBleLayer();
CHIPoBLEServiceMode GetCHIPoBLEServiceMode();
Expand Down Expand Up @@ -381,6 +388,31 @@ inline bool ConnectivityManager::HaveServiceConnectivity()
return static_cast<ImplClass *>(this)->_HaveServiceConnectivity();
}

inline CHIP_ERROR ConnectivityManager::GetEthPacketRxCount(uint64_t & packetRxCount)
{
return static_cast<ImplClass *>(this)->_GetEthPacketRxCount(packetRxCount);
}

inline CHIP_ERROR ConnectivityManager::GetEthPacketTxCount(uint64_t & packetTxCount)
{
return static_cast<ImplClass *>(this)->_GetEthPacketTxCount(packetTxCount);
}

inline CHIP_ERROR ConnectivityManager::GetEthTxErrCount(uint64_t & txErrCount)
{
return static_cast<ImplClass *>(this)->_GetEthTxErrCount(txErrCount);
}

inline CHIP_ERROR ConnectivityManager::GetEthCollisionCount(uint64_t & collisionCount)
{
return static_cast<ImplClass *>(this)->_GetEthCollisionCount(collisionCount);
}

inline CHIP_ERROR ConnectivityManager::GetEthOverrunCount(uint64_t & overrunCount)
{
return static_cast<ImplClass *>(this)->_GetEthOverrunCount(overrunCount);
}

inline ConnectivityManager::ThreadMode ConnectivityManager::GetThreadMode()
{
return static_cast<ImplClass *>(this)->_GetThreadMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class GenericConnectivityManagerImpl_NoWiFi
uint32_t _GetWiFiAPIdleTimeoutMS(void);
void _SetWiFiAPIdleTimeoutMS(uint32_t val);
CHIP_ERROR _GetAndLogWifiStatsCounters(void);
CHIP_ERROR _GetEthPacketRxCount(uint64_t & packetRxCount);
CHIP_ERROR _GetEthPacketTxCount(uint64_t & packetTxCount);
CHIP_ERROR _GetEthTxErrCount(uint64_t & txErrCount);
CHIP_ERROR _GetEthCollisionCount(uint64_t & collisionCount);
CHIP_ERROR _GetEthOverrunCount(uint64_t & overrunCount);
bool _CanStartWiFiScan();
void _OnWiFiScanDone();
void _OnWiFiStationProvisionChange();
Expand Down Expand Up @@ -235,6 +240,36 @@ inline const char * GenericConnectivityManagerImpl_NoWiFi<ImplClass>::_WiFiAPSta
return NULL;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi<ImplClass>::_GetEthPacketRxCount(uint64_t & packetRxCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi<ImplClass>::_GetEthPacketTxCount(uint64_t & packetTxCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi<ImplClass>::_GetEthTxErrCount(uint64_t & txErrCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi<ImplClass>::_GetEthCollisionCount(uint64_t & collisionCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi<ImplClass>::_GetEthOverrunCount(uint64_t & overrunCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class GenericConnectivityManagerImpl_WiFi
uint32_t _GetWiFiAPIdleTimeoutMS();
void _SetWiFiAPIdleTimeoutMS(uint32_t val);
CHIP_ERROR _GetAndLogWifiStatsCounters();
CHIP_ERROR _GetEthPacketRxCount(uint64_t & packetRxCount);
CHIP_ERROR _GetEthPacketTxCount(uint64_t & packetTxCount);
CHIP_ERROR _GetEthTxErrCount(uint64_t & txErrCount);
CHIP_ERROR _GetEthCollisionCount(uint64_t & collisionCount);
CHIP_ERROR _GetEthOverrunCount(uint64_t & overrunCount);
bool _CanStartWiFiScan();
void _OnWiFiScanDone();
void _OnWiFiStationProvisionChange();
Expand Down Expand Up @@ -181,6 +186,36 @@ template <class ImplClass>
inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_OnWiFiStationProvisionChange()
{}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetEthPacketRxCount(uint64_t & packetRxCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetEthPacketTxCount(uint64_t & packetTxCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetEthTxErrCount(uint64_t & txErrCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetEthCollisionCount(uint64_t & collisionCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ImplClass>
inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetEthOverrunCount(uint64_t & overrunCount)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
Loading

0 comments on commit eda07d5

Please sign in to comment.