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.api.openflow.md.core.session.IMessageDispatchService;
22 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
23 import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
24 import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
25 import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
26 import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationEnqueuer;
27 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortGrouping;
30 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
35 public class SessionContextOFImpl implements SessionContext {
37 private GetFeaturesOutput features;
38 private ConnectionConductor primaryConductor;
39 private NotificationEnqueuer notificationEnqueuer;
40 private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
41 private boolean valid;
42 private SwitchSessionKeyOF sessionKey;
43 private IMessageDispatchService mdService;
44 private final AtomicLong xid;
45 private final Map<Long, PortGrouping> physicalPorts;
46 private final Map<Long, Boolean> portBandwidth;
47 private CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration;
54 public SessionContextOFImpl() {
55 auxiliaryConductors = new ConcurrentHashMap<>();
56 mdService = new MessageDispatchServiceImpl(this);
57 xid = new AtomicLong();
58 this.physicalPorts = new HashMap<Long, PortGrouping>();
59 this.portBandwidth = new HashMap<Long, Boolean>();
63 public ConnectionConductor getPrimaryConductor() {
64 return primaryConductor;
68 public ConnectionConductor getAuxiliaryConductor(
69 SwitchConnectionDistinguisher auxiliaryKey) {
70 return auxiliaryConductors.get(auxiliaryKey);
74 public void addAuxiliaryConductor(
75 SwitchConnectionDistinguisher auxiliaryKey,
76 ConnectionConductor conductor) {
77 auxiliaryConductors.put(auxiliaryKey, conductor);
81 public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
82 return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
86 public GetFeaturesOutput getFeatures() {
94 public void setFeatures(GetFeaturesOutput features) {
95 this.features = features;
99 * @param primaryConductor
100 * the primaryConductor to set
102 public void setPrimaryConductor(ConnectionConductor primaryConductor) {
103 this.primaryConductor = primaryConductor;
107 public ConnectionConductor removeAuxiliaryConductor(
108 SwitchConnectionDistinguisher connectionCookie) {
109 return auxiliaryConductors.remove(connectionCookie);
113 public boolean isValid() {
118 public void setValid(boolean valid) {
123 * @param sessionKey the sessionKey to set
125 public void setSessionKey(SwitchSessionKeyOF sessionKey) {
126 this.sessionKey = sessionKey;
130 * @param seed the seed to set
132 public void setSeed(int seed) {
137 public SwitchSessionKeyOF getSessionKey() {
142 public IMessageDispatchService getMessageDispatchService() {
147 public Long getNextXid() {
148 return xid.incrementAndGet();
152 public Map<Long, PortGrouping> getPhysicalPorts() {
153 return this.physicalPorts;
157 public Map<Long, Boolean> getPortsBandwidth() {
158 return this.portBandwidth;
162 public Set<Long> getPorts() {
163 return this.physicalPorts.keySet();
167 public PortGrouping getPhysicalPort(Long portNumber) {
168 return this.physicalPorts.get(portNumber);
172 public Boolean getPortBandwidth(Long portNumber) {
173 return this.portBandwidth.get(portNumber);
177 public boolean isPortEnabled(long portNumber) {
178 return isPortEnabled(physicalPorts.get(portNumber));
182 public boolean isPortEnabled(PortGrouping port) {
186 if (port.getConfig().isPortDown()) {
189 if (port.getState().isLinkDown()) {
192 if (port.getState().isBlocked()) {
199 public List<PortGrouping> getEnabledPorts() {
200 List<PortGrouping> result = new ArrayList<PortGrouping>();
201 synchronized (this.physicalPorts) {
202 for (PortGrouping port : physicalPorts.values()) {
203 if (isPortEnabled(port)) {
212 public void setProviderRegistration(
213 CompositeObjectRegistration<ModelDrivenSwitch> providerRegistration) {
214 this.providerRegistration = providerRegistration;
218 public CompositeObjectRegistration<ModelDrivenSwitch> getProviderRegistration() {
219 return providerRegistration;
223 public int getSeed() {
228 * @param notificationEnqueuer the notificationEnqueuer to set
230 public void setNotificationEnqueuer(
231 NotificationEnqueuer notificationEnqueuer) {
232 this.notificationEnqueuer = notificationEnqueuer;
236 public NotificationEnqueuer getNotificationEnqueuer() {
237 return notificationEnqueuer;