Merge "Clean DeviceState"
[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
44     public DeviceStateImpl(@CheckForNull final FeaturesReply featuresReply, @Nonnull final NodeId nodeId) {
45         Preconditions.checkArgument(featuresReply != null);
46         featuresOutput = new GetFeaturesOutputBuilder(featuresReply).build();
47         this.nodeId = Preconditions.checkNotNull(nodeId);
48         nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
49         version = featuresReply.getVersion();
50     }
51
52     @Override
53     public NodeId getNodeId() {
54         return nodeId;
55     }
56
57     @Override
58     public KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier() {
59         return nodeII;
60     }
61
62     @Override
63     public GetFeaturesOutput getFeatures() {
64         return featuresOutput;
65     }
66
67     @Override
68     public boolean isValid() {
69         return valid;
70     }
71
72     @Override
73     public void setValid(final boolean valid) {
74         this.valid = valid;
75     }
76
77     @Override
78     public short getVersion() {
79         return version;
80     }
81
82 }