检测以太网链路变化
介绍
监控以太网链路速度有助于在系统性能下降或吞吐量低于目标值之前检测到网络性能下降。链路速度意外下降可能表明存在线缆故障、连接器故障或意外的网络拓扑结构变更。
本教程演示如何读取和监控每台相机的两个以太网链路速度状态:
CameraState::Network::Ethernet::LinkSpeed(相机端)CameraState::Network::LocalInterface::Ethernet::LinkSpeed(主机端)
读取链路速度
通过查询上面列出的 API,读取监控回路中每个相机的链路速度。
The host-side link speed is read from the local interface and does not require a connection to the camera:
// Reading the host-side (local interface) Ethernet link speed does not require a connection to the camera.
const auto localInterface = getUsersLocalInterface(camera);
const auto localInterfaceLinkSpeed = localInterface.ethernet().linkSpeed();
std::cout << "Camera " << camera.info().serialNumber()
<< ": local interface Ethernet link speed=" << localInterfaceLinkSpeed << std::endl;
// Reading the host-side (local interface) Ethernet link speed does not require a connection to the camera.
var localInterfaceLinkSpeed = GetUsersLocalInterface(camera).Ethernet.LinkSpeed;
Console.WriteLine("Camera {0}: local interface Ethernet link speed={1}",
camera.Info.SerialNumber,
localInterfaceLinkSpeed);
# Reading the host-side (local interface) Ethernet link speed does not require a connection to the camera.
local_interface_link_speed = get_users_local_interface(camera).ethernet.link_speed
print(f"Camera {camera.info.serial_number}: local interface Ethernet link speed={local_interface_link_speed}")
The camera-side link speed is read from the camera state and does require being connected to the camera:
// Reading the camera-side Ethernet link speed requires being connected to the camera.
camera.connect();
try
{
const auto cameraLinkSpeed = camera.state().network().ethernet().linkSpeed();
std::cout << "Camera " << camera.info().serialNumber() << ": camera Ethernet link speed=" << cameraLinkSpeed
<< std::endl;
}
catch(...)
{
camera.disconnect();
throw;
}
camera.disconnect();
// Reading the camera-side Ethernet link speed requires being connected to the camera.
camera.Connect();
try
{
var cameraLinkSpeed = camera.State.Network.Ethernet.LinkSpeed;
Console.WriteLine("Camera {0}: camera Ethernet link speed={1}",
camera.Info.SerialNumber,
cameraLinkSpeed);
}
finally
{
camera.Disconnect();
}
For the corresponding API, see NetworkConfiguration.
拓扑学解释
相机直连到电脑
如果相机直接连接到主机 NIC :
相机链路速度代表的是相机与主机 NIC 之间直接连接的线缆段。
本地接口链路速度代表来自主机侧的同一直连电缆段的速度。
在这种情况下,两个 API 应当报告相同的链路速度。无论哪一个 API 的数值发生变化,都表明相机与主机之间的连接状态发生了改变。
相机通过交换机连接到电脑
如果相机和主机通过同一个交换机连接:
相机链路速度代表相机到交换机的链路速度。
Local interface link speed represents the host-NIC-to-switch segment.
在这种情况下,两个 API 监控的是不同的网络段。因此,任何一个 API 的数值发生变化,都表明其对应的那个网络段出现了状态改变。
多交换机配置
在多交换机配置中,这些 API 仅观测从每个端点出发的第一跳连接:
相机链路速度报告的是相机到第一个网络设备之间的链路速度。
本地链路速度报告的是主机 NIC 到第一个网络设备之间的链路速度。
这些 API 不会 交换机与交换机之间的中间网络段!
在这种情况下,任何一个 API 的数值发生变化,都表明其对应的那个网络段出现了状态改变;但中间网络段的变化可能无法被检测到。
如果线缆损坏了会产生什么影响?
损坏的线缆通常不会立即彻底失效。相反,链路往往会触发重新协商并降速运行,例如:
状况 |
链路速度 |
|---|---|
正常链接 |
|
降速之后 |
|
即使通信尚未完全中断,这种降速很可能是线缆或连接器出现问题的早期预警信号。在实际场景中,链路可能会在受到干扰时短暂断开,然后以较低的协商速度重新连接。链路以这种方式恢复时,吞吐量会下降,并且连接不稳定或未来断开连接的风险会增加。
如果监测结果显示性能持续下降,请检查并更换受影响段的线缆。
If your camera disconnects or restarts repeatedly during operation without a sustained link speed downgrade, see Camera disconnects or restarts repeatedly during operation for further diagnostic steps.
示例
这些 API 的完整示例可在此处查看: