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.object;
10 import org.opendaylight.protocol.concepts.IPv6;
11 import org.opendaylight.protocol.concepts.IPv6Address;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.PCEPDocumentedException;
14 import org.opendaylight.protocol.pcep.PCEPObject;
15 import org.opendaylight.protocol.pcep.impl.PCEPObjectParser;
16 import org.opendaylight.protocol.pcep.impl.Util;
17 import org.opendaylight.protocol.pcep.object.PCEPUnreachedDestinationObject;
19 public class PCEPUnreachedIPv6DestinationObjectParser implements PCEPObjectParser {
22 * fields lengths and offsets for IPv6 in bytes
24 public static final int DEST6_F_LENGTH = 16;
26 public static final int DEST6_F_OFFSET = 0;
29 public PCEPObject parse(byte[] bytes, boolean processed, boolean ignored) throws PCEPDeserializerException, PCEPDocumentedException {
31 throw new IllegalArgumentException("Array of bytes is mandatory");
33 return new PCEPUnreachedDestinationObject<IPv6Address>(Util.parseAddresses(bytes, DEST6_F_OFFSET, IPv6.FAMILY, DEST6_F_LENGTH), processed, ignored);
37 public byte[] put(PCEPObject obj) {
38 if (!(obj instanceof PCEPUnreachedDestinationObject))
39 throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + obj.getClass() + ". Needed PCEPUnreachedDestinationObject.");
41 final PCEPUnreachedDestinationObject<?> uDObj = (PCEPUnreachedDestinationObject<?>) obj;
43 if (uDObj.getUnreachedDestinations().isEmpty())
46 if (!(uDObj.getUnreachedDestinations().get(0) instanceof IPv6Address))
47 throw new IllegalArgumentException("Wrong instance of NetworkAddress. Passed " + uDObj.getUnreachedDestinations().get(0).getClass()
48 + ". Needed IPv6Address");
50 final byte[] retBytes = new byte[DEST6_F_LENGTH * uDObj.getUnreachedDestinations().size()];
51 Util.putAddresses(retBytes, DEST6_F_OFFSET, uDObj.getUnreachedDestinations(), DEST6_F_LENGTH);