blob: 49f5f180e591a37c6b4b45e4267e957b2b467170 [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
Priyanka Bc77921a2015-12-07 20:59:41 +053020import java.util.HashMap;
21import java.util.Map;
Satish Kf6d87cb2015-11-30 19:59:22 +053022import java.util.Objects;
23
24/**
25 * Represents Route type of the prefix in the OSPF domain.
26 */
27public class RouteType {
28 private final Type routeType;
29
30 /**
31 * Enum to provide Route type.
32 */
33 public enum Type {
34 Intra_Area(1), Inter_Area(2), External_1(3), External_2(4), NSSA_1(5), NSSA_2(6);
35 int value;
36
37 /**
38 * Constructor to assign value.
39 *
40 * @param val route type
41 */
42 Type(int val) {
43 value = val;
44 }
45
Priyanka Bc77921a2015-12-07 20:59:41 +053046 static Map<Integer, Type> map = new HashMap<>();
47
48 static {
49 for (Type type : Type.values()) {
50 map.put(type.value, type);
51 }
52 }
53
54 /**
55 * A method that returns enum value.
56 *
57 * @param value route type
58 * @return Enum value
59 */
60 public static Type getEnumType(int value) {
61 return map.get(value);
62 }
63
Satish Kf6d87cb2015-11-30 19:59:22 +053064 /**
65 * Provides route type.
66 *
67 * @return route type
68 */
69 public byte type() {
70 return (byte) value;
71 }
72 }
73
74 /**
75 * Constructor to initialize routeType.
76 *
77 * @param routeType Route type
78 */
79 public RouteType(Type routeType) {
80 this.routeType = routeType;
81 }
82
83 /**
84 * Provides Route type of the prefix.
85 *
86 * @return Route type
87 */
88 public Type routeType() {
89 return routeType;
90 }
91
92 @Override
93 public int hashCode() {
94 return Objects.hash(routeType);
95 }
96
97 @Override
98 public boolean equals(Object obj) {
99 if (this == obj) {
100 return true;
101 }
102
103 if (obj instanceof RouteType) {
104 RouteType other = (RouteType) obj;
105 return Objects.equals(routeType, other.routeType);
106 }
107 return false;
108 }
109
110 @Override
111 public String toString() {
112 return toStringHelper(this)
113 .add("routeType", routeType)
114 .toString();
115 }
116}