Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 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.iptopology.api; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
Priyanka B | 41615e5 | 2015-12-05 21:22:21 +0530 | [diff] [blame] | 20 | import java.util.HashMap; |
| 21 | import java.util.Map; |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Represents protection capabilities of the link. |
| 26 | */ |
| 27 | public class ProtectionType { |
| 28 | private final LinkProtectionType protectionType; |
| 29 | |
| 30 | /** |
| 31 | * Enum to provide Link Protection type. |
| 32 | */ |
| 33 | public enum LinkProtectionType { |
| 34 | Extra_Traffic(1), Unprotected(2), Shared(4), Enhanced(0x20), Dedicated_OneIsToOne(8), |
| 35 | Dedicated_OnePlusOne(0x10), Reserved(0x40); |
| 36 | int value; |
| 37 | |
| 38 | /** |
| 39 | * Constructor to assign value. |
| 40 | * |
| 41 | * @param val link protection type |
| 42 | */ |
| 43 | LinkProtectionType(int val) { |
| 44 | value = val; |
| 45 | } |
| 46 | |
Priyanka B | 41615e5 | 2015-12-05 21:22:21 +0530 | [diff] [blame] | 47 | static Map<Integer, LinkProtectionType> map = new HashMap<>(); |
| 48 | |
| 49 | static { |
| 50 | for (LinkProtectionType type : LinkProtectionType.values()) { |
| 51 | map.put(type.value, type); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * A method that returns enum value. |
| 57 | * |
| 58 | * @param value link protection type |
| 59 | * @return Enum value |
| 60 | */ |
| 61 | public static LinkProtectionType getEnumType(int value) { |
| 62 | return map.get(value); |
| 63 | } |
| 64 | |
Satish K | f6d87cb | 2015-11-30 19:59:22 +0530 | [diff] [blame] | 65 | /** |
| 66 | * Provides Link protection type. |
| 67 | * |
| 68 | * @return protection type |
| 69 | */ |
| 70 | public byte type() { |
| 71 | return (byte) value; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Constructor to initialize protection type. |
| 77 | * |
| 78 | * @param protectionType link protection type |
| 79 | */ |
| 80 | public ProtectionType(LinkProtectionType protectionType) { |
| 81 | this.protectionType = protectionType; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Provides protection capabilities of the link. |
| 86 | * |
| 87 | * @return link protection type. |
| 88 | */ |
| 89 | public LinkProtectionType protectionType() { |
| 90 | return protectionType; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public int hashCode() { |
| 95 | return Objects.hash(protectionType); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public boolean equals(Object obj) { |
| 100 | if (this == obj) { |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | if (obj instanceof ProtectionType) { |
| 105 | ProtectionType other = (ProtectionType) obj; |
| 106 | return Objects.equals(protectionType, other.protectionType); |
| 107 | } |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public String toString() { |
| 113 | return toStringHelper(this) |
| 114 | .add("protectionType", protectionType) |
| 115 | .toString(); |
| 116 | } |
| 117 | } |