简体   繁体   English

Opendaylight:如何从数据路径ID获取交换机的MAC地址?

[英]Opendaylight: how to get MAC address of switch from datapath ID?

I am developing an application for opendaylight Carbon where I need to know the MAC address of the switch. 我正在为opendaylight Carbon开发一个应用程序,我需要知道该交换机的MAC地址。 Can I determine this from the DpnId when the switch connects? 交换机连接时能否从DpnId确定这一点? Thanks. 谢谢。

Not sure which MAC you are referring to. 不确定您要指的是哪个MAC。 If you are referring MAC address of each ofport of the DPN then you can register listener for FlowCapableNodeConnector model and you can get MAC by calling FlowCapableNodeConnector#getHardwareAddress in add method of listener. 如果要引用DPN每个端口的MAC地址,则可以为FlowCapableNodeConnector模型注册侦听器,并且可以通过在侦听器的add方法中调用FlowCapableNodeConnector#getHardwareAddress来获取MAC。 And if you are talking about VM/packet Source/destination MAC, then you first you need to punt the packet to controller and then you can use PacketProcessingListener and extract MAC as shown below. 而且,如果您正在谈论VM /数据包源/目标MAC,则首先需要将数据包平移到控制器,然后可以使用PacketProcessingListener并提取MAC,如下所示。

public void onPacketReceived(PacketReceived notification) {

   final short tableId = notification.getTableId().getValue();
   final byte[] data = notification.getPayload();
   Ethernet res = new Ethernet();

    try {
        res.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte);
    } catch (Exception e) {
        LOG.warn("PacketInHandler: Failed to decode Packet ", e);
        return;
    }
    try {
        Packet pkt = res.getPayload();
        LOG.info("Packet type is ->{}", pkt.getClass().getName());
        if (pkt instanceof IPv4) {
            IPv4 ipv4 = (IPv4) pkt;
            byte[] srcMac = res.getSourceMACAddress();
            byte[] dstMac = res.getDestinationMACAddress();
        }
    }
}

The DPID uniquely identifies the switch. DPID唯一标识交换机。 The MAC address is generally not exposed. MAC地址通常不公开。 Moreover, the switch itself generally does not have a MAC address (they may have tens of MAC addresses for different functions/interfaces). 此外,交换机本身通常没有MAC地址(对于不同的功能/接口,它们可能具有数十个MAC地址)。 Switches work at a lower level, though, they work with MAC addresses. 交换机工作在较低级别,但是它们使用MAC地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM