blob: 1a328151b73c6da4ad1bb38f000816c167331e1d [file] [log] [blame]
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +05303 *
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
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053024import org.onosproject.net.AnnotationKeys;
25import org.onosproject.net.Annotations;
26import org.onosproject.net.Device;
27import org.onosproject.net.DeviceId;
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053028import org.onosproject.net.Link;
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053029import org.onosproject.net.resource.ContinuousResource;
30import org.onosproject.net.resource.ResourceService;
31import org.onosproject.net.resource.Resource;
32import org.onosproject.net.resource.DiscreteResource;
33import org.onosproject.net.resource.Resources;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053034import org.onosproject.ui.UiTopoOverlay;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053035import org.onosproject.ui.topo.PropertyPanel;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053036import org.onosproject.net.device.DeviceService;
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053037import org.onosproject.net.link.LinkEvent;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053038import org.onosproject.ui.topo.TopoConstants.CoreButtons;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053039import org.onosproject.cli.AbstractShellCommand;
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053040import org.onlab.packet.Ip4Address;
41import org.onlab.packet.IpAddress;
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053042/**
43 * PCE WEB topology overlay.
44 */
45public class PceWebTopovOverlay extends UiTopoOverlay {
46
Ray Milkey312221c2019-02-19 11:31:29 -080047 // NOTE: this must match the ID defined in pcewebTopovOverlay.js
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053048 private static final String OVERLAY_ID = "PCE-web-overlay";
49 private static final String MY_TITLE = "Device details";
50
51 public static final String AS_NUMBER = "asNumber";
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053052 public static final String LSR_ID = "lsrId";
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053053 public static final String ABR_BIT = "abrBit";
54 public static final String ASBR_BIT = "externalBit";
55 public static final String TE_METRIC = "teCost";
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053056 public static final String ABR = "ABR";
57 public static final String ASBR = "ASBR";
58 public static final String ABR_ASBR = "ABR/ASBR";
59 public static final String INNER = "Inner";
60 public static final long IDENTIFIER_SET = 0x100000000L;
61 public static final long SET = 0xFFFFFFFFL;
Ray Milkey312221c2019-02-19 11:31:29 -080062 public static final String TYPE_LABEL = "Type";
63 public static final String AS_NUMBER_LABEL = "AS Number";
64 public static final String LSR_ID_LABEL = "LSR ID";
65 public static final String POSITION_LABEL = "Position";
66
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053067 /**
68 * Initialize the overlay ID.
69 */
70 public PceWebTopovOverlay() {
71 super(OVERLAY_ID);
72 }
73
74 @Override
75 public void deactivate() {
76 super.deactivate();
77 log.debug("Deactivated");
78 }
79
80 @Override
81 public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) {
82
83 pp.title(MY_TITLE);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053084 DeviceService deviceService = AbstractShellCommand.get(DeviceService.class);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053085 pp.removeAllProps();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053086 pp.removeButtons(CoreButtons.SHOW_PORT_VIEW)
87 .removeButtons(CoreButtons.SHOW_GROUP_VIEW)
88 .removeButtons(CoreButtons.SHOW_METER_VIEW);
89
90 if (deviceService != null) {
91
92 Device device = deviceService.getDevice(deviceId);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053093 Annotations annots = device.annotations();
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +053094
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053095 String type = annots.value(AnnotationKeys.TYPE);
96 String asNumber = annots.value(AS_NUMBER);
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +053097 String lsrId = annots.value(LSR_ID);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +053098 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) {
Ray Milkey312221c2019-02-19 11:31:29 -0800102 pp.addProp(TYPE_LABEL, TYPE_LABEL, type);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530103 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530104
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530105 if (asNumber != null) {
Ray Milkey312221c2019-02-19 11:31:29 -0800106 pp.addProp(AS_NUMBER_LABEL, AS_NUMBER_LABEL, asNumber);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530107 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530108
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530109 if (lsrId != null) {
Ray Milkey312221c2019-02-19 11:31:29 -0800110 pp.addProp(LSR_ID_LABEL, LSR_ID_LABEL, lsrId);
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530111 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530112
kdarapu7abfe0e2017-04-16 05:30:44 +0530113 if (Boolean.valueOf(abrStatus).equals(true) && Boolean.valueOf(asbrStatus).equals(true)) {
Ray Milkey312221c2019-02-19 11:31:29 -0800114 pp.addProp(POSITION_LABEL, POSITION_LABEL, ABR_ASBR);
kdarapu7abfe0e2017-04-16 05:30:44 +0530115 } else if (Boolean.valueOf(abrStatus).equals(true)) {
Ray Milkey312221c2019-02-19 11:31:29 -0800116 pp.addProp(POSITION_LABEL, POSITION_LABEL, ABR);
kdarapu7abfe0e2017-04-16 05:30:44 +0530117 } else if (Boolean.valueOf(asbrStatus).equals(true)) {
Ray Milkey312221c2019-02-19 11:31:29 -0800118 pp.addProp(POSITION_LABEL, POSITION_LABEL, ASBR);
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530119 } else {
Ray Milkey312221c2019-02-19 11:31:29 -0800120 pp.addProp(POSITION_LABEL, POSITION_LABEL, INNER);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530121 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530122 }
123 }
124
125 @Override
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530126 public Map<String, String> additionalLinkData(LinkEvent event) {
127 Map<String, String> map = new HashMap<>();
128 Link link = event.subject();
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530129 long srcPortNo;
130 long dstPortNo;
131 IpAddress ipDstAddress = null;
132 IpAddress ipSrcAddress = null;
133 String srcPort;
134 String dstPort;
135 String bandWidth;
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530136
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530137 srcPortNo = link.src().port().toLong();
138 if (((srcPortNo & IDENTIFIER_SET) == IDENTIFIER_SET)) {
139 srcPort = String.valueOf(srcPortNo);
140 } else {
141 ipSrcAddress = Ip4Address.valueOf((int) srcPortNo);
142 srcPort = ipSrcAddress.toString();
143 }
144
145 dstPortNo = link.dst().port().toLong();
146 if (((dstPortNo & IDENTIFIER_SET) == IDENTIFIER_SET)) {
147 dstPort = String.valueOf(dstPortNo);
148 } else {
149 ipDstAddress = Ip4Address.valueOf((int) dstPortNo);
150 dstPort = ipDstAddress.toString();
151 }
152
153 map.put("Src Address", srcPort);
154 map.put("Dst Address", dstPort);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530155 map.put("Te metric", link.annotations().value(TE_METRIC));
156
157 ResourceService resService = AbstractShellCommand.get(ResourceService.class);
158 DiscreteResource devResource = Resources.discrete(link.src().deviceId(), link.src().port()).resource();
159 if (resService == null) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530160 log.warn("resource service does not exist");
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530161 return map;
162 }
163
164 if (devResource == null) {
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530165 log.warn("Device resources does not exist");
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530166 return map;
167 }
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530168 double regBandwidth = 0;
169 try {
170 Thread.sleep(100);
171 } catch (InterruptedException e) {
Ray Milkeyc108a6b2017-08-23 15:23:50 -0700172 log.error("Exception occurred while getting the bandwidth.");
Ray Milkey5c7d4882018-02-05 14:50:39 -0800173 Thread.currentThread().interrupt();
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530174 }
175 Set<Resource> resources = resService.getRegisteredResources(devResource.id());
176 for (Resource res : resources) {
177 if (res instanceof ContinuousResource) {
178 regBandwidth = ((ContinuousResource) res).value();
179 break;
180 }
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530181 }
182
MaheshRaju-Huawei4bf9f2d2016-07-01 19:03:18 +0530183 if (regBandwidth != 0) {
184 bandWidth = String.valueOf(regBandwidth);
185 map.put("Bandwidth", bandWidth);
Mahesh Raju-Huawei31d31c02016-06-04 17:20:57 +0530186 }
187
188 return map;
189 }
Mahesh Raju-Huawei85930052016-04-26 21:09:57 +0530190}