use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project jmulticard by ctt-gob-es.
the class ContextSpecific method decodeValue.
@Override
protected void decodeValue() throws Asn1Exception, TlvException {
final Tlv tlv = new Tlv(this.getRawDerValue());
final DecoderObject tmpDo;
try {
tmpDo = this.elementType.getConstructor().newInstance();
} catch (final Exception e) {
throw new Asn1Exception(// $NON-NLS-1$ //$NON-NLS-2$
"No se ha podido instanciar un " + this.elementType.getName() + " en el contexto especifico: " + e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
tmpDo.setDerValue(tlv.getValue());
this.object = tmpDo;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.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.rev171207.Tlv in project bgpcep by opendaylight.
the class SimpleRegistryTest method testSimpleBgpPrefixSidTlvRegistry.
@Test
public void testSimpleBgpPrefixSidTlvRegistry() {
final BgpPrefixSidTlvRegistry sidTlvReg = this.ctx.getBgpPrefixSidTlvRegistry();
final byte[] tlvBytes = { 0x00, 0x03, 0x00, 0x00, 0x00 };
final BgpPrefixSidTlv tlv = mock(BgpPrefixSidTlv.class);
doReturn(BgpPrefixSidTlv.class).when(tlv).getImplementedInterface();
final ByteBuf buffer = Unpooled.buffer(tlvBytes.length);
sidTlvReg.serializeBgpPrefixSidTlv(tlv, buffer);
verify(this.activator.sidTlvSerializer, times(1)).serializeBgpPrefixSidTlv(Mockito.any(BgpPrefixSidTlv.class), Mockito.any(ByteBuf.class));
sidTlvReg.parseBgpPrefixSidTlv(BgpTestActivator.TYPE, Unpooled.wrappedBuffer(tlvBytes));
verify(this.activator.sidTlvParser, times(1)).parseBgpPrefixSidTlv(Mockito.any(ByteBuf.class));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project bgpcep by opendaylight.
the class InitiationHandler method parseMessageBody.
@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
final InitiationMessageBuilder initiationBuilder = new InitiationMessageBuilder();
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
tlvsBuilder.setStringInformation(ImmutableList.of());
parseTlvs(tlvsBuilder, bytes);
if (tlvsBuilder.getDescriptionTlv() == null || tlvsBuilder.getDescriptionTlv().getDescription() == null) {
throw new BmpDeserializationException("Inclusion of sysDescr TLV is mandatory.");
}
if (tlvsBuilder.getNameTlv() == null || tlvsBuilder.getNameTlv().getName() == null) {
throw new BmpDeserializationException("Inclusion of sysName TLV is mandatory.");
}
return initiationBuilder.setTlvs(tlvsBuilder.build()).build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv in project bgpcep by opendaylight.
the class TerminationHandler method parseMessageBody.
@Override
public Notification parseMessageBody(final ByteBuf bytes) throws BmpDeserializationException {
final TerminationMessageBuilder terminationMessage = new TerminationMessageBuilder();
final TlvsBuilder tlvsBuilder = new TlvsBuilder();
tlvsBuilder.setStringInformation(ImmutableList.of());
parseTlvs(tlvsBuilder, bytes);
if (tlvsBuilder.getReasonTlv() == null || tlvsBuilder.getReasonTlv().getReason() == null) {
throw new BmpDeserializationException("Inclusion of Reason TLV is mandatory.");
}
return terminationMessage.setTlvs(tlvsBuilder.build()).build();
}
Aggregations