blob: f2346fd69adac57c4c71641199318e0c2c1264c3 [file] [log] [blame]
Satish Kf6d87cb2015-11-30 19:59:22 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Satish Kf6d87cb2015-11-30 19:59:22 +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 */
16package org.onosproject.iptopology.api;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
Priyanka B41615e52015-12-05 21:22:21 +053020import java.util.HashMap;
21import java.util.Map;
Satish Kf6d87cb2015-11-30 19:59:22 +053022import java.util.Objects;
23
24/**
25 * Represents protection capabilities of the link.
26 */
27public 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 B41615e52015-12-05 21:22:21 +053047 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 Kf6d87cb2015-11-30 19:59:22 +053065 /**
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}