blob: be7fb5a9936bc896886c6b1961b722286905bc34 [file] [log] [blame]
Satish Kf6d87cb2015-11-30 19:59:22 +05301/*
2 * Copyright 2015 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 */
16package org.onosproject.iptopology.api;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20import java.util.Objects;
21
22/**
23 * Represents protection capabilities of the link.
24 */
25public class ProtectionType {
26 private final LinkProtectionType protectionType;
27
28 /**
29 * Enum to provide Link Protection type.
30 */
31 public enum LinkProtectionType {
32 Extra_Traffic(1), Unprotected(2), Shared(4), Enhanced(0x20), Dedicated_OneIsToOne(8),
33 Dedicated_OnePlusOne(0x10), Reserved(0x40);
34 int value;
35
36 /**
37 * Constructor to assign value.
38 *
39 * @param val link protection type
40 */
41 LinkProtectionType(int val) {
42 value = val;
43 }
44
45 /**
46 * Provides Link protection type.
47 *
48 * @return protection type
49 */
50 public byte type() {
51 return (byte) value;
52 }
53 }
54
55 /**
56 * Constructor to initialize protection type.
57 *
58 * @param protectionType link protection type
59 */
60 public ProtectionType(LinkProtectionType protectionType) {
61 this.protectionType = protectionType;
62 }
63
64 /**
65 * Provides protection capabilities of the link.
66 *
67 * @return link protection type.
68 */
69 public LinkProtectionType protectionType() {
70 return protectionType;
71 }
72
73 @Override
74 public int hashCode() {
75 return Objects.hash(protectionType);
76 }
77
78 @Override
79 public boolean equals(Object obj) {
80 if (this == obj) {
81 return true;
82 }
83
84 if (obj instanceof ProtectionType) {
85 ProtectionType other = (ProtectionType) obj;
86 return Objects.equals(protectionType, other.protectionType);
87 }
88 return false;
89 }
90
91 @Override
92 public String toString() {
93 return toStringHelper(this)
94 .add("protectionType", protectionType)
95 .toString();
96 }
97}