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