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 org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
13 import org.opendaylight.openflowplugin.api.openflow.device.XidGenerator;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
20 import javax.annotation.CheckForNull;
21 import javax.annotation.Nonnull;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
30 * org.opendaylight.openflowplugin.impl.device
32 * DeviceState is builded from {@link FeaturesReply} and {@link NodeId}. Both values are inside
33 * {@link org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext}
35 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
37 * Created: Mar 29, 2015
39 class DeviceStateImpl implements DeviceState {
41 private final GetFeaturesOutput featuresOutput;
42 private final Map<Long, PortGrouping> portGrouping;
43 private final Map<Long, Long> portsBandwidth;
44 private final XidGenerator xidGenerator;
45 private final NodeId nodeId;
46 private boolean valid;
48 public DeviceStateImpl(@CheckForNull final FeaturesReply featuresReply, @Nonnull final NodeId nodeId) {
49 Preconditions.checkArgument(featuresReply != null);
50 Preconditions.checkArgument(featuresReply.getPhyPort() != null);
51 featuresOutput = new GetFeaturesOutputBuilder(featuresReply).build();
52 this.nodeId = Preconditions.checkNotNull(nodeId);
53 xidGenerator = new XidGenerator();
54 portGrouping = new HashMap<>();
55 portsBandwidth = new HashMap<>();
56 for (final PhyPort port : featuresReply.getPhyPort()) {
57 portGrouping.put(port.getPortNo(), port);
58 portsBandwidth.put(port.getPortNo(), port.getMaxSpeed());
63 public NodeId getNodeId() {
68 public GetFeaturesOutput getFeatures() {
69 return featuresOutput;
73 public boolean isValid() {
78 public void setValid(final boolean valid) {
83 public Map<Long, PortGrouping> getPhysicalPorts() {
88 public Map<Long, Long> getPortsBandwidth() {
89 return portsBandwidth;
93 public Set<Long> getPorts() {
94 return portGrouping.keySet();
98 public PortGrouping getPhysicalPort(final Long portNumber) {
99 return portGrouping.get(portNumber);
103 public Long getPortBandwidth(final Long portNumber) {
104 return portsBandwidth.get(portNumber);
108 public boolean isPortEnabled(final long portNumber) {
109 return portGrouping.containsKey(portNumber);
113 public boolean isPortEnabled(final PortGrouping port) {
114 return portGrouping.containsValue(port);
118 public List<PortGrouping> getEnabledPorts() {
119 return new ArrayList<PortGrouping>(portGrouping.values());
123 public int getSeed() {