/** * Returns Linked list of optional tlvs. * * @param cb of channel buffer. * @return list of optional tlvs * @throws PcepParseException when unsupported tlv is received */ protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { LinkedList<PcepValueType> llOutOptionalTlv; llOutOptionalTlv = new LinkedList<>(); while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { PcepValueType tlv = null; short hType = cb.readShort(); short hLength = cb.readShort(); int iValue = 0; switch (hType) { case StatefulIPv4LspIdentifiersTlv.TYPE: tlv = StatefulIPv4LspIdentifiersTlv.read(cb); break; case StatefulLspErrorCodeTlv.TYPE: iValue = cb.readInt(); tlv = new StatefulLspErrorCodeTlv(iValue); break; case StatefulRsvpErrorSpecTlv.TYPE: tlv = StatefulRsvpErrorSpecTlv.read(cb); break; case SymbolicPathNameTlv.TYPE: tlv = SymbolicPathNameTlv.read(cb, hLength); break; case StatefulLspDbVerTlv.TYPE: tlv = StatefulLspDbVerTlv.read(cb); break; default: // Skip the unknown TLV. cb.skipBytes(hLength); tlv = null; log.info("Received unsupported TLV type :" + hType + " in LSP object."); } // Check for the padding int pad = hLength % 4; if (0 < pad) { pad = 4 - pad; if (pad <= cb.readableBytes()) { cb.skipBytes(pad); } } if (tlv != null) { llOutOptionalTlv.add(tlv); } } if (0 < cb.readableBytes()) { throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); } return llOutOptionalTlv; }
/** Test case for Symbolic path tlv. */ public class SymbolicPathNameTlvTest { private final byte[] value1 = {0x41}; private final Short length1 = new Short((short) 2); private final SymbolicPathNameTlv tlv1 = SymbolicPathNameTlv.of(value1, length1); private final byte[] value2 = {0x41}; private final Short length2 = new Short((short) 2); private final SymbolicPathNameTlv tlv2 = SymbolicPathNameTlv.of(value1, length2); private final byte[] value3 = {0x41, 0x43}; private final Short length3 = new Short((short) 3); private final SymbolicPathNameTlv tlv3 = SymbolicPathNameTlv.of(value3, length3); @Test public void basics() { new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); } }