Open Kilda Java Documentation
MockSwitchManager.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.floodlight;
17 
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.concurrent.ConcurrentHashMap;
26 
27 import net.floodlightcontroller.core.FloodlightContext;
28 import net.floodlightcontroller.core.IOFConnectionBackend;
29 import net.floodlightcontroller.core.IOFSwitch;
30 import net.floodlightcontroller.core.IOFSwitch.SwitchStatus;
31 import net.floodlightcontroller.core.IOFSwitchBackend;
32 import net.floodlightcontroller.core.IOFSwitchDriver;
33 import net.floodlightcontroller.core.IOFSwitchListener;
34 import net.floodlightcontroller.core.LogicalOFMessageCategory;
35 import net.floodlightcontroller.core.PortChangeType;
36 import net.floodlightcontroller.core.SwitchDescription;
37 import net.floodlightcontroller.core.internal.IAppHandshakePluginFactory;
38 import net.floodlightcontroller.core.internal.IOFSwitchManager;
39 import net.floodlightcontroller.core.internal.IOFSwitchService;
40 import net.floodlightcontroller.core.internal.OFSwitchHandshakeHandler;
41 import net.floodlightcontroller.core.internal.SwitchManagerCounters;
42 import net.floodlightcontroller.core.module.FloodlightModuleContext;
43 import net.floodlightcontroller.core.module.FloodlightModuleException;
44 import net.floodlightcontroller.core.module.IFloodlightModule;
45 import net.floodlightcontroller.core.module.IFloodlightService;
46 import net.floodlightcontroller.debugcounter.DebugCounterServiceImpl;
47 
48 import org.projectfloodlight.openflow.protocol.OFFactory;
49 import org.projectfloodlight.openflow.protocol.OFMessage;
50 import org.projectfloodlight.openflow.protocol.OFPortDesc;
51 import org.projectfloodlight.openflow.types.DatapathId;
52 
53 import com.google.common.collect.ImmutableList;
54 
55 public class MockSwitchManager implements IFloodlightModule, IOFSwitchManager, IOFSwitchService {
56 
57  private Map<DatapathId, OFSwitchHandshakeHandler> switchHandlers;
58  private Map<DatapathId, IOFSwitch> switches;
59  private final SwitchManagerCounters counters;
60  //private final CopyOnWriteArrayList<IOFSwitchListener> switchListeners;
61 
63  switchHandlers = new ConcurrentHashMap<DatapathId, OFSwitchHandshakeHandler>();
64  switches = new ConcurrentHashMap<DatapathId, IOFSwitch>();
65  counters = new SwitchManagerCounters(new DebugCounterServiceImpl());
66  //switchListeners = new CopyOnWriteArrayList<IOFSwitchListener>();
67  }
68 
69  @Override
70  public void switchAdded(IOFSwitchBackend sw) {
71  // do nothing
72 
73  }
74 
75  @Override
76  public void switchDisconnected(IOFSwitchBackend sw) {
77  // do nothing
78 
79  }
80 
81  @Override
82  public void handshakeDisconnected(DatapathId dpid) {
83  // do nothing
84  }
85 
86  @Override
87  public void notifyPortChanged(IOFSwitchBackend sw, OFPortDesc port,
88  PortChangeType type) {
89  // do nothing
90 
91  }
92 
93  @Override
94  public IOFSwitchBackend
95  getOFSwitchInstance(IOFConnectionBackend connection,
96  SwitchDescription description,
97  OFFactory factory, DatapathId datapathId) {
98  return null;
99  }
100 
101  @Override
102  public void handleMessage(IOFSwitchBackend sw, OFMessage m,
103  FloodlightContext bContext) {
104  // do nothing
105 
106  }
107 
108  @Override
109  public void handleOutgoingMessage(IOFSwitch sw, OFMessage m) {
110  // do nothing
111 
112  }
113 
114  public void setSwitchHandshakeHandlers(Map<DatapathId, OFSwitchHandshakeHandler> handlers) {
115  this.switchHandlers = handlers;
116  }
117  @Override
118  public ImmutableList<OFSwitchHandshakeHandler>
120  return ImmutableList.copyOf(this.switchHandlers.values());
121  }
122 
123  @Override
124  public void addOFSwitchDriver(String manufacturerDescriptionPrefix,
125  IOFSwitchDriver driver) {
126  // do nothing
127 
128  }
129 
130  @Override
131  public void switchStatusChanged(IOFSwitchBackend sw,
132  SwitchStatus oldStatus,
133  SwitchStatus newStatus) {
134  // do nothing
135 
136  }
137 
138  @Override
140  return 0;
141  }
142 
143  @Override
144  public void addSwitchEvent(DatapathId switchDpid, String reason,
145  boolean flushNow) {
146  // do nothing
147 
148  }
149 
150  @Override
151  public List<IAppHandshakePluginFactory> getHandshakePlugins() {
152  return null;
153  }
154 
155  @Override
156  public SwitchManagerCounters getCounters() {
157  return this.counters;
158  }
159 
160  @Override
161  public boolean isCategoryRegistered(LogicalOFMessageCategory category) {
162  return false;
163  }
164 
165  public void setSwitches(Map<DatapathId, IOFSwitch> switches) {
166  this.switches = switches;
167  }
168 
169  @Override
170  public Map<DatapathId, IOFSwitch> getAllSwitchMap() {
171  return Collections.unmodifiableMap(switches);
172  }
173 
174  @Override
175  public IOFSwitch getSwitch(DatapathId dpid) {
176  return this.switches.get(dpid);
177  }
178 
179  @Override
180  public IOFSwitch getActiveSwitch(DatapathId dpid) {
181  IOFSwitch sw = this.switches.get(dpid);
182  if(sw != null && sw.getStatus().isVisible())
183  return sw;
184  else
185  return null;
186  }
187 
188  @Override
189  public void addOFSwitchListener(IOFSwitchListener listener) {
190  // do nothing
191  }
192 
193  @Override
194  public void removeOFSwitchListener(IOFSwitchListener listener) {
195  // do nothing
196  }
197 
198  @Override
199  public void registerLogicalOFMessageCategory(LogicalOFMessageCategory category) {
200  // do nothing
201  }
202 
203  @Override
204  public void registerHandshakePlugin(IAppHandshakePluginFactory plugin) {
205  // do nothing
206 
207  }
208 
209  @Override
210  public Set<DatapathId> getAllSwitchDpids() {
211  return this.switches.keySet();
212  }
213 
214  @Override
215  public Collection<Class<? extends IFloodlightService>>
217  Collection<Class<? extends IFloodlightService>> services =
218  new ArrayList<Class<? extends IFloodlightService>>(1);
219  services.add(IOFSwitchService.class);
220  return services;
221  }
222 
223  @Override
224  public Map<Class<? extends IFloodlightService>, IFloodlightService>
226  Map<Class<? extends IFloodlightService>,
227  IFloodlightService> m =
228  new HashMap<Class<? extends IFloodlightService>,
229  IFloodlightService>();
230  m.put(IOFSwitchService.class, this);
231  return m;
232  }
233 
234  @Override
235  public Collection<Class<? extends IFloodlightService>>
237  return null;
238  }
239 
240  @Override
241  public void init(FloodlightModuleContext context) throws FloodlightModuleException {
242  // do nothing
243  }
244 
245  @Override
246  public void startUp(FloodlightModuleContext context) throws FloodlightModuleException {
247  // do nothing
248  }
249 }
Collection< Class<? extends IFloodlightService > > getModuleServices()
List< IAppHandshakePluginFactory > getHandshakePlugins()
boolean isCategoryRegistered(LogicalOFMessageCategory category)
void addOFSwitchDriver(String manufacturerDescriptionPrefix, IOFSwitchDriver driver)
void handleMessage(IOFSwitchBackend sw, OFMessage m, FloodlightContext bContext)
void setSwitchHandshakeHandlers(Map< DatapathId, OFSwitchHandshakeHandler > handlers)
void startUp(FloodlightModuleContext context)
void handleOutgoingMessage(IOFSwitch sw, OFMessage m)
description
Definition: setup.py:26
Map< Class<? extends IFloodlightService >, IFloodlightService > getServiceImpls()
Map< DatapathId, IOFSwitch > getAllSwitchMap()
ImmutableList< OFSwitchHandshakeHandler > getSwitchHandshakeHandlers()
void addSwitchEvent(DatapathId switchDpid, String reason, boolean flushNow)
void switchStatusChanged(IOFSwitchBackend sw, SwitchStatus oldStatus, SwitchStatus newStatus)
void registerLogicalOFMessageCategory(LogicalOFMessageCategory category)
void notifyPortChanged(IOFSwitchBackend sw, OFPortDesc port, PortChangeType type)
void init(FloodlightModuleContext context)
void removeOFSwitchListener(IOFSwitchListener listener)
IOFSwitchBackend getOFSwitchInstance(IOFConnectionBackend connection, SwitchDescription description, OFFactory factory, DatapathId datapathId)
Collection< Class<? extends IFloodlightService > > getModuleDependencies()
void addOFSwitchListener(IOFSwitchListener listener)
void setSwitches(Map< DatapathId, IOFSwitch > switches)
net
Definition: plan-b.py:46
void registerHandshakePlugin(IAppHandshakePluginFactory plugin)