BUG-58: refactor to take advantage of netty
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPSessionProposalFactoryImpl.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 java.net.InetSocketAddress;
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
15 import org.opendaylight.protocol.pcep.PCEPTlv;
16 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
17 import org.opendaylight.protocol.pcep.tlv.LSPCleanupTlv;
18 import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv;
19
20 public class PCEPSessionProposalFactoryImpl implements PCEPSessionProposalFactory {
21
22         private final int keepAlive, deadTimer, timeout;
23
24         private final boolean stateful, active, versioned, instant;
25
26         public PCEPSessionProposalFactoryImpl(final int deadTimer, final int keepAlive, final boolean stateful, final boolean active, final boolean versioned, final boolean instant, final int timeout) {
27                 this.deadTimer = deadTimer;
28                 this.keepAlive = keepAlive;
29                 this.stateful = stateful;
30                 this.active = active;
31                 this.versioned = versioned;
32                 this.instant = instant;
33                 this.timeout = timeout;
34         }
35
36         @Override
37         public PCEPOpenObject getSessionProposal(final InetSocketAddress address, final int sessionId) {
38                 List<PCEPTlv> tlvs = null;
39                 if (PCEPSessionProposalFactoryImpl.this.stateful) {
40                         tlvs = new ArrayList<PCEPTlv>();
41                         tlvs.add(new PCEStatefulCapabilityTlv(PCEPSessionProposalFactoryImpl.this.instant, PCEPSessionProposalFactoryImpl.this.active, PCEPSessionProposalFactoryImpl.this.versioned));
42                         if (PCEPSessionProposalFactoryImpl.this.instant) {
43                                 tlvs.add(new LSPCleanupTlv(PCEPSessionProposalFactoryImpl.this.timeout));
44                         }
45                 }
46                 return new PCEPOpenObject(PCEPSessionProposalFactoryImpl.this.keepAlive, PCEPSessionProposalFactoryImpl.this.deadTimer, sessionId, tlvs);
47         }
48
49         public int getKeepAlive() {
50                 return this.keepAlive;
51         }
52
53         public int getDeadTimer() {
54                 return this.deadTimer;
55         }
56
57         public boolean isStateful() {
58                 return this.stateful;
59         }
60
61         public boolean isActive() {
62                 return this.active;
63         }
64
65         public boolean isVersioned() {
66                 return this.versioned;
67         }
68
69         public boolean isInstant() {
70                 return this.instant;
71         }
72
73         public int getTimeout() {
74                 return this.timeout;
75         }
76 }