clean pcep/impl
[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.rev181109.open.object.Open;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
19 import org.opendaylight.yangtools.yang.common.Uint8;
20
21 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
22     private final PCEPSessionListener listener;
23     private final int maxUnknownMessages;
24
25     public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
26             final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages,
27             final Open localPrefs, final Tls tlsConfiguration) {
28         super(promise, channel);
29         super.setTlsConfiguration(tlsConfiguration);
30         this.maxUnknownMessages = maxUnknownMessages;
31         this.myLocalPrefs = new OpenBuilder()
32                 .setKeepalive(localPrefs.getKeepalive())
33                 .setDeadTimer(localPrefs.getDeadTimer())
34                 .setSessionId(Uint8.valueOf(sessionId))
35                 .setTlvs(localPrefs.getTlvs())
36                 .build();
37         this.listener = requireNonNull(listener);
38     }
39
40     public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
41             final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages,
42             final Open localPrefs) {
43         this(promise, channel, listener, sessionId, maxUnknownMessages, localPrefs, null);
44     }
45
46     private final Open myLocalPrefs;
47
48     @Override
49     protected Open getInitialProposal() {
50         return this.myLocalPrefs;
51     }
52
53     @Override
54     @VisibleForTesting
55     public PCEPSessionImpl createSession(final Channel channel, final Open localPrefs, final Open remotePrefs) {
56         return new PCEPSessionImpl(this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
57     }
58
59     @Override
60     protected boolean isProposalAcceptable(final Open open) {
61         return true;
62     }
63
64     @Override
65     protected Open getCounterProposal(final Open open) {
66         return null;
67     }
68
69     @Override
70     protected Open getRevisedProposal(final Open suggestion) {
71         return this.myLocalPrefs;
72     }
73 }