use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open in project bgpcep by opendaylight.
the class PCCMockCommon method checkSynchronizedSession.
static void checkSynchronizedSession(final int numberOfLsp, final TestingSessionListener pceSessionListener, final BigInteger expectedeInitialDb) throws Exception {
assertTrue(pceSessionListener.isUp());
// Send Open with LspDBV = 1
final int numberOfSyncMessage = 1;
int numberOfLspExpected = numberOfLsp;
if (!expectedeInitialDb.equals(BigInteger.ZERO)) {
checkEquals(() -> checkSequequenceDBVersionSync(pceSessionListener, expectedeInitialDb));
numberOfLspExpected += numberOfSyncMessage;
}
checkReceivedMessages(pceSessionListener, numberOfLspExpected);
final PCEPSession session = pceSessionListener.getSession();
checkSession(session, DEAD_TIMER, KEEP_ALIVE);
assertTrue(session.getRemoteTlvs().getAugmentation(Tlvs1.class).getStateful().getAugmentation(Stateful1.class).isInitiation());
assertNull(session.getLocalTlvs().getAugmentation(Tlvs3.class).getLspDbVersion().getLspDbVersionValue());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open in project openflowplugin by opendaylight.
the class Activator method onDataTreeChanged.
@Override
public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<FlowCapableNode>> modifications) {
for (DataTreeModification modification : modifications) {
if (modification.getRootNode().getModificationType() == ModificationType.WRITE) {
LOG.info("Node connected: {}", modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class));
final NodeRef nodeRef = new NodeRef(modification.getRootPath().getRootIdentifier().firstIdentifierOf(Node.class));
final ControlBundleInput openBundleInput = new ControlBundleInputBuilder().setNode(nodeRef).setBundleId(BUNDLE_ID).setFlags(BUNDLE_FLAGS).setType(BundleControlType.ONFBCTOPENREQUEST).build();
final ControlBundleInput commitBundleInput = new ControlBundleInputBuilder().setNode(nodeRef).setBundleId(BUNDLE_ID).setFlags(BUNDLE_FLAGS).setType(BundleControlType.ONFBCTCOMMITREQUEST).build();
final List<Message> innerMessages = createMessages(nodeRef);
final Messages messages = new MessagesBuilder().setMessage(innerMessages).build();
final AddBundleMessagesInput addBundleMessagesInput = new AddBundleMessagesInputBuilder().setNode(nodeRef).setBundleId(BUNDLE_ID).setFlags(BUNDLE_FLAGS).setMessages(messages).build();
makeCompletableFuture(bundleService.controlBundle(openBundleInput)).thenComposeAsync(voidRpcResult -> {
LOG.debug("Open successful: {}, msg: {}", voidRpcResult.isSuccessful(), voidRpcResult.getErrors());
final CompletableFuture<RpcResult<Void>> addFuture = makeCompletableFuture(bundleService.addBundleMessages(addBundleMessagesInput));
return addFuture;
}).thenComposeAsync(voidRpcResult -> {
LOG.debug("AddBundleMessages successful: {}, msg: {}", voidRpcResult.isSuccessful(), voidRpcResult.getErrors());
final CompletableFuture<RpcResult<Void>> controlCommitFuture = makeCompletableFuture(bundleService.controlBundle(commitBundleInput));
return controlCommitFuture;
}).thenAccept(voidRpcResult -> {
LOG.debug("Commit successful: {}, msg: {}", voidRpcResult.isSuccessful(), voidRpcResult.getErrors());
});
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open in project bgpcep by opendaylight.
the class PCEPOpenMessageParser method serializeMessage.
@Override
public void serializeMessage(final Message message, final ByteBuf out) {
checkArgument(message instanceof OpenMessage, "Wrong instance of Message. Passed instance of %s. Need OpenMessage.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.message.OpenMessage open = ((OpenMessage) message).getOpenMessage();
checkArgument(open.getOpen() != null, "Open Object must be present in Open Message.");
final ByteBuf buffer = Unpooled.buffer();
serializeObject(open.getOpen(), buffer);
MessageUtil.formatMessage(TYPE, buffer, out);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open in project bgpcep by opendaylight.
the class StrictBGPPeerRegistry method getPeer.
@Override
public synchronized BGPSessionListener getPeer(final IpAddressNoZone ip, final Ipv4AddressNoZone sourceId, final Ipv4AddressNoZone remoteId, final Open openObj) throws BGPDocumentedException {
requireNonNull(ip);
requireNonNull(sourceId);
requireNonNull(remoteId);
final AsNumber remoteAsNumber = AsNumberUtil.advertizedAsNumber(openObj);
requireNonNull(remoteAsNumber);
final BGPSessionPreferences prefs = getPeerPreferences(ip);
checkPeerConfigured(ip);
final BGPSessionId currentConnection = new BGPSessionId(sourceId, remoteId, remoteAsNumber);
final BGPSessionListener p = this.peers.get(ip);
final BGPSessionId previousConnection = this.sessionIds.get(ip);
if (previousConnection != null) {
LOG.warn("Duplicate BGP session established with {}", ip);
// Session reestablished with different ids
if (!previousConnection.equals(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Same session already present {}", ip, currentConnection, previousConnection);
throw new BGPDocumentedException(String.format("BGP session with %s %s has to be dropped. Same session already present %s", ip, currentConnection, previousConnection), BGPError.CEASE);
// Session reestablished with lower source bgp id, dropping current
} else if (previousConnection.isHigherDirection(currentConnection) || previousConnection.hasHigherAsNumber(currentConnection)) {
LOG.warn("BGP session with {} {} has to be dropped. Opposite session already present", ip, currentConnection);
throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Opposite session already present", ip, currentConnection), BGPError.CEASE);
// Session reestablished with higher source bgp id, dropping previous
} else if (currentConnection.isHigherDirection(previousConnection) || currentConnection.hasHigherAsNumber(previousConnection)) {
LOG.warn("BGP session with {} {} released. Replaced by opposite session", ip, previousConnection);
this.peers.get(ip).releaseConnection();
return this.peers.get(ip);
// Session reestablished with same source bgp id, dropping current as duplicate
} else {
LOG.warn("BGP session with {} initiated from {} to {} has to be dropped. Same session already present", ip, sourceId, remoteId);
throw new BGPDocumentedException(String.format("BGP session with %s initiated %s has to be dropped. " + "Same session already present", ip, currentConnection), BGPError.CEASE);
}
}
validateAs(remoteAsNumber, openObj, prefs);
// Map session id to peer IP address
this.sessionIds.put(ip, currentConnection);
for (final PeerRegistrySessionListener peerRegistrySessionListener : this.sessionListeners) {
peerRegistrySessionListener.onSessionCreated(ip);
}
return p;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open 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