Configuring CDP and LLDP for ESXi vSwitches

CDP and LLDP are discovery protocols that allow devices (or hosts in the case of ESXi) to share network information with the networking equipment they are connected to. Discovery protocols are most commonly used between switches and routers, but can also be configured on an ESXi host. CDP stands for Cisco Discovery Protocol, and is Cisco proprietary, whilst LLDP stands for Link Layer Discovery Protocol and is an open standard. Both protocols perform similar functions, and the choice between the two generally comes down to which protocol the physical networking equipment supports and is configured to use.

  • Cisco Discovery Protocol (CDP) can be used on standard and distributed vSwitches which are connected to Cisco network equipment.
  • Link Layer Discovery Protocol (LLDP) can be used on dvSwitches that are version 5.0 or later. LLDP is vendor neutral.

On a standard vSwitch you can view CDP information by clicking on the ‘speech’ icon next to the physical adapters:

cdp-esxi

Configuring Cisco Discovery Protocol (CDP) on ESXi Hosts

CDP is enabled by default on standard vSwitches, though you can view and configure CDP status using command line tools.

CDP can be disabled or configured on a per vSwitch basis. If it is enabled, it will be running in one of three possible modes:

  • Listen – When in listen mode the host will display information about the physical switch it is connect to, but will not send CDP data, so CDP information on the vSwitch will not be available on the physical switch.
  • Advertise – In this mode, the host will send CDP information to the physical switch, but will not display any information about the physical switch. Therefore this is the opposite of the listen mode.
  • Both – When Both is set as the mode the host both receives/displays CDP data and sends CDP to the physical switch.

To view the CDP status for a vSwitch you can run:

~ # esxcfg-vswitch vSwitch0 -b
listen

To change the mode that CDP is running in you can run:

~ # esxcfg-vswitch vSwitch0 -B both

Using ‘both’ as the mode in the example above means that CDP on that vSwitch will both listen for and advertise CDP information. The following segment from the help file shows the possible CDP modes that can be set:

-B|--set-cdp                Set the CDP status for a given virtual switch.
                            To set pass one of "down", "listen", "advertise", "both".
-b|--get-cdp                Print the current CDP setting for this switch.

You can also view and change the status using ESXCLI. For example, to set the CDP status to ‘both’, you can run the following:

~ # esxcli network vswitch standard set --cdp-status=both -v vSwitch0

And to view CDP status for a vSwitch you can run:

~ # esxcli network vswitch standard list
vSwitch0
   Name: vSwitch0
   Class: etherswitch
   Num Ports: 128
   Used Ports: 5
   Configured Ports: 128
   MTU: 1500
   CDP Status: both
   Beacon Enabled: false
   Beacon Interval: 1
   Beacon Threshold: 3
   Beacon Required By:
   Uplinks: vmnic1, vmnic0
   Portgroups: vMotion, Management Network
CDP Configuration on a dvSwitch

CDP is configured on a dvSwitch by editing the dvSwitch settings. On the Properties tab, Click Advanced, then set the discovery protocol as required:
cdp-dvswitch

Configuring Link Layer Discovery Protocol (LLDP) on ESXi Hosts

LLDP is available only on distributed switches. It is configured in the Advanced settings of the dvSwitch:

dvswitch-lldp

As with CDP, there are the different modes of operation (Listen, Advertise and Both) or LLDP can be disabled entirely.


通过 PowerCLI 获取 CDP 信息

