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.ModelDrivenSwitch;
22 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
23 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
26 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
31 public class SessionContextOFImpl implements SessionContext {
33 private GetFeaturesOutput features;
34 private ConnectionConductor primaryConductor;
35 private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
36 private boolean valid;
37 private SwitchSessionKeyOF sessionKey;
38 private IMessageDispatchService mdService;
39 private final AtomicLong xid;
40 private final Map<Long, PortGrouping> physicalPorts;
41 private final Map<Long, Boolean> portBandwidth;
42 private CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration;
49 public SessionContextOFImpl() {
50 auxiliaryConductors = new ConcurrentHashMap<>();
51 mdService = new MessageDispatchServiceImpl(this);
52 xid = new AtomicLong();
53 this.physicalPorts = new HashMap<Long, PortGrouping>();
54 this.portBandwidth = new HashMap<Long, Boolean>();
58 public ConnectionConductor getPrimaryConductor() {
59 return primaryConductor;
63 public ConnectionConductor getAuxiliaryConductor(
64 SwitchConnectionDistinguisher auxiliaryKey) {
65 return auxiliaryConductors.get(auxiliaryKey);
69 public void addAuxiliaryConductor(
70 SwitchConnectionDistinguisher auxiliaryKey,
71 ConnectionConductor conductor) {
72 auxiliaryConductors.put(auxiliaryKey, conductor);
76 public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
77 return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
81 public GetFeaturesOutput getFeatures() {
89 public void setFeatures(GetFeaturesOutput features) {
90 this.features = features;
94 * @param primaryConductor
95 * the primaryConductor to set
97 public void setPrimaryConductor(ConnectionConductor primaryConductor) {
98 this.primaryConductor = primaryConductor;
102 public ConnectionConductor removeAuxiliaryConductor(
103 SwitchConnectionDistinguisher connectionCookie) {
104 return auxiliaryConductors.remove(connectionCookie);
108 public boolean isValid() {
113 public void setValid(boolean valid) {
118 * @param sessionKey the sessionKey to set
120 public void setSessionKey(SwitchSessionKeyOF sessionKey) {
121 this.sessionKey = sessionKey;
125 * @param seed the seed to set
127 public void setSeed(int seed) {
132 public SwitchSessionKeyOF getSessionKey() {
137 public IMessageDispatchService getMessageDispatchService() {
142 public Long getNextXid() {
143 return xid.incrementAndGet();
147 public Map<Long, PortGrouping> getPhysicalPorts() {
148 return this.physicalPorts;
152 public Map<Long, Boolean> getPortsBandwidth() {
153 return this.portBandwidth;
157 public Set<Long> getPorts() {
158 return this.physicalPorts.keySet();
162 public PortGrouping getPhysicalPort(Long portNumber) {
163 return this.physicalPorts.get(portNumber);
167 public Boolean getPortBandwidth(Long portNumber) {
168 return this.portBandwidth.get(portNumber);
172 public boolean isPortEnabled(long portNumber) {
173 return isPortEnabled(physicalPorts.get(portNumber));
177 public boolean isPortEnabled(PortGrouping port) {
181 if (port.getConfig().isPortDown()) {
184 if (port.getState().isLinkDown()) {
187 if (port.getState().isBlocked()) {
194 public List<PortGrouping> getEnabledPorts() {
195 List<PortGrouping> result = new ArrayList<PortGrouping>();
196 synchronized (this.physicalPorts) {
197 for (PortGrouping port : physicalPorts.values()) {
198 if (isPortEnabled(port)) {
207 public void setProviderRegistration(
208 CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration) {
209 this.providerRegistration = providerRegistration;
213 public CompositeObjectRegistration<ModelDrivenSwitch> getProviderRegistration() {
214 return providerRegistration;
218 public int getSeed() {