Merge "BUG-1287: migrate tests to new APIs"
[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 com.google.common.annotations.VisibleForTesting;
11 import com.google.common.base.Preconditions;
12
13 import io.netty.channel.Channel;
14 import io.netty.util.Timer;
15 import io.netty.util.concurrent.Promise;
16
17 import org.opendaylight.protocol.pcep.PCEPSessionListener;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
20
21 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
22     private final PCEPSessionListener listener;
23     private final int maxUnknownMessages;
24
25     public DefaultPCEPSessionNegotiator(final Timer timer, final Promise<PCEPSessionImpl> promise, final Channel channel,
26             final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final Open localPrefs) {
27         super(timer, promise, channel);
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 = Preconditions.checkNotNull(listener);
32     }
33
34     private final Open myLocalPrefs;
35
36     @Override
37     protected Open getInitialProposal() {
38         return this.myLocalPrefs;
39     }
40
41     @Override
42     @VisibleForTesting
43     public PCEPSessionImpl createSession(final Timer timer, final Channel channel, final Open localPrefs, final Open remotePrefs) {
44         return new PCEPSessionImpl(timer, this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
45     }
46
47     @Override
48     protected boolean isProposalAcceptable(final Open open) {
49         return true;
50     }
51
52     @Override
53     protected Open getCounterProposal(final Open open) {
54         return null;
55     }
56
57     @Override
58     protected Open getRevisedProposal(final Open suggestion) {
59         return this.myLocalPrefs;
60     }
61 }