Search in sources :

Example 21 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder 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(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(Uint32.TEN), this.objectParser));
    this.regs.add(this.ctx.registerVendorInformationObjectSerializer(EnterpriseSpecificInformation.class, this.objectSerializer));
    this.regs.add(this.ctx.registerVendorInformationTlvParser(new EnterpriseNumber(Uint32.valueOf(12)), 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.rev181109.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.rev181109.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(Uint32.TEN), new ObjectHeaderImpl(true, false), buffer);
    this.ctx.getVendorInformationObjectRegistry().serializeVendorInformationObject(this.esi, buffer);
    this.ctx.getVendorInformationTlvRegistry().parseVendorInformationTlv(new EnterpriseNumber(Uint32.valueOf(12)), buffer);
    this.ctx.getVendorInformationTlvRegistry().serializeVendorInformationTlv(this.viTlv, buffer);
}
Also used : 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.rev181109.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.rev181109.vendor.information.EnterpriseSpecificInformation) OfListBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.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.rev181109.KeepaliveBuilder) Rp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder) OfList(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.list.tlv.OfList) Keepalive(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive) Type1LabelCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCaseBuilder) Mockito.doReturn(org.mockito.Mockito.doReturn) 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 22 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder in project bgpcep by opendaylight.

the class PCEPStatefulPeerProposal method setPeerSpecificProposal.

@Override
public void setPeerSpecificProposal(final InetSocketAddress address, final TlvsBuilder openBuilder) {
    // Check if we are dealing with synchronization optimization
    final var statefulTlv = openBuilder.augmentation(Tlvs1.class);
    if (statefulTlv == null) {
        return;
    }
    final var stateful = statefulTlv.getStateful();
    if (stateful == null || stateful.augmentation(Stateful1.class) == null) {
        return;
    }
    final var nodeId = ServerSessionManager.createNodeId(address.getAddress());
    final var dbVersion = lspDbVersions.map.get(nodeId);
    final var speakerId = speakerIds.map.get(nodeId);
    if (speakerId == null && dbVersion == null) {
        // Nothing to add
        return;
    }
    final Tlvs3Builder syncBuilder = new Tlvs3Builder();
    if (dbVersion != null) {
        syncBuilder.setLspDbVersion(dbVersion);
    }
    if (speakerId != null) {
        syncBuilder.setSpeakerEntityId(new SpeakerEntityIdBuilder().setSpeakerEntityIdValue(speakerId).build());
    }
    openBuilder.addAugmentation(syncBuilder.build()).build();
}
Also used : SpeakerEntityIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.speaker.entity.id.tlv.SpeakerEntityIdBuilder) Tlvs3Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.Tlvs3Builder)

Example 23 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder in project bgpcep by opendaylight.

the class BmpMockUtil method createOpen.

private static OpenMessage createOpen(final Ipv4Address address) {
    final OpenBuilder msgBuilder = new OpenBuilder();
    msgBuilder.setBgpIdentifier(address);
    msgBuilder.setHoldTimer(HOLD_TIMER);
    msgBuilder.setMyAsNumber(ASN.getValue().intValue());
    msgBuilder.setVersion(PROTOCOL_VERSION);
    return msgBuilder.build();
}
Also used : ReceivedOpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.ReceivedOpenBuilder) OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) SentOpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.peer.up.SentOpenBuilder)

Example 24 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder in project bgpcep by opendaylight.

the class BGPOpenMessageParser method parseMessageBody.

/**
 * Parses given byte array to BGP Open message
 *
 * @param body byte array representing BGP Open message, without header
 * @param messageLength the length of the message
 * @return {@link Open} BGP Open Message
 * @throws BGPDocumentedException if the parsing was unsuccessful
 */
