Skip to content
Snippets Groups Projects
Commit f60a2479 authored by Shudong Zhou's avatar Shudong Zhou
Browse files

Move switch event history from LinkDiscovery to Controller

parent ea292ebe
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,11 @@ import java.util.List;
import java.util.Set;
import java.util.Map;
import net.floodlightcontroller.core.internal.EventHistorySwitch;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.util.EventHistory;
import net.floodlightcontroller.util.EventHistory.EvAction;
import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFType;
......@@ -304,4 +307,18 @@ public interface IFloodlightProviderService extends
*/
public void addOFSwitchDriver(String desc, IOFSwitchDriver driver);
/**
* Record a switch event in in-memory event history
* @param switchDPID
* @param actn Action associated with this event
* @param reason Reason for this event
*/
public void addSwitchEvent(long switchDPID, EvAction actn, String reason);
/**
* Retrieve switch event history
* @return The EventHistory object for switch events
*/
public EventHistory<EventHistorySwitch> getSwitchEventHistory();
}
......@@ -22,6 +22,7 @@ import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
......@@ -68,6 +69,7 @@ import net.floodlightcontroller.counter.ICounterStoreService;
import net.floodlightcontroller.debugcounter.IDebugCounterService;
import net.floodlightcontroller.debugcounter.IDebugCounterService.CounterType;
import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.packet.IPv4;
import net.floodlightcontroller.perfmon.IPktInProcessingTimeService;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.storage.IResultSet;
......@@ -75,7 +77,9 @@ import net.floodlightcontroller.storage.IStorageSourceListener;
import net.floodlightcontroller.storage.IStorageSourceService;
import net.floodlightcontroller.storage.StorageException;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import net.floodlightcontroller.util.EventHistory;
import net.floodlightcontroller.util.LoadMonitor;
import net.floodlightcontroller.util.EventHistory.EvAction;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipelineFactory;
......@@ -777,12 +781,15 @@ public class Controller implements IFloodlightProviderService,
private Role role;
private ConcurrentHashMap<Long,IOFSwitch> activeSwitches;
private ConcurrentHashMap<Long,IOFSwitch> syncedSwitches;
private EventHistory<EventHistorySwitch> evHistSwitch;
public SwitchManager(Role role) {
this.role = role;
this.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>();
this.syncedSwitches = new ConcurrentHashMap<Long, IOFSwitch>();
}
this.evHistSwitch = new EventHistory<EventHistorySwitch>(
EventHistory.EV_HISTORY_DEFAULT_SIZE);
}
@Override
public void keysModified(Iterator<Long> keys, UpdateType type) {
......@@ -1254,6 +1261,31 @@ public class Controller implements IFloodlightProviderService,
return sw;
return this.syncedSwitches.get(dpid);
}
public void addSwitchEvent(long dpid, EvAction actn, String reason) {
EventHistorySwitch evSwitch = new EventHistorySwitch();
evSwitch.dpid = dpid;
// NOTE: when this method is called due to switch removed event,
// floodlightProvier may not have the switch object, thus may be
// null.
IOFSwitch sw = getSwitch(dpid);
if ( sw != null &&
(SocketAddress.class.isInstance(sw.getInetAddress()))) {
evSwitch.ipv4Addr = IPv4.toIPv4Address(((InetSocketAddress)
(sw.getInetAddress())).getAddress()
.getAddress());
evSwitch.l4Port = ((InetSocketAddress)
(sw.getInetAddress())).getPort();
} else {
evSwitch.ipv4Addr = 0;
evSwitch.l4Port = 0;
}
evSwitch.reason = reason;
evSwitch = evHistSwitch.put(evSwitch, actn);
}
}
......@@ -2298,6 +2330,18 @@ public class Controller implements IFloodlightProviderService,
return driverRegistry.getOFSwitchInstance(desc);
}
/**
* Switch Added/Deleted Events
*/
@Override
public void addSwitchEvent(long switchDPID, EvAction actn, String reason) {
switchManager.addSwitchEvent(switchDPID, actn, reason);
}
@Override
public EventHistory<EventHistorySwitch> getSwitchEventHistory() {
return switchManager.evHistSwitch;
}
@LogMessageDoc(level="WARN",
message="Failure adding update {} to queue",
......@@ -2356,5 +2400,4 @@ public class Controller implements IFloodlightProviderService,
return this.switchManager;
}
}
......@@ -16,7 +16,9 @@
package net.floodlightcontroller.core.web;
import net.floodlightcontroller.core.IFloodlightProviderService;
import net.floodlightcontroller.core.internal.EventHistorySwitch;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService;
import net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager;
import net.floodlightcontroller.util.EventHistory;
......@@ -32,22 +34,12 @@ public class EventHistoryTopologySwitchResource extends ServerResource {
@Get("json")
public EventHistory<EventHistorySwitch> handleEvHistReq() {
// Get the event history count. Last <count> events would be returned
String evHistCount = (String)getRequestAttributes().get("count");
int count = EventHistory.EV_HISTORY_DEFAULT_SIZE;
try {
count = Integer.parseInt(evHistCount);
}
catch(NumberFormatException nFE) {
// Invalid input for event count - use default value
}
LinkDiscoveryManager topoManager =
(LinkDiscoveryManager)getContext().getAttributes().
get(ILinkDiscoveryService.class.getCanonicalName());
IFloodlightProviderService floodlightProvider =
(IFloodlightProviderService)getContext().getAttributes().
get(IFloodlightProviderService.class.getCanonicalName());
return new EventHistory<EventHistorySwitch>(
topoManager.evHistTopologySwitch, count);
floodlightProvider.getSwitchEventHistory(), count);
}
}
......@@ -1626,7 +1626,8 @@ public class LinkDiscoveryManager implements IOFMessageListener,
@Override
public void switchRemoved(long sw) {
// Update event history
evHistTopoSwitch(sw, EvAction.SWITCH_DISCONNECTED, "None");
floodlightProvider.addSwitchEvent(sw, EvAction.SWITCH_DISCONNECTED,
"None");
List<Link> eraseList = new ArrayList<Link>();
lock.writeLock().lock();
try {
......@@ -1667,7 +1668,8 @@ public class LinkDiscoveryManager implements IOFMessageListener,
}
}
// Update event history
evHistTopoSwitch(switchId, EvAction.SWITCH_CONNECTED, "None");
floodlightProvider.addSwitchEvent(switchId, EvAction.SWITCH_CONNECTED,
"None");
LDUpdate update = new LDUpdate(sw.getId(), null,
UpdateOperation.SWITCH_UPDATED);
updates.add(update);
......@@ -1992,7 +1994,6 @@ public class LinkDiscoveryManager implements IOFMessageListener,
this.quarantineQueue = new LinkedBlockingQueue<NodePortTuple>();
this.maintenanceQueue = new LinkedBlockingQueue<NodePortTuple>();
this.evHistTopologySwitch = new EventHistory<EventHistorySwitch>(EVENT_HISTORY_SIZE);
this.evHistTopologyLink = new EventHistory<EventHistoryTopologyLink>(EVENT_HISTORY_SIZE);
this.evHistTopologyCluster = new EventHistory<EventHistoryTopologyCluster>(EVENT_HISTORY_SIZE);
this.ignoreMACSet = Collections.newSetFromMap(
......@@ -2152,40 +2153,11 @@ public class LinkDiscoveryManager implements IOFMessageListener,
/**
* Topology Manager event history
*/
public EventHistory<EventHistorySwitch> evHistTopologySwitch;
public EventHistory<EventHistoryTopologyLink> evHistTopologyLink;
public EventHistory<EventHistoryTopologyCluster> evHistTopologyCluster;
public EventHistorySwitch evTopoSwitch;
public EventHistoryTopologyLink evTopoLink;
public EventHistoryTopologyCluster evTopoCluster;
/**
* Switch Added/Deleted Events
*/
private void evHistTopoSwitch(long switchDPID, EvAction actn, String reason) {
if (evTopoSwitch == null) {
evTopoSwitch = new EventHistorySwitch();
}
evTopoSwitch.dpid = switchDPID;
// NOTE: when this method is called due to switch removed event,
// floodlightProvier may not have the switch object, thus may be
// null.
IOFSwitch sw = floodlightProvider.getSwitch(switchDPID);
if ( sw != null &&
(SocketAddress.class.isInstance(sw.getInetAddress()))) {
evTopoSwitch.ipv4Addr = IPv4.toIPv4Address(((InetSocketAddress) (sw.getInetAddress())).getAddress()
.getAddress());
evTopoSwitch.l4Port = ((InetSocketAddress) (sw.getInetAddress())).getPort();
} else {
evTopoSwitch.ipv4Addr = 0;
evTopoSwitch.l4Port = 0;
}
evTopoSwitch.reason = reason;
evTopoSwitch = evHistTopologySwitch.put(evTopoSwitch, actn);
}
private void evHistTopoLink(long srcDpid, long dstDpid, short srcPort,
short dstPort, int srcPortState,
int dstPortState,
......
......@@ -45,12 +45,15 @@ import net.floodlightcontroller.core.IOFSwitchListener;
import net.floodlightcontroller.core.IListener.Command;
import net.floodlightcontroller.core.IReadyForReconcileListener;
import net.floodlightcontroller.core.RoleInfo;
import net.floodlightcontroller.core.internal.EventHistorySwitch;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.core.util.ListenerDispatcher;
import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.util.EventHistory;
import net.floodlightcontroller.util.EventHistory.EvAction;
import org.openflow.protocol.OFMessage;
import org.openflow.protocol.OFPacketIn;
......@@ -402,4 +405,15 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro
public void addReadyForReconcileListener(IReadyForReconcileListener l) {
// do nothing.
}
@Override
public void addSwitchEvent(long switchDPID, EvAction actn, String reason) {
// TODO Auto-generated method stub
}
@Override
public EventHistory<EventHistorySwitch> getSwitchEventHistory() {
// TODO Auto-generated method stub
return null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment