Merge "handled review comments (sending rpc message to library and version negotiation )"
[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 import java.util.concurrent.atomic.AtomicLong;
16
17 import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor;
18 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
20
21 /**
22  * @author mirehak
23  */
24 public class SessionContextOFImpl implements SessionContext {
25
26     private GetFeaturesOutput features;
27     private ConnectionConductor primaryConductor;
28     private ConcurrentHashMap<SwitchConnectionDistinguisher, ConnectionConductor> auxiliaryConductors;
29     private boolean valid;
30     private SwitchConnectionDistinguisher sessionKey;
31     private IMessageDispatchService mdService;
32     private final AtomicLong xid;
33
34     /**
35      * default ctor
36      */
37     public SessionContextOFImpl() {
38         auxiliaryConductors = new ConcurrentHashMap<>();
39         mdService = new MessageDispatchServiceImpl(this);
40         xid = new AtomicLong();
41     }
42
43     @Override
44     public ConnectionConductor getPrimaryConductor() {
45         return primaryConductor;
46     }
47
48     @Override
49     public ConnectionConductor getAuxiliaryConductor(
50             SwitchConnectionDistinguisher auxiliaryKey) {
51         return auxiliaryConductors.get(auxiliaryKey);
52     }
53
54     @Override
55     public void addAuxiliaryConductor(
56             SwitchConnectionDistinguisher auxiliaryKey,
57             ConnectionConductor conductor) {
58         auxiliaryConductors.put(auxiliaryKey, conductor);
59     }
60
61     @Override
62     public Set<Entry<SwitchConnectionDistinguisher, ConnectionConductor>> getAuxiliaryConductors() {
63         return Collections.unmodifiableSet(auxiliaryConductors.entrySet());
64     }
65
66     @Override
67     public GetFeaturesOutput getFeatures() {
68         return features;
69     }
70
71     /**
72      * @param features
73      *            the features to set
74      */
75     public void setFeatures(GetFeaturesOutput features) {
76         this.features = features;
77     }
78
79     /**
80      * @param primaryConductor
81      *            the primaryConductor to set
82      */
83     public void setPrimaryConductor(ConnectionConductor primaryConductor) {
84         this.primaryConductor = primaryConductor;
85     }
86
87     @Override
88     public ConnectionConductor removeAuxiliaryConductor(
89             SwitchConnectionDistinguisher connectionCookie) {
90         return auxiliaryConductors.remove(connectionCookie);
91     }
92
93     @Override
94     public boolean isValid() {
95         return valid;
96     }
97
98     @Override
99     public void setValid(boolean valid) {
100         this.valid = valid;
101     }
102
103     /**
104      * @param sessionKey the sessionKey to set
105      */
106     public void setSessionKey(SwitchConnectionDistinguisher sessionKey) {
107         this.sessionKey = sessionKey;
108     }
109
110     @Override
111     public SwitchConnectionDistinguisher getSessionKey() {
112         return sessionKey;
113     }
114
115     @Override
116     public IMessageDispatchService getMessageDispatchService() {
117         return mdService;
118     }
119
120     @Override
121     public Long getNextXid() {
122         return xid.incrementAndGet();
123     }
124 }