2 * Copyright (c) 2013 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.openflow.md.core.session;
11 import java.util.ArrayList;
12 import java.util.Collections;
13 import java.util.HashMap;
14 import java.util.List;
16 import java.util.Map.Entry;
18 import java.util.concurrent.ConcurrentHashMap;
19 import java.util.concurrent.atomic.AtomicLong;
21 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
22 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Port;
29 public class SessionContextOFImpl implements SessionContext {
31 private GetFeaturesOutput features;
32 private ConnectionConductor primaryConductor;
33 private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
34 private boolean valid;
35 private SwitchConnectionDistinguisher sessionKey;
36 private IMessageDispatchService mdService;
37 private final AtomicLong xid;
38 private final Map<Long, Port> physicalPorts;
39 private final Map<Long, Boolean> portBandwidth;
44 public SessionContextOFImpl() {
45 auxiliaryConductors = new ConcurrentHashMap<>();
46 mdService = new MessageDispatchServiceImpl(this);
47 xid = new AtomicLong();
48 this.physicalPorts = new HashMap<Long, Port>();
49 this.portBandwidth = new HashMap<Long, Boolean>();
53 public ConnectionConductor getPrimaryConductor() {
54 return primaryConductor;
58 public ConnectionConductor getAuxiliaryConductor(
59 SwitchConnectionDistinguisher auxiliaryKey) {
60 return auxiliaryConductors.get(auxiliaryKey);
64 public void addAuxiliaryConductor(
65 SwitchConnectionDistinguisher auxiliaryKey,
66 ConnectionConductor conductor) {
67 auxiliaryConductors.put(auxiliaryKey, conductor);
71 public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
72 return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
76 public GetFeaturesOutput getFeatures() {
84 public void setFeatures(GetFeaturesOutput features) {
85 this.features = features;
89 * @param primaryConductor
90 * the primaryConductor to set
92 public void setPrimaryConductor(ConnectionConductor primaryConductor) {
93 this.primaryConductor = primaryConductor;
97 public ConnectionConductor removeAuxiliaryConductor(
98 SwitchConnectionDistinguisher connectionCookie) {
99 return auxiliaryConductors.remove(connectionCookie);
103 public boolean isValid() {
108 public void setValid(boolean valid) {
113 * @param sessionKey the sessionKey to set
115 public void setSessionKey(SwitchConnectionDistinguisher sessionKey) {
116 this.sessionKey = sessionKey;
120 public SwitchConnectionDistinguisher getSessionKey() {
125 public IMessageDispatchService getMessageDispatchService() {
130 public Long getNextXid() {
131 return xid.incrementAndGet();
135 public Map<Long, Port> getPhysicalPorts() {
136 return this.physicalPorts;
140 public Map<Long, Boolean> getPortsBandwidth() {
141 return this.portBandwidth;
145 public Set<Long> getPorts() {
146 return this.physicalPorts.keySet();
150 public Port getPhysicalPort(Long portNumber) {
151 return this.physicalPorts.get(portNumber);
155 public Boolean getPortBandwidth(Long portNumber) {
156 return this.portBandwidth.get(portNumber);
160 public boolean isPortEnabled(long portNumber) {
161 return isPortEnabled(physicalPorts.get(portNumber));
165 public boolean isPortEnabled(Port port) {
169 if (port.getConfig().isPortDown()) {
172 if (port.getState().isLinkDown()) {
175 if (port.getState().isBlocked()) {
182 public List<Port> getEnabledPorts() {
183 List<Port> result = new ArrayList<Port>();
184 synchronized (this.physicalPorts) {
185 for (Port port : physicalPorts.values()) {
186 if (isPortEnabled(port)) {