}
}
+ grouping unreach-destination-object {
+ description "UNREACH-DESTINATION Object";
+ reference "https://tools.ietf.org/html/rfc8306#section-3.14";
+
+ container unreach-destination-obj {
+ uses object;
+
+ choice destination {
+ case ipv4-destination-case {
+ uses ipv4-destinations;
+ }
+ case ipv6-destination-case {
+ uses ipv6-destinations;
+ }
+ }
+ }
+ }
+
grouping bandwidth {
// No possibility to carry TLVs
leaf bandwidth {
import org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPP2MPEndPointsIpv4ObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPP2MPEndPointsIpv6ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv4UnreachDestinationParser;
+import org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv6UnreachDestinationParser;
+import org.opendaylight.protocol.pcep.parser.object.unreach.PCEPUnreachDestinationSerializer;
import org.opendaylight.protocol.pcep.parser.subobject.EROAsNumberSubobjectParser;
import org.opendaylight.protocol.pcep.parser.subobject.EROIpv4PrefixSubobjectParser;
import org.opendaylight.protocol.pcep.parser.subobject.EROIpv6PrefixSubobjectParser;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.secondary.explicit.route.object.Sero;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.secondary.reported.route.object.Srro;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.svec.object.Svec;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObj;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.LabelCase;
final PCEPEndPointsIpv6ObjectParser endpoints6Parser = new PCEPEndPointsIpv6ObjectParser();
regs.add(context.registerObjectParser(endpoints6Parser));
+ final PCEPIpv4UnreachDestinationParser unreachIpv4Parser = new PCEPIpv4UnreachDestinationParser();
+ final PCEPIpv6UnreachDestinationParser unreachIpv6Parser = new PCEPIpv6UnreachDestinationParser();
+ regs.add(context.registerObjectParser(unreachIpv4Parser));
+ regs.add(context.registerObjectParser(unreachIpv6Parser));
+
+ final PCEPUnreachDestinationSerializer unreachSerializer= new PCEPUnreachDestinationSerializer();
+ regs.add(context.registerObjectSerializer(UnreachDestinationObj.class, unreachSerializer));
+
final PCEPP2MPEndPointsIpv4ObjectParser endpoints4Pp2mparser = new PCEPP2MPEndPointsIpv4ObjectParser();
regs.add(context.registerObjectParser(endpoints4Pp2mparser));
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.object.unreach;
+
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv4Address;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Ipv4Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObj;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCaseBuilder;
+
+public final class PCEPIpv4UnreachDestinationParser extends CommonObjectParser {
+ private static final int CLASS = 28;
+ private static final int TYPE = 1;
+
+ public PCEPIpv4UnreachDestinationParser() {
+ super(CLASS, TYPE);
+ }
+
+ public static void serializeObject(
+ final Boolean processing,
+ final Boolean ignore,
+ final Ipv4DestinationCase ipv4Case,
+ final ByteBuf buffer) {
+ final List<Ipv4AddressNoZone> dest = ipv4Case.getDestinationIpv4Address();
+ Preconditions.checkArgument(dest != null, "DestinationIpv4Address is mandatory.");
+ final ByteBuf body = Unpooled.buffer(Ipv4Util.IP4_LENGTH * dest.size());
+ dest.forEach(ipv4 -> writeIpv4Address(ipv4, body));
+ ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
+ }
+
+ @Override
+ public UnreachDestinationObj parseObject(final ObjectHeader header, final ByteBuf bytes)
+ throws PCEPDeserializerException {
+ Preconditions.checkArgument(bytes != null && bytes.isReadable(),
+ "Array of bytes is mandatory. Can't be null or empty.");
+ final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
+ if (bytes.readableBytes() % Ipv4Util.IP4_LENGTH != 0) {
+ throw new PCEPDeserializerException("Wrong length of array of bytes.");
+ }
+ builder.setIgnore(header.isIgnore());
+ builder.setProcessingRule(header.isProcessingRule());
+ List<Ipv4AddressNoZone> dest = new ArrayList<>();
+ while (bytes.isReadable()) {
+ dest.add(Ipv4Util.noZoneAddressForByteBuf(bytes));
+ }
+ builder.setDestination(new Ipv4DestinationCaseBuilder().setDestinationIpv4Address(dest).build());
+ return builder.build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.object.unreach;
+
+import static org.opendaylight.protocol.util.ByteBufWriteUtil.writeIpv6Address;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.util.ArrayList;
+import java.util.List;
+import org.opendaylight.protocol.pcep.spi.CommonObjectParser;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+import org.opendaylight.protocol.util.Ipv6Util;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObj;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCaseBuilder;
+
+public final class PCEPIpv6UnreachDestinationParser extends CommonObjectParser {
+ private static final int CLASS = 28;
+ private static final int TYPE = 2;
+
+ public PCEPIpv6UnreachDestinationParser() {
+ super(CLASS, TYPE);
+ }
+
+ public static void serializeObject(
+ final Boolean processing,
+ final Boolean ignore,
+ final Ipv6DestinationCase ipv6Case,
+ final ByteBuf buffer) {
+ final List<Ipv6AddressNoZone> dest = ipv6Case.getDestinationIpv6Address();
+ Preconditions.checkArgument(dest != null, "Destinationipv6Address is mandatory.");
+ final ByteBuf body = Unpooled.buffer(Ipv6Util.IPV6_LENGTH * dest.size());
+ dest.forEach(ipv6 -> writeIpv6Address(ipv6, body));
+ ObjectUtil.formatSubobject(TYPE, CLASS, processing, ignore, body, buffer);
+ }
+
+ @Override
+ public UnreachDestinationObj parseObject(final ObjectHeader header, final ByteBuf bytes)
+ throws PCEPDeserializerException {
+ Preconditions.checkArgument(bytes != null && bytes.isReadable(),
+ "Array of bytes is mandatory. Can't be null or empty.");
+ final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
+ if (bytes.readableBytes() % Ipv6Util.IPV6_LENGTH != 0) {
+ throw new PCEPDeserializerException("Wrong length of array of bytes.");
+ }
+ builder.setIgnore(header.isIgnore());
+ builder.setProcessingRule(header.isProcessingRule());
+ List<Ipv6AddressNoZone> dest = new ArrayList<>();
+ while (bytes.isReadable()) {
+ dest.add(Ipv6Util.noZoneAddressForByteBuf(bytes));
+ }
+ builder.setDestination(new Ipv6DestinationCaseBuilder().setDestinationIpv6Address(dest).build());
+ return builder.build();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 AT&T Intellectual Property. 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.object.unreach;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObj;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase;
+
+public final class PCEPUnreachDestinationSerializer implements ObjectSerializer {
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof UnreachDestinationObj,
+ "Wrong instance of PCEPObject. Passed %s. Needed UnreachDestinationObj.", object.getClass());
+ final UnreachDestinationObj uPObj = (UnreachDestinationObj) object;
+ final Destination destination = uPObj.getDestination();
+ final Boolean processing = object.isProcessingRule();
+ final Boolean ignore = object.isIgnore();
+ if (destination instanceof Ipv6DestinationCase) {
+ final Ipv6DestinationCase ipv6 = ((Ipv6DestinationCase) destination);
+ PCEPIpv6UnreachDestinationParser.serializeObject(processing, ignore, ipv6, buffer);
+ } else if (destination instanceof Ipv4DestinationCase) {
+ final Ipv4DestinationCase ipv4 = ((Ipv4DestinationCase) destination);
+ PCEPIpv4UnreachDestinationParser.serializeObject(processing, ignore, ipv4, buffer);
+ }
+ }
+}
\ No newline at end of file
import io.netty.buffer.Unpooled;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsObjectSerializer;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPP2MPEndPointsIpv4ObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPP2MPEndPointsIpv6ObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv4UnreachDestinationParser;
+import org.opendaylight.protocol.pcep.parser.object.unreach.PCEPIpv6UnreachDestinationParser;
+import org.opendaylight.protocol.pcep.parser.object.unreach.PCEPUnreachDestinationSerializer;
import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.protocol.pcep.spi.PCEPErrors;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.req.missing.tlv.ReqMissingBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.RpBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.svec.object.SvecBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.UnreachDestinationObjBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv4DestinationCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.destination.Ipv6DestinationCaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObjectBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
}
}
+
+ @Test
+ public void testPCEPIpv4UnreachDestinationObject() throws Exception {
+ final byte[] expected = {
+ 0x1c, 0x10, 0x0, 0x8,
+ (byte) 0x7F, (byte) 0x0, (byte) 0x0, (byte) 0x1
+ };
+
+ final PCEPIpv4UnreachDestinationParser parser = new PCEPIpv4UnreachDestinationParser();
+ final PCEPUnreachDestinationSerializer serializer = new PCEPUnreachDestinationSerializer();
+ final ByteBuf result = Unpooled.wrappedBuffer(expected);
+
+ final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final Ipv4DestinationCase dest = new Ipv4DestinationCaseBuilder()
+ .setDestinationIpv4Address(Collections.singletonList(new Ipv4AddressNoZone("127.0.0.1")))
+ .build();
+ builder.setDestination(dest);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
+ result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ serializer.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testPCEPIpv6UnreachDestinationObject() throws Exception {
+ final byte[] expected = {
+ 0x1c, 0x20, 0x0, 0x14,
+ (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
+ (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
+ (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x0,
+ (byte) 0x0, (byte) 0x0, (byte) 0x0, (byte) 0x1
+ };
+
+ final PCEPIpv6UnreachDestinationParser parser = new PCEPIpv6UnreachDestinationParser();
+ final PCEPUnreachDestinationSerializer serializer = new PCEPUnreachDestinationSerializer();
+ final ByteBuf result = Unpooled.wrappedBuffer(expected);
+
+ final UnreachDestinationObjBuilder builder = new UnreachDestinationObjBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final Ipv6DestinationCase dest = new Ipv6DestinationCaseBuilder()
+ .setDestinationIpv6Address(Collections.singletonList(new Ipv6AddressNoZone("::1")))
+ .build();
+ builder.setDestination(dest);
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
+ result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ serializer.serializeObject(builder.build(), buf);
+ assertArrayEquals(result.array(), ByteArray.getAllBytes(buf));
+
+ try {
+ parser.parseObject(new ObjectHeaderImpl(true, true), null);
+ fail();
+ } catch (final IllegalArgumentException e) {
+ assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
+ }
+ }
}