use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Tlv in project openflowplugin by opendaylight.
the class LLDPDiscoveryUtils method lldpToNodeConnectorRef.
/**
* Returns the encoded in custom TLV for the given lldp.
*
* @param payload lldp payload
* @param useExtraAuthenticatorCheck make it more secure (CVE-2015-1611 CVE-2015-1612)
* @return nodeConnectorId - encoded in custom TLV of given lldp
*/
@SuppressWarnings("checkstyle:IllegalCatch")
public static NodeConnectorRef lldpToNodeConnectorRef(byte[] payload, boolean useExtraAuthenticatorCheck) {
NodeConnectorRef nodeConnectorRef = null;
if (isLLDP(payload)) {
Ethernet ethPkt = new Ethernet();
try {
ethPkt.deserialize(payload, 0, payload.length * NetUtils.NUM_BITS_IN_A_BYTE);
} catch (PacketException e) {
LOG.warn("Failed to decode LLDP packet {}", e);
return nodeConnectorRef;
}
LLDP lldp = (LLDP) ethPkt.getPayload();
try {
NodeId srcNodeId = null;
NodeConnectorId srcNodeConnectorId = null;
final LLDPTLV systemIdTLV = lldp.getSystemNameId();
if (systemIdTLV != null) {
String srcNodeIdString = new String(systemIdTLV.getValue(), Charset.defaultCharset());
srcNodeId = new NodeId(srcNodeIdString);
} else {
throw new Exception("Node id wasn't specified via systemNameId in LLDP packet.");
}
final LLDPTLV nodeConnectorIdLldptlv = lldp.getCustomTLV(LLDPTLV.createPortSubTypeCustomTLVKey());
if (nodeConnectorIdLldptlv != null) {
srcNodeConnectorId = new NodeConnectorId(LLDPTLV.getCustomString(nodeConnectorIdLldptlv.getValue(), nodeConnectorIdLldptlv.getLength()));
} else {
throw new Exception("Node connector wasn't specified via Custom TLV in LLDP packet.");
}
if (useExtraAuthenticatorCheck) {
boolean secure = checkExtraAuthenticator(lldp, srcNodeConnectorId);
if (!secure) {
LOG.warn("SECURITY ALERT: there is probably a LLDP spoofing attack in progress.");
throw new Exception("Attack. LLDP packet with inconsistent extra authenticator field was received.");
}
}
InstanceIdentifier<NodeConnector> srcInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(srcNodeId)).child(NodeConnector.class, new NodeConnectorKey(srcNodeConnectorId)).toInstance();
nodeConnectorRef = new NodeConnectorRef(srcInstanceId);
} catch (Exception e) {
LOG.debug("Caught exception while parsing out lldp optional and custom fields", e);
}
}
return nodeConnectorRef;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Tlv in project bgpcep by opendaylight.
the class PCEPObjectParserTest method testLspaObject.
@Test
public void testLspaObject() throws IOException, PCEPDeserializerException {
final Stateful07LspaObjectParser parser = new Stateful07LspaObjectParser(this.tlvRegistry, this.viTlvRegistry);
final LspaBuilder builder = new LspaBuilder();
final ByteBuf result = Unpooled.wrappedBuffer(ByteArray.fileToBytes("src/test/resources/PCEPLspaObject3RandVals.bin"));
final SymbolicPathName tlv = new SymbolicPathNameBuilder().setPathName(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev171025.SymbolicPathName(new byte[] { (byte) 0x4d, (byte) 0x65, (byte) 0x64, (byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x20, (byte) 0x6f, (byte) 0x66, (byte) 0x20, (byte) 0x73, (byte) 0x79, (byte) 0x6d, (byte) 0x62, (byte) 0x6f, (byte) 0x6c, (byte) 0x69, (byte) 0x63, (byte) 0x20, (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65 })).build();
builder.setIgnore(false);
builder.setProcessingRule(false);
builder.setExcludeAny(new AttributeFilter(0x20A1FEE3L));
builder.setIncludeAny(new AttributeFilter(0x1A025CC7L));
builder.setIncludeAll(new AttributeFilter(0x2BB66532L));
builder.setHoldPriority((short) 0x02);
builder.setSetupPriority((short) 0x03);
builder.setLocalProtectionDesired(true);
builder.setTlvs(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lspa.object.lspa.TlvsBuilder().addAugmentation(Tlvs2.class, new Tlvs2Builder().setSymbolicPathName(tlv).build()).build());
// Tlvs container does not contain toString
final Object o = parser.parseObject(new ObjectHeaderImpl(true, true), result.slice(4, result.readableBytes() - 4));
assertEquals(tlv, ((Lspa) o).getTlvs().getAugmentation(Tlvs2.class).getSymbolicPathName());
// assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(true, true), ByteArray.cutBytes(result,
// 4)));
final ByteBuf buf = Unpooled.buffer();
parser.serializeObject(builder.build(), buf);
assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Tlv in project bgpcep by opendaylight.
the class Stateful07LSPIdentifierIpv4TlvParser method parseTlv.
@Override
public LspIdentifiers parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
if (buffer == null) {
return null;
}
Preconditions.checkArgument(buffer.readableBytes() == V4_LENGTH, "Length %s does not match LSP Identifiers Ipv4 tlv length.", buffer.readableBytes());
final Ipv4Builder builder = new Ipv4Builder();
builder.setIpv4TunnelSenderAddress(Ipv4Util.addressForByteBuf(buffer));
final LspId lspId = new LspId((long) buffer.readUnsignedShort());
final TunnelId tunnelId = new TunnelId(buffer.readUnsignedShort());
builder.setIpv4ExtendedTunnelId(new Ipv4ExtendedTunnelId(Ipv4Util.addressForByteBuf(buffer)));
builder.setIpv4TunnelEndpointAddress(Ipv4Util.addressForByteBuf(buffer));
final AddressFamily afi = new Ipv4CaseBuilder().setIpv4(builder.build()).build();
return new LspIdentifiersBuilder().setAddressFamily(afi).setLspId(lspId).setTunnelId(tunnelId).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Tlv in project bgpcep by opendaylight.
the class Stateful07LspUpdateErrorTlvParser method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof LspErrorCode, "LspErrorCodeTlv is mandatory.");
final ByteBuf body = Unpooled.buffer(CONTENT_LENGTH);
writeUnsignedInt(((LspErrorCode) tlv).getErrorCode(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev200120.Tlv in project bgpcep by opendaylight.
the class Stateful07RSVPErrorSpecTlvParser method serializeTlv.
@Override
public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
Preconditions.checkArgument(tlv instanceof RsvpErrorSpec, "RSVPErrorSpecTlv is mandatory.");
final RsvpErrorSpec rsvp = (RsvpErrorSpec) tlv;
final ByteBuf body = Unpooled.buffer();
if (rsvp.getErrorType().getImplementedInterface().equals(RsvpCase.class)) {
final RsvpCase r = (RsvpCase) rsvp.getErrorType();
serializeRsvp(r.getRsvpError(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
} else {
final UserCase u = (UserCase) rsvp.getErrorType();
serializerUserError(u.getUserError(), body);
TlvUtil.formatTlv(TYPE, body, buffer);
}
}
Aggregations