Add netcfg for INT
Use network config subsystem to handle such configs
Change-Id: I8ec14d31c30e3d1d8cd2c703d8db5535bb8b5cd4
diff --git a/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/ui/IntAppUiMessageHandler.java b/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/ui/IntAppUiMessageHandler.java
index 34e8fb4..9d1fb90 100644
--- a/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/ui/IntAppUiMessageHandler.java
+++ b/apps/inbandtelemetry/app/src/main/java/org/onosproject/inbandtelemetry/app/ui/IntAppUiMessageHandler.java
@@ -20,14 +20,11 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
-import org.onlab.packet.IpAddress;
-import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onosproject.inbandtelemetry.api.IntIntent;
import org.onosproject.inbandtelemetry.api.IntIntentId;
import org.onosproject.net.behaviour.inbandtelemetry.IntMetadataType;
import org.onosproject.inbandtelemetry.api.IntService;
-import org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.ui.RequestHandler;
@@ -43,8 +40,6 @@
private static final String INT_INTENT_ADD_REQUEST = "intIntentAddRequest";
private static final String INT_INTENT_DEL_REQUEST = "intIntentDelRequest";
- private static final String INT_CONFIG_ADD_REQUEST = "intConfigAddRequest";
-// private static final String INT_CONFIG_DEL_REQUEST = "intConfigDelRequest";
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -54,46 +49,10 @@
protected Collection<RequestHandler> createRequestHandlers() {
return ImmutableSet.of(
new IntIntentAddRequestHandler(),
- new IntIntentDelRequestHandler(),
- new IntConfigAddRequestHandler()
- //new intConfigDelRequestHandler()
+ new IntIntentDelRequestHandler()
);
}
- private final class IntConfigAddRequestHandler extends RequestHandler {
- private IntConfigAddRequestHandler() {
- super(INT_CONFIG_ADD_REQUEST);
- }
-
- @Override
- public void process(ObjectNode payload) {
- log.info("intConfigAddRequest: {}", payload);
-
- intService = get(IntService.class);
- IntDeviceConfig.Builder builder = IntDeviceConfig.builder();
-
- if (payload.get("collectorIp") != null) {
- builder.withCollectorIp(IpAddress.valueOf(payload.get("collectorIp").asText()));
- } else {
- builder.withCollectorIp(IpAddress.valueOf("127.0.0.1"));
- }
-
- if (payload.get("collectorPort") != null) {
- builder.withCollectorPort(TpPort.tpPort(
- payload.get("collectorPort").asInt()));
- } else {
- builder.withCollectorPort(TpPort.tpPort(1234));
- }
-
- builder.enabled(true)
- .withSinkIp(IpAddress.valueOf("10.192.19.180"))
- .withSinkMac(MacAddress.NONE)
- .withCollectorNextHopMac(MacAddress.BROADCAST);
-
- intService.setConfig(builder.build());
- }
- }
-
private final class IntIntentDelRequestHandler extends RequestHandler {
private IntIntentDelRequestHandler() {
super(INT_INTENT_DEL_REQUEST);
diff --git a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html
index 7b69168..44698dd 100644
--- a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html
+++ b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.html
@@ -9,32 +9,6 @@
<div class="tabular-header">
<h2>
- INT Collector Configuration
- </h2>
- <div class="config-panel">
- <h3>
- Collector IPv4 address and UDP port
- </h3>
- <div>
- <input type="text" required
- pattern="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
- ng-model="collectorIp" placeholder="IPv4 address">
- :
- <input type="text" required pattern="^[0-9]{0,5}$"
- ng-model="collectorPort" placeholder="port">
- </div>
- </div>
- <div class="config-button-panel">
- <div class="int-app-config-button" ng-click="sendIntConfigString()">
- Apply Configuration
- </div>
- </div>
- </div>
-
- <hr>
-
- <div class="tabular-header">
- <h2>
INT Watchlist Rules
</h2>
diff --git a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.js b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.js
index 3d4f652..efcb3b4 100644
--- a/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.js
+++ b/apps/inbandtelemetry/app/src/main/resources/app/view/intApp/intApp.js
@@ -7,21 +7,12 @@
// constants
var intIntentAddReq = 'intIntentAddRequest';
var intIntentDelReq = 'intIntentDelRequest';
- var intConfigAddReq = 'intConfigAddRequest';
var refreshInterval = 1000;
var propOrder = ['id', 'srcAddr', 'dstAddr', 'srcPort', 'dstPort', 'insMask'];
var friendlyProps = ['IntIntent ID', 'Src Address', 'Dst Address', 'Src Port', 'Dst Port', 'Ins Mask'];
- function sendIntConfigString() {
- var configObjectNode = {
- "collectorIp": $scope.collectorIp,
- "collectorPort": $scope.collectorPort
- };
- wss.sendEvent(intConfigAddReq, configObjectNode);
- }
-
function sendIntIntentString() {
var inst = [];
if ($scope.metaSwId) inst.push("SWITCH_ID");
diff --git a/apps/inbandtelemetry/impl/BUILD b/apps/inbandtelemetry/impl/BUILD
index b3a1d46..c3c3fba 100644
--- a/apps/inbandtelemetry/impl/BUILD
+++ b/apps/inbandtelemetry/impl/BUILD
@@ -4,7 +4,7 @@
"//apps/inbandtelemetry/api:onos-apps-inbandtelemetry-api",
]
-TEST_DEPS = TEST_ADAPTERS
+TEST_DEPS = TEST_ADAPTERS + JACKSON
osgi_jar_with_tests(
test_deps = TEST_DEPS,
diff --git a/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/SimpleIntManager.java b/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/SimpleIntManager.java
index 906efd8..48a7a24 100644
--- a/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/SimpleIntManager.java
+++ b/apps/inbandtelemetry/impl/src/main/java/org/onosproject/inbandtelemetry/impl/SimpleIntManager.java
@@ -21,6 +21,7 @@
import org.onlab.util.SharedScheduledExecutors;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
+import org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig;
import org.onosproject.net.behaviour.inbandtelemetry.IntMetadataType;
import org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig;
import org.onosproject.inbandtelemetry.api.IntIntent;
@@ -34,6 +35,12 @@
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import org.onosproject.net.PortNumber;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.SubjectFactories;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
@@ -108,6 +115,12 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY)
private HostService hostService;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ private NetworkConfigService netcfgService;
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY)
+ private NetworkConfigRegistry netcfgRegistry;
+
private final Striped<Lock> deviceLocks = Striped.lock(10);
private final ConcurrentMap<DeviceId, ScheduledFuture<?>> scheduledDeviceTasks = Maps.newConcurrentMap();
@@ -127,6 +140,16 @@
private final InternalIntStartedListener intStartedListener = new InternalIntStartedListener();
private final InternalDeviceToConfigureListener devicesToConfigureListener =
new InternalDeviceToConfigureListener();
+ private final NetworkConfigListener appConfigListener = new IntAppConfigListener();
+
+ private final ConfigFactory<ApplicationId, IntReportConfig> intAppConfigFactory =
+ new ConfigFactory<>(SubjectFactories.APP_SUBJECT_FACTORY,
+ IntReportConfig.class, "report") {
+ @Override
+ public IntReportConfig createConfig() {
+ return new IntReportConfig();
+ }
+ };
@Activate
public void activate() {
@@ -185,6 +208,9 @@
hostService.addListener(hostListener);
deviceService.addListener(deviceListener);
+ netcfgRegistry.registerConfigFactory(intAppConfigFactory);
+ netcfgService.addListener(appConfigListener);
+
startInt();
log.info("Started", appId.id());
}
@@ -524,4 +550,35 @@
}
}
}
+
+ private class IntAppConfigListener implements NetworkConfigListener {
+
+ @Override
+ public void event(NetworkConfigEvent event) {
+ switch (event.type()) {
+ case CONFIG_ADDED:
+ case CONFIG_UPDATED:
+ event.config()
+ .map(config -> (IntReportConfig) config)
+ .ifPresent(config -> {
+ IntDeviceConfig intDeviceConfig = IntDeviceConfig.builder()
+ .withMinFlowHopLatencyChangeNs(config.minFlowHopLatencyChangeNs())
+ .withCollectorPort(config.collectorPort())
+ .withCollectorIp(config.collectorIp())
+ .enabled(true)
+ .build();
+ setConfig(intDeviceConfig);
+ });
+ break;
+ // TODO: Support removing INT config.
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public boolean isRelevant(NetworkConfigEvent event) {
+ return event.configClass() == IntReportConfig.class;
+ }
+ }
}
diff --git a/apps/inbandtelemetry/impl/src/test/java/org/onosproject/inbandtelemetry/impl/SimpleIntManagerTest.java b/apps/inbandtelemetry/impl/src/test/java/org/onosproject/inbandtelemetry/impl/SimpleIntManagerTest.java
new file mode 100644
index 0000000..6f7ed96
--- /dev/null
+++ b/apps/inbandtelemetry/impl/src/test/java/org/onosproject/inbandtelemetry/impl/SimpleIntManagerTest.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2020-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.inbandtelemetry.impl;
+
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.google.common.collect.ImmutableList;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.TpPort;
+import org.onosproject.TestApplicationId;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.core.CoreService;
+import org.onosproject.mastership.MastershipService;
+import org.onosproject.net.behaviour.inbandtelemetry.IntReportConfig;
+import org.onosproject.net.behaviour.inbandtelemetry.IntDeviceConfig;
+import org.onosproject.net.config.ConfigApplyDelegate;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.host.HostService;
+import org.onosproject.store.service.StorageService;
+import org.onosproject.store.service.TestStorageService;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.newCapture;
+import static org.easymock.EasyMock.replay;
+import static org.junit.Assert.assertEquals;
+import static org.onlab.junit.TestUtils.setField;
+
+public class SimpleIntManagerTest {
+ private static final String APP_NAME = "org.onosproject.inbandtelemetry";
+ private static final ApplicationId APP_ID = new TestApplicationId(APP_NAME);
+ private static final IpAddress COLLECTOR_IP = IpAddress.valueOf("10.0.0.1");
+ private static final TpPort COLLECTOR_PORT = TpPort.tpPort(5500);
+ private static final int MIN_FLOW_HOP_LATENCY_CHANGE_NS = 16;
+
+ private SimpleIntManager manager;
+ private StorageService storageService;
+ private MastershipService mastershipService;
+ private CoreService coreService;
+ private HostService hostService;
+ private DeviceService deviceService;
+ private NetworkConfigRegistry networkConfigRegistry;
+ private NetworkConfigService networkConfigService;
+ private NetworkConfigListener networkConfigListener;
+
+
+ @Before
+ public void setup() {
+ storageService = new TestStorageService();
+ mastershipService = createNiceMock(MastershipService.class);
+ coreService = createNiceMock(CoreService.class);
+ hostService = createNiceMock(HostService.class);
+ deviceService = createNiceMock(DeviceService.class);
+ expect(deviceService.getDevices()).andReturn(ImmutableList.of()).anyTimes();
+ networkConfigRegistry = createNiceMock(NetworkConfigRegistry.class);
+ networkConfigService = createNiceMock(NetworkConfigService.class);
+
+ manager = new SimpleIntManager();
+ setField(manager, "coreService", coreService);
+ setField(manager, "deviceService", deviceService);
+ setField(manager, "storageService", storageService);
+ setField(manager, "mastershipService", mastershipService);
+ setField(manager, "hostService", hostService);
+ setField(manager, "netcfgService", networkConfigService);
+ setField(manager, "netcfgRegistry", networkConfigRegistry);
+
+ expect(coreService.registerApplication(APP_NAME)).andReturn(APP_ID).once();
+ networkConfigRegistry.registerConfigFactory(anyObject());
+ expectLastCall().once();
+
+ Capture<NetworkConfigListener> capture = newCapture();
+ networkConfigService.addListener(EasyMock.capture(capture));
+ expectLastCall().once();
+ replay(mastershipService, deviceService, coreService,
+ hostService, networkConfigRegistry, networkConfigService);
+ manager.activate();
+ networkConfigListener = capture.getValue();
+ }
+
+ @After
+ public void teardown() {
+ manager.deactivate();
+ }
+
+ @Test
+ public void testPushIntAppConfig() {
+ IntReportConfig config = new IntReportConfig();
+ ObjectMapper mapper = new ObjectMapper();
+ ConfigApplyDelegate delegate = configApply -> { };
+ config.init(APP_ID, "report", JsonNodeFactory.instance.objectNode(), mapper, delegate);
+ config.setCollectorIp(COLLECTOR_IP)
+ .setCollectorPort(COLLECTOR_PORT)
+ .setMinFlowHopLatencyChangeNs(MIN_FLOW_HOP_LATENCY_CHANGE_NS);
+
+ NetworkConfigEvent event =
+ new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, APP_ID,
+ config, null, IntReportConfig.class);
+ networkConfigListener.event(event);
+
+ // We expected that the manager will store the device config which
+ // converted from the app config.
+ IntDeviceConfig deviceConfig = manager.getConfig();
+ assertEquals(COLLECTOR_IP, deviceConfig.collectorIp());
+ assertEquals(COLLECTOR_PORT, deviceConfig.collectorPort());
+ assertEquals(MIN_FLOW_HOP_LATENCY_CHANGE_NS, deviceConfig.minFlowHopLatencyChangeNs());
+ }
+}
diff --git a/apps/inbandtelemetry/impl/src/test/java/org/onosproject/inbandtelemetry/impl/package-info.java b/apps/inbandtelemetry/impl/src/test/java/org/onosproject/inbandtelemetry/impl/package-info.java
new file mode 100644
index 0000000..c918fea
--- /dev/null
+++ b/apps/inbandtelemetry/impl/src/test/java/org/onosproject/inbandtelemetry/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2020-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.
+ */
+
+/**
+ * Unit tests for SimpleIntManager class.
+ */
+package org.onosproject.inbandtelemetry.impl;