I am developing an application for opendaylight Carbon where I need to know the MAC address of the switch. Can I determine this from the DpnId when the switch connects? Thanks.
Opendaylight: how to get MAC address of switch from datapath ID?
610 views Asked by LostInTheFrequencyDomain At
2
There are 2 answers
1
On
Not sure which MAC you are referring to. 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. 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.
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. The MAC address is generally not exposed. Moreover, the switch itself generally does not have a MAC address (they may have tens of MAC addresses for different functions/interfaces). Switches work at a lower level, though, they work with MAC addresses.