2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.impl.subobject;
10 import java.util.Arrays;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.spi.EROSubobjectParser;
14 import org.opendaylight.protocol.pcep.spi.EROSubobjectSerializer;
15 import org.opendaylight.protocol.util.ByteArray;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.Subobjects;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.SubobjectsBuilder;
19 public class EROPathKeySubobjectParser implements EROSubobjectParser, EROSubobjectSerializer {
21 public static final int TYPE = 64;
23 public static final int TYPE128 = 65;
25 public static final int PK_F_LENGTH = 2;
26 public static final int PCE_ID_F_LENGTH = 4;
28 public static final int PCE128_ID_F_LENGTH = 16;
30 public static final int PK_F_OFFSET = 0;
31 public static final int PCE_ID_F_OFFSET = PK_F_OFFSET + PK_F_LENGTH;
33 public static final int CONTENT_LENGTH = PCE_ID_F_OFFSET + PCE_ID_F_LENGTH;
36 public Subobjects parseSubobject(final byte[] buffer, final boolean loose) throws PCEPDeserializerException {
37 if (buffer == null || buffer.length == 0)
38 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
39 if (buffer.length != CONTENT_LENGTH)
40 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.length + "; Expected: >"
41 + CONTENT_LENGTH + ".");
43 final int pathKey = ByteArray.bytesToShort(Arrays.copyOfRange(buffer, PK_F_OFFSET, PCE_ID_F_OFFSET)) & 0xFFFF;
45 final byte[] pceId = Arrays.copyOfRange(buffer, PCE_ID_F_OFFSET, CONTENT_LENGTH);
47 final SubobjectsBuilder builder = new SubobjectsBuilder();
48 builder.setLoose(loose);
49 // builder.setSubobjectType(value);
50 return builder.build();
54 public byte[] serializeSubobject(final Subobjects subobject) {
55 final byte[] retBytes = new byte[CONTENT_LENGTH];
57 // System.arraycopy(ByteArray.shortToBytes((short) objToSerialize.getPathKey()), 0, retBytes, PK_F_OFFSET,
60 // if (objToSerialize.getPceId().length != PCE_ID_F_LENGTH)
61 // throw new IllegalArgumentException("Wrong length of pce id. Passed: " + objToSerialize.getPceId().length +
63 // + PCE_ID_F_LENGTH);
64 // System.arraycopy(objToSerialize.getPceId(), 0, retBytes, PCE_ID_F_OFFSET, PCE_ID_F_LENGTH);
70 public int getType() {
74 public int getType128() {