2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.impl;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.VisibleForTesting;
13 import io.netty.channel.Channel;
14 import io.netty.util.concurrent.Promise;
15 import org.opendaylight.protocol.pcep.PCEPSessionListener;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.app.config.rev160707.pcep.dispatcher.config.Tls;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
20 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
21 private final PCEPSessionListener listener;
22 private final int maxUnknownMessages;
24 public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
25 final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages,
26 final Open localPrefs, final Tls tlsConfiguration) {
27 super(promise, channel);
28 super.setTlsConfiguration(tlsConfiguration);
29 this.maxUnknownMessages = maxUnknownMessages;
30 this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive())
31 .setDeadTimer(localPrefs.getDeadTimer()).setSessionId(
32 sessionId).setTlvs(localPrefs.getTlvs()).build();
33 this.listener = requireNonNull(listener);
36 public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
37 final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages,
38 final Open localPrefs) {
39 this(promise, channel, listener, sessionId, maxUnknownMessages, localPrefs, null);
42 private final Open myLocalPrefs;
45 protected Open getInitialProposal() {
46 return this.myLocalPrefs;
51 public PCEPSessionImpl createSession(final Channel channel, final Open localPrefs, final Open remotePrefs) {
52 return new PCEPSessionImpl(this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
56 protected boolean isProposalAcceptable(final Open open) {
61 protected Open getCounterProposal(final Open open) {
66 protected Open getRevisedProposal(final Open suggestion) {
67 return this.myLocalPrefs;