alshabib
Committed by Gerrit Code Review

FlowRule api no longer uses TableTypes. Existing usages are converted to

integer representations via Type.ordinal() call

Change-Id: Ie2a26c5ced166e12f0e1ea22e39cd5195455a1ad
...@@ -137,7 +137,7 @@ public class FlowsListCommand extends AbstractShellCommand { ...@@ -137,7 +137,7 @@ public class FlowsListCommand extends AbstractShellCommand {
137 .put("bytes", flow.bytes()) 137 .put("bytes", flow.bytes())
138 .put("packets", flow.packets()) 138 .put("packets", flow.packets())
139 .put("life", flow.life()) 139 .put("life", flow.life())
140 - .put("tableId", flow.type().toString()) 140 + .put("tableId", flow.tableId())
141 .put("appId", appName); 141 .put("appId", appName);
142 result.set("selector", crit); 142 result.set("selector", crit);
143 result.set("treatment", instr); 143 result.set("treatment", instr);
...@@ -192,7 +192,7 @@ public class FlowsListCommand extends AbstractShellCommand { ...@@ -192,7 +192,7 @@ public class FlowsListCommand extends AbstractShellCommand {
192 if (!empty) { 192 if (!empty) {
193 for (FlowEntry f : flows) { 193 for (FlowEntry f : flows) {
194 print(FMT, Long.toHexString(f.id().value()), f.state(), 194 print(FMT, Long.toHexString(f.id().value()), f.state(),
195 - f.bytes(), f.packets(), f.life(), f.priority(), f.type(), 195 + f.bytes(), f.packets(), f.life(), f.priority(), f.tableId(),
196 coreService.getAppId(f.appId()).name()); 196 coreService.getAppId(f.appId()).name());
197 print(SFMT, f.selector().criteria()); 197 print(SFMT, f.selector().criteria());
198 print(TFMT, f.treatment()); 198 print(TFMT, f.treatment());
......
...@@ -42,7 +42,6 @@ public class DefaultFlowRule implements FlowRule { ...@@ -42,7 +42,6 @@ public class DefaultFlowRule implements FlowRule {
42 private final boolean permanent; 42 private final boolean permanent;
43 private final GroupId groupId; 43 private final GroupId groupId;
44 44
45 - private final Type type;
46 private final Integer tableId; 45 private final Integer tableId;
47 46
48 47
...@@ -61,7 +60,6 @@ public class DefaultFlowRule implements FlowRule { ...@@ -61,7 +60,6 @@ public class DefaultFlowRule implements FlowRule {
61 this.appId = (short) (flowId >>> 48); 60 this.appId = (short) (flowId >>> 48);
62 this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF)); 61 this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
63 this.id = FlowId.valueOf(flowId); 62 this.id = FlowId.valueOf(flowId);
64 - this.type = Type.DEFAULT;
65 this.tableId = 0; 63 this.tableId = 0;
66 } 64 }
67 65
...@@ -80,8 +78,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -80,8 +78,7 @@ public class DefaultFlowRule implements FlowRule {
80 this.appId = (short) (flowId >>> 48); 78 this.appId = (short) (flowId >>> 48);
81 this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF)); 79 this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
82 this.id = FlowId.valueOf(flowId); 80 this.id = FlowId.valueOf(flowId);
83 - this.type = tableType; 81 + this.tableId = tableType.ordinal();
84 - this.tableId = 0;
85 82
86 } 83 }
87 84
...@@ -111,8 +108,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -111,8 +108,7 @@ public class DefaultFlowRule implements FlowRule {
111 this.timeout = timeout; 108 this.timeout = timeout;
112 this.permanent = permanent; 109 this.permanent = permanent;
113 this.created = System.currentTimeMillis(); 110 this.created = System.currentTimeMillis();
114 - this.type = type; 111 + this.tableId = type.ordinal();
115 - this.tableId = 0;
116 112
117 /* 113 /*
118 * id consists of the following. 114 * id consists of the following.
...@@ -141,7 +137,6 @@ public class DefaultFlowRule implements FlowRule { ...@@ -141,7 +137,6 @@ public class DefaultFlowRule implements FlowRule {
141 this.timeout = timeout; 137 this.timeout = timeout;
142 this.permanent = permanent; 138 this.permanent = permanent;
143 this.created = System.currentTimeMillis(); 139 this.created = System.currentTimeMillis();
144 - this.type = Type.DEFAULT;
145 this.tableId = 0; 140 this.tableId = 0;
146 141
147 /* 142 /*
...@@ -163,7 +158,6 @@ public class DefaultFlowRule implements FlowRule { ...@@ -163,7 +158,6 @@ public class DefaultFlowRule implements FlowRule {
163 this.timeout = rule.timeout(); 158 this.timeout = rule.timeout();
164 this.permanent = rule.isPermanent(); 159 this.permanent = rule.isPermanent();
165 this.created = System.currentTimeMillis(); 160 this.created = System.currentTimeMillis();
166 - this.type = rule.type();
167 this.tableId = rule.tableId(); 161 this.tableId = rule.tableId();
168 162
169 } 163 }
...@@ -187,7 +181,6 @@ public class DefaultFlowRule implements FlowRule { ...@@ -187,7 +181,6 @@ public class DefaultFlowRule implements FlowRule {
187 181
188 //FIXME: fields below will be removed. 182 //FIXME: fields below will be removed.
189 this.groupId = null; 183 this.groupId = null;
190 - this.type = null;
191 184
192 185
193 } 186 }
...@@ -235,11 +228,11 @@ public class DefaultFlowRule implements FlowRule { ...@@ -235,11 +228,11 @@ public class DefaultFlowRule implements FlowRule {
235 * @see java.lang.Object#equals(java.lang.Object) 228 * @see java.lang.Object#equals(java.lang.Object)
236 */ 229 */
237 public int hashCode() { 230 public int hashCode() {
238 - return Objects.hash(deviceId, selector, priority, type, tableId); 231 + return Objects.hash(deviceId, selector, priority, tableId);
239 } 232 }
240 233
241 public int hash() { 234 public int hash() {
242 - return Objects.hash(deviceId, selector, treatment, type); 235 + return Objects.hash(deviceId, selector, treatment, tableId);
243 } 236 }
244 237
245 @Override 238 @Override
...@@ -258,8 +251,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -258,8 +251,7 @@ public class DefaultFlowRule implements FlowRule {
258 return Objects.equals(deviceId, that.deviceId) && 251 return Objects.equals(deviceId, that.deviceId) &&
259 Objects.equals(priority, that.priority) && 252 Objects.equals(priority, that.priority) &&
260 Objects.equals(selector, that.selector) && 253 Objects.equals(selector, that.selector) &&
261 - Objects.equals(tableId, that.tableId) && 254 + Objects.equals(tableId, that.tableId);
262 - Objects.equals(type, that.type);
263 255
264 } 256 }
265 return false; 257 return false;
...@@ -273,7 +265,7 @@ public class DefaultFlowRule implements FlowRule { ...@@ -273,7 +265,7 @@ public class DefaultFlowRule implements FlowRule {
273 .add("priority", priority) 265 .add("priority", priority)
274 .add("selector", selector.criteria()) 266 .add("selector", selector.criteria())
275 .add("treatment", treatment == null ? "N/A" : treatment.allInstructions()) 267 .add("treatment", treatment == null ? "N/A" : treatment.allInstructions())
276 - .add("table type", type) 268 + .add("tableId", tableId)
277 .add("created", created) 269 .add("created", created)
278 .toString(); 270 .toString();
279 } 271 }
...@@ -289,11 +281,6 @@ public class DefaultFlowRule implements FlowRule { ...@@ -289,11 +281,6 @@ public class DefaultFlowRule implements FlowRule {
289 } 281 }
290 282
291 @Override 283 @Override
292 - public Type type() {
293 - return type;
294 - }
295 -
296 - @Override
297 public int tableId() { 284 public int tableId() {
298 return tableId; 285 return tableId;
299 } 286 }
......
...@@ -127,14 +127,6 @@ public interface FlowRule { ...@@ -127,14 +127,6 @@ public interface FlowRule {
127 boolean isPermanent(); 127 boolean isPermanent();
128 128
129 /** 129 /**
130 - * Returns the flow rule type.
131 - *
132 - * @return flow rule type
133 - */
134 - @Deprecated
135 - Type type();
136 -
137 - /**
138 * Returns the table id for this rule. 130 * Returns the table id for this rule.
139 * 131 *
140 * @return an integer. 132 * @return an integer.
......
...@@ -333,13 +333,13 @@ public class IntentTestsMocks { ...@@ -333,13 +333,13 @@ public class IntentTestsMocks {
333 static int nextId = 0; 333 static int nextId = 0;
334 334
335 int priority; 335 int priority;
336 - Type type; 336 + int tableId;
337 long timestamp; 337 long timestamp;
338 int id; 338 int id;
339 339
340 public MockFlowRule(int priority) { 340 public MockFlowRule(int priority) {
341 this.priority = priority; 341 this.priority = priority;
342 - this.type = Type.DEFAULT; 342 + this.tableId = 0;
343 this.timestamp = System.currentTimeMillis(); 343 this.timestamp = System.currentTimeMillis();
344 this.id = nextId++; 344 this.id = nextId++;
345 } 345 }
...@@ -408,13 +408,8 @@ public class IntentTestsMocks { ...@@ -408,13 +408,8 @@ public class IntentTestsMocks {
408 } 408 }
409 409
410 @Override 410 @Override
411 - public Type type() {
412 - return type;
413 - }
414 -
415 - @Override
416 public int tableId() { 411 public int tableId() {
417 - return 0; 412 + return tableId;
418 } 413 }
419 } 414 }
420 415
......
...@@ -124,7 +124,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -124,7 +124,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
124 .setMatch(match) 124 .setMatch(match)
125 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) 125 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
126 .setPriority(flowRule().priority()) 126 .setPriority(flowRule().priority())
127 - .setTableId(TableId.of(flowRule().type().ordinal())) 127 + .setTableId(TableId.of(flowRule().tableId()))
128 .build(); 128 .build();
129 129
130 return fm; 130 return fm;
...@@ -161,7 +161,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -161,7 +161,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
161 .setMatch(match) 161 .setMatch(match)
162 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) 162 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
163 .setPriority(flowRule().priority()) 163 .setPriority(flowRule().priority())
164 - .setTableId(TableId.of(flowRule().type().ordinal())) 164 + .setTableId(TableId.of(flowRule().tableId()))
165 .build(); 165 .build();
166 166
167 return fm; 167 return fm;
...@@ -180,7 +180,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder { ...@@ -180,7 +180,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
180 .setMatch(match) 180 .setMatch(match)
181 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) 181 .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
182 .setPriority(flowRule().priority()) 182 .setPriority(flowRule().priority())
183 - .setTableId(TableId.of(flowRule().type().ordinal())) 183 + .setTableId(TableId.of(flowRule().tableId()))
184 .build(); 184 .build();
185 185
186 return fm; 186 return fm;
......
...@@ -144,11 +144,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -144,11 +144,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
144 144
145 private void applyRule(FlowRule flowRule) { 145 private void applyRule(FlowRule flowRule) {
146 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); 146 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri()));
147 - if (flowRule.type() == FlowRule.Type.DEFAULT) { 147 + if (flowRule.tableId() == 0) {
148 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), 148 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
149 Optional.empty()).buildFlowAdd()); 149 Optional.empty()).buildFlowAdd());
150 } else { 150 } else {
151 - OpenFlowSwitch.TableType type = getTableType(flowRule.type()); 151 + OpenFlowSwitch.TableType type = getTableType(flowRule.tableId());
152 sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(), 152 sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
153 Optional.empty()).buildFlowAdd(), 153 Optional.empty()).buildFlowAdd(),
154 type); 154 type);
...@@ -166,12 +166,12 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -166,12 +166,12 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
166 166
167 private void removeRule(FlowRule flowRule) { 167 private void removeRule(FlowRule flowRule) {
168 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); 168 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri()));
169 - if (flowRule.type() == FlowRule.Type.DEFAULT) { 169 + if (flowRule.tableId() == 0) {
170 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), 170 sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
171 Optional.empty()).buildFlowDel()); 171 Optional.empty()).buildFlowDel());
172 } else { 172 } else {
173 sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(), 173 sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
174 - Optional.empty()).buildFlowDel(), getTableType(flowRule.type())); 174 + Optional.empty()).buildFlowDel(), getTableType(flowRule.tableId()));
175 } 175 }
176 } 176 }
177 177
...@@ -211,10 +211,10 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -211,10 +211,10 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
211 fbe.operator(), fbe); 211 fbe.operator(), fbe);
212 continue; 212 continue;
213 } 213 }
214 - if (fbe.target().type() == FlowRule.Type.DEFAULT) { 214 + if (fbe.target().tableId() == 0) {
215 sw.sendMsg(mod); 215 sw.sendMsg(mod);
216 } else { 216 } else {
217 - sw.transformAndSendMsg(mod, getTableType(fbe.target().type())); 217 + sw.transformAndSendMsg(mod, getTableType(fbe.target().tableId()));
218 } 218 }
219 } 219 }
220 OFBarrierRequest.Builder builder = sw.factory() 220 OFBarrierRequest.Builder builder = sw.factory()
...@@ -223,8 +223,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -223,8 +223,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
223 sw.sendMsg(builder.build()); 223 sw.sendMsg(builder.build());
224 } 224 }
225 225
226 - private OpenFlowSwitch.TableType getTableType(FlowRule.Type type) { 226 + private OpenFlowSwitch.TableType getTableType(int type) {
227 - switch (type) { 227 + switch (FlowRule.Type.values()[type]) {
228 228
229 case DEFAULT: 229 case DEFAULT:
230 return OpenFlowSwitch.TableType.NONE; 230 return OpenFlowSwitch.TableType.NONE;
......
...@@ -147,13 +147,13 @@ public class FlowsResourceTest extends ResourceTest { ...@@ -147,13 +147,13 @@ public class FlowsResourceTest extends ResourceTest {
147 } 147 }
148 148
149 @Override 149 @Override
150 - public short appId() { 150 + public GroupId groupId() {
151 - return 2; 151 + return new DefaultGroupId(3);
152 } 152 }
153 153
154 @Override 154 @Override
155 - public GroupId groupId() { 155 + public short appId() {
156 - return new DefaultGroupId(3); 156 + return 2;
157 } 157 }
158 158
159 @Override 159 @Override
...@@ -187,11 +187,6 @@ public class FlowsResourceTest extends ResourceTest { ...@@ -187,11 +187,6 @@ public class FlowsResourceTest extends ResourceTest {
187 } 187 }
188 188
189 @Override 189 @Override
190 - public Type type() {
191 - return Type.DEFAULT;
192 - }
193 -
194 - @Override
195 public int tableId() { 190 public int tableId() {
196 return 0; 191 return 0;
197 } 192 }
......