16 package org.openkilda.floodlight;
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;
25 import java.util.concurrent.ConcurrentHashMap;
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;
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;
53 import com.google.common.collect.ImmutableList;
55 public class MockSwitchManager implements IFloodlightModule, IOFSwitchManager, IOFSwitchService {
57 private Map<DatapathId, OFSwitchHandshakeHandler> switchHandlers;
58 private Map<DatapathId, IOFSwitch> switches;
59 private final SwitchManagerCounters counters;
63 switchHandlers =
new ConcurrentHashMap<DatapathId, OFSwitchHandshakeHandler>();
64 switches =
new ConcurrentHashMap<DatapathId, IOFSwitch>();
65 counters =
new SwitchManagerCounters(
new DebugCounterServiceImpl());
88 PortChangeType
type) {
94 public IOFSwitchBackend
97 OFFactory factory, DatapathId datapathId) {
103 FloodlightContext bContext) {
115 this.switchHandlers = handlers;
118 public ImmutableList<OFSwitchHandshakeHandler>
120 return ImmutableList.copyOf(this.switchHandlers.values());
125 IOFSwitchDriver driver) {
132 SwitchStatus oldStatus,
133 SwitchStatus newStatus) {
157 return this.counters;
166 this.switches = switches;
171 return Collections.unmodifiableMap(switches);
176 return this.switches.get(dpid);
181 IOFSwitch sw = this.switches.get(dpid);
182 if(sw != null && sw.getStatus().isVisible())
211 return this.switches.keySet();
215 public Collection<Class<? extends IFloodlightService>>
217 Collection<Class<? extends IFloodlightService>> services =
218 new ArrayList<Class<? extends IFloodlightService>>(1);
219 services.add(IOFSwitchService.class);
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);
235 public Collection<Class<? extends IFloodlightService>>
241 public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
246 public void startUp(FloodlightModuleContext context)
throws FloodlightModuleException {
Collection< Class<? extends IFloodlightService > > getModuleServices()
List< IAppHandshakePluginFactory > getHandshakePlugins()
boolean isCategoryRegistered(LogicalOFMessageCategory category)
void switchDisconnected(IOFSwitchBackend sw)
void switchAdded(IOFSwitchBackend sw)
void addOFSwitchDriver(String manufacturerDescriptionPrefix, IOFSwitchDriver driver)
void handleMessage(IOFSwitchBackend sw, OFMessage m, FloodlightContext bContext)
void setSwitchHandshakeHandlers(Map< DatapathId, OFSwitchHandshakeHandler > handlers)
void startUp(FloodlightModuleContext context)
SwitchManagerCounters getCounters()
void handleOutgoingMessage(IOFSwitch sw, OFMessage m)
IOFSwitch getActiveSwitch(DatapathId dpid)
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)
Set< DatapathId > getAllSwitchDpids()
void notifyPortChanged(IOFSwitchBackend sw, OFPortDesc port, PortChangeType type)
void init(FloodlightModuleContext context)
int getNumRequiredConnections()
void removeOFSwitchListener(IOFSwitchListener listener)
IOFSwitch getSwitch(DatapathId dpid)
IOFSwitchBackend getOFSwitchInstance(IOFConnectionBackend connection, SwitchDescription description, OFFactory factory, DatapathId datapathId)
Collection< Class<? extends IFloodlightService > > getModuleDependencies()
void handshakeDisconnected(DatapathId dpid)
void addOFSwitchListener(IOFSwitchListener listener)
void setSwitches(Map< DatapathId, IOFSwitch > switches)
void registerHandshakePlugin(IAppHandshakePluginFactory plugin)