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