2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.device;
11 import com.google.common.base.Preconditions;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
17 import javax.annotation.CheckForNull;
18 import javax.annotation.Nonnull;
19 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
33 * org.opendaylight.openflowplugin.impl.device
35 * DeviceState is builded from {@link FeaturesReply} and {@link NodeId}. Both values are inside
36 * {@link org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext}
38 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
40 * Created: Mar 29, 2015
42 class DeviceStateImpl implements DeviceState {
44 private final GetFeaturesOutput featuresOutput;
45 private final Map<Long, PortGrouping> portGrouping;
46 private final Map<Long, Long> portsBandwidth;
47 private final NodeId nodeId;
48 private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
49 private final short version;
50 private boolean valid;
52 public DeviceStateImpl(@CheckForNull final FeaturesReply featuresReply, @Nonnull final NodeId nodeId) {
53 Preconditions.checkArgument(featuresReply != null);
54 featuresOutput = new GetFeaturesOutputBuilder(featuresReply).build();
55 this.nodeId = Preconditions.checkNotNull(nodeId);
56 nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
57 version = featuresReply.getVersion();
58 portGrouping = new HashMap<>();
59 portsBandwidth = new HashMap<>();
61 // for (final PhyPort port : featuresReply.getPhyPort()) {
62 // portGrouping.put(port.getPortNo(), port);
63 // portsBandwidth.put(port.getPortNo(), port.getMaxSpeed());
68 public NodeId getNodeId() {
73 public KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier() {
78 public GetFeaturesOutput getFeatures() {
79 return featuresOutput;
83 public boolean isValid() {
88 public void setValid(final boolean valid) {
93 public Map<Long, PortGrouping> getPhysicalPorts() {
98 public Map<Long, Long> getPortsBandwidth() {
99 return portsBandwidth;
103 public Set<Long> getPorts() {
104 return portGrouping.keySet();
108 public PortGrouping getPhysicalPort(final Long portNumber) {
109 return portGrouping.get(portNumber);
113 public Long getPortBandwidth(final Long portNumber) {
114 return portsBandwidth.get(portNumber);
118 public boolean isPortEnabled(final long portNumber) {
119 return portGrouping.containsKey(portNumber);
123 public boolean isPortEnabled(final PortGrouping port) {
124 return portGrouping.containsValue(port);
128 public List<PortGrouping> getEnabledPorts() {
129 return new ArrayList<PortGrouping>(portGrouping.values());
133 public int getSeed() {
138 public short getVersion() {