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 org.opendaylight.protocol.pcep.PCEPDeserializerException;
11 import org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject;
12 import org.opendaylight.protocol.pcep.subobject.ReportedRouteSubobject;
13 import org.opendaylight.protocol.util.ByteArray;
16 * Parser for {@link org.opendaylight.protocol.pcep.subobject.RROUnnumberedInterfaceSubobject
17 * RROUnnumberedInterfaceSubobject}
19 public class RROUnnumberedInterfaceSubobjectParser {
20 public static final int ROUTER_ID_NUMBER_LENGTH = 4;
21 public static final int INTERFACE_ID_NUMBER_LENGTH = 4;
23 public static final int ROUTER_ID_NUMBER_OFFSET = 2; // added reserved field of size 2
24 public static final int INTERFACE_ID_NUMBER_OFFSET = ROUTER_ID_NUMBER_OFFSET + ROUTER_ID_NUMBER_LENGTH;
26 public static final int CONTENT_LENGTH = INTERFACE_ID_NUMBER_OFFSET + INTERFACE_ID_NUMBER_LENGTH;
28 public static RROUnnumberedInterfaceSubobject parse(final byte[] soContentsBytes) throws PCEPDeserializerException {
29 if (soContentsBytes == null || soContentsBytes.length == 0)
30 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
31 if (soContentsBytes.length != CONTENT_LENGTH)
32 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: "
33 + CONTENT_LENGTH + ".");
35 // return new RROUnnumberedInterfaceSubobject(new IPv4Address(
36 // ByteArray.subByte(soContentsBytes, ROUTER_ID_NUMBER_OFFSET, ROUTER_ID_NUMBER_LENGTH)), new
37 // UnnumberedInterfaceIdentifier(
38 // UnsignedInts.toLong(ByteArray.bytesToInt(ByteArray.subByte(soContentsBytes, INTERFACE_ID_NUMBER_OFFSET,
39 // INTERFACE_ID_NUMBER_LENGTH)))));
43 public static byte[] put(final ReportedRouteSubobject objToSerialize) {
44 if (!(objToSerialize instanceof RROUnnumberedInterfaceSubobject))
45 throw new IllegalArgumentException("Unknown ReportedRouteSubobject instance. Passed " + objToSerialize.getClass()
46 + ". Needed RROUnnumberedInterfaceSubobject.");
49 retBytes = new byte[CONTENT_LENGTH];
50 final RROUnnumberedInterfaceSubobject specObj = (RROUnnumberedInterfaceSubobject) objToSerialize;
52 ByteArray.copyWhole(specObj.getRouterID().getAddress(), retBytes, ROUTER_ID_NUMBER_OFFSET);
53 System.arraycopy(ByteArray.longToBytes(specObj.getInterfaceID().getInterfaceId()), Long.SIZE / Byte.SIZE
54 - INTERFACE_ID_NUMBER_LENGTH, retBytes, INTERFACE_ID_NUMBER_OFFSET, INTERFACE_ID_NUMBER_LENGTH);