BUG-47 : unfinished PCEP migration to generated DTOs.
[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
12 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.StatefulCapabilityTlv.Flags;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.message.open.message.OpenBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.TlvsBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.tlvs.StatefulBuilder;
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,
27                         final boolean versioned, final boolean instant, final int timeout) {
28                 this.deadTimer = deadTimer;
29                 this.keepAlive = keepAlive;
30                 this.stateful = stateful;
31                 this.active = active;
32                 this.versioned = versioned;
33                 this.instant = instant;
34                 this.timeout = timeout;
35         }
36
37         @Override
38         public OpenObject getSessionProposal(final InetSocketAddress address, final int sessionId) {
39                 final Tlvs tlvs = null;
40                 final TlvsBuilder builder = new TlvsBuilder();
41                 if (PCEPSessionProposalFactoryImpl.this.stateful) {
42                         builder.setStateful((new StatefulBuilder().setFlags(new Flags(PCEPSessionProposalFactoryImpl.this.versioned, PCEPSessionProposalFactoryImpl.this.instant, PCEPSessionProposalFactoryImpl.this.active)).build()));
43                 }
44                 return new OpenBuilder().setKeepalive((short) PCEPSessionProposalFactoryImpl.this.keepAlive).setDeadTimer(
45                                 (short) PCEPSessionProposalFactoryImpl.this.deadTimer).setSessionId((short) sessionId).setTlvs(tlvs).build();
46         }
47
48         public int getKeepAlive() {
49                 return this.keepAlive;
50         }
51
52         public int getDeadTimer() {
53                 return this.deadTimer;
54         }
55
56         public boolean isStateful() {
57                 return this.stateful;
58         }
59
60         public boolean isActive() {
61                 return this.active;
62         }
63
64         public boolean isVersioned() {
65                 return this.versioned;
66         }
67
68         public boolean isInstant() {
69                 return this.instant;
70         }
71
72         public int getTimeout() {
73                 return this.timeout;
74         }
75 }