Replace Preconditions.CheckNotNull per RequireNonNull
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / DefaultPCEPSessionNegotiator.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
10 import static java.util.Objects.requireNonNull;
11
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.rev131005.open.object.Open;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
19
20 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
21     private final PCEPSessionListener listener;
22     private final int maxUnknownMessages;
23
24     public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
25             final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final Open localPrefs, final Tls tlsConfiguration) {
26         super(promise, channel);
27         super.setTlsConfiguration(tlsConfiguration);
28         this.maxUnknownMessages = maxUnknownMessages;
29         this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive()).setDeadTimer(localPrefs.getDeadTimer()).setSessionId(
30                 sessionId).setTlvs(localPrefs.getTlvs()).build();
31         this.listener = requireNonNull(listener);
32     }
33
34     public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
35             final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final Open localPrefs) {
36         this(promise, channel, listener, sessionId, maxUnknownMessages, localPrefs, null);
37     }
38
39     private final Open myLocalPrefs;
40
41     @Override
42     protected Open getInitialProposal() {
43         return this.myLocalPrefs;
44     }
45
46     @Override
47     @VisibleForTesting
48     public PCEPSessionImpl createSession(final Channel channel, final Open localPrefs, final Open remotePrefs) {
49         return new PCEPSessionImpl(this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
50     }
51
52     @Override
53     protected boolean isProposalAcceptable(final Open open) {
54         return true;
55     }
56
57     @Override
58     protected Open getCounterProposal(final Open open) {
59         return null;
60     }
61
62     @Override
63     protected Open getRevisedProposal(final Open suggestion) {
64         return this.myLocalPrefs;
65     }
66 }