diff --git a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java index 7f9ff596ad0ab785fa33660c55512ef6d94fd37e..683e0dee8436e941e5663378d3e352f38cafafc9 100644 --- a/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java +++ b/src/main/java/net/floodlightcontroller/core/IFloodlightProviderService.java @@ -211,6 +211,17 @@ public interface IFloodlightProviderService extends */ public void setAlwaysClearFlowsOnSwAdd(boolean value); + /** + * Get controller memory information + */ + public Map<String, Long> getMemory(); + + /** + * returns the uptime of this controller. + * @return + */ + public Long getUptime(); + /** * Adds an OFSwitch driver * @param desc The starting portion of switch's manufacturer string diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index db0e2e87be822d5855bff33897e046428305a419..104b1d26eb3de013d52c5048c285d9f390279cc0 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -19,6 +19,8 @@ package net.floodlightcontroller.core.internal; import java.io.FileInputStream; import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; import java.util.ArrayList; @@ -199,9 +201,6 @@ public class Controller implements IFloodlightProviderService, protected RoleChanger roleChanger; protected SingletonTask roleChangeDamper; - // Start time of the controller - protected long systemStartTime; - // Flag to always flush flow table on switch reconnect (HA or otherwise) protected boolean alwaysClearFlowsOnSwAdd = false; @@ -1791,7 +1790,6 @@ public class Controller implements IFloodlightProviderService, this.notifiedRole = this.role; this.roleChanger = new RoleChanger(this); initVendorMessages(); - this.systemStartTime = System.currentTimeMillis(); String option = configParams.get("flushSwitchesOnReconnect"); @@ -1972,7 +1970,8 @@ public class Controller implements IFloodlightProviderService, @Override public long getSystemStartTime() { - return (this.systemStartTime); + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); + return rb.getStartTime(); } @Override @@ -1984,6 +1983,21 @@ public class Controller implements IFloodlightProviderService, return this.alwaysClearFlowsOnSwAdd; } + @Override + public Map<String, Long> getMemory() { + Map<String, Long> m = new HashMap<String, Long>(); + Runtime runtime = Runtime.getRuntime(); + m.put("total", runtime.totalMemory()); + m.put("free", runtime.freeMemory()); + return m; + } + + @Override + public Long getUptime() { + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); + return rb.getUptime(); + } + @Override public void addOFSwitchDriver(String description, IOFSwitchDriver driver) { IOFSwitchDriver existingDriver = switchBindingMap.get(description); diff --git a/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java b/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java index 978419873037467e4ad67439905fae510c24ea72..b6981ef252fc7c6c5a8ad69e39e3197ecf30c06c 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/SystemUptimeResource.java @@ -23,25 +23,24 @@ import org.restlet.resource.ServerResource; public class SystemUptimeResource extends ServerResource { - - public class UptimeRest { - long systemUptimeMsec; - - public long getSystemUptimeMsec() { - return systemUptimeMsec; - } - } - - @Get("json") - public UptimeRest retrieve() { - IFloodlightProviderService floodlightProvider = - (IFloodlightProviderService)getContext().getAttributes(). - get(IFloodlightProviderService.class.getCanonicalName()); - - UptimeRest uptime = new UptimeRest(); - uptime.systemUptimeMsec = - System.currentTimeMillis() - floodlightProvider.getSystemStartTime(); - - return (uptime); - } + + public class UptimeRest { + long systemUptimeMsec; + + public long getSystemUptimeMsec() { + return systemUptimeMsec; + } + } + + @Get("json") + public UptimeRest retrieve() { + IFloodlightProviderService floodlightProvider = + (IFloodlightProviderService)getContext().getAttributes(). + get(IFloodlightProviderService.class.getCanonicalName()); + + UptimeRest uptime = new UptimeRest(); + uptime.systemUptimeMsec = floodlightProvider.getUptime(); + + return (uptime); + } } diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java index 2839e4ee5cd472b10ae4e49d7cc7c3b6aac1a0d9..2c82e6076f2b4c8c4b90961386c8ed9fd779a6f0 100755 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceManagerImpl.java @@ -794,7 +794,7 @@ IFlowReconcileListener, IInfoProvider, IHAListener { if (srcEntity == null) return Command.STOP; - // Learn from ARP packet. + // Learn from ARP packet for special VRRP settings. // In VRRP settings, the source MAC address and sender MAC // addresses can be different. In such cases, we need to learn // the IP to MAC mapping of the VRRP IP address. The source @@ -1077,9 +1077,10 @@ IFlowReconcileListener, IInfoProvider, IHAListener { * the given source device. The source device is important since * there could be ambiguity in the destination device without the * attachment point information. - * @param source the source device. The returned destination will be - * in the same entity class as the source. - * @param dstEntity the entity to look up + * @param reference the source device's entity class. + * The returned destination will be + * in the same entity class as the source. + * @param dstEntity the entity to look up * @return an {@link Device} or null if no device is found. */ protected Device findDestByEntity(IEntityClass reference, diff --git a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java index 4f2d3f8c4995b466f2fc5e22edbf11160fbaf3ab..4811013e77258654c9577b0271a51f72c31bfd8d 100644 --- a/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java +++ b/src/main/java/net/floodlightcontroller/devicemanager/internal/DeviceUniqueIndex.java @@ -1,7 +1,7 @@ /** -* Copyright 2012 Big Switch Networks, Inc. +* Copyright 2012 Big Switch Networks, Inc. * Originally created by David Erickson, Stanford University -* +* * 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 @@ -31,7 +31,7 @@ public class DeviceUniqueIndex extends DeviceIndex { /** * The index */ - private ConcurrentHashMap<IndexedEntity, Long> index; + private final ConcurrentHashMap<IndexedEntity, Long> index; /** * Construct a new device index using the provided key fields @@ -51,10 +51,10 @@ public class DeviceUniqueIndex extends DeviceIndex { final Long deviceKey = findByEntity(entity); if (deviceKey != null) return Collections.<Long>singleton(deviceKey).iterator(); - + return Collections.<Long>emptySet().iterator(); } - + @Override public Iterator<Long> getAll() { return index.values().iterator(); @@ -68,15 +68,15 @@ public class DeviceUniqueIndex extends DeviceIndex { Long ret = index.putIfAbsent(ie, deviceKey); if (ret != null && !ret.equals(deviceKey)) { - // If the return value is non-null, then fail the insert - // (this implies that a device using this entity has + // If the return value is non-null, then fail the insert + // (this implies that a device using this entity has // already been created in another thread). return false; } } return true; } - + @Override public void updateIndex(Entity entity, Long deviceKey) { IndexedEntity ie = new IndexedEntity(keyFields, entity); diff --git a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java index 6db18a150c8fed2d8fb84c412cfe0bfa3aad3c98..7b5cd6293c1888250299c6352918c610df70733c 100644 --- a/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java +++ b/src/test/java/net/floodlightcontroller/core/test/MockFloodlightProvider.java @@ -17,6 +17,8 @@ package net.floodlightcontroller.core.test; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -361,4 +363,18 @@ public class MockFloodlightProvider implements IFloodlightModule, IFloodlightPro return null; } + @Override + public Map<String, Long> getMemory() { + Map<String, Long> m = new HashMap<String, Long>(); + Runtime runtime = Runtime.getRuntime(); + m.put("total", runtime.totalMemory()); + m.put("free", runtime.freeMemory()); + return m; + } + + @Override + public Long getUptime() { + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); + return rb.getUptime(); + } }