cc783478c7d7e020955086d028e2ea4a8ce2ae8d
[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.io.Closeable;
11 import java.io.IOException;
12 import java.net.InetSocketAddress;
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.opendaylight.protocol.pcep.PCEPSessionPreferences;
17 import org.opendaylight.protocol.pcep.PCEPSessionProposal;
18 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
19 import org.opendaylight.protocol.pcep.PCEPTlv;
20 import org.opendaylight.protocol.pcep.object.PCEPOpenObject;
21 import org.opendaylight.protocol.pcep.tlv.LSPCleanupTlv;
22 import org.opendaylight.protocol.pcep.tlv.PCEStatefulCapabilityTlv;
23
24 public class PCEPSessionProposalFactoryImpl extends PCEPSessionProposalFactory implements Closeable {
25
26         private final int keepAlive, deadTimer, timeout;
27
28         private final boolean stateful, active, versioned, instant;
29
30         public PCEPSessionProposalFactoryImpl(final int deadTimer, final int keepAlive, final boolean stateful, final boolean active, final boolean versioned, final boolean instant, final int timeout) {
31                 this.deadTimer = deadTimer;
32                 this.keepAlive = keepAlive;
33                 this.stateful = stateful;
34                 this.active = active;
35                 this.versioned = versioned;
36                 this.instant = instant;
37                 this.timeout = timeout;
38         }
39
40         @Override
41         public PCEPSessionProposal getSessionProposal(final InetSocketAddress address, final int sessionId) {
42                 return new PCEPSessionProposal() {
43
44                         @Override
45                         public PCEPSessionPreferences getProposal() {
46                                 List<PCEPTlv> tlvs = null;
47                                 if (PCEPSessionProposalFactoryImpl.this.stateful) {
48                                         tlvs = new ArrayList<PCEPTlv>();
49                                         tlvs.add(new PCEStatefulCapabilityTlv(PCEPSessionProposalFactoryImpl.this.instant, PCEPSessionProposalFactoryImpl.this.active, PCEPSessionProposalFactoryImpl.this.versioned));
50                                         if (PCEPSessionProposalFactoryImpl.this.instant) {
51                                                 tlvs.add(new LSPCleanupTlv(PCEPSessionProposalFactoryImpl.this.timeout));
52                                         }
53                                 }
54                                 return new PCEPSessionPreferences(new PCEPOpenObject(PCEPSessionProposalFactoryImpl.this.keepAlive, PCEPSessionProposalFactoryImpl.this.deadTimer, sessionId, tlvs));
55                         }
56
57                 };
58         }
59
60         public int getKeepAlive() {
61                 return this.keepAlive;
62         }
63
64         public int getDeadTimer() {
65                 return this.deadTimer;
66         }
67
68         public boolean isStateful() {
69                 return this.stateful;
70         }
71
72         public boolean isActive() {
73                 return this.active;
74         }
75
76         public boolean isVersioned() {
77                 return this.versioned;
78         }
79
80         public boolean isInstant() {
81                 return this.instant;
82         }
83
84         public int getTimeout() {
85                 return this.timeout;
86         }
87
88         @Override
89         public void close() throws IOException {
90                 // nothing to close
91         }
92 }