Bug 2231 - Secure transport for PCEP
[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 import io.netty.channel.Channel;
13 import io.netty.util.concurrent.Promise;
14 import org.opendaylight.controller.config.yang.pcep.impl.Tls;
15 import org.opendaylight.protocol.pcep.PCEPSessionListener;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Open;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
18
19 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
20     private final PCEPSessionListener listener;
21     private final int maxUnknownMessages;
22
23     public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
24             final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final Open localPrefs, final Tls tlsConfiguration) {
25         super(promise, channel);
26         super.setTlsConfiguration(tlsConfiguration);
27         this.maxUnknownMessages = maxUnknownMessages;
28         this.myLocalPrefs = new OpenBuilder().setKeepalive(localPrefs.getKeepalive()).setDeadTimer(localPrefs.getDeadTimer()).setSessionId(
29                 sessionId).setTlvs(localPrefs.getTlvs()).build();
30         this.listener = Preconditions.checkNotNull(listener);
31     }
32
33     public DefaultPCEPSessionNegotiator(final Promise<PCEPSessionImpl> promise, final Channel channel,
34             final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final Open localPrefs) {
35         this(promise, channel, listener, sessionId, maxUnknownMessages, localPrefs, null);
36     }
37
38     private final Open myLocalPrefs;
39
40     @Override
41     protected Open getInitialProposal() {
42         return this.myLocalPrefs;
43     }
44
45     @Override
46     @VisibleForTesting
47     public PCEPSessionImpl createSession(final Channel channel, final Open localPrefs, final Open remotePrefs) {
48         return new PCEPSessionImpl(this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
49     }
50
51     @Override
52     protected boolean isProposalAcceptable(final Open open) {
53         return true;
54     }
55
56     @Override
57     protected Open getCounterProposal(final Open open) {
58         return null;
59     }
60
61     @Override
62     protected Open getRevisedProposal(final Open suggestion) {
63         return this.myLocalPrefs;
64     }
65 }