BUG-47 : unfinished PCEP migration to generated DTOs.
[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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
17
18 import com.google.common.base.Preconditions;
19
20 public final class DefaultPCEPSessionNegotiator extends AbstractPCEPSessionNegotiator {
21         private final PCEPSessionListener listener;
22         private final int maxUnknownMessages;
23
24         public DefaultPCEPSessionNegotiator(final Timer timer, final Promise<PCEPSessionImpl> promise, final Channel channel,
25                         final PCEPSessionListener listener, final short sessionId, final int maxUnknownMessages, final OpenObject localPrefs) {
26                 super(timer, promise, channel);
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         private final OpenObject myLocalPrefs;
34
35         @Override
36         protected OpenObject getInitialProposal() {
37                 return this.myLocalPrefs;
38         }
39
40         @Override
41         protected PCEPSessionImpl createSession(final Timer timer, final Channel channel, final OpenObject localPrefs,
42                         final OpenObject remotePrefs) {
43                 return new PCEPSessionImpl(timer, this.listener, this.maxUnknownMessages, channel, localPrefs, remotePrefs);
44         }
45
46         @Override
47         protected boolean isProposalAcceptable(final OpenObject open) {
48                 return true;
49         }
50
51         @Override
52         protected OpenObject getCounterProposal(final OpenObject open) {
53                 return null;
54         }
55
56         @Override
57         protected OpenObject getRevisedProposal(final OpenObject suggestion) {
58                 return this.myLocalPrefs;
59         }
60 }