要使用 PowerCLI 来显示 CDP 信息,请执行以下操作:

  1. 使用 PowerCLI 来连接 ESX 主机或 vCenter Server:

    # Connect-VIServer esx-or-vc-hostname 

  2. 在 PowerCLI 中运行以下脚本:

    Get-VMHost | Where-Object {$_.State -eq "Connected"} |
    %{Get-View $_.ID} |
    %{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} |
    %{ foreach($physnic in $_.NetworkInfo.Pnic){
        $pnicInfo = $_.QueryNetworkHint($physnic.Device)
        foreach($hint in $pnicInfo){
          Write-Host $esxname $physnic.Device
          if( $hint.ConnectedSwitchPort ) {
            $hint.ConnectedSwitchPort
        }
        else {
          Write-Host "No CDP information available."; Write-Host
        }
      }
     }
    }

    此时会显示连接的每台 ESX 主机上每个物理网络接口的 CDP 信息。

    例如:

    esxhostname vmnic0
    CdpVersion       : 2
    Timeout          : 0
    Ttl              : 177
    Samples          : 54732
    DevId            : example-lab-b2-c02
    Address          : 10.11.12.254
    PortId           : GigabitEthernet1/0/7 <<< Switch Port ID >>>
    DeviceCapability : VMware.Vim.PhysicalNicCdpDeviceCapability
    SoftwareVersion  : Cisco IOS Software, C3750 Softw
    HardwarePlatform : cisco WS-C3750G-24TS-1U
    IpPrefix         : 0.0.0.0
    IpPrefixLen      : 0
    Vlan             : 1 <<< VLan ID >>>
    FullDuplex       : True
    Mtu              : 0
    SystemName       :
    SystemOID        :
    MgmtAddr         : 10.11.12.254
    Location         : 

  3. 要获取有关上行链路 Cisco 交换机以及为 CDP 配置的相关物理交换机端口的信息,请在 PowerCLI 中运行以下脚本:

    param($VMHost)
    $vmh = Get-VMHost $VMHost
    If ($vmh.State -ne "Connected") {
      Write-Output "Host $($vmh) state is not connected, skipping."
      }
    Else {
      Get-View $vmh.ID | `
      % { $esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} | `
      % { foreach ($physnic in $_.NetworkInfo.Pnic) {
        $pnicInfo = $_.QueryNetworkHint($physnic.Device)
        foreach( $hint in $pnicInfo ){
          # Write-Host $esxname $physnic.Device
          if ( $hint.ConnectedSwitchPort ) {
             $hint.ConnectedSwitchPort | select @{n="VMHost"
    e={$esxname}},@{n="VMNic";
    e={$physnic.Device}},DevId,Address,PortId,HardwarePlatform
             }
           else {
             Write-Host "No CDP information available."
            }
          }
        }
      }
    }

    例如,如果此脚本另存为 Get-mVMHostCDPInfo.ps1

    # Get-mVMHostCDPInfo.ps1 -VMHost esxhostname | ft -a

    VMHost VMNic DevId Address PortId HardwarePlatform
    ------ ----- ----- ------- ------ ----------------
    esxhostname vmnic0 esx1.mon.com 1.1.1.1 GigabitEthernet1/0/9 cisco WS-C3750G-24TS-1U
    esxhostname vmnic1 esx1.mon.com 1.1.1.1 GigabitEthernet2/0/21 cisco WS-C3750G-24TS-1U
    esxhostname vmnic2 esx1.mon.com 1.1.1.1 GigabitEthernet1/0/10 cisco WS-C3750G-24TS-1U
    esxhostname vmnic3 esx1.mon.com 1.1.1.1 GigabitEthernet2/0/10 cisco WS-C3750G-24TS-1U
    esxhostname vmnic4 esx1.mon.com 1.1.1.1 GigabitEthernet1/0/11 cisco WS-C3750G-24TS-1U
    esxhostname vmnic5 esx1.mon.com 1.1.1.1 GigabitEthernet2/0/11 cisco WS-C3750G-24TS-1U
    esxhostname vmnic6 esx2.mon.com 1.1.1.2 GigabitEthernet1/0/6 cisco WS-C3750G-24TS-1U
    esxhostname vmnic7 esx2.mon.com 1.1.1.2 GigabitEthernet1/0/8 cisco WS-C3750G-24TS-1U

通过 ESX/ESXi 命令行获取 CDP 信息

