Adding GUI for displaying the DHCP Mappings. DHCP REST API disabled.
Change-Id: I59f4600e3efd3e53f3ebcb5d4ced7381625529c4
diff --git a/onos-app-dhcpserver/pom.xml b/onos-app-dhcpserver/pom.xml
index 4797108..de84083 100644
--- a/onos-app-dhcpserver/pom.xml
+++ b/onos-app-dhcpserver/pom.xml
@@ -117,6 +117,7 @@
<build>
<plugins>
+ <!-- FIXME this breaks the UI
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
@@ -155,6 +156,7 @@
</instructions>
</configuration>
</plugin>
+ -->
</plugins>
</build>
diff --git a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPUi.java b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPUi.java
new file mode 100644
index 0000000..a8cf50a
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DHCPUi.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.dhcpserver.impl;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.apache.felix.scr.annotations.Service;
+import org.onosproject.ui.UiExtension;
+import org.onosproject.ui.UiExtensionService;
+import org.onosproject.ui.UiMessageHandlerFactory;
+import org.onosproject.ui.UiView;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import static org.onosproject.ui.UiView.Category.NETWORK;
+
+/**
+ * Mechanism to stream data to the GUI.
+ */
+@Component(immediate = true, enabled = true)
+@Service(value = DHCPUi.class)
+public class DHCPUi {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final ClassLoader CL = DHCPUi.class.getClassLoader();
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected UiExtensionService uiExtensionService;
+
+ private final UiMessageHandlerFactory messageHandlerFactory =
+ () -> ImmutableList.of(new DhcpViewMessageHandler());
+
+ private final List<UiView> views = ImmutableList.of(
+ new UiView(NETWORK, "dhcp", "DHCP Server")
+ );
+
+ private final UiExtension uiExtension =
+ new UiExtension.Builder(CL, views)
+ .messageHandlerFactory(messageHandlerFactory)
+ .build();
+
+ @Activate
+ protected void activate() {
+ uiExtensionService.register(uiExtension);
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ uiExtensionService.unregister(uiExtension);
+ log.info("Stopped");
+ }
+
+}
\ No newline at end of file
diff --git a/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DhcpViewMessageHandler.java b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DhcpViewMessageHandler.java
new file mode 100644
index 0000000..ee5a224
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/java/org/onosproject/dhcpserver/impl/DhcpViewMessageHandler.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.dhcpserver.impl;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import org.onlab.packet.Ip4Address;
+import org.onlab.packet.MacAddress;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.dhcpserver.DHCPService;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiMessageHandler;
+import org.onosproject.ui.table.TableModel;
+import org.onosproject.ui.table.TableRequestHandler;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * DHCPViewMessageHandler class implementation.
+ */
+public class DhcpViewMessageHandler extends UiMessageHandler {
+
+ private static final String DHCP_DATA_REQ = "dhcpDataRequest";
+ private static final String DHCP_DATA_RESP = "dhcpDataResponse";
+ private static final String DHCP = "dhcps";
+
+ private static final String MAC = "mac";
+ private static final String IP = "ip";
+
+ private static final String[] COL_IDS = {
+ MAC, IP
+ };
+
+ @Override
+ protected Collection<RequestHandler> createRequestHandlers() {
+ return ImmutableSet.of(
+ new DataRequestHandler()
+ );
+ }
+
+ private final class DataRequestHandler extends TableRequestHandler {
+
+ private DataRequestHandler() {
+ super(DHCP_DATA_REQ, DHCP_DATA_RESP, DHCP);
+ }
+
+ @Override
+ protected String defaultColumnId() {
+ return MAC;
+ }
+
+ @Override
+ protected String[] getColumnIds() {
+ return COL_IDS;
+ }
+
+ @Override
+ protected void populateTable(TableModel tm, ObjectNode payload) {
+ DHCPService dhcpService = AbstractShellCommand.get(DHCPService.class);
+ Map<MacAddress, Ip4Address> allocationMap = dhcpService.listMapping();
+
+ for (Map.Entry<MacAddress, Ip4Address> entry : allocationMap.entrySet()) {
+ populateRow(tm.addRow(), entry);
+ }
+ }
+
+ private void populateRow(TableModel.Row row, Map.Entry<MacAddress, Ip4Address> entry) {
+ row.cell(MAC, entry.getKey())
+ .cell(IP, entry.getValue());
+ }
+ }
+}
diff --git a/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.css b/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.css
new file mode 100644
index 0000000..e0a2931
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.css
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/*
+ ONOS GUI -- DHCP Server -- CSS file
+ */
+
+#ov-dhcp h2 {
+ display: inline-block;
+}
+
+#ov-dhcp div.ctrl-btns {
+ width: 45px;
+}
diff --git a/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.html b/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.html
new file mode 100644
index 0000000..09f67e0
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.html
@@ -0,0 +1,45 @@
+<!-- DHCP Server partial HTML -->
+<div id="ov-dhcp">
+ <div class="tabular-header">
+ <h2>DHCP Mappings ({{tableData.length}} total)</h2>
+ <div class="ctrl-btns">
+ <div class="refresh" ng-class="{active: autoRefresh}"
+ icon icon-size="36" icon-id="refresh"
+ tooltip tt-msg="autoRefreshTip"
+ ng-click="toggleRefresh()"></div>
+ </div>
+ </div>
+
+ <div class="summary-list" onos-table-resize>
+ <div ng-show="loading" class="loading-wheel"
+ icon icon-id="loading" icon-size="75"></div>
+
+ <div class="table-header" onos-sortable-header>
+ <table>
+ <tr>
+ <td colId="mac" sortable>MAC Address</td>
+ <td colId="ip" sortable>IP Address</td>
+ </tr>
+ </table>
+ </div>
+
+ <div class="table-body">
+ <table onos-flash-changes id-prop="mac">
+ <tr ng-if="!tableData.length" class="no-data">
+ <td colspan="2">
+ No mappings found
+ </td>
+ </tr>
+
+ <tr ng-repeat="dhcp in tableData track by $index"
+ ng-click="selectCallback($event, dhcp)"
+ ng-repeat-complete row-id="{{dhcp.mac}}">
+ <td>{{dhcp.mac}}</td>
+ <td>{{dhcp.ip}}</td>
+ </tr>
+ </table>
+ </div>
+
+ </div>
+
+</div>
diff --git a/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.js b/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.js
new file mode 100644
index 0000000..061d0de
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/resources/app/view/dhcp/dhcp.js
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * 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.
+ */
+
+/*
+ ONOS GUI -- DHCP Server View Module
+ */
+
+(function () {
+ 'use strict';
+
+ // injected refs
+ var $log, $scope;
+
+ angular.module('ovDhcp', [])
+ .controller('OvDhcpCtrl',
+ ['$log', '$scope', 'TableBuilderService',
+
+ function (_$log_, _$scope_, tbs) {
+ $log = _$log_;
+ $scope = _$scope_;
+
+ function selCb($event, row) {
+ $log.debug('Got a click on:', row);
+ }
+
+ tbs.buildTable({
+ scope: $scope,
+ tag: 'dhcp',
+ selCb: selCb
+ });
+
+ $scope.$on('$destroy', function () {
+ $log.debug('OvDhcpCtrl has been destroyed');
+ });
+
+ $log.log('OvDhcpCtrl has been created');
+ }]);
+}());
\ No newline at end of file
diff --git a/onos-app-dhcpserver/src/main/resources/css.html b/onos-app-dhcpserver/src/main/resources/css.html
new file mode 100644
index 0000000..d02ad44
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/resources/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/dhcp/dhcp.css">
\ No newline at end of file
diff --git a/onos-app-dhcpserver/src/main/resources/js.html b/onos-app-dhcpserver/src/main/resources/js.html
new file mode 100644
index 0000000..d37b576
--- /dev/null
+++ b/onos-app-dhcpserver/src/main/resources/js.html
@@ -0,0 +1 @@
+<script src="app/view/dhcp/dhcp.js"></script>
\ No newline at end of file