Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 1 | /* |
Carmelo Cascone | aa8b629 | 2016-04-13 14:27:06 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [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 | |
Carmelo Cascone | aa8b629 | 2016-04-13 14:27:06 -0700 | [diff] [blame] | 17 | package org.onosproject.bmv2.api.model; |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 18 | |
| 19 | import com.google.common.base.Objects; |
| 20 | |
| 21 | import java.util.List; |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | |
| 26 | /** |
| 27 | * BMv2 model table representation. |
| 28 | */ |
| 29 | public final class Bmv2ModelTable { |
| 30 | |
| 31 | private final String name; |
| 32 | private final int id; |
| 33 | private final String matchType; |
| 34 | private final String type; |
| 35 | private final int maxSize; |
| 36 | private final boolean hasCounters; |
| 37 | private final boolean hasTimeouts; |
| 38 | private final List<Bmv2ModelTableKey> keys; |
| 39 | private final Set<Bmv2ModelAction> actions; |
| 40 | |
| 41 | /** |
| 42 | * Creates a new table. |
| 43 | * |
| 44 | * @param name name |
| 45 | * @param id id |
| 46 | * @param matchType match type |
| 47 | * @param type type |
| 48 | * @param maxSize max number of entries |
| 49 | * @param withCounters if table has counters |
| 50 | * @param supportTimeout if table supports aging |
| 51 | * @param keys list of match keys |
| 52 | * @param actions list of actions |
| 53 | */ |
| 54 | protected Bmv2ModelTable(String name, int id, String matchType, String type, |
| 55 | int maxSize, boolean withCounters, boolean supportTimeout, |
| 56 | List<Bmv2ModelTableKey> keys, Set<Bmv2ModelAction> actions) { |
| 57 | this.name = name; |
| 58 | this.id = id; |
| 59 | this.matchType = matchType; |
| 60 | this.type = type; |
| 61 | this.maxSize = maxSize; |
| 62 | this.hasCounters = withCounters; |
| 63 | this.hasTimeouts = supportTimeout; |
| 64 | this.keys = keys; |
| 65 | this.actions = actions; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the name of this table. |
| 70 | * |
| 71 | * @return a string value |
| 72 | */ |
| 73 | public String name() { |
| 74 | return name; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Returns the id of this table. |
| 79 | * |
| 80 | * @return an integer value |
| 81 | */ |
| 82 | public int id() { |
| 83 | return id; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Return the match type of this table. |
| 88 | * |
| 89 | * @return a string value |
| 90 | */ |
| 91 | public String matchType() { |
| 92 | return matchType; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Return the match type of this table. |
| 97 | * |
| 98 | * @return a string value |
| 99 | */ |
| 100 | public String type() { |
| 101 | return type; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Returns the maximum number of entries supported by this table. |
| 106 | * |
| 107 | * @return an integer value |
| 108 | */ |
| 109 | public int maxSize() { |
| 110 | return maxSize; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Returns true if this table has counters, false otherwise. |
| 115 | * |
| 116 | * @return a boolean value |
| 117 | */ |
Carmelo Cascone | f8cf288 | 2016-05-04 14:06:17 -0700 | [diff] [blame] | 118 | public boolean hasCounters() { |
Carmelo Cascone | 5899c13 | 2016-04-06 22:09:08 -0700 | [diff] [blame] | 119 | return hasCounters; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns true if this table supports aging, false otherwise. |
| 124 | * |
| 125 | * @return a boolean value |
| 126 | */ |
| 127 | public boolean hasTimeouts() { |
| 128 | return hasTimeouts; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Returns the list of match keys supported by this table. |
| 133 | * The list is ordered accordingly to the model's table definition. |
| 134 | * |
| 135 | * @return a list of match keys |
| 136 | */ |
| 137 | public List<Bmv2ModelTableKey> keys() { |
| 138 | return keys; |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Returns the set of actions supported by this table. |
| 143 | * |
| 144 | * @return a list of actions |
| 145 | */ |
| 146 | public Set<Bmv2ModelAction> actions() { |
| 147 | return actions; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public int hashCode() { |
| 152 | return Objects.hashCode(name, id, matchType, type, maxSize, hasCounters, |
| 153 | hasTimeouts, keys, actions); |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public boolean equals(Object obj) { |
| 158 | if (this == obj) { |
| 159 | return true; |
| 160 | } |
| 161 | if (obj == null || getClass() != obj.getClass()) { |
| 162 | return false; |
| 163 | } |
| 164 | final Bmv2ModelTable other = (Bmv2ModelTable) obj; |
| 165 | return Objects.equal(this.name, other.name) |
| 166 | && Objects.equal(this.id, other.id) |
| 167 | && Objects.equal(this.matchType, other.matchType) |
| 168 | && Objects.equal(this.type, other.type) |
| 169 | && Objects.equal(this.maxSize, other.maxSize) |
| 170 | && Objects.equal(this.hasCounters, other.hasCounters) |
| 171 | && Objects.equal(this.hasTimeouts, other.hasTimeouts) |
| 172 | && Objects.equal(this.keys, other.keys) |
| 173 | && Objects.equal(this.actions, other.actions); |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public String toString() { |
| 178 | return toStringHelper(this) |
| 179 | .add("name", name) |
| 180 | .add("id", id) |
| 181 | .add("matchType", matchType) |
| 182 | .add("type", type) |
| 183 | .add("maxSize", maxSize) |
| 184 | .add("hasCounters", hasCounters) |
| 185 | .add("hasTimeouts", hasTimeouts) |
| 186 | .add("keys", keys) |
| 187 | .add("actions", actions) |
| 188 | .toString(); |
| 189 | } |
| 190 | |
| 191 | } |