Merge "device state holds information about device synchronization status"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / DeviceStateImpl.java
1 /**
2  * Copyright (c) 2015 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
9 package org.opendaylight.openflowplugin.impl.device;
10
11 import com.google.common.base.Preconditions;
12 import javax.annotation.CheckForNull;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
24
25 /**
26  * openflowplugin-impl
27  * org.opendaylight.openflowplugin.impl.device
28  * <p/>
29  * DeviceState is builded from {@link FeaturesReply} and {@link NodeId}. Both values are inside
30  * {@link org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext}
31  *
32  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
33  *         <p/>
34  *         Created: Mar 29, 2015
35  */
36 class DeviceStateImpl implements DeviceState {
37
38     private final GetFeaturesOutput featuresOutput;
39     private final NodeId nodeId;
40     private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
41     private final short version;
42     private boolean valid;
43     private boolean meterIsAvailable;
44     private boolean groupIsAvailable;
45     private boolean deviceSynchronized;
46
47
48     public DeviceStateImpl(@CheckForNull final FeaturesReply featuresReply, @Nonnull final NodeId nodeId) {
49         Preconditions.checkArgument(featuresReply != null);
50         featuresOutput = new GetFeaturesOutputBuilder(featuresReply).build();
51         this.nodeId = Preconditions.checkNotNull(nodeId);
52         nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
53         version = featuresReply.getVersion();
54     }
55
56     @Override
57     public NodeId getNodeId() {
58         return nodeId;
59     }
60
61     @Override
62     public KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier() {
63         return nodeII;
64     }
65
66     @Override
67     public GetFeaturesOutput getFeatures() {
68         return featuresOutput;
69     }
70
71     @Override
72     public boolean isValid() {
73         return valid;
74     }
75
76     @Override
77     public void setValid(final boolean valid) {
78         this.valid = valid;
79     }
80
81     @Override
82     public short getVersion() {
83         return version;
84     }
85
86     @Override
87     public boolean isMetersAvailable() {
88         return meterIsAvailable;
89     }
90
91     @Override
92     public void meterIsAvailable() {
93         meterIsAvailable = true;
94     }
95
96     @Override
97     public boolean isGroupAvailable() {
98         return groupIsAvailable;
99     }
100
101     @Override
102     public void groupIsAvailable() {
103         groupIsAvailable = true;
104     }
105
106     @Override
107     public boolean deviceSynchronized() {
108         return deviceSynchronized;
109     }
110
111     @Override
112     public void setDeviceSynchronized(final boolean _deviceSynchronized) {
113         deviceSynchronized = _deviceSynchronized;
114     }
115
116 }