Thomas Vachuska

Modifying packaging to make the DHCP GUI work from WAR bundle-style packaging.

Change-Id: I1b9685fa1eebcac63ad41bc60db1f98b30aba656
/*
* Copyright 2014 Open Networking Laboratory
* 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.
......@@ -30,7 +30,7 @@ public interface DHCPService {
*
* @return collection of mappings.
*/
Map<MacAddress, Ip4Address> listMapping();
Map<MacAddress, IPAssignment> listMapping();
/**
* Returns the default lease time granted by the DHCP Server.
......
/*
* Copyright 2014 Open Networking Laboratory
* 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.
......@@ -77,7 +77,7 @@ public interface DHCPStore {
*
* @return the collection of the mappings
*/
Map<MacAddress, Ip4Address> listMapping();
Map<MacAddress, IPAssignment> listMapping();
/**
* Assigns the requested IP to the MAC ID (if available) for an indefinite period of time.
......
/*
* Copyright 2014 Open Networking Laboratory
* 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.
......@@ -16,10 +16,10 @@
package org.onosproject.dhcp.cli;
import org.apache.karaf.shell.commands.Command;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.dhcp.DHCPService;
import org.onosproject.dhcp.IPAssignment;
import java.util.Map;
......@@ -35,10 +35,10 @@ public class DHCPListAllMappings extends AbstractShellCommand {
protected void execute() {
DHCPService dhcpService = AbstractShellCommand.get(DHCPService.class);
Map<MacAddress, Ip4Address> allocationMap = dhcpService.listMapping();
Map<MacAddress, IPAssignment> allocationMap = dhcpService.listMapping();
for (Map.Entry<MacAddress, Ip4Address> entry : allocationMap.entrySet()) {
print(DHCP_MAPPING_FORMAT, entry.getKey().toString(), entry.getValue().toString());
for (Map.Entry<MacAddress, IPAssignment> entry : allocationMap.entrySet()) {
print(DHCP_MAPPING_FORMAT, entry.getKey().toString(), entry.getValue().ipAddress().toString());
}
}
}
......
......@@ -38,6 +38,7 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.dhcp.DHCPService;
import org.onosproject.dhcp.DHCPStore;
import org.onosproject.dhcp.IPAssignment;
import org.onosproject.net.config.ConfigFactory;
import org.onosproject.net.config.NetworkConfigEvent;
import org.onosproject.net.config.NetworkConfigListener;
......@@ -213,8 +214,7 @@ public class DHCPManager implements DHCPService {
}
@Override
public Map<MacAddress, Ip4Address> listMapping() {
public Map<MacAddress, IPAssignment> listMapping() {
return dhcpStore.listMapping();
}
......
/*
* 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.dhcp.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)
.resourcePath("gui")
.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
/*
* 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.dhcp.impl;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.ImmutableSet;
import org.onlab.packet.MacAddress;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.dhcp.DHCPService;
import org.onosproject.dhcp.IPAssignment;
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.Date;
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 LEASE = "lease";
private static final String[] COL_IDS = {
MAC, IP, LEASE
};
@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, IPAssignment> allocationMap = dhcpService.listMapping();
for (Map.Entry<MacAddress, IPAssignment> entry : allocationMap.entrySet()) {
populateRow(tm.addRow(), entry);
}
}
private void populateRow(TableModel.Row row, Map.Entry<MacAddress, IPAssignment> entry) {
if (entry.getValue().leasePeriod() > 0) {
Date now = new Date(entry.getValue().timestamp().getTime() + entry.getValue().leasePeriod());
row.cell(MAC, entry.getKey())
.cell(IP, entry.getValue().ipAddress())
.cell(LEASE, now.toString());
} else {
row.cell(MAC, entry.getKey())
.cell(IP, entry.getValue().ipAddress())
.cell(LEASE, "Infinite Static Lease");
}
}
}
}
/*
* Copyright 2014 Open Networking Laboratory
* 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.
......@@ -224,17 +224,17 @@ public class DistributedDHCPStore implements DHCPStore {
}
@Override
public Map<MacAddress, Ip4Address> listMapping() {
public Map<MacAddress, IPAssignment> listMapping() {
Map<MacAddress, Ip4Address> allMapping = new HashMap<>();
Map<MacAddress, IPAssignment> allMapping = new HashMap<>();
for (Map.Entry<MacAddress, Versioned<IPAssignment>> entry: allocationMap.entrySet()) {
IPAssignment assignment = entry.getValue().value();
if (assignment.assignmentStatus() == IPAssignment.AssignmentStatus.Option_Assigned) {
allMapping.put(entry.getKey(), assignment.ipAddress());
allMapping.put(entry.getKey(), assignment);
}
}
return allMapping;
}
@Override
......
......@@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.MacAddress;
import org.onosproject.dhcp.DHCPService;
import org.onosproject.dhcp.IPAssignment;
import org.onosproject.rest.AbstractWebResource;
import javax.ws.rs.Consumes;
......@@ -71,11 +72,11 @@ public class DHCPWebResource extends AbstractWebResource {
public Response listMappings() {
ObjectNode root = mapper().createObjectNode();
final Map<MacAddress, Ip4Address> intents = service.listMapping();
final Map<MacAddress, IPAssignment> intents = service.listMapping();
ArrayNode arrayNode = root.putArray("mappings");
intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
.put("mac", i.getKey().toString())
.put("ip", i.getValue().toString())));
.put("ip", i.getValue().ipAddress().toString())));
return ok(root.toString()).build();
}
......@@ -123,11 +124,11 @@ public class DHCPWebResource extends AbstractWebResource {
}
}
final Map<MacAddress, Ip4Address> intents = service.listMapping();
final Map<MacAddress, IPAssignment> intents = service.listMapping();
ArrayNode arrayNode = root.putArray("mappings");
intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
.put("mac", i.getKey().toString())
.put("ip", i.getValue().toString())));
.put("ip", i.getValue().ipAddress().toString())));
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
......@@ -149,11 +150,11 @@ public class DHCPWebResource extends AbstractWebResource {
if (!service.removeStaticMapping(MacAddress.valueOf(macID))) {
throw new IllegalArgumentException("Static Mapping Removal Failed.");
}
final Map<MacAddress, Ip4Address> intents = service.listMapping();
final Map<MacAddress, IPAssignment> intents = service.listMapping();
ArrayNode arrayNode = root.putArray("mappings");
intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode()
.put("mac", i.getKey().toString())
.put("ip", i.getValue().toString())));
.put("ip", i.getValue().ipAddress().toString())));
return ok(root.toString()).build();
}
......
/*
* 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;
}
<!-- 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>
<td colId="lease" sortable>Lease Expiry</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>
<td>{{dhcp.lease}}</td>
</tr>
</table>
</div>
</div>
</div>
/*
* 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
<link rel="stylesheet" href="app/view/dhcp/dhcp.css">
\ No newline at end of file
<script src="app/view/dhcp/dhcp.js"></script>
\ No newline at end of file
/*
* Copyright 2014 Open Networking Laboratory
* 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.
......@@ -29,9 +29,10 @@ import org.onlab.packet.MacAddress;
import org.onlab.packet.UDP;
import org.onosproject.core.CoreServiceAdapter;
import org.onosproject.dhcp.DHCPStore;
import org.onosproject.net.config.NetworkConfigRegistryAdapter;
import org.onosproject.dhcp.IPAssignment;
import org.onosproject.net.Host;
import org.onosproject.net.HostId;
import org.onosproject.net.config.NetworkConfigRegistryAdapter;
import org.onosproject.net.host.HostDescription;
import org.onosproject.net.host.HostProvider;
import org.onosproject.net.host.HostProviderRegistry;
......@@ -49,6 +50,7 @@ import org.onosproject.net.provider.ProviderId;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -238,9 +240,15 @@ public class DHCPManagerTest {
public void releaseIP(MacAddress macID) {
}
public Map<MacAddress, Ip4Address> listMapping() {
Map<MacAddress, Ip4Address> map = new HashMap<>();
map.put(CLIENT1_MAC, Ip4Address.valueOf(EXPECTED_IP));
public Map<MacAddress, IPAssignment> listMapping() {
Map<MacAddress, IPAssignment> map = new HashMap<>();
IPAssignment assignment = IPAssignment.builder()
.ipAddress(Ip4Address.valueOf(EXPECTED_IP))
.assignmentStatus(IPAssignment.AssignmentStatus.Option_Assigned)
.leasePeriod(300)
.timestamp(new Date())
.build();
map.put(CLIENT1_MAC, assignment);
return map;
}
......