BUG-58: refactor to take advantage of netty
[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 io.netty.channel.Channel;
11 import io.netty.util.Timer;
12 import io.netty.util.concurrent.Promise;
13
14 import org.opendaylight.protocol.pcep.PCEPSessionListener;
15 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
16
17 import com.google.common.base.Preconditions;
18
19 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
20         private final PCEPSessionListener listener;
21         private final int maxUnknownMessages;
22
23         public DefaultPCEPSessionNegotiator(final Timer timer, final Promise<PCEPSessionImpl> promise, final Channel channel,
24                         final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final PCEPOpenObject localPrefs) {
25                 super(timer, promise, channel);
26                 this.maxUnknownMessages = maxUnknownMessages;
27                 this.myLocalPrefs = new PCEPOpenObject(localPrefs.getKeepAliveTimerValue(), localPrefs.getDeadTimerValue(), sessionId, localPrefs.getTlvs());
28                 this.listener = Preconditions.checkNotNull(listener);
29         }
30
31         private final PCEPOpenObject myLocalPrefs;
32
33         @Override
34         protected PCEPOpenObject getInitialProposal() {
35                 return myLocalPrefs;
36         }
37
38         @Override
39         protected PCEPSessionImpl createSession(final Timer timer, final Channel channel, final PCEPOpenObject localPrefs, final PCEPOpenObject remotePrefs) {
40                 return new PCEPSessionImpl(timer, listener, maxUnknownMessages, channel, localPrefs, remotePrefs);
41         }
42
43         @Override
44         protected boolean isProposalAcceptable(final PCEPOpenObject open) {
45                 return true;
46         }
47
48         @Override
49         protected PCEPOpenObject getCounterProposal(final PCEPOpenObject open) {
50                 return null;
51         }
52
53         @Override
54         protected PCEPOpenObject getRevisedProposal(final PCEPOpenObject suggestion) {
55                 return myLocalPrefs;
56         }
57 }