use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.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);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.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();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.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);
}
}
Aggregations