public static boolean verify(ONOSLLDP probe, String secret, long maxDelay) { if (secret == null) { return true; } String deviceId = probe.getDeviceString(); int portNum = probe.getPort(); long timestamp = probe.getTimestamp(); byte[] sig = probe.getSig(); if (deviceId == null || sig == null) { return false; } if (timestamp + maxDelay <= System.currentTimeMillis() || timestamp > System.currentTimeMillis()) { return false; } return verifySig(sig, deviceId, portNum, timestamp, secret); }
/** * Creates a link probe for link discovery/verification. * @deprecated since 1.15. Insecure, do not use. * * @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 */ @Deprecated public static ONOSLLDP onosLLDP(String deviceId, ChassisId chassisId, int portNum, String portDesc) { ONOSLLDP probe = onosLLDP(deviceId, chassisId, portNum); addPortDesc(probe, portDesc); return probe; }
ONOSLLDP probe = null; if (secret == null) { probe = new ONOSLLDP(NAME_SUBTYPE, DEVICE_SUBTYPE); } else { probe = new ONOSLLDP(NAME_SUBTYPE, DEVICE_SUBTYPE, TIMESTAMP_SUBTYPE, SIG_SUBTYPE); probe.setPortId(portNum); probe.setDevice(deviceId); probe.setChassisId(chassisId); probe.setTimestamp(ts); byte[] sig = createSig(deviceId, portNum, ts, secret); if (sig == null) { return null; probe.setSig(sig); sig = null;
/** * 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 * @param secret LLDP secret * @return ONOSLLDP probe message */ public static ONOSLLDP onosSecureLLDP(String deviceId, ChassisId chassisId, int portNum, String portDesc, String secret) { ONOSLLDP probe = onosSecureLLDP(deviceId, chassisId, portNum, secret); addPortDesc(probe, portDesc); return probe; }
/** * Creates a link probe for link discovery/verification. * @deprecated since 1.15. Insecure, do not use. * * @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 */ @Deprecated 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; }
ONOSLLDP onoslldp = ONOSLLDP.parseONOSLLDP(eth); if (onoslldp != null) { Type lt; PortNumber srcPort = portNumber(onoslldp.getPort()); PortNumber dstPort = packetContext.inPacket().receivedFrom().port(); String idString = onoslldp.getDeviceString(); if (!isNullOrEmpty(idString)) { DeviceId srcDeviceId = DeviceId.deviceId(idString);
/** * Given an ethernet packet, determines if this is an LLDP from * ONOS and returns the device the LLDP came from. * @param eth an ethernet packet * @return a the lldp packet or null */ public static ONOSLLDP parseONOSLLDP(Ethernet eth) { if (eth.getEtherType() == Ethernet.TYPE_LLDP || eth.getEtherType() == Ethernet.TYPE_BSN) { ONOSLLDP onosLldp = new ONOSLLDP((LLDP) eth.getPayload()); if (ONOSLLDP.DEFAULT_NAME.equals(onosLldp.getNameString())) { return onosLldp; } } return null; }
private ONOSLLDP getLinkProbe(Long port) { return ONOSLLDP.onosLLDP(device.id().toString(), device.chassisId(), port.intValue()); }
public String getDeviceString() { LLDPOrganizationalTLV tlv = getDeviceTLV(); if (tlv != null) { return new String(tlv.getInfoString(), StandardCharsets.UTF_8); } return null; }
public String getDomainString() { LLDPOrganizationalTLV tlv = getDomainTLV(); if (tlv != null) { return new String(tlv.getInfoString(), StandardCharsets.UTF_8); } return null; }
public MacAddress getChassisIdByMac() { ByteBuffer portBB = ByteBuffer.wrap(this.getChassisId().getValue()); byte type = portBB.get(); if (type == CHASSIS_TLV_SUBTYPE) { byte[] bytes = new byte[portBB.remaining()]; System.arraycopy(portBB.array(), portBB.position(), bytes, 0, MacAddress.MAC_ADDRESS_LENGTH); return new MacAddress(bytes); } else { return MacAddress.NONE; } }
private static boolean verifySig(byte[] sig, String deviceId, int portNum, long timestamp, String secret) { byte[] nsig = createSig(deviceId, portNum, timestamp, secret); if (nsig == null) { return false; } if (!ArrayUtils.isSameLength(nsig, sig)) { return false; } boolean fail = false; for (int i = 0; i < nsig.length; i++) { if (sig[i] != nsig[i]) { fail = true; } } if (fail) { return false; } return true; }
private static void addPortDesc(ONOSLLDP probe, String portDesc) { 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); } }
/** * Given an ethernet packet, returns the device the LLDP came from. * @param eth an ethernet packet * @return a the lldp packet or null */ public static ONOSLLDP parseLLDP(Ethernet eth) { if (eth.getEtherType() == Ethernet.TYPE_LLDP || eth.getEtherType() == Ethernet.TYPE_BSN) { return new ONOSLLDP((LLDP) eth.getPayload()); } log.error("Packet is not the LLDP or BSN."); return null; }