blob: 044b7a2438cdbad63772e9744d8e26269a9467c0 [file] [log] [blame]
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +05301/*
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
17package org.onosproject.pceweb;
18
19
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053020import java.util.HashMap;
21import java.util.Map;
22import java.util.Set;
23
24import org.onlab.util.Bandwidth;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053025import org.onosproject.net.AnnotationKeys;
26import org.onosproject.net.Annotations;
27import org.onosproject.net.Device;
28import org.onosproject.net.DeviceId;
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053029import org.onosproject.net.Link;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053030import org.onosproject.ui.UiTopoOverlay;
31import org.onosproject.ui.topo.ButtonId;
32import org.onosproject.ui.topo.PropertyPanel;
33import org.onosproject.net.HostId;
34import org.onosproject.net.device.DeviceService;
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053035import org.onosproject.net.link.LinkEvent;
36import org.onosproject.net.resource.ContinuousResource;
37import org.onosproject.net.resource.DiscreteResource;
38import org.onosproject.net.resource.Resource;
39import org.onosproject.net.resource.ResourceService;
40import org.onosproject.net.resource.Resources;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053041import org.onosproject.ui.topo.TopoConstants.CoreButtons;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053042import org.onosproject.cli.AbstractShellCommand;
43
44/**
45 * PCE WEB topology overlay.
46 */
47public 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-Huawei31d31c02016-06-04 17:20:57 +053055 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-Huawei85930052016-04-26 21:09:57 +053058
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-Huawei85930052016-04-26 21:09:57 +053078
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-Huawei31d31c02016-06-04 17:20:57 +053092 Annotations annots = device.annotations();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053093
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053094 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-Huawei85930052016-04-26 21:09:57 +0530100
101 if (type != null) {
102 pp.addProp("Type", type);
103 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530104
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530105 if (routerId != null) {
106 pp.addProp("Router-ID", routerId);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530107 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530108
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530109 if (asNumber != null) {
110 pp.addProp("AS Number", asNumber);
111 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530112
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530113 if (domain != null) {
114 pp.addProp("Domain ID", domain);
115 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530116
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-Huawei85930052016-04-26 21:09:57 +0530124 }
125 }
126
127 @Override
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530128 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-Huawei85930052016-04-26 21:09:57 +0530161 public void modifyHostDetails(PropertyPanel pp, HostId hostId) {
162 pp.addButton(SRC_BUTTON).addButton(DST_BUTTON);
163 }
164}