Fixed broken tests.
[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.open.object.Open;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.OpenBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.Stateful.Flags;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.stateful.capability.tlv.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 Open 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                 final OpenBuilder oBuilder = new OpenBuilder();
45                 oBuilder.setSessionId((short) sessionId);
46                 if (PCEPSessionProposalFactoryImpl.this.keepAlive != 0) {
47                         oBuilder.setKeepalive((short) PCEPSessionProposalFactoryImpl.this.keepAlive);
48                 }
49                 if (PCEPSessionProposalFactoryImpl.this.deadTimer != 0) {
50                         oBuilder.setDeadTimer((short) PCEPSessionProposalFactoryImpl.this.deadTimer);
51                 }
52                 return oBuilder.setTlvs(tlvs).build();
53         }
54
55         public int getKeepAlive() {
56                 return this.keepAlive;
57         }
58
59         public int getDeadTimer() {
60                 return this.deadTimer;
61         }
62
63         public boolean isStateful() {
64                 return this.stateful;
65         }
66
67         public boolean isActive() {
68                 return this.active;
69         }
70
71         public boolean isVersioned() {
72                 return this.versioned;
73         }
74
75         public boolean isInstant() {
76                 return this.instant;
77         }
78
79         public int getTimeout() {
80                 return this.timeout;
81         }
82 }