+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.bgpcep.bgp.topology.provider;
-
-import java.util.EventListener;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-/**
- * @deprecated This interface is slated for removal in a future release.
- */
-@Deprecated
-public interface LocRIBListener extends EventListener {
- /**
- * @param trans Modification transaction. The implementation must explicitly commit it if it wishes to have its
- * modifications propagated. The transaction is not shared with any other entity and will be cleaned up by
- * the caller if it is not committed before this method returns.
- * @param event Data change event
- */
- void onLocRIBChange(ReadWriteTransaction trans, AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event);
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.pcep.parser.tlv;
-
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeUnsignedInt;
-
-import com.google.common.base.Preconditions;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
-import org.opendaylight.protocol.pcep.spi.TlvParser;
-import org.opendaylight.protocol.pcep.spi.TlvSerializer;
-import org.opendaylight.protocol.pcep.spi.TlvUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.VsTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.VsTlvBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.vs.tlv.VendorPayload;
-
-/**
- * Vs-tlv model has been deprecated, vendor-information-tlv should be used instead.
- * Therefore parsers/serializers wont be need it any more and this class is slated
- * for removal in a future release.
- */
-@Deprecated
-public abstract class AbstractVendorSpecificTlvParser implements TlvParser, TlvSerializer {
-
- public static final int TYPE = 27;
-
- @Override
- public void serializeTlv(final Tlv tlv, final ByteBuf buffer) {
- Preconditions.checkArgument(tlv instanceof VsTlv, "Vendor Specific Tlv is mandatory.");
- final VsTlv vsTlv = (VsTlv) tlv;
- final ByteBuf body = Unpooled.buffer();
- if (vsTlv.getEnterpriseNumber().getValue() == getEnterpriseNumber()) {
- Preconditions.checkArgument(vsTlv.getEnterpriseNumber() != null, "EnterpriseNumber is mandatory.");
- writeUnsignedInt(vsTlv.getEnterpriseNumber().getValue(), body);
- serializeVendorPayload(vsTlv.getVendorPayload(), body);
- TlvUtil.formatTlv(TYPE, body, buffer);
- }
- }
-
- @Override
- public VsTlv parseTlv(final ByteBuf buffer) throws PCEPDeserializerException {
- if (buffer == null) {
- return null;
- }
- final VsTlvBuilder vsTlvBuider = new VsTlvBuilder();
- final long en = buffer.readUnsignedInt();
- if (en == getEnterpriseNumber()) {
- vsTlvBuider.setEnterpriseNumber(new EnterpriseNumber(getEnterpriseNumber()));
- VendorPayload vendorPayload = null;
- if (buffer.isReadable()) {
- final ByteBuf payloadBytes = buffer.slice();
- vendorPayload = parseVendorPayload(payloadBytes);
- if (vendorPayload != null) {
- vsTlvBuider.setVendorPayload(vendorPayload);
- }
- }
- }
- return vsTlvBuider.build();
- }
-
- protected abstract void serializeVendorPayload(final VendorPayload payload, final ByteBuf buffer);
-
- protected abstract long getEnterpriseNumber();
-
- protected abstract VendorPayload parseVendorPayload(final ByteBuf payloadBytes) throws PCEPDeserializerException;
-}
import java.util.List;
import org.junit.Test;
import org.opendaylight.protocol.pcep.impl.TestVendorInformationTlvParser.TestEnterpriseSpecificInformation;
-import org.opendaylight.protocol.pcep.parser.tlv.AbstractVendorSpecificTlvParser;
import org.opendaylight.protocol.pcep.parser.tlv.NoPathVectorTlvParser;
import org.opendaylight.protocol.pcep.parser.tlv.OFListTlvParser;
import org.opendaylight.protocol.pcep.parser.tlv.OrderTlvParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.req.missing.tlv.ReqMissingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlvBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.VsTlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.VsTlvBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vs.tlv.vs.tlv.VendorPayload;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
public class PCEPTlvParserTest {
private static final byte[] orderBytes = { 0x00, 0x05, 0x00, 0x08, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x00, 0x00,
0x00, 0x01 };
private static final byte[] ofListBytes = { 0x00, 0x04, 0x00, 0x04, 0x12, 0x34, 0x56, 0x78 };
- private static final byte[] vsTlvBytes = { 0x00, 0x1b, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
- 0x05 };
private static final byte[] VENDOR_INFO_BYTES = {
0x00, 0x07, 0x00, 0x08,
/* Enterprise number */
private static final byte[] PST_TLV_BYTES_UNSUPPORTED = { 0x0, 0x1C, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1 };
- private final AbstractVendorSpecificTlvParser vsParser = new AbstractVendorSpecificTlvParser() {
-
- @Override
- protected void serializeVendorPayload(final VendorPayload payload, final ByteBuf buffer) {
- buffer.writeBytes(new byte[] { 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05 });
- }
-
- @Override
- protected VendorPayload parseVendorPayload(final ByteBuf payloadBytes) throws PCEPDeserializerException {
- return PCEPTlvParserTest.this.vp;
- }
-
- @Override
- protected long getEnterpriseNumber() {
- return 9;
- }
- };
-
- private final VendorPayload vp = new VendorPayload() {
-
- @Override
- public Class<? extends DataContainer> getImplementedInterface() {
- return null;
- }
- };
-
@Test
public void testNoPathVectorTlv() throws PCEPDeserializerException {
final NoPathVectorTlvParser parser = new NoPathVectorTlvParser();
assertNull(parser.parseTlv(null));
}
- @Test
- public void testVendorSpecificTlv() throws PCEPDeserializerException {
- final VsTlv tlv = new VsTlvBuilder().setEnterpriseNumber(new EnterpriseNumber(9L)).setVendorPayload(this.vp).build();
- assertEquals(tlv, this.vsParser.parseTlv(Unpooled.wrappedBuffer(ByteArray.cutBytes(vsTlvBytes, 4))));
- final ByteBuf buff = Unpooled.buffer();
- this.vsParser.serializeTlv(tlv, buff);
- assertArrayEquals(vsTlvBytes, ByteArray.getAllBytes(buff));
- assertNull(this.vsParser.parseTlv(null));
- }
-
@Test
public void testVendorInformationTlv() throws PCEPDeserializerException {
final TestVendorInformationTlvParser parser = new TestVendorInformationTlvParser();
return Arrays.copyOfRange(bytes, count, bytes.length);
}
- /**
- * Parse byte to bits, from the leftmost bit.
- *
- * @param b byte to be parsed
- * @return array of booleans with size of 8
- */
- @Deprecated
- public static boolean[] parseBits(final byte b) {
- final boolean[] bits = new boolean[Byte.SIZE];
- int j = 0;
- for (int i = Byte.SIZE - 1; i >= 0; i--) {
- bits[j] = ((b & (1 << i)) != 0);
- j++;
- }
- return bits;
- }
-
- /**
- * Parses array of bytes to BitSet, from left most bit.
- *
- * @param bytes array of bytes to be parsed
- * @return BitSet with length = bytes.length * Byte.SIZE
- */
- @Deprecated
- public static BitSet bytesToBitSet(final byte[] bytes) {
- final BitSet bitSet = new BitSet(bytes.length * Byte.SIZE);
- for (int bytesIter = 0; bytesIter < bytes.length; bytesIter++) {
- final int offset = bytesIter * Byte.SIZE;
- for (int byteIter = Byte.SIZE - 1; byteIter >= 0; byteIter--) {
- bitSet.set(offset + (Byte.SIZE - byteIter - 1), (bytes[bytesIter] & 1 << (byteIter)) != 0);
- }
- }
- return bitSet;
- }
-
- /**
- * Parses BitSet to bytes, from most left bit.
- *
- * @param bitSet BitSet to be parsed
- * @param returnedLength Length of returned array. Overlapping flags are truncated.
- * @return parsed array of bytes with length of bitSet.length / Byte.SIZE
- */
- @Deprecated
- public static byte[] bitSetToBytes(final BitSet bitSet, final int returnedLength) {
- final byte[] bytes = new byte[returnedLength];
-
- for (int bytesIter = 0; bytesIter < bytes.length; bytesIter++) {
- final int offset = bytesIter * Byte.SIZE;
-
- for (int byteIter = Byte.SIZE - 1; byteIter >= 0; byteIter--) {
- bytes[bytesIter] |= (bitSet.get(offset + (Byte.SIZE - byteIter - 1)) ? 1 << byteIter : 0);
- }
- }
- return bytes;
- }
-
/**
* Parses file to array of bytes
*
output.writeZero(FLOAT32_BYTES_LENGTH);
}
}
-
- /**
- * Writes BitSet's bits if not null, otherwise writes zeros to the
- * <code>output</code> ByteBuf. ByteBuf's writerIndex is increased by
- * specified length.
- *
- * @param bitSet
- * BitSet values to be written to the output, starting from left most bit.
- * @param outputLength
- * Number of bytes to be written, must be greater than 0.
- * @param output
- * ByteBuf, where bitSet or zeros are written.
- */
- public static void writeBitSet(final BitSet bitSet, final int outputLength, final ByteBuf output) {
- Preconditions.checkArgument(outputLength > 0);
- if (bitSet != null) {
- output.writeBytes(ByteArray.bitSetToBytes(bitSet, outputLength));
- } else {
- output.writeZero(outputLength);
- }
- }
-
}
ByteArray.cutBytes(this.before, 0);
}
- @Test
- public void testParseBits() {
- final byte b = (byte) -76; // 1011 0100
- final boolean[] after = ByteArray.parseBits(b);
- assertTrue(after[0]);
- assertFalse(after[1]);
- assertTrue(after[2]);
- assertTrue(after[3]);
- assertFalse(after[4]);
- assertTrue(after[5]);
- assertFalse(after[6]);
- assertFalse(after[7]);
- }
-
private final byte[] inBytes = { (byte) 0x03, (byte) 0xFF, (byte) 0x01, (byte) 0x80 };
final BitSet inBitSet = new BitSet();
this.inBitSet.set(24);
}
- @Test
- public void testBytesToBitSetFunction() {
- final BitSet iputBitSet = ByteArray.bytesToBitSet(this.inBytes);
-
- assertEquals(this.inBitSet, iputBitSet);
- }
-
- @Test
- public void testBitSetToBytesFunction() {
- byte[] resultBytes = ByteArray.bitSetToBytes(this.inBitSet, this.inBytes.length);
- assertArrayEquals(this.inBytes, resultBytes);
-
- resultBytes = ByteArray.bitSetToBytes(this.inBitSet, this.inBytes.length - 1);
- assertArrayEquals(Arrays.copyOf(this.inBytes, this.inBytes.length - 1), resultBytes);
-
- resultBytes = ByteArray.bitSetToBytes(this.inBitSet, this.inBytes.length + 1);
- assertArrayEquals(Arrays.copyOf(this.inBytes, this.inBytes.length + 1), resultBytes);
- }
-
@Test
public void testFileToBytes() throws IOException {
final String FILE_TO_TEST = "src/test/resources/PCEStatefulCapabilityTlv1.bin";
package org.opendaylight.protocol.util;
import static org.junit.Assert.assertArrayEquals;
-import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBitSet;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeBoolean;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeFloat32;
import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeInt;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigInteger;
-import java.util.BitSet;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
assertArrayEquals(FOUR_BYTE_ZEROS, output.array());
}
- @Test
- public void testWriteBitSet() {
- final byte[] result = { 1 };
- final ByteBuf output = Unpooled.buffer(1);
- final BitSet bitSet = new BitSet(8);
- bitSet.set(7);
- writeBitSet(bitSet, 1, output);
- assertArrayEquals(result, output.array());
-
- output.clear();
- writeBitSet(null, 1, output);
- assertArrayEquals(ONE_BYTE_ZERO, output.array());
- }
-
@Test(expected=UnsupportedOperationException.class)
public void testPrivateConstructor() throws Throwable {
final Constructor<ByteBufWriteUtil> c = ByteBufWriteUtil.class.getDeclaredConstructor();