blob: 9ec3777b8814202bdd0b51b97e53d36dc3bf1005 [file] [log] [blame]
Jian Li136fd6c2017-02-10 14:54:59 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li136fd6c2017-02-10 14:54:59 +09003 *
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.mapping.instructions;
17
18import java.util.Objects;
19
20/**
21 * Abstraction of an uni-cast mapping traffic engineering.
22 */
23public abstract class UnicastMappingInstruction implements MappingInstruction {
24
25 private static final String SEPARATOR = ":";
26
27 /**
28 * Represents the type of Unicast traffic engineering.
29 */
30 public enum UnicastType {
31
32 /**
33 * Signifies the weight value that used in unicast traffic engineering.
34 */
35 WEIGHT,
36
37 /**
38 * Signifies the priority value that used in unicast traffic engineering.
39 */
40 PRIORITY
41 }
42
43 public abstract UnicastType subtype();
44
45 @Override
46 public final Type type() {
47 return Type.UNICAST;
48 }
49
50 /**
51 * Represents an unicast weight configuration instruction.
52 */
53 public static final class WeightMappingInstruction extends UnicastMappingInstruction {
54
55 private final UnicastType subtype;
56 private final int weight;
57
58 WeightMappingInstruction(UnicastType subType, int weight) {
59 this.subtype = subType;
60 this.weight = weight;
61 }
62
63 @Override
64 public UnicastType subtype() {
65 return subtype;
66 }
67
68 /**
69 * Returns weight value of unicast TE.
70 *
71 * @return weight value of unicast TE
72 */
73 public int weight() {
74 return this.weight;
75 }
76
77 @Override
78 public String toString() {
79 return subtype().toString() + SEPARATOR + weight;
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(type(), subtype, weight);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (obj instanceof WeightMappingInstruction) {
93 WeightMappingInstruction that = (WeightMappingInstruction) obj;
94 return Objects.equals(weight, that.weight) &&
95 Objects.equals(subtype, that.subtype);
96 }
97 return false;
98 }
99 }
100
101 /**
102 * Represents an unicast priority configuration instruction.
103 */
104 public static final class PriorityMappingInstruction extends UnicastMappingInstruction {
105
106 private final UnicastType subtype;
107 private final int priority;
108
109 PriorityMappingInstruction(UnicastType subType, int priority) {
110 this.subtype = subType;
111 this.priority = priority;
112 }
113
114 @Override
115 public UnicastType subtype() {
116 return this.subtype;
117 }
118
119 /**
120 * Returns priority value of unicast TE.
121 *
122 * @return priority value of unicast TE
123 */
124 public int priority() {
125 return this.priority;
126 }
127
128 @Override
129 public String toString() {
130 return subtype().toString() + SEPARATOR + priority;
131 }
132
133 @Override
134 public int hashCode() {
135 return Objects.hash(type(), subtype, priority);
136 }
137
138 @Override
139 public boolean equals(Object obj) {
140 if (this == obj) {
141 return true;
142 }
143 if (obj instanceof PriorityMappingInstruction) {
144 PriorityMappingInstruction that = (PriorityMappingInstruction) obj;
145 return Objects.equals(priority, that.priority) &&
146 Objects.equals(subtype, that.subtype);
147 }
148 return false;
149 }
150 }
151}