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.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
34 * org.opendaylight.openflowplugin.impl.device
36 * DeviceState is builded from {@link FeaturesReply} and {@link NodeId}. Both values are inside
37 * {@link org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext}
39 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
41 * Created: Mar 29, 2015
43 class DeviceStateImpl implements DeviceState {
45 private final GetFeaturesOutput featuresOutput;
46 private final Map<Long, PortGrouping> portGrouping;
47 private final Map<Long, Long> portsBandwidth;
48 private final NodeId nodeId;
49 private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
50 private final short version;
51 private boolean valid;
53 public DeviceStateImpl(@CheckForNull final FeaturesReply featuresReply, @Nonnull final NodeId nodeId) {
54 Preconditions.checkArgument(featuresReply != null);
55 Preconditions.checkArgument(featuresReply.getPhyPort() != null);
56 featuresOutput = new GetFeaturesOutputBuilder(featuresReply).build();
57 this.nodeId = Preconditions.checkNotNull(nodeId);
58 nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
59 version = featuresReply.getVersion();
60 portGrouping = new HashMap<>();
61 portsBandwidth = new HashMap<>();
62 for (final PhyPort port : featuresReply.getPhyPort()) {
63 portGrouping.put(port.getPortNo(), port);
64 portsBandwidth.put(port.getPortNo(), port.getMaxSpeed());
69 public NodeId getNodeId() {
74 public KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier() {
79 public GetFeaturesOutput getFeatures() {
80 return featuresOutput;
84 public boolean isValid() {
89 public void setValid(final boolean valid) {
94 public Map<Long, PortGrouping> getPhysicalPorts() {
99 public Map<Long, Long> getPortsBandwidth() {
100 return portsBandwidth;
104 public Set<Long> getPorts() {
105 return portGrouping.keySet();
109 public PortGrouping getPhysicalPort(final Long portNumber) {
110 return portGrouping.get(portNumber);
114 public Long getPortBandwidth(final Long portNumber) {
115 return portsBandwidth.get(portNumber);
119 public boolean isPortEnabled(final long portNumber) {
120 return portGrouping.containsKey(portNumber);
124 public boolean isPortEnabled(final PortGrouping port) {
125 return portGrouping.containsValue(port);
129 public List<PortGrouping> getEnabledPorts() {
130 return new ArrayList<PortGrouping>(portGrouping.values());
134 public int getSeed() {
139 public short getVersion() {