}
}
+ grouping bnc {
+ uses object;
+ // No possibility of TLVs
+ list subobject {
+ leaf loose {
+ type boolean;
+ mandatory true;
+ }
+
+ uses rsvp:ip-prefix-subobject;
+ ordered-by user;
+ }
+ }
+
+ grouping branch-node-object {
+ description "Branch Node Object";
+ reference "https://tools.ietf.org/html/rfc8306#section-3.11.1";
+
+ container branch-node-list {
+ uses bnc;
+ }
+ }
+
+ grouping non-branch-node-object {
+ description "Branch Node Object";
+ reference "https://tools.ietf.org/html/rfc8306#section-3.11.1";
+
+ container non-branch-node-list {
+ uses bnc;
+ }
+ }
+
+ grouping bnc-object {
+ choice branch-node-type {
+ case branch-node-case {
+ uses branch-node-object;
+ }
+ case non-branch-node-case {
+ uses non-branch-node-object;
+ }
+ }
+ }
+
grouping bandwidth {
// No possibility to carry TLVs
leaf bandwidth {
import org.opendaylight.protocol.pcep.parser.object.PCEPBandwidthObjectParser;
import org.opendaylight.protocol.pcep.parser.object.PCEPClassTypeObjectParser;
import org.opendaylight.protocol.pcep.parser.object.PCEPCloseObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.bnc.BranchNodeListObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.bnc.NonBranchNodeListObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsIpv4ObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsIpv6ObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsObjectSerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Pcreq;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Starttls;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.Bandwidth;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.branch.node.object.BranchNodeList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CClose;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.object.EndpointsObj;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lspa.object.Lspa;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.metric.object.Metric;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.notification.object.CNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.list.tlv.OfList;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of;
final PCEPP2MPEndPointsIpv6ObjectParser endpoints6Pp2mparser = new PCEPP2MPEndPointsIpv6ObjectParser();
regs.add(context.registerObjectParser(endpoints6Pp2mparser));
+ final EROSubobjectRegistry subRegistry = context.getEROSubobjectHandlerRegistry();
+
+ final BranchNodeListObjectParser bncPArser = new BranchNodeListObjectParser(subRegistry);
+ regs.add(context.registerObjectParser(bncPArser));
+ regs.add(context.registerObjectSerializer(BranchNodeList.class, bncPArser));
+
+ final NonBranchNodeListObjectParser nonBncPArser = new NonBranchNodeListObjectParser(subRegistry);
+ regs.add(context.registerObjectParser(nonBncPArser));
+
final PCEPBandwidthObjectParser bwParser = new PCEPBandwidthObjectParser();
final PCEPExistingBandwidthObjectParser bwExistingParser = new PCEPExistingBandwidthObjectParser();
regs.add(context.registerObjectParser(bwParser));
--- /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.bnc;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bnc.Subobject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bnc.SubobjectBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
+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.IpPrefixCaseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder;
+
+public final class BNCUtil {
+ private BNCUtil() {
+ throw new UnsupportedOperationException();
+ }
+
+ public static List<Subobject> toBncSubobject(final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml
+ .ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject> subobject) {
+ return subobject.stream()
+ .map(sob -> {
+ final SubobjectType type = sob.getSubobjectType();
+ Preconditions.checkArgument(type instanceof IpPrefixCase,
+ "Wrong instance of PCEPObject. Passed %s. Needed IpPrefixCase.", type.getClass());
+ return new SubobjectBuilder().setIpPrefix(((IpPrefixCase) type).getIpPrefix().getIpPrefix())
+ .setLoose(sob.isLoose()).build();
+ }).collect(Collectors.toList());
+ }
+
+ public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
+ .route.object.ero.Subobject> toIroSubject(final List<Subobject> subobject) {
+ return subobject.stream()
+ .map(sob -> {
+ final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit
+ .route.subobjects.subobject.type.ip.prefix._case.IpPrefix prefix = new IpPrefixBuilder()
+ .setIpPrefix(sob.getIpPrefix()).build();
+ final IpPrefixCase subObjType = new IpPrefixCaseBuilder().setIpPrefix(prefix).build();
+ return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109
+ .explicit.route.object.ero.SubobjectBuilder()
+ .setSubobjectType(subObjType)
+ .setLoose(sob.isLoose())
+ .build();
+ }).collect(Collectors.toList());
+ }
+}
--- /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.bnc;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.pcep.parser.object.AbstractEROWithSubobjectsParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+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.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.branch.node.object.BranchNodeList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.branch.node.object.BranchNodeListBuilder;
+
+public final class BranchNodeListObjectParser extends AbstractEROWithSubobjectsParser {
+
+ private static final int CLASS = 31;
+ private static final int TYPE = 1;
+
+ public BranchNodeListObjectParser(final EROSubobjectRegistry subobjReg) {
+ super(subobjReg, CLASS, TYPE);
+ }
+
+ @Override
+ public BranchNodeList 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 BranchNodeListBuilder builder = new BranchNodeListBuilder();
+ builder.setIgnore(header.isIgnore());
+ builder.setProcessingRule(header.isProcessingRule());
+ builder.setSubobject(BNCUtil.toBncSubobject(parseSubobjects(bytes))).build();
+ return builder.build();
+ }
+
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof BranchNodeList,
+ "Wrong instance of PCEPObject. Passed %s. Needed BranchNodeList.", object.getClass());
+ final BranchNodeList nbnc = ((BranchNodeList) object);
+ final ByteBuf body = Unpooled.buffer();
+ serializeSubobject(BNCUtil.toIroSubject(nbnc.getSubobject()), body);
+ ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+}
--- /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.bnc;
+
+import com.google.common.base.Preconditions;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.opendaylight.protocol.pcep.parser.object.AbstractEROWithSubobjectsParser;
+import org.opendaylight.protocol.pcep.spi.EROSubobjectRegistry;
+import org.opendaylight.protocol.pcep.spi.ObjectUtil;
+import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
+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.ObjectHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeListBuilder;
+
+public final class NonBranchNodeListObjectParser extends AbstractEROWithSubobjectsParser {
+ private static final int CLASS = 31;
+ private static final int TYPE = 2;
+
+ public NonBranchNodeListObjectParser(final EROSubobjectRegistry subobjReg) {
+ super(subobjReg, CLASS, TYPE);
+ }
+
+ @Override
+ public NonBranchNodeList 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 NonBranchNodeListBuilder builder = new NonBranchNodeListBuilder();
+ builder.setIgnore(header.isIgnore());
+ builder.setProcessingRule(header.isProcessingRule());
+ builder.setSubobject(BNCUtil.toBncSubobject(parseSubobjects(bytes)));
+ return builder.build();
+ }
+
+ @Override
+ public void serializeObject(final Object object, final ByteBuf buffer) {
+ Preconditions.checkArgument(object instanceof NonBranchNodeList,
+ "Wrong instance of PCEPObject. Passed %s. Needed NonBranchNodeList.", object.getClass());
+ final NonBranchNodeList nbnc = ((NonBranchNodeList) object);
+ final ByteBuf body = Unpooled.buffer();
+ serializeSubobject(BNCUtil.toIroSubject(nbnc.getSubobject()), body);
+ ObjectUtil.formatSubobject(TYPE, CLASS, object.isProcessingRule(), object.isIgnore(), body, buffer);
+ }
+}
import org.opendaylight.protocol.pcep.parser.object.PCEPReportedRouteObjectParser;
import org.opendaylight.protocol.pcep.parser.object.PCEPRequestParameterObjectParser;
import org.opendaylight.protocol.pcep.parser.object.PCEPSvecObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.bnc.BNCUtil;
+import org.opendaylight.protocol.pcep.parser.object.bnc.BranchNodeListObjectParser;
+import org.opendaylight.protocol.pcep.parser.object.bnc.NonBranchNodeListObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsIpv4ObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsIpv6ObjectParser;
import org.opendaylight.protocol.pcep.parser.object.end.points.PCEPEndPointsObjectSerializer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ProtocolVersion;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.RequestId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.bandwidth.object.BandwidthBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.branch.node.object.BranchNodeListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.classtype.object.ClassTypeBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.close.object.CCloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.endpoints.address.family.Ipv4CaseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.Monitoring.Flags;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.monitoring.object.MonitoringBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.non.branch.node.object.NonBranchNodeListBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.notification.object.CNotificationBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.OfBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
parser.serializeObject(builder.build(), buf);
assertArrayEquals(rpObjectWithPstTlvBytes, ByteArray.getAllBytes(buf));
}
+
+ @Test
+ public void testBranchNodeListObject() throws Exception {
+ final byte[] expected = {
+ 0x1f, 0x10, 0x0, 0xc,
+ (byte) 0x81, 0x8,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x20, 0x0,
+ };
+
+ final BranchNodeListObjectParser parser
+ = new BranchNodeListObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
+ final ByteBuf result = Unpooled.wrappedBuffer(expected);
+
+ final BranchNodeListBuilder builder = new BranchNodeListBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
+ .route.object.ero.Subobject> subs = Lists.newArrayList();
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
+ .route.object.ero.SubobjectBuilder()
+ .setLoose(true)
+ .setSubobjectType(new IpPrefixCaseBuilder()
+ .setIpPrefix(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
+ builder.setSubobject(BNCUtil.toBncSubobject(subs));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
+ result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.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 testNonBranchNodeListObject() throws Exception {
+ final byte[] expected = {
+ 0x1f, 0x20, 0x0, 0xc,
+ (byte) 0x81, 0x8,
+ (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0x20, 0x0,
+ };
+
+ final NonBranchNodeListObjectParser parser
+ = new NonBranchNodeListObjectParser(this.ctx.getEROSubobjectHandlerRegistry());
+ final ByteBuf result = Unpooled.wrappedBuffer(expected);
+
+ final NonBranchNodeListBuilder builder = new NonBranchNodeListBuilder();
+ builder.setProcessingRule(false);
+ builder.setIgnore(false);
+ final List<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
+ .route.object.ero.Subobject> subs = Lists.newArrayList();
+ subs.add(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit
+ .route.object.ero.SubobjectBuilder()
+ .setLoose(true)
+ .setSubobjectType(new IpPrefixCaseBuilder()
+ .setIpPrefix(new IpPrefixBuilder().setIpPrefix(
+ new IpPrefix(new Ipv4Prefix("255.255.255.255/32"))).build()).build()).build());
+ builder.setSubobject(BNCUtil.toBncSubobject(subs));
+
+ assertEquals(builder.build(), parser.parseObject(new ObjectHeaderImpl(false, false),
+ result.slice(4, result.readableBytes() - 4)));
+ final ByteBuf buf = Unpooled.buffer();
+ parser.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());
+ }
+ }
}