added disconnect delegator to conductor, session invalidation
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / session / SessionContextOFImpl.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.openflow.md.core.session;
10
11 import java.util.Collections;
12 import java.util.Map.Entry;
13 import java.util.Set;
14 import java.util.concurrent.ConcurrentHashMap;
15
16 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
17 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
19
20 /**
21  * @author mirehak
22  */
23 public class SessionContextOFImpl implements SessionContext {
24
25     private GetFeaturesOutput features;
26     private ConnectionConductor primaryConductor;
27     private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
28     private boolean valid;
29     private SwitchConnectionDistinguisher sessionKey;
30
31     /**
32      * default ctor
33      */
34     public SessionContextOFImpl() {
35         auxiliaryConductors = new ConcurrentHashMap<>();
36     }
37
38     @Override
39     public ConnectionConductor getPrimaryConductor() {
40         return primaryConductor;
41     }
42
43     @Override
44     public ConnectionConductor getAuxiliaryConductor(
45             SwitchConnectionDistinguisher auxiliaryKey) {
46         return auxiliaryConductors.get(auxiliaryKey);
47     }
48
49     @Override
50     public void addAuxiliaryConductor(
51             SwitchConnectionDistinguisher auxiliaryKey,
52             ConnectionConductor conductor) {
53         auxiliaryConductors.put(auxiliaryKey, conductor);
54     }
55
56     @Override
57     public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
58         return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
59     }
60
61     @Override
62     public GetFeaturesOutput getFeatures() {
63         return features;
64     }
65
66     /**
67      * @param features
68      *            the features to set
69      */
70     public void setFeatures(GetFeaturesOutput features) {
71         this.features = features;
72     }
73
74     /**
75      * @param primaryConductor
76      *            the primaryConductor to set
77      */
78     public void setPrimaryConductor(ConnectionConductor primaryConductor) {
79         this.primaryConductor = primaryConductor;
80     }
81
82     @Override
83     public ConnectionConductor removeAuxiliaryConductor(
84             SwitchConnectionDistinguisher connectionCookie) {
85         return auxiliaryConductors.remove(connectionCookie);
86     }
87
88     @Override
89     public boolean isValid() {
90         return valid;
91     }
92
93     @Override
94     public void setValid(boolean valid) {
95         this.valid = valid;
96     }
97
98     /**
99      * @param sessionKey the sessionKey to set
100      */
101     public void setSessionKey(SwitchConnectionDistinguisher sessionKey) {
102         this.sessionKey = sessionKey;
103     }
104
105     @Override
106     public SwitchConnectionDistinguisher getSessionKey() {
107         return sessionKey;
108     }
109 }