ONOS链路发现源码
//send LLDP by ynogpu
private void sendProbes(Long portNumber, String portDesc) {
if (context.packetService() == null) {
return;
}
OutboundPacket pkt = createOutBoundLldp(portNumber, portDesc);
context.packetService().emit(pkt);
if (context.useBddp()) {
OutboundPacket bpkt = createOutBoundBddp(portNumber, portDesc);
context.packetService().emit(bpkt);
}
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
/**
* Creates packet_out LLDP for specified output port.
* @param portNumber the port
* @param portDesc the port description
* @return Packet_out message with LLDP data
*/
//为指定的输出端口创建packet_out LLDP
private OutboundPacket createOutBoundLldp(Long portNumber, String portDesc) {
log.info("yongpu-----createOutBoundLldp{}@{}",portNumber,portDesc);
if (portNumber == null) {
return null;
}
ONOSLLDP lldp = getLinkProbe(context.deviceService().getDevice(device.id()).chassisId(),
portNumber, portDesc);
ethPacket.setSourceMACAddress(context.fingerprint()).setPayload(lldp);
return new DefaultOutboundPacket(device.id(),
builder().setOutput(portNumber(portNumber)).build(),
ByteBuffer.wrap(ethPacket.serialize()));
}
private ONOSLLDP getLinkProbe(ChassisId chassisId, Long portNumber, String portDesc) {
return ONOSLLDP.onosLLDP(device.id().toString(), chassisId, portNumber.intValue(), portDesc);
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
/**
* Creates a link probe for link discovery/verification.
* @param deviceId The device ID as a String
* @param chassisId The chassis ID of the device
* @param portNum Port number of port to send probe out of
* @param portDesc Port description of port to send probe out of
* @return ONOSLLDP probe message
*/
public static ONOSLLDP onosLLDP(String deviceId, ChassisId chassisId, int portNum, String portDesc) {
ONOSLLDP probe = onosLLDP(deviceId, chassisId, portNum);
if (portDesc != null && !portDesc.isEmpty()) {
byte[] bPortDesc = portDesc.getBytes(StandardCharsets.UTF_8);
if (bPortDesc.length > LLDPTLV.MAX_LENGTH) {
bPortDesc = Arrays.copyOf(bPortDesc, LLDPTLV.MAX_LENGTH);
}
LLDPTLV portDescTlv = new LLDPTLV()
.setType(PORT_DESC_TLV_TYPE)
.setLength((short) bPortDesc.length)
.setValue(bPortDesc);
probe.addOptionalTLV(portDescTlv);
}
return probe;
}
----------------------------------------------------------------------------
----------------------------------------------------------------------------
/**
* Creates a link probe for link discovery/verification.
* @param deviceId The device ID as a String
* @param chassisId The chassis ID of the device
* @param portNum Port number of port to send probe out of
* @return ONOSLLDP probe message
*/
public static ONOSLLDP onosLLDP(String deviceId, ChassisId chassisId, int portNum) {
ONOSLLDP probe = new ONOSLLDP(NAME_SUBTYPE, DEVICE_SUBTYPE);
probe.setPortId(portNum);
probe.setDevice(deviceId);
probe.setChassisId(chassisId);
return probe;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)