blob: 8f6fa55c4eb64f82335f7323c53151687921ee3c [file] [log] [blame]
Carmelo Cascone5899c132016-04-06 22:09:08 -07001/*
Carmelo Casconeaa8b6292016-04-13 14:27:06 -07002 * Copyright 2016-present Open Networking Laboratory
Carmelo Cascone5899c132016-04-06 22:09:08 -07003 *
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 Cascone17fc9e42016-05-31 11:29:21 -070017package org.onosproject.bmv2.api.context;
Carmelo Cascone5899c132016-04-06 22:09:08 -070018
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070019import com.google.common.annotations.Beta;
Carmelo Cascone5899c132016-04-06 22:09:08 -070020import com.google.common.base.Objects;
21
22import java.util.List;
23import java.util.Set;
24
25import static com.google.common.base.MoreObjects.toStringHelper;
26
27/**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070028 * A BMv2 table model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070029 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070030@Beta
31public final class Bmv2TableModel {
Carmelo Cascone5899c132016-04-06 22:09:08 -070032
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 Cascone17fc9e42016-05-31 11:29:21 -070040 private final List<Bmv2TableKeyModel> keys;
41 private final Set<Bmv2ActionModel> actions;
Carmelo Cascone5899c132016-04-06 22:09:08 -070042
43 /**
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070044 * Creates a new table model.
Carmelo Cascone5899c132016-04-06 22:09:08 -070045 *
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 Cascone17fc9e42016-05-31 11:29:21 -070056 protected Bmv2TableModel(String name, int id, String matchType, String type,
Carmelo Cascone5899c132016-04-06 22:09:08 -070057 int maxSize, boolean withCounters, boolean supportTimeout,
Carmelo Cascone17fc9e42016-05-31 11:29:21 -070058 List<Bmv2TableKeyModel> keys, Set<Bmv2ActionModel> actions) {
Carmelo Cascone5899c132016-04-06 22:09:08 -070059 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 Casconef8cf2882016-05-04 14:06:17 -0700120 public boolean hasCounters() {
Carmelo Cascone5899c132016-04-06 22:09:08 -0700121 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 Cascone17fc9e42016-05-31 11:29:21 -0700139 public List<Bmv2TableKeyModel> keys() {
Carmelo Cascone5899c132016-04-06 22:09:08 -0700140 return keys;
141 }
142
143 /**
144 * Returns the set of actions supported by this table.
145 *
146 * @return a list of actions
147 */
Carmelo Cascone17fc9e42016-05-31 11:29:21 -0700148 public Set<Bmv2ActionModel> actions() {
Carmelo Cascone5899c132016-04-06 22:09:08 -0700149 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 Cascone17fc9e42016-05-31 11:29:21 -0700166 final Bmv2TableModel other = (Bmv2TableModel) obj;
Carmelo Cascone5899c132016-04-06 22:09:08 -0700167 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}