要使用 ESX/ESXi 命令行查看 CDP 信息,请执行以下操作:

  1. 以 root 身份通过 SSH 或控制台登录到 ESX/ESXi。
  2. 运行以下命令来查看 CDP 信息:

    对于 ESX 4.x:

        # vmware-vim-cmd hostsvc/net/query_networkhint

    对于 ESXi 4.x 和 5.x:

        # vim-cmd hostsvc/net/query_networkhint

    对于 ESXi 4.x 和 5.x,如果您希望仅指定一个物理网卡进行查询,请运行:

        # vim-cmd hostsvc/net/query_networkhint --pnic-name=vmnic[xx]

    注意:从控制台登录到 ESXi 主机。有关详细信息,请参见用来获得紧急支持的技术支持模式 (1003677) (Tech Support Mode for Emergency Support (1003677))

    此时会显示连接的每台 ESX 主机上每个物理网络接口的 CDP 信息。

    例如:

    (vim.host.PhysicalNic.NetworkHint) [
      (vim.host.PhysicalNic.NetworkHint) {
        dynamicType = <unset>,
        device = "vmnic3",
        subnet = (vim.host.PhysicalNic.NetworkHint.IpNetwork) [
          (vim.host.PhysicalNic.NetworkHint.IpNetwork) {
            dynamicType = <unset>,
            vlanId = 0,
            ipSubnet = "10.21.4.1-10.21.7.254",
         }
       ],
     connectedSwitchPort = (vim.host.PhysicalNic.CdpInfo) null,
    },
    (vim.host.PhysicalNic.NetworkHint) {
      dynamicType = <unset>,
      device = "vmnic1",
      subnet = (vim.host.PhysicalNic.NetworkHint.IpNetwork) [
        (vim.host.PhysicalNic.NetworkHint.IpNetwork) {
        dynamicType = <unset>,
        vlanId = 0,
        ipSubnet = "10.21.3.1-10.21.3.15",
      }
    ],
    connectedSwitchPort = (vim.host.PhysicalNic.CdpInfo) {
      dynamicType = <unset>,
      cdpVersion = 0,
      timeout = 0,
      ttl = 169,
      samples = 2982,
      devId = "PA-3210-2-R15-SW1",
      address = "10.21.10.115",
      portId = "GigabitEthernet1/0/7", <<< Switch Port ID >>>
      deviceCapability = (vim.host.PhysicalNic.CdpDeviceCapability) {
         dynamicType = <unset>,
          router = false,
          transparentBridge = false,
         sourceRouteBridge = false,
         networkSwitch = true,
         host = false,
         igmpEnabled = true,
         repeater = false,
      },
         softwareVersion = "Cisco IOS Software, C3750 Softw",
         hardwarePlatform = "cisco WS-C3750G-48TS",
         ipPrefix = "0.0.0.0",
         ipPrefixLen = 0,
         vlan = 3, <<< VLan ID >>>
         fullDuplex = true,
         mtu = 0,
         systemName = "",
         systemOID = "",
         mgmtAddr = "10.21.10.115",
         location = "",
        },
      }, 
    ]
  3. 也可以通过运行以下命令来找到相同的 CDP 信息:

    # esxcfg-info | less

    搜索特定的 vmnic#(在本示例中为 vmnic0)来查找 CDP 信息。

    示例输出:

    |----Name........................................vmnic0
    |----PCI Bus.....................................3
    |----PCI Slot....................................0
    |----PCI function................................0
    |----MAC Address.................................xx:xx:xx:xx:xx:xx
    |----Virtual MAC Address.........................xx:xx:xx:xx:xx:xy
    |----Driver......................................bnx2
    |----Network Hint................................0 10.112.100.0/255.255.252.0
    |----MTU.........................................1500
    |----Configured Speed............................1000
    |----Actual Speed................................1000
    |----Configured Duplex...........................1
    |----Actual Duplex...............................1
    |----Link Up.....................................true
    |----enabled.....................................true
    |----Wake on LAN supported ......................true
    |----Wake on LAN enabled ........................true
    |----Resource scheduler allowed ................true
    |----Resource scheduler supported ...............true
    |----CDP Network.................................true
    \==+CDP Summary :
    |----Cdp Version.............................2
    |----Timeout.................................0
    |----Time-to-live............................177
    |----Samples.................................20131
    |----Device Id...............................c2960G-lab-c18
    |----Ip Address..............................10.112.106.86
    |----Ip Prefix...............................0.0.0.0/0
    |----Port Id.................................GigabitEthernet0/35
    |----Capabilities............................40
    |----Version.................................Cisco IOS Software, C2960 Software
    |----Platform................................cisco WS-C2960G-48TC-L
    |----Vlan....................................1032
    |----Duplex..................................true
    |----MTU.....................................0
    |----System Name.............................
    |----System OID..............................
    |----Mgmt Ip Address.........................10.112.106.86

使用 PowerCLI 设置 CDP 信息

$esxcli = Get-EsxCli -VMHost $myhost
$esxcli.network.vswitch.standard.set("both","1500","vSwitch0")

使用 esxcli 命令在 ESXi 5.x 上设置 CDP 信息

# esxcli network vswitch standard set –c both –v vSwitch#

注意:请使用 vSwitch 编号来替换 #

使用 esxcli 设置链路层发现协议 (LLDP) 信息

# esxcli network vswitch standard list -v vSwitch#


### 构建任务失败解决方案 当遇到 `Execution failed for task ':app:shrinkReleaseRes'` 错误时,这通常意味着资源压缩过程中出现了问题。此错误可能由多种原因引起,包括但不限于配置不正确、依赖冲突或特定于项目的其他因素。 #### 可能的原因分析 1. **ProGuard 或 R8 配置不当** ProGuard 和 R8 是用于优化和混淆代码以及减少 APK 大小的工具。如果这些工具的配置存在问题,可能会导致资源无法正常处理[^1]。 2. **重复资源** 如果项目中有多个模块定义了相同的资源名称,可能导致冲突并引发该错误。检查是否存在重名的 drawable、string 等资源文件[^2]。 3. **第三方库兼容性** 某些第三方库可能与当前使用的 Gradle 插件版本或其他库存在兼容性问题,从而影响到资源打包过程中的行为[^3]。 4. **Gradle 缓存问题** 有时旧缓存数据会干扰新编译的结果,尝试清理本地仓库和重新同步项目可以帮助排除此类潜在障碍[^4]。 #### 推荐的操作方法 为了有效解决问题,建议按照以下步骤逐一排查: ```bash # 清理项目构建目录 ./gradlew clean # 删除 .gradle 文件夹下的所有内容以清除缓存 rm -rf ~/.gradle/caches/ ``` 调整 `build.gradle` 中的相关设置也是一个重要环节: ```groovy android { ... buildTypes { release { minifyEnabled true // 是否启用代码缩减 shrinkResources true // 是否开启资源压缩 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' // 尝试禁用 shrinkResources 来测试是否为资源压缩引起的错误 // shrinkResources false } } } ``` 此外,在 `proguard-rules.pro` 文件内添加必要的保留规则,防止关键类被意外移除: ```text -keep class com.example.yourpackage.** { *; } # 替换为你自己的包路径 -dontwarn androidx.**,com.google.** # 忽略警告信息 ``` 最后,确保所使用的 Android Studio 版本是最新的稳定版,并且已经应用了所有的补丁更新。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值