daniel park | 128c52c | 2017-09-04 13:15:51 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | package org.onosproject.openstacknetworkingui; |
| 17 | |
| 18 | import org.onosproject.net.Link; |
| 19 | import org.onosproject.net.LinkKey; |
| 20 | |
| 21 | import org.onosproject.ui.topo.BiLink; |
| 22 | import org.onosproject.ui.topo.LinkHighlight; |
| 23 | import org.onosproject.ui.topo.Mod; |
| 24 | |
| 25 | import java.util.Objects; |
| 26 | |
| 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 28 | import static org.onosproject.ui.topo.LinkHighlight.Flavor.SECONDARY_HIGHLIGHT; |
| 29 | |
| 30 | /** |
| 31 | * Link for OpenStack Networking UI service. |
| 32 | */ |
| 33 | public class OpenstackLink extends BiLink { |
| 34 | |
| 35 | private static final Mod PORT_TRAFFIC_GREEN = new Mod("port-traffic-green"); |
| 36 | private static final Mod PORT_TRAFFIC_ORANGE = new Mod("port-traffic-orange"); |
| 37 | |
| 38 | public OpenstackLink(LinkKey key, Link link) { |
| 39 | super(key, link); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public boolean equals(Object obj) { |
| 44 | if (this == obj) { |
| 45 | return true; |
| 46 | } |
| 47 | if (obj instanceof OpenstackLink) { |
| 48 | OpenstackLink that = (OpenstackLink) obj; |
| 49 | if (Objects.equals(linkId(), that.linkId())) { |
| 50 | return true; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | return Objects.hash(linkId()); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public String toString() { |
| 64 | return toStringHelper(this) |
| 65 | .add("linkId", linkId()) |
| 66 | .add("link src", one().src().deviceId()) |
| 67 | .add("link dst", one().dst().deviceId()) |
| 68 | .toString(); |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public LinkHighlight highlight(Enum<?> type) { |
| 73 | RequestType requestType = (RequestType) type; |
| 74 | |
| 75 | Mod m = null; |
| 76 | |
| 77 | switch (requestType) { |
| 78 | case HOST_SELECTED: |
| 79 | m = PORT_TRAFFIC_GREEN; |
| 80 | break; |
| 81 | case DEVICE_SELECTED: |
| 82 | m = PORT_TRAFFIC_ORANGE; |
| 83 | break; |
| 84 | default: |
| 85 | break; |
| 86 | } |
| 87 | LinkHighlight hlite = new LinkHighlight(linkId(), SECONDARY_HIGHLIGHT); |
| 88 | if (m != null) { |
| 89 | hlite.addMod(m); |
| 90 | } |
| 91 | |
| 92 | return hlite; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Designates requested type. |
| 97 | */ |
| 98 | public enum RequestType { |
| 99 | HOST_SELECTED, |
| 100 | DEVICE_SELECTED, |
| 101 | } |
| 102 | } |