@Override
public Open parseMessageBody(final ByteBuf body, final int messageLength) throws BGPDocumentedException {
    Preconditions.checkArgument(body != null, "Buffer cannot be null.");
    if (body.readableBytes() < MIN_MSG_LENGTH) {
        throw BGPDocumentedException.badMessageLength("Open message too small.", messageLength);
    }
    final int version = body.readUnsignedByte();
    if (version != BGP_VERSION) {
        throw new BGPDocumentedException("BGP Protocol version " + version + " not supported.", BGPError.VERSION_NOT_SUPPORTED);
    }
    final AsNumber as = new AsNumber((long) body.readUnsignedShort());
    final int holdTime = body.readUnsignedShort();
    if (holdTime == 1 || holdTime == 2) {
        throw new BGPDocumentedException("Hold time value not acceptable.", BGPError.HOLD_TIME_NOT_ACC);
    }
    Ipv4Address bgpId = null;
    try {
        bgpId = Ipv4Util.addressForByteBuf(body);
    } catch (final IllegalArgumentException e) {
        throw new BGPDocumentedException("BGP Identifier is not a valid IPv4 Address", BGPError.BAD_BGP_ID, e);
    }
    final int optLength = body.readUnsignedByte();
    final List<BgpParameters> optParams = new ArrayList<>();
    if (optLength > 0) {
        fillParams(body.slice(), optParams);
    }
    LOG.debug("BGP Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as, holdTime, bgpId, optParams);
    return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer(holdTime).setBgpIdentifier(bgpId).setBgpParameters(optParams).build();
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.OpenBuilder) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) ArrayList(java.util.ArrayList) BgpParameters(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.BgpParameters) AsNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 25 with OpenBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder in project bgpcep by opendaylight.

the class AbstractBGPSessionNegotiator method startNegotiation.

@SuppressWarnings("checkstyle:illegalCatch")
private synchronized void startNegotiation() {
    LOG.debug("Starting negotiating with {}, current state: {}", channel.remoteAddress(), state);
    if (!(this.state == State.IDLE || this.state == State.OPEN_CONFIRM)) {
        return;
    }
    // Open can be sent first either from ODL (IDLE) or from peer (OPEN_CONFIRM)
    final IpAddressNoZone remoteIp = getRemoteIp();
    try {
        // Check if peer is configured in registry before retrieving preferences
        if (!this.registry.isPeerConfigured(remoteIp)) {
            final BGPDocumentedException cause = new BGPDocumentedException(String.format("BGP peer with ip: %s not configured, check configured peers in : %s", remoteIp, this.registry), BGPError.CONNECTION_REJECTED);
            negotiationFailed(cause);
            return;
        }
        final BGPSessionPreferences preferences = this.registry.getPeerPreferences(remoteIp);
        final Uint16 as = openASNumber(preferences.getMyAs().getValue().longValue());
        sendMessage(new OpenBuilder().setMyAsNumber(as).setHoldTimer(Uint16.valueOf(preferences.getHoldTime())).setBgpIdentifier(preferences.getBgpId()).setBgpParameters(preferences.getParams()).build());
        if (this.state != State.FINISHED) {
            this.state = State.OPEN_SENT;
            this.pending = this.channel.eventLoop().schedule(() -> {
                synchronized (AbstractBGPSessionNegotiator.this) {
                    AbstractBGPSessionNegotiator.this.pending = null;
                    if (AbstractBGPSessionNegotiator.this.state != State.FINISHED) {
                        AbstractBGPSessionNegotiator.this.sendMessage(buildErrorNotify(BGPError.HOLD_TIMER_EXPIRED));
                        negotiationFailed(new BGPDocumentedException("HoldTimer expired", BGPError.FSM_ERROR));
                        AbstractBGPSessionNegotiator.this.state = State.FINISHED;
                    }
                }
            }, INITIAL_HOLDTIMER, TimeUnit.MINUTES);
        }
    } catch (final Exception e) {
        LOG.warn("Unexpected negotiation failure", e);
        negotiationFailedCloseChannel(e);
    }
}
Also used : OpenBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder) BGPSessionPreferences(org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException) Uint16(org.opendaylight.yangtools.yang.common.Uint16) IpAddressNoZone(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone) BGPDocumentedException(org.opendaylight.protocol.bgp.parser.BGPDocumentedException)

Aggregations

OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.OpenBuilder)21 Test (org.junit.Test)17 Ipv4AddressNoZone (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone)12 Open (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.Open)12 ArrayList (java.util.ArrayList)11 ProtocolVersion (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.ProtocolVersion)11 BgpParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParametersBuilder)11 OptionalCapabilitiesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilitiesBuilder)11 CParametersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.CParametersBuilder)11 ByteBuf (io.netty.buffer.ByteBuf)10 CParameters1Builder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.CParameters1Builder)10 Notification (org.opendaylight.yangtools.yang.binding.Notification)10 OptionalCapabilities (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.OptionalCapabilities)9 MultiprotocolCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.mp.capabilities.MultiprotocolCapabilityBuilder)9 BgpParameters (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.BgpParameters)8 AsNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber)7 As4BytesCapabilityBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.open.message.bgp.parameters.optional.capabilities.c.parameters.As4BytesCapabilityBuilder)7 Before (org.junit.Before)6 OpenBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.OpenBuilder)6 OpenMessageBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessageBuilder)6