Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.pceweb; |
| 18 | |
| 19 | |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 20 | import java.util.HashMap; |
| 21 | import java.util.Map; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import org.onlab.util.Bandwidth; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 25 | import org.onosproject.net.AnnotationKeys; |
| 26 | import org.onosproject.net.Annotations; |
| 27 | import org.onosproject.net.Device; |
| 28 | import org.onosproject.net.DeviceId; |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 29 | import org.onosproject.net.Link; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 30 | import org.onosproject.ui.UiTopoOverlay; |
| 31 | import org.onosproject.ui.topo.ButtonId; |
| 32 | import org.onosproject.ui.topo.PropertyPanel; |
| 33 | import org.onosproject.net.HostId; |
| 34 | import org.onosproject.net.device.DeviceService; |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 35 | import org.onosproject.net.link.LinkEvent; |
| 36 | import org.onosproject.net.resource.ContinuousResource; |
| 37 | import org.onosproject.net.resource.DiscreteResource; |
| 38 | import org.onosproject.net.resource.Resource; |
| 39 | import org.onosproject.net.resource.ResourceService; |
| 40 | import org.onosproject.net.resource.Resources; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 41 | import org.onosproject.ui.topo.TopoConstants.CoreButtons; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 42 | import org.onosproject.cli.AbstractShellCommand; |
| 43 | |
| 44 | /** |
| 45 | * PCE WEB topology overlay. |
| 46 | */ |
| 47 | public class PceWebTopovOverlay extends UiTopoOverlay { |
| 48 | |
| 49 | // NOTE: this must match the ID defined in pcewebTopovOverlay.js |
| 50 | private static final String OVERLAY_ID = "PCE-web-overlay"; |
| 51 | private static final String MY_TITLE = "Device details"; |
| 52 | |
| 53 | public static final String AS_NUMBER = "asNumber"; |
| 54 | public static final String DOMAIN_IDENTIFIER = "domainIdentifier"; |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 55 | public static final String ABR_BIT = "abrBit"; |
| 56 | public static final String ASBR_BIT = "externalBit"; |
| 57 | public static final String TE_METRIC = "teCost"; |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 58 | |
| 59 | private static final ButtonId SRC_BUTTON = new ButtonId("src"); |
| 60 | private static final ButtonId DST_BUTTON = new ButtonId("dst"); |
| 61 | /** |
| 62 | * Initialize the overlay ID. |
| 63 | */ |
| 64 | public PceWebTopovOverlay() { |
| 65 | super(OVERLAY_ID); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void deactivate() { |
| 70 | super.deactivate(); |
| 71 | log.debug("Deactivated"); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) { |
| 76 | |
| 77 | pp.title(MY_TITLE); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 78 | |
| 79 | DeviceService deviceService = AbstractShellCommand.get(DeviceService.class); |
| 80 | |
| 81 | pp.removeAllProps(); |
| 82 | |
| 83 | pp.addButton(SRC_BUTTON).addButton(DST_BUTTON); |
| 84 | |
| 85 | pp.removeButtons(CoreButtons.SHOW_PORT_VIEW) |
| 86 | .removeButtons(CoreButtons.SHOW_GROUP_VIEW) |
| 87 | .removeButtons(CoreButtons.SHOW_METER_VIEW); |
| 88 | |
| 89 | if (deviceService != null) { |
| 90 | |
| 91 | Device device = deviceService.getDevice(deviceId); |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 92 | Annotations annots = device.annotations(); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 93 | |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 94 | String routerId = annots.value(AnnotationKeys.ROUTER_ID); |
| 95 | String type = annots.value(AnnotationKeys.TYPE); |
| 96 | String asNumber = annots.value(AS_NUMBER); |
| 97 | String domain = annots.value(DOMAIN_IDENTIFIER); |
| 98 | String abrStatus = annots.value(ABR_BIT); |
| 99 | String asbrStatus = annots.value(ASBR_BIT); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 100 | |
| 101 | if (type != null) { |
| 102 | pp.addProp("Type", type); |
| 103 | } |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 104 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 105 | if (routerId != null) { |
| 106 | pp.addProp("Router-ID", routerId); |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 107 | } |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 108 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 109 | if (asNumber != null) { |
| 110 | pp.addProp("AS Number", asNumber); |
| 111 | } |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 112 | |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 113 | if (domain != null) { |
| 114 | pp.addProp("Domain ID", domain); |
| 115 | } |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 116 | |
| 117 | if (abrStatus != null) { |
| 118 | pp.addProp("ABR Role", abrStatus); |
| 119 | } |
| 120 | |
| 121 | if (asbrStatus != null) { |
| 122 | pp.addProp("ASBR Role", asbrStatus); |
| 123 | } |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | @Override |
Mahesh Raju-Huawei | 31d31c0 | 2016-06-04 17:20:57 +0530 | [diff] [blame^] | 128 | public Map<String, String> additionalLinkData(LinkEvent event) { |
| 129 | Map<String, String> map = new HashMap<>(); |
| 130 | Link link = event.subject(); |
| 131 | |
| 132 | map.put("Src port", link.src().port().toString()); |
| 133 | map.put("Dst port", link.dst().port().toString()); |
| 134 | map.put("Te metric", link.annotations().value(TE_METRIC)); |
| 135 | |
| 136 | ResourceService resService = AbstractShellCommand.get(ResourceService.class); |
| 137 | DiscreteResource devResource = Resources.discrete(link.src().deviceId(), link.src().port()).resource(); |
| 138 | if (resService == null) { |
| 139 | log.warn("resource service does not exist "); |
| 140 | return map; |
| 141 | } |
| 142 | |
| 143 | if (devResource == null) { |
| 144 | log.warn("Device resources does not exist "); |
| 145 | return map; |
| 146 | } |
| 147 | Set<Resource> resources = resService.getAvailableResources(devResource.id(), Bandwidth.class); |
| 148 | if (resources.isEmpty()) { |
| 149 | log.warn("Bandwidth resources does not exist "); |
| 150 | return map; |
| 151 | } |
| 152 | |
| 153 | if (resources.iterator().next() instanceof ContinuousResource) { |
| 154 | map.put("Bandwidth", ((ContinuousResource) resources.iterator().next()).toString()); |
| 155 | } |
| 156 | |
| 157 | return map; |
| 158 | } |
| 159 | |
| 160 | @Override |
Mahesh Raju-Huawei | 8593005 | 2016-04-26 21:09:57 +0530 | [diff] [blame] | 161 | public void modifyHostDetails(PropertyPanel pp, HostId hostId) { |
| 162 | pp.addButton(SRC_BUTTON).addButton(DST_BUTTON); |
| 163 | } |
| 164 | } |