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.parser.object.end.points;
10 import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
12 import com.google.common.base.Preconditions;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
16 import org.opendaylight.protocol.pcep.spi.ObjectUtil;
17 import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
18 import org.opendaylight.protocol.pcep.spi.PCEPErrors;
19 import org.opendaylight.protocol.pcep.spi.UnknownObject;
20 import org.opendaylight.protocol.util.Ipv6Util;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv6CaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv6._case.Ipv6;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.ipv6._case.Ipv6Builder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.object.EndpointsObj;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.object.EndpointsObjBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Parser for IPv6 {@link EndpointsObj}
34 public final class PCEPEndPointsIpv6ObjectParser extends CommonObjectParser {
36 private static final int CLASS = 4;
37 private static final int TYPE = 2;
38 private static final Logger LOG = LoggerFactory.getLogger(PCEPEndPointsIpv6ObjectParser.class);
40 public PCEPEndPointsIpv6ObjectParser() {
44 public static void serializeObject(
45 final Boolean processing,
48 final ByteBuf buffer) {
49 final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH + Ipv6Util.IPV6_LENGTH);
50 Preconditions.checkArgument(ipv6.getSourceIpv6Address() != null,
51 "SourceIpv6Address is mandatory.");
52 writeIpv6Address(ipv6.getSourceIpv6Address(), body);
53 Preconditions.checkArgument(ipv6.getDestinationIpv6Address() != null,
54 "DestinationIpv6Address is mandatory.");
55 writeIpv6Address(ipv6.getDestinationIpv6Address(), body);
56 ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
60 public Object parseObject(final ObjectHeader header, final ByteBuf bytes) throws PCEPDeserializerException {
61 Preconditions.checkArgument(bytes != null && bytes.isReadable(),
62 "Array of bytes is mandatory. Can't be null or empty.");
63 final EndpointsObjBuilder builder = new EndpointsObjBuilder();
64 if (!header.isProcessingRule()) {
65 LOG.debug("Processed bit not set on Endpoints OBJECT, ignoring it.");
66 return new UnknownObject(PCEPErrors.P_FLAG_NOT_SET, builder.build());
68 if (bytes.readableBytes() != Ipv6Util.IPV6_LENGTH * 2) {
69 throw new PCEPDeserializerException("Wrong length of array of bytes.");
71 builder.setIgnore(header.isIgnore());
72 builder.setProcessingRule(header.isProcessingRule());
73 final Ipv6Builder b = new Ipv6Builder();
74 b.setSourceIpv6Address(Ipv6Util.noZoneAddressForByteBuf(bytes));
75 b.setDestinationIpv6Address(Ipv6Util.noZoneAddressForByteBuf(bytes));
76 builder.setAddressFamily(new Ipv6CaseBuilder().setIpv6(b.build()).build());
77 return builder.build();