Skip to content

Commit

Permalink
Added ability to configure GUI traffic refresh rate
Browse files Browse the repository at this point in the history
Change-Id: Iceb1196a20c16f09218218da2e095fbe9644bb04
  • Loading branch information
tomikazi authored and Charles Chan committed Apr 6, 2021
1 parent f17d173 commit a5e986d
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@
*/
public class AbstractTopoMonitor {

/**
* Creates a new topo monitor base.
*/
protected AbstractTopoMonitor() {
}

/**
* Number of milliseconds between invocations of sending traffic data.
*/
protected static long trafficPeriod = 5000;

/**
* Sets the traffic refresh period in milliseconds.
*
* @param ms refresh rate in millis
*/
public static void setTrafficPeriod(long ms) {
trafficPeriod = ms;
}

/**
* Returns the traffic refresh period in milliseconds.
*
* @return refresh rate in millis
*/
public static long getTrafficPeriod() {
return trafficPeriod;
}

// TODO: pull common code up into this class

// Note to Andrea:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2018-present Open Networking Foundation
*
* 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 org.onosproject.ui.impl;

public final class OsgiPropertyConstants {
private OsgiPropertyConstants() {
}

public static final String TRAFFIC_REFRESH_MS = "trafficRefreshMs";
public static final int TRAFFIC_REFRESH_MS_DEFAULT = 5000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public enum ProtectedMode {
SELECTED_INTENT
}

private final long trafficPeriod;
private final ServicesBundle services;
private final TopologyViewMessageHandler msgHandler;

Expand All @@ -110,13 +109,11 @@ public enum ProtectedMode {
/**
* Constructs a protected intent monitor.
*
* @param trafficPeriod traffic task period in ms
* @param services bundle of services
* @param msgHandler our message handler
*/
public ProtectedIntentMonitor(long trafficPeriod, ServicesBundle services,
public ProtectedIntentMonitor(ServicesBundle services,
TopologyViewMessageHandler msgHandler) {
this.trafficPeriod = trafficPeriod;
this.services = services;
this.msgHandler = msgHandler;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {

private static final String SLASH = "/";

private static final long TRAFFIC_PERIOD = 5000;
private static final long SUMMARY_PERIOD = 30000;

private static final Comparator<? super ControllerNode> NODE_COMPARATOR =
Expand Down Expand Up @@ -214,8 +213,8 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase {
public void init(UiConnection connection, ServiceDirectory directory) {
super.init(connection, directory);
appId = directory.get(CoreService.class).registerApplication(MY_APP_ID);
traffic = new TrafficMonitor(TRAFFIC_PERIOD, services, this);
protectedIntentMonitor = new ProtectedIntentMonitor(TRAFFIC_PERIOD, services, this);
traffic = new TrafficMonitor(services, this);
protectedIntentMonitor = new ProtectedIntentMonitor(services, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ public class TrafficMonitor extends TrafficMonitorBase {
/**
* Constructs a traffic monitor.
*
* @param trafficPeriod traffic task period in ms
* @param servicesBundle bundle of services
* @param msgHandler our message handler
*/
public TrafficMonitor(long trafficPeriod, ServicesBundle servicesBundle,
TopologyViewMessageHandler msgHandler) {
super(trafficPeriod, servicesBundle, msgHandler);
public TrafficMonitor(ServicesBundle servicesBundle, TopologyViewMessageHandler msgHandler) {
super(servicesBundle, msgHandler);
this.msgHandler = msgHandler;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,6 @@ public enum Mode {
CUSTOM_TRAFFIC_MONITOR
}

/**
* Number of milliseconds between invocations of sending traffic data.
*/
protected final long trafficPeriod;

/**
* Holds references to services.
Expand All @@ -314,14 +310,11 @@ public enum Mode {
* Constructs the monitor, initializing the task period and
* services bundle reference.
*
* @param trafficPeriod traffic task period in ms
* @param servicesBundle bundle of services
* @param msgHandler Traffic Message handler
*/
protected TrafficMonitorBase(long trafficPeriod,
ServicesBundle servicesBundle,
protected TrafficMonitorBase(ServicesBundle servicesBundle,
TopoologyTrafficMessageHandlerAbstract msgHandler) {
this.trafficPeriod = trafficPeriod;
this.services = servicesBundle;
this.msgHandler = msgHandler;
timer = new Timer("uiTopo-" + getClass().getSimpleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.mastership.MastershipService;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.ConsistentMap;
Expand Down Expand Up @@ -61,16 +62,20 @@
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
import org.onosproject.ui.lion.LionBundle;
import org.onosproject.ui.lion.LionUtils;
import org.onosproject.ui.topo.AbstractTopoMonitor;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Modified;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Dictionary;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
Expand All @@ -88,13 +93,23 @@
import static org.onosproject.security.AppPermission.Type.UI_WRITE;
import static org.onosproject.ui.UiView.Category.NETWORK;
import static org.onosproject.ui.UiView.Category.PLATFORM;
import static org.onosproject.ui.impl.OsgiPropertyConstants.TRAFFIC_REFRESH_MS;
import static org.onosproject.ui.impl.OsgiPropertyConstants.TRAFFIC_REFRESH_MS_DEFAULT;
import static org.onosproject.ui.impl.lion.BundleStitcher.generateBundles;

/**
* Manages the user interface extensions.
*/
@Component(immediate = true, service = { UiExtensionService.class, UiPreferencesService.class, SpriteService.class,
UiTokenService.class })
@Component(immediate = true,
service = {
UiExtensionService.class,
UiPreferencesService.class,
SpriteService.class,
UiTokenService.class
},
property = {
TRAFFIC_REFRESH_MS + ":Integer=" + TRAFFIC_REFRESH_MS_DEFAULT,
})
public class UiExtensionManager
implements UiExtensionService, UiPreferencesService, SpriteService,
UiTokenService {
Expand Down Expand Up @@ -155,6 +170,9 @@ public class UiExtensionManager
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected StorageService storageService;

@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected ComponentConfigService cfgService;

@Reference(cardinality = ReferenceCardinality.MANDATORY)
private UiSharedTopologyModel sharedModel;

Expand All @@ -178,6 +196,7 @@ public class UiExtensionManager

private LionBundle navLion;

protected int trafficRefreshMs = TRAFFIC_REFRESH_MS_DEFAULT;

private String lionNavText(String id) {
return navLion.getValue("nav_item_" + id);
Expand Down Expand Up @@ -281,7 +300,7 @@ private UiExtension createCoreExtension() {


@Activate
public void activate() {
public void activate(ComponentContext context) {
Serializer serializer = Serializer.using(KryoNamespaces.API,
ObjectNode.class, ArrayNode.class,
JsonNodeFactory.class, LinkedHashMap.class,
Expand All @@ -303,21 +322,37 @@ public void activate() {
.withRelaxedReadConsistency()
.build();
tokens = tokensConsistentMap.asJavaMap();
cfgService.registerProperties(getClass());

register(core);

log.info("Started");
}

@Deactivate
public void deactivate() {
public void deactivate(ComponentContext context) {
cfgService.unregisterProperties(getClass(), false);
prefsConsistentMap.removeListener(prefsListener);
eventHandlingExecutor.shutdown();
UiWebSocketServlet.closeAll();
unregister(core);
log.info("Stopped");
}

@Modified
protected void modified(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
Integer trafficRefresh = Tools.getIntegerProperty(properties, TRAFFIC_REFRESH_MS);

if (trafficRefresh != null && trafficRefresh > 10) {
AbstractTopoMonitor.setTrafficPeriod(trafficRefresh);
} else if (trafficRefresh != null) {
log.warn("trafficRefresh must be greater than 10");
}

log.info("Settings: trafficRefresh={}", trafficRefresh);
}

@Override
public synchronized void register(UiExtension extension) {
checkPermission(UI_WRITE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ public class Topo2TrafficMessageHandler extends TopoologyTrafficMessageHandlerAb
private static final String SRC = "src";
private static final String DST = "dst";

// configuration parameters
private static final long TRAFFIC_PERIOD = 5000;

protected ServicesBundle services;
private static final String MY_APP_ID = "org.onosproject.gui";
private ApplicationId appId;
Expand All @@ -96,7 +93,7 @@ public void init(UiConnection connection, ServiceDirectory directory) {
super.init(connection, directory);
appId = directory.get(CoreService.class).registerApplication(MY_APP_ID);
services = new ServicesBundle(directory);
traffic2 = new Traffic2Monitor(TRAFFIC_PERIOD, services, this);
traffic2 = new Traffic2Monitor(services, this);
topoSession = ((UiWebSocket) connection).topoSession();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ public class Traffic2Monitor extends TrafficMonitorBase {
/**
* Constructs a traffic monitor.
*
* @param trafficPeriod traffic task period in ms
* @param servicesBundle bundle of services
* @param msgHandler our message handler
*/
public Traffic2Monitor(long trafficPeriod, ServicesBundle servicesBundle,
public Traffic2Monitor(ServicesBundle servicesBundle,
Topo2TrafficMessageHandler msgHandler) {
super(trafficPeriod, servicesBundle, msgHandler);
super(servicesBundle, msgHandler);
this.msgHandler = msgHandler;
}

Expand Down

0 comments on commit a5e986d

Please sign in to comment.