diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java index 96fe14eb827f3479db6af672a007d8c5ec036ed1..c0aa1fd6d5faa9426c7580d7e02fc685c0a96021 100644 --- a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java @@ -23,11 +23,8 @@ 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; @@ -59,7 +56,7 @@ public interface IFloodlightProviderService extends MASTER(OFRoleVendorData.NX_ROLE_MASTER), SLAVE(OFRoleVendorData.NX_ROLE_SLAVE); - private int nxRole; + private final int nxRole; private Role(int nxRole) { this.nxRole = nxRole; @@ -308,18 +305,12 @@ public interface IFloodlightProviderService extends public void addOFSwitchDriver(String desc, IOFSwitchDriver driver); /** - * Record a switch event in in-memory event history + * Record a switch event in in-memory debug-event * @param switchDPID - * @param actn Action associated with this event * @param reason Reason for this event + * @param flushNow see debug-event flushing in IDebugEventService */ - public void addSwitchEvent(long switchDPID, EvAction actn, String reason); - - /** - * Retrieve switch event history - * @return The EventHistory object for switch events - */ - public EventHistory<EventHistorySwitch> getSwitchEventHistory(); + public void addSwitchEvent(long switchDPID, String reason, boolean flushNow); /** * Get the set of port prefixes that will define an UPLINK port. diff --git a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java index deb838e8bbb676d676fbbcb57b9e63099e309287..84c5099f6b159ca743994d60f08c1eb5c5b48e13 100644 --- a/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java +++ b/src/main/java/net/floodlightcontroller/core/OFSwitchBase.java @@ -51,7 +51,6 @@ import net.floodlightcontroller.devicemanager.SwitchPort; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.routing.ForwardingBase; import net.floodlightcontroller.threadpool.IThreadPoolService; -import net.floodlightcontroller.util.EventHistory.EvAction; import net.floodlightcontroller.util.LinkedHashSetWrapper; import net.floodlightcontroller.util.MACAddress; import net.floodlightcontroller.util.OrderedCollection; @@ -1020,14 +1019,14 @@ public abstract class OFSwitchBase implements IOFSwitch { new Object[] { this.stringId, activeCount, maxEntry}); int percentFull = activeCount * 100 / maxEntry; if (flowTableFull && percentFull < 90) { - log.info("Switch {} flow table is capacity is back to normal", + log.info("Switch {} flow table capacity is back to normal", toString()); floodlightProvider.addSwitchEvent(this.datapathId, - EvAction.SWITCH_FLOW_TABLE_NORMAL, "< 90% full"); + "SWITCH_FLOW_TABLE_NORMAL < 90% full", false); } else if (percentFull >= 98) { log.info("Switch {} flow table is almost full", toString()); floodlightProvider.addSwitchEvent(this.datapathId, - EvAction.SWITCH_FLOW_TABLE_ALMOST_FULL, ">= 98% full"); + "SWITCH_FLOW_TABLE_ALMOST_FULL >= 98% full", false); } } } @@ -1377,7 +1376,7 @@ public abstract class OFSwitchBase implements IOFSwitch { /** * We rely on the fact that packet in processing is single threaded - * per switch, so no locking is necessary. + * per packet-in, so no locking is necessary. */ private void disablePacketInThrottle() { ofMatchCache = null; @@ -1387,8 +1386,8 @@ public abstract class OFSwitchBase implements IOFSwitch { portBlockedCache = null; packetInThrottleEnabled = false; floodlightProvider.addSwitchEvent(this.datapathId, - EvAction.SWITCH_OVERLOAD_THROTTLE_DISABLED, - "Pktin rate " + currentRate + "/s"); + "SWITCH_OVERLOAD_THROTTLE_DISABLED ==>" + + "Pktin rate " + currentRate + "/s", false); log.info("Packet in rate is {}, disable throttling on {}", currentRate, this); } @@ -1402,8 +1401,8 @@ public abstract class OFSwitchBase implements IOFSwitch { packetInThrottleEnabled = true; messageCountUniqueOFMatch = 0; floodlightProvider.addSwitchEvent(this.datapathId, - EvAction.SWITCH_OVERLOAD_THROTTLE_ENABLED, - "Pktin rate " + currentRate + "/s"); + "SWITCH_OVERLOAD_THROTTLE_ENABLED ==>" + + "Pktin rate " + currentRate + "/s", false); log.info("Packet in rate is {}, enable throttling on {}", currentRate, this); } @@ -1472,8 +1471,8 @@ public abstract class OFSwitchBase implements IOFSwitch { swPort, srcMac.toLong(), (short) 5, AppCookie.makeCookie(OFSWITCH_APP_ID, 0)); floodlightProvider.addSwitchEvent(this.datapathId, - EvAction.SWITCH_PORT_BLOCKED_TEMPORARILY, - "OFPort " + port + " mac " + srcMac); + "SWITCH_PORT_BLOCKED_TEMPORARILY " + + "OFPort " + port + " mac " + srcMac, false); log.info("Excessive packet in from {} on {}, block host for 5 sec", srcMac.toString(), swPort); } @@ -1500,8 +1499,8 @@ public abstract class OFSwitchBase implements IOFSwitch { swPort, -1L, (short) 5, AppCookie.makeCookie(OFSWITCH_APP_ID, 1)); floodlightProvider.addSwitchEvent(this.datapathId, - EvAction.SWITCH_PORT_BLOCKED_TEMPORARILY, - "OFPort " + port); + "SWITCH_PORT_BLOCKED_TEMPORARILY " + + "OFPort " + port, false); log.info("Excessive packet in from {}, block port for 5 sec", swPort); } @@ -1518,8 +1517,8 @@ public abstract class OFSwitchBase implements IOFSwitch { public void setTableFull(boolean isFull) { if (isFull && !flowTableFull) { floodlightProvider.addSwitchEvent(this.datapathId, - EvAction.SWITCH_FLOW_TABLE_FULL, - "Table full error from switch"); + "SWITCH_FLOW_TABLE_FULL " + + "Table full error from switch", false); log.warn("Switch {} flow table is full", stringId); } flowTableFull = isFull; diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index fd6c35865ebb9b24127509b6375d367aeae0f71b..3340e0664b324d0a735e05d4cc6271451207cde5 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -22,7 +22,6 @@ 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.Collection; import java.util.Arrays; @@ -84,7 +83,6 @@ import net.floodlightcontroller.debugevent.IDebugEventService.MaxEventsRegistere import net.floodlightcontroller.notification.INotificationManager; import net.floodlightcontroller.notification.NotificationManagerFactory; 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; @@ -92,9 +90,7 @@ 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 net.floodlightcontroller.util.TimedCache; import org.jboss.netty.bootstrap.ServerBootstrap; @@ -910,14 +906,11 @@ public class Controller implements IFloodlightProviderService, private Role role; private final ConcurrentHashMap<Long,IOFSwitch> activeSwitches; private final ConcurrentHashMap<Long,IOFSwitch> syncedSwitches; - private final 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 @@ -1018,7 +1011,6 @@ public class Controller implements IFloodlightProviderService, counters.switchActivated.updateCounterWithFlush(); IOFSwitch oldSw = this.activeSwitches.put(dpid, sw); // Update event history - addSwitchEvent(dpid, EvAction.SWITCH_CONNECTED, "None"); evSwitch.updateEventWithFlush(new SwitchEvent(dpid, "connected")); if (oldSw == sw) { @@ -1197,7 +1189,6 @@ public class Controller implements IFloodlightProviderService, // TODO: this is asymmetric with respect to connect event // in switchActivated(). Should we have events on the // slave as well? - addSwitchEvent(dpid, EvAction.SWITCH_DISCONNECTED, "None"); evSwitch.updateEventWithFlush(new SwitchEvent(dpid, "disconnected")); counters.switchDisconnected.updateCounterWithFlush(); IOFSwitch oldSw = this.activeSwitches.get(dpid); @@ -1424,28 +1415,11 @@ public class Controller implements IFloodlightProviderService, 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); + public void addSwitchEvent(long dpid, String reason, boolean flushNow) { + if (flushNow) + evSwitch.updateEventWithFlush(new SwitchEvent(dpid, reason)); + else + evSwitch.updateEventNoFlush(new SwitchEvent(dpid, reason)); } } @@ -2637,13 +2611,8 @@ public class Controller implements IFloodlightProviderService, * 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; + public void addSwitchEvent(long switchDPID, String reason, boolean flushNow) { + switchManager.addSwitchEvent(switchDPID, reason, flushNow); } @LogMessageDoc(level="WARN", diff --git a/src/main/java/net/floodlightcontroller/core/internal/EventHistorySwitch.java b/src/main/java/net/floodlightcontroller/core/internal/EventHistorySwitch.java deleted file mode 100644 index 0ce64bf9ec91d927f6961e5f40285452d35e64b8..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/core/internal/EventHistorySwitch.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.core.internal; - -import net.floodlightcontroller.core.web.serializers.DPIDSerializer; -import net.floodlightcontroller.core.web.serializers.IPv4Serializer; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -/*** - * Topology Switch event history related classes and members - * @author subrata - * - */ -public class EventHistorySwitch { - // The following fields are not stored as String to save memory - // They should be converted to appropriate human-readable strings by - // the front end (e.g. in cli in Python) - public long dpid; - public int ipv4Addr; - public int l4Port; - public String reason; - - @JsonProperty("Switch") - @JsonSerialize(using=DPIDSerializer.class) - public long getDpid() { - return dpid; - } - @JsonProperty("IpAddr") - @JsonSerialize(using=IPv4Serializer.class) - public int getIpv4Addr() { - return ipv4Addr; - } - @JsonProperty("Port") - public int getL4Port() { - return l4Port; - } - @JsonProperty("Reason") - public String getReason() { - return reason; - } -} diff --git a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java index 069925b5e38a6a33b1487eb09a635dfb2ed1ab64..a4fe5d657184b8ce479d15887227f0f725fa04b8 100644 --- a/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java +++ b/src/main/java/net/floodlightcontroller/core/web/CoreWebRoutable.java @@ -48,13 +48,6 @@ public class CoreWebRoutable implements RestletRoutable { router.attach("/counter/categories/{switchId}/{counterName}/{layer}/json", SwitchCounterCategoriesResource.class); router.attach("/memory/json", ControllerMemoryResource.class); router.attach("/packettrace/json", PacketTraceResource.class); - // Get the last {count} events from the event histories - router.attach("/event-history/topology-switch/{count}/json", - EventHistoryTopologySwitchResource.class); - router.attach("/event-history/topology-link/{count}/json", - EventHistoryTopologyLinkResource.class); - router.attach("/event-history/topology-cluster/{count}/json", - EventHistoryTopologyClusterResource.class); router.attach("/storage/tables/json", StorageSourceTablesResource.class); router.attach("/controller/summary/json", ControllerSummaryResource.class); router.attach("/role/json", ControllerRoleResource.class); diff --git a/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologyClusterResource.java b/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologyClusterResource.java deleted file mode 100644 index 9c3768dd2878443cf76bec2611d78c847310d649..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologyClusterResource.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.core.web; - -import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService; -import net.floodlightcontroller.linkdiscovery.internal.EventHistoryTopologyCluster; -import net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager; -import net.floodlightcontroller.util.EventHistory; - -import org.restlet.resource.Get; -import org.restlet.resource.ServerResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author subrata - * - */ -public class EventHistoryTopologyClusterResource extends ServerResource { - // TODO - Move this to the LinkDiscovery rest API - protected static Logger log = - LoggerFactory.getLogger(EventHistoryTopologyClusterResource.class); - - @Get("json") - public EventHistory<EventHistoryTopologyCluster> 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()); - if (topoManager != null) { - return new EventHistory<EventHistoryTopologyCluster>( - topoManager.evHistTopologyCluster, count); - } - - return null; - } -} diff --git a/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologyLinkResource.java b/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologyLinkResource.java deleted file mode 100644 index da611b026e51fee8def40cff8a0d7183cad6bf77..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologyLinkResource.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.core.web; - -import net.floodlightcontroller.linkdiscovery.ILinkDiscoveryService; -import net.floodlightcontroller.linkdiscovery.internal.EventHistoryTopologyLink; -import net.floodlightcontroller.linkdiscovery.internal.LinkDiscoveryManager; -import net.floodlightcontroller.util.EventHistory; - -import org.restlet.resource.Get; -import org.restlet.resource.ServerResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author subrata - * - */ -public class EventHistoryTopologyLinkResource extends ServerResource { - // TODO - Move this to the DeviceManager Rest API - protected static Logger log = - LoggerFactory.getLogger(EventHistoryTopologyLinkResource.class); - - @Get("json") - public EventHistory<EventHistoryTopologyLink> 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 linkDiscoveryManager = - (LinkDiscoveryManager)getContext().getAttributes(). - get(ILinkDiscoveryService.class.getCanonicalName()); - if (linkDiscoveryManager != null) { - return new EventHistory<EventHistoryTopologyLink>( - linkDiscoveryManager.evHistTopologyLink, count); - } - - return null; - } -} diff --git a/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologySwitchResource.java b/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologySwitchResource.java deleted file mode 100644 index 73a4308c4024c3a24d21575132344d85fbcdc832..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/core/web/EventHistoryTopologySwitchResource.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.core.web; - -import net.floodlightcontroller.core.IFloodlightProviderService; -import net.floodlightcontroller.core.internal.EventHistorySwitch; -import net.floodlightcontroller.util.EventHistory; - -import org.restlet.resource.Get; -import org.restlet.resource.ServerResource; - -/** - * @author subrata - * - */ -public class EventHistoryTopologySwitchResource extends ServerResource { - - @Get("json") - public EventHistory<EventHistorySwitch> handleEvHistReq() { - int count = EventHistory.EV_HISTORY_DEFAULT_SIZE; - IFloodlightProviderService floodlightProvider = - (IFloodlightProviderService)getContext().getAttributes(). - get(IFloodlightProviderService.class.getCanonicalName()); - - return new EventHistory<EventHistorySwitch>( - floodlightProvider.getSwitchEventHistory(), count); - } -} diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/EventHistoryTopologyCluster.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/EventHistoryTopologyCluster.java deleted file mode 100644 index 5cfabd821f167bfb0d112323de301bfb24991398..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/EventHistoryTopologyCluster.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.linkdiscovery.internal; - -import net.floodlightcontroller.core.web.serializers.DPIDSerializer; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -/*** - * Topology Cluster merge/split event history related classes and members - * @author subrata - * - */ -public class EventHistoryTopologyCluster { - // The following fields are not stored as String to save memory - // They should be converted to appropriate human-readable strings by - // the front end (e.g. in cli in Python) - public long dpid; - public long clusterIdOld; // Switch with dpid moved from cluster x to y - public long clusterIdNew; - public String reason; - - @JsonProperty("Switch") - @JsonSerialize(using=DPIDSerializer.class) - public long getDpid() { - return dpid; - } - @JsonProperty("OldClusterId") - @JsonSerialize(using=DPIDSerializer.class) - public long getClusterIdOld() { - return clusterIdOld; - } - @JsonProperty("NewClusterId") - @JsonSerialize(using=DPIDSerializer.class) - public long getClusterIdNew() { - return clusterIdNew; - } - @JsonProperty("Reason") - public String getReason() { - return reason; - } - - -} diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/EventHistoryTopologyLink.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/EventHistoryTopologyLink.java deleted file mode 100644 index 63fea03499118609b6c87ec22c936c4ed48d06db..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/EventHistoryTopologyLink.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.linkdiscovery.internal; - -import net.floodlightcontroller.core.web.serializers.DPIDSerializer; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -/*** - * Topology link up/down event history related classes and members - * @author subrata - * - */ -public class EventHistoryTopologyLink { - // The following fields are not stored as String to save memory - // They should be converted to appropriate human-readable strings by - // the front end (e.g. in cli in Python) - public long srcSwDpid; - public long dstSwDpid; - public int srcSwport; - public int dstSwport; - public String linkType; - public String reason; - - @JsonProperty("Source-Switch") - @JsonSerialize(using=DPIDSerializer.class) - public long getSrcSwDpid() { - return srcSwDpid; - } - @JsonProperty("Dest-Switch") - @JsonSerialize(using=DPIDSerializer.class) - public long getDstSwDpid() { - return dstSwDpid; - } - @JsonProperty("SrcPort") - public int getSrcSwport() { - return srcSwport; - } - @JsonProperty("DstPort") - public int getDstSwport() { - return dstSwport; - } - @JsonProperty("LinkType") - public String getLinkType() { - return linkType; - } - @JsonProperty("Reason") - public String getReason() { - return reason; - } - - -} diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java index 6231f837b043c68f9ea604f64139a008eaf56ee8..ec0d4a074f2a3f0f684aee70397a4c9a38529328 100644 --- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java +++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java @@ -94,8 +94,6 @@ import net.floodlightcontroller.storage.OperatorPredicate; import net.floodlightcontroller.storage.StorageException; import net.floodlightcontroller.threadpool.IThreadPoolService; import net.floodlightcontroller.topology.NodePortTuple; -import net.floodlightcontroller.util.EventHistory; -import net.floodlightcontroller.util.EventHistory.EvAction; import org.openflow.protocol.OFMessage; import org.openflow.protocol.OFPacketIn; @@ -1339,12 +1337,8 @@ public class LinkDiscoveryManager implements IOFMessageListener, if (linkType == ILinkDiscovery.LinkType.DIRECT_LINK) { log.info("Inter-switch link detected: {}", lt); evDirectLink.updateEventNoFlush(new DirectLinkEvent(lt.getSrc(), - lt.getSrcPort(), lt.getDst(), lt.getDstPort(), "link-added")); + lt.getSrcPort(), lt.getDst(), lt.getDstPort(), "direct-link-added::rcvd LLDP")); } - evHistTopoLink(lt.getSrc(), lt.getDst(), lt.getSrcPort(), - lt.getDstPort(), - linkType, - EvAction.LINK_ADDED, "LLDP Recvd"); notifier.postNotification("Link added: " + lt.toString()); } else { linkChanged = updateLink(lt, oldInfo, newInfo); @@ -1354,14 +1348,9 @@ public class LinkDiscoveryManager implements IOFMessageListener, if (linkType == ILinkDiscovery.LinkType.DIRECT_LINK) { log.info("Inter-switch link updated: {}", lt); evDirectLink.updateEventNoFlush(new DirectLinkEvent(lt.getSrc(), - lt.getSrcPort(), lt.getDst(), lt.getDstPort(), "link-updated")); + lt.getSrcPort(), lt.getDst(), lt.getDstPort(), + "link-port-state-updated::rcvd LLDP")); } - // Add to event history - evHistTopoLink(lt.getSrc(), lt.getDst(), - lt.getSrcPort(), lt.getDstPort(), - linkType, - EvAction.LINK_PORT_STATE_UPDATED, - "LLDP Recvd"); notifier.postNotification("Link updated: " + lt.toString()); } } @@ -1461,15 +1450,11 @@ public class LinkDiscoveryManager implements IOFMessageListener, linkType, UpdateOperation.LINK_REMOVED)); - // Update Event History - evHistTopoLink(lt.getSrc(), lt.getDst(), lt.getSrcPort(), - lt.getDstPort(), - ILinkDiscovery.LinkType.INVALID_LINK, - EvAction.LINK_DELETED, reason); - // link type shows up as invalid now -- thus not checking if + // FIXME: link type shows up as invalid now -- thus not checking if // link type is a direct link evDirectLink.updateEventWithFlush(new DirectLinkEvent(lt.getSrc(), - lt.getSrcPort(), lt.getDst(), lt.getDstPort(), "link-removed")); + lt.getSrcPort(), lt.getDst(), lt.getDstPort(), + "link-deleted::" + reason)); // remove link from storage. removeLinkFromStorage(lt); @@ -1997,8 +1982,6 @@ public class LinkDiscoveryManager implements IOFMessageListener, this.quarantineQueue = new LinkedBlockingQueue<NodePortTuple>(); this.maintenanceQueue = new LinkedBlockingQueue<NodePortTuple>(); - this.evHistTopologyLink = new EventHistory<EventHistoryTopologyLink>(EVENT_HISTORY_SIZE); - this.evHistTopologyCluster = new EventHistory<EventHistoryTopologyCluster>(EVENT_HISTORY_SIZE); this.ignoreMACSet = Collections.newSetFromMap( new ConcurrentHashMap<MACRange,Boolean>()); this.haListener = new HAListenerDelegate(); @@ -2199,60 +2182,6 @@ public class LinkDiscoveryManager implements IOFMessageListener, } } - // **************************************************** - // Topology Manager's Event History members and methods - // **************************************************** - - /** - * Topology Manager event history - */ - public EventHistory<EventHistoryTopologyLink> evHistTopologyLink; - public EventHistory<EventHistoryTopologyCluster> evHistTopologyCluster; - public EventHistoryTopologyLink evTopoLink; - public EventHistoryTopologyCluster evTopoCluster; - - private void evHistTopoLink(long srcDpid, long dstDpid, short srcPort, - short dstPort, - ILinkDiscovery.LinkType linkType, - EvAction actn, String reason) { - if (evTopoLink == null) { - evTopoLink = new EventHistoryTopologyLink(); - } - evTopoLink.srcSwDpid = srcDpid; - evTopoLink.dstSwDpid = dstDpid; - evTopoLink.srcSwport = srcPort & 0xffff; - evTopoLink.dstSwport = dstPort & 0xffff; - evTopoLink.reason = reason; - switch (linkType) { - case DIRECT_LINK: - evTopoLink.linkType = "DIRECT_LINK"; - break; - case MULTIHOP_LINK: - evTopoLink.linkType = "MULTIHOP_LINK"; - break; - case TUNNEL: - evTopoLink.linkType = "TUNNEL"; - break; - case INVALID_LINK: - default: - evTopoLink.linkType = "Unknown"; - break; - } - evTopoLink = evHistTopologyLink.put(evTopoLink, actn); - } - - public void evHistTopoCluster(long dpid, long clusterIdOld, - long clusterIdNew, EvAction action, - String reason) { - if (evTopoCluster == null) { - evTopoCluster = new EventHistoryTopologyCluster(); - } - evTopoCluster.dpid = dpid; - evTopoCluster.clusterIdOld = clusterIdOld; - evTopoCluster.clusterIdNew = clusterIdNew; - evTopoCluster.reason = reason; - evTopoCluster = evHistTopologyCluster.put(evTopoCluster, action); - } //********************* // IInfoProvider diff --git a/src/main/java/net/floodlightcontroller/util/EventHistory.java b/src/main/java/net/floodlightcontroller/util/EventHistory.java deleted file mode 100644 index 5de326ce875057b33c76004b270afe8e78cbc76a..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/util/EventHistory.java +++ /dev/null @@ -1,190 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.util; - -import java.util.ArrayList; - -/** - * @author subrata - * - */ - -public class EventHistory<T> { - public static final int EV_HISTORY_DEFAULT_SIZE = 1024; - - public int event_history_size; - public int current_index; - public boolean full; // true if all are in use - public ArrayList<Event> events; - - public int getEvent_history_size() { - return event_history_size; - } - public int getCurrent_index() { - return current_index; - } - public boolean isFull() { - return full; - } - public ArrayList<Event> getEvents() { - return events; - } - - public class Event { - public EventHistoryBaseInfo base_info; - public T info; - } - - public enum EvState { - FREE, // no valid event written yet - BEING_MODIFIED, // event is being updated with new value, skip - ACTIVE, // event is active and can be displayed - } - - public enum EvAction { - ADDED, // specific entry added - REMOVED, // specific entry removed - UPDATED, // Entry updated - BLOCKED, // Blocked - used for Attachment Points - UNBLOCKED, - CLEARED, // All entries are removed - PKT_IN, - PKT_OUT, - SWITCH_CONNECTED, - SWITCH_DISCONNECTED, - LINK_ADDED, - LINK_DELETED, - LINK_PORT_STATE_UPDATED, - CLUSTER_ID_CHANGED_FOR_CLUSTER, - CLUSTER_ID_CHANGED_FOR_A_SWITCH, - SWITCH_OVERLOAD_THROTTLE_ENABLED, - SWITCH_OVERLOAD_THROTTLE_DISABLED, - SWITCH_PORT_BLOCKED_TEMPORARILY, - SWITCH_FLOW_TABLE_FULL, - SWITCH_FLOW_TABLE_ALMOST_FULL, - SWITCH_FLOW_TABLE_NORMAL, - } - - // Constructor - public EventHistory(int maxEvents) { - events = new ArrayList<Event>(maxEvents); - - for (int idx = 0; idx < maxEvents; idx++) { - Event evH = new Event(); - evH.base_info = new EventHistoryBaseInfo(); - evH.info = null; - evH.base_info.state = EvState.FREE; - evH.base_info.idx = idx; - events.add(idx, evH); - } - - event_history_size = maxEvents; - current_index = 0; - full = false; - } - - // Constructor for default size - public EventHistory() { - this(EV_HISTORY_DEFAULT_SIZE); - } - - // Copy constructor - copy latest k items of the event history - public EventHistory(EventHistory<T> eventHist, int latestK) { - if (eventHist == null) { - return; - } - int curSize = (eventHist.full)?eventHist.event_history_size: - eventHist.current_index; - int size = (latestK < curSize)?latestK:curSize; - int evIdx = eventHist.current_index; - int topSz = (evIdx >= size)?size:evIdx; - - // Need to create a new one since size is different - events = new ArrayList<Event>(size); - - // Get the top part - int origIdx = evIdx; - for (int idx = 0; idx < topSz; idx++) { - Event evH = eventHist.events.get(--origIdx); - evH.base_info.idx = idx; - events.add(idx, evH); - } - - // Get the bottom part - origIdx = eventHist.event_history_size; - for (int idx = topSz; idx < size; idx++) { - Event evH = eventHist.events.get(--origIdx); - evH.base_info.idx = idx; - events.add(idx, evH); - } - - event_history_size = size; - current_index = 0; // since it is full - full = true; - } - - // Get an index for writing a new event. This method is synchronized for - // this event history infra. to be thread-safe. Once the index is obtained - // by the caller event at the index is updated without any lock - public synchronized int NextIdx() { - // curIdx should be in the 0 to evArraySz-1 - if (current_index == (event_history_size-1)) { - current_index = 0; - full = true; - return (event_history_size-1); - } else { - current_index++; - return (current_index-1); - } - } - - /** - * Add an event to the event history - * Eliminate java garbage cration by reusing the same object T - * Supplied object t is used to populate the event history array - * and the current object at that array location is returned to the - * calling process so that the calling process can use that object - * for the next event of the same type - * @param t - * @param op - * @return - */ - - public T put(T t, EvAction action) { - int idx = NextIdx(); - Event evH = events.get(idx); - evH.base_info.state = EvState.BEING_MODIFIED; - evH.base_info.time_ms = System.currentTimeMillis(); - evH.base_info.action = action; - T temp = evH.info; - evH.info = t; - evH.base_info.state = EvState.ACTIVE; - return temp; - } - - /*** - * Clear the event history, needs to be done under lock - */ - public void clear() { - for (int idx = 0; idx < event_history_size; idx++) { - Event evH = events.get(idx); - evH.base_info.state = EvState.FREE; - current_index = 0; - full = false; - } - } -} diff --git a/src/main/java/net/floodlightcontroller/util/EventHistoryBaseInfo.java b/src/main/java/net/floodlightcontroller/util/EventHistoryBaseInfo.java deleted file mode 100644 index 8568d0d576484361db2ab45f8f2d091e34ebec10..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/util/EventHistoryBaseInfo.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2013, Big Switch Networks, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - **/ - -package net.floodlightcontroller.util; - -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -@JsonSerialize(using=EventHistoryBaseInfoJSONSerializer.class) -public class EventHistoryBaseInfo { - public int idx; - public long time_ms; // timestamp in milliseconds - public EventHistory.EvState state; - public EventHistory.EvAction action; - - // Getters - public int getIdx() { - return idx; - } - public long getTime_ms() { - return time_ms; - } - public EventHistory.EvState getState() { - return state; - } - public EventHistory.EvAction getAction() { - return action; - } -} \ No newline at end of file diff --git a/src/main/java/net/floodlightcontroller/util/EventHistoryBaseInfoJSONSerializer.java b/src/main/java/net/floodlightcontroller/util/EventHistoryBaseInfoJSONSerializer.java deleted file mode 100644 index ad14372607371e0aa70357092b02430b7b99651d..0000000000000000000000000000000000000000 --- a/src/main/java/net/floodlightcontroller/util/EventHistoryBaseInfoJSONSerializer.java +++ /dev/null @@ -1,69 +0,0 @@ -/** -* Copyright 2011, Big Switch Networks, Inc. -* -* Licensed under the Apache License, Version 2.0 (the "License"); you may -* not use this file except in compliance with the License. You may obtain -* a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -* License for the specific language governing permissions and limitations -* under the License. -**/ - -package net.floodlightcontroller.util; - -import java.io.IOException; - -import java.sql.Timestamp; - - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; - - -/** - * @author subrata - * - */ - -public class EventHistoryBaseInfoJSONSerializer extends - JsonSerializer<EventHistoryBaseInfo> { - - - /** - * Performs the serialization of a EventHistory.BaseInfo object - */ - @Override - public void serialize(EventHistoryBaseInfo base_info, JsonGenerator jGen, - SerializerProvider serializer) - throws IOException, JsonProcessingException { - jGen.writeStartObject(); - jGen.writeNumberField("Idx", base_info.getIdx()); - Timestamp ts = new Timestamp(base_info.getTime_ms()); - String tsStr = ts.toString(); - while (tsStr.length() < 23) { - tsStr = tsStr.concat("0"); - } - jGen.writeStringField("Time", tsStr); - jGen.writeStringField("State", base_info.getState().name()); - String acStr = base_info.getAction().name().toLowerCase(); - // Capitalize the first letter - acStr = acStr.substring(0,1).toUpperCase().concat(acStr.substring(1)); - jGen.writeStringField("Action", acStr); - jGen.writeEndObject(); - } - - /** - * Tells SimpleModule that we are the serializer for OFMatch - */ - @Override - public Class<EventHistoryBaseInfo> handledType() { - return EventHistoryBaseInfo.class; - } -} diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index 14567fdb0561778317c0a1b02a8664ba04fdf429..b06589a30a6493bd22d7da347a7bab7e6d4fd642 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -1832,7 +1832,6 @@ public class ControllerTest extends FloodlightTestCase { IOFSwitch sw = doActivateNewSwitch(1L, null, null); expect(sw.getId()).andReturn(1L).anyTimes(); expect(sw.getStringId()).andReturn(HexString.toHexString(1L)).anyTimes(); - expect(sw.getInetAddress()).andReturn(null).once(); sw.cancelAllStatisticsReplies(); expectLastCall().once(); IOFSwitchListener listener = createMock(IOFSwitchListener.class); diff --git a/src/test/java/net/floodlightcontroller/core/internal/OFSwitchBaseTest.java b/src/test/java/net/floodlightcontroller/core/internal/OFSwitchBaseTest.java index 51891b1c492afe3b102d6c7d4b37b5b76c2d60be..2899d44400ad49663c009ede80e5141cebff077e 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/OFSwitchBaseTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/OFSwitchBaseTest.java @@ -43,7 +43,6 @@ import net.floodlightcontroller.packet.ARP; import net.floodlightcontroller.packet.Ethernet; import net.floodlightcontroller.packet.IPacket; import net.floodlightcontroller.packet.IPv4; -import net.floodlightcontroller.util.EventHistory.EvAction; import org.junit.Before; import org.junit.Test; @@ -241,8 +240,7 @@ public class OFSwitchBaseTest { @Test public void testPacketInStartThrottle() { floodlightProvider.addSwitchEvent(anyLong(), - (EvAction) anyObject(), - (String)anyObject()); + (String)anyObject(), anyBoolean()); replay(floodlightProvider); int high = 500; @@ -266,8 +264,7 @@ public class OFSwitchBaseTest { @Test public void testPacketInStopThrottle() throws InterruptedException { floodlightProvider.addSwitchEvent(anyLong(), - (EvAction) anyObject(), - (String)anyObject()); + (String)anyObject(), anyBoolean()); expectLastCall().times(2); replay(floodlightProvider); @@ -297,8 +294,7 @@ public class OFSwitchBaseTest { @Test public void testPacketInBlockHost() { floodlightProvider.addSwitchEvent(anyLong(), - (EvAction) anyObject(), - (String)anyObject()); + (String)anyObject(), anyBoolean()); expectLastCall().times(2); replay(floodlightProvider); @@ -345,8 +341,7 @@ public class OFSwitchBaseTest { @Test public void testPacketInBlockPort() { floodlightProvider.addSwitchEvent(anyLong(), - (EvAction) anyObject(), - (String)anyObject()); + (String)anyObject(), anyBoolean()); expectLastCall().times(2); replay(floodlightProvider); diff --git a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java index 7743fc92d96098ff0369a862705ed3bbf2eb1dc5..92e082b740c276bee6de2e19c3288783a76e387d 100644 --- a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java +++ b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java @@ -45,15 +45,12 @@ 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; @@ -407,16 +404,10 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro } @Override - public void addSwitchEvent(long switchDPID, EvAction actn, String reason) { + public void addSwitchEvent(long switchDPID, String reason, boolean flushNow) { // TODO Auto-generated method stub } - @Override - public EventHistory<EventHistorySwitch> getSwitchEventHistory() { - // TODO Auto-generated method stub - return null; - } - @Override public Set<String> getUplinkPortPrefixSet() { // TODO Auto-generated method stub