Search in sources :

Example 6 with IpPrefixCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder in project bgpcep by opendaylight.

the class XROIpv4PrefixSubobjectParser method parseSubobject.

@Override
public SubobjectContainer parseSubobject(final ByteBuf buffer, final boolean mandatory) throws RSVPParsingException {
    Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty.");
    final SubobjectContainerBuilder builder = new SubobjectContainerBuilder();
    builder.setMandatory(mandatory);
    if (buffer.readableBytes() != CONTENT4_LENGTH) {
        throw new RSVPParsingException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + ";");
    }
    final int length = buffer.getUnsignedByte(PREFIX4_F_OFFSET);
    final IpPrefixBuilder prefix = new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv4Util.prefixForBytes(ByteArray.readBytes(buffer, Ipv4Util.IP4_LENGTH), length)));
    builder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(prefix.build()).build());
    buffer.skipBytes(PREFIX_F_LENGTH);
    builder.setAttribute(ExcludeRouteSubobjects.Attribute.forValue(buffer.readUnsignedByte()));
    return builder.build();
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) SubobjectContainerBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder) IpPrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder) RSVPParsingException(org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)

Example 7 with IpPrefixCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder in project bgpcep by opendaylight.

the class RegistryTest method testRegistry.

@Test
public void testRegistry() throws PCEPDeserializerException {
    this.regs.add(this.ctx.registerXROSubobjectParser(2, this.xroParser));
    this.regs.add(this.ctx.registerXROSubobjectSerializer(AsNumberCase.class, this.xroSerializer));
    this.regs.add(this.ctx.registerRROSubobjectParser(3, this.rroParser));
    this.regs.add(this.ctx.registerRROSubobjectSerializer(LabelCase.class, this.rroSerializer));
    this.regs.add(this.ctx.registerEROSubobjectParser(4, this.eroParser));
    this.regs.add(this.ctx.registerEROSubobjectSerializer(IpPrefixCase.class, this.eroSerializer));
    this.regs.add(this.ctx.registerTlvParser(1, this.tlvParser));
    this.regs.add(this.ctx.registerTlvSerializer(OfList.class, this.tlvSerializer));
    this.regs.add(this.ctx.registerObjectParser(5, 1, this.objectParser));
    this.regs.add(this.ctx.registerObjectSerializer(Rp.class, this.objectSerializer));
    this.regs.add(this.ctx.registerMessageParser(6, this.msgParser));
    this.regs.add(this.ctx.registerMessageSerializer(Keepalive.class, this.msgSerializer));
    this.regs.add(this.ctx.registerLabelParser(7, this.labelParser));
    this.regs.add(this.ctx.registerLabelSerializer(Type1LabelCase.class, this.labelSerializer));
    this.regs.add(this.ctx.registerVendorInformationObjectParser(new EnterpriseNumber(10L), this.objectParser));
    this.regs.add(this.ctx.registerVendorInformationObjectSerializer(EnterpriseSpecificInformation.class, this.objectSerializer));
    this.regs.add(this.ctx.registerVendorInformationTlvParser(new EnterpriseNumber(12L), this.tlvParser));
    this.regs.add(this.ctx.registerVendorInformationTlvSerializer(EnterpriseSpecificInformation.class, this.tlvSerializer));
    final ByteBuf buffer = Unpooled.buffer();
    this.ctx.getXROSubobjectHandlerRegistry().parseSubobject(2, buffer, false);
    this.ctx.getXROSubobjectHandlerRegistry().serializeSubobject(new SubobjectBuilder().setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer);
    this.ctx.getEROSubobjectHandlerRegistry().parseSubobject(3, buffer, true);
    this.ctx.getEROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder().setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer);
    this.ctx.getRROSubobjectHandlerRegistry().parseSubobject(4, buffer);
    this.ctx.getRROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder().setSubobjectType(new IpPrefixCaseBuilder().build()).build(), buffer);
    this.ctx.getLabelHandlerRegistry().parseLabel(1, buffer);
    this.ctx.getLabelHandlerRegistry().serializeLabel(true, false, new Type1LabelCaseBuilder().build(), buffer);
    this.ctx.getTlvHandlerRegistry().parseTlv(2, buffer);
    this.ctx.getTlvHandlerRegistry().serializeTlv(new OfListBuilder().build(), buffer);
    this.ctx.getObjectHandlerRegistry().parseObject(4, 1, new ObjectHeaderImpl(true, false), buffer);
    this.ctx.getObjectHandlerRegistry().serializeObject(new OpenBuilder().build(), buffer);
    this.ctx.getMessageHandlerRegistry().parseMessage(6, buffer, Collections.emptyList());
    this.ctx.getMessageHandlerRegistry().serializeMessage(new KeepaliveBuilder().build(), buffer);
    this.ctx.getVendorInformationObjectRegistry().parseVendorInformationObject(new EnterpriseNumber(10L), new ObjectHeaderImpl(true, false), buffer);
    this.ctx.getVendorInformationObjectRegistry().serializeVendorInformationObject(this.esi, buffer);
    this.ctx.getVendorInformationTlvRegistry().parseVendorInformationTlv(new EnterpriseNumber(12L), buffer);
    this.ctx.getVendorInformationTlvRegistry().serializeVendorInformationTlv(this.viTlv, buffer);
    this.activator.start(this.ctx);
    this.activator.close();
}
Also used : MockitoAnnotations(org.mockito.MockitoAnnotations) Collections(java.util.Collections) AsNumberCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder) AsNumberCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase) Type1LabelCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase) ByteBuf(io.netty.buffer.ByteBuf) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder) LabelCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.LabelCase) Type1LabelCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase) IpPrefixCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase) EnterpriseSpecificInformation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.EnterpriseSpecificInformation) OfListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfListBuilder) EnterpriseNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber) KeepaliveBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.rp.object.Rp) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder) OfList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.Keepalive) Type1LabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCaseBuilder) IpPrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder) Test(org.junit.Test)

Example 8 with IpPrefixCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder in project bgpcep by opendaylight.

the class AbstractPCEPSessionTest method createEroWithIpPrefixes.

Ero createEroWithIpPrefixes(final List<String> ipPrefixes) {
    final List<Subobject> subobjs = new ArrayList<>(ipPrefixes.size());
    final SubobjectBuilder subobjBuilder = new SubobjectBuilder();
    for (final String ipPrefix : ipPrefixes) {
        subobjBuilder.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix(ipPrefix))).build()).build());
        subobjs.add(subobjBuilder.build());
    }
    return new EroBuilder().setSubobject(subobjs).build();
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) Subobject(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.Subobject) IpPrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder) ArrayList(java.util.ArrayList) EroBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.EroBuilder) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder)

Example 9 with IpPrefixCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder in project bgpcep by opendaylight.

the class PCEPRROSubobjectParserTest method testRROIp4PrefixSubobject.

@Test
public void testRROIp4PrefixSubobject() throws PCEPDeserializerException {
    final RROIpv4PrefixSubobjectParser parser = new RROIpv4PrefixSubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    subs.setProtectionAvailable(true);
    subs.setProtectionInUse(false);
    subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(new Ipv4Prefix("255.255.255.255/22"))).build()).build());
    assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip4PrefixBytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    assertArrayEquals(ip4PrefixBytes, ByteArray.getAllBytes(buff));
    try {
        parser.parseSubobject(null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpPrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix) RROIpv4PrefixSubobjectParser(org.opendaylight.protocol.pcep.parser.subobject.RROIpv4PrefixSubobjectParser) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder) Test(org.junit.Test)

Example 10 with IpPrefixCaseBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder in project bgpcep by opendaylight.

the class PCEPRROSubobjectParserTest method testRROIp6PrefixSubobject.

@Test
public void testRROIp6PrefixSubobject() throws PCEPDeserializerException {
    final RROIpv6PrefixSubobjectParser parser = new RROIpv6PrefixSubobjectParser();
    final SubobjectBuilder subs = new SubobjectBuilder();
    subs.setProtectionAvailable(false);
    subs.setProtectionInUse(true);
    subs.setSubobjectType(new IpPrefixCaseBuilder().setIpPrefix(new IpPrefixBuilder().setIpPrefix(new IpPrefix(Ipv6Util.prefixForBytes(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }, 22))).build()).build());
    assertEquals(subs.build(), parser.parseSubobject(Unpooled.wrappedBuffer(ByteArray.cutBytes(ip6PrefixBytes, 2))));
    final ByteBuf buff = Unpooled.buffer();
    parser.serializeSubobject(subs.build(), buff);
    assertArrayEquals(ip6PrefixBytes, ByteArray.getAllBytes(buff));
    try {
        parser.parseSubobject(null);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
    try {
        parser.parseSubobject(Unpooled.EMPTY_BUFFER);
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("Array of bytes is mandatory. Can't be null or empty.", e.getMessage());
    }
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) RROIpv6PrefixSubobjectParser(org.opendaylight.protocol.pcep.parser.subobject.RROIpv6PrefixSubobjectParser) IpPrefixCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder) ByteBuf(io.netty.buffer.ByteBuf) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder) SubobjectBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.reported.route.object.rro.SubobjectBuilder) Test(org.junit.Test)

Aggregations

IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)31 IpPrefixCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCaseBuilder)23 IpPrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder)23 ByteBuf (io.netty.buffer.ByteBuf)16 Test (org.junit.Test)16 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)13 IpPrefixCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.IpPrefixCaseBuilder)9 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.SubobjectBuilder)8 IpPrefixBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.subobject.type.ip.prefix._case.IpPrefixBuilder)8 SubobjectBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.ero.SubobjectBuilder)7 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)6 RSVPParsingException (org.opendaylight.protocol.rsvp.parser.spi.RSVPParsingException)6 BitArray (org.opendaylight.protocol.util.BitArray)4 AsNumberCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder)4 SubobjectContainerBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.exclude.route.object.exclude.route.object.SubobjectContainerBuilder)4 SubobjectContainerBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.explicit.route.subobjects.list.SubobjectContainerBuilder)4 SubobjectContainerBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.list.SubobjectContainerBuilder)4 ObjectHeaderImpl (org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl)3 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)3 Subobject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.xro.Subobject)3