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 {
.put("bytes", flow.bytes())
.put("packets", flow.packets())
.put("life", flow.life())
.put("tableId", flow.type().toString())
.put("tableId", flow.tableId())
.put("appId", appName);
result.set("selector", crit);
result.set("treatment", instr);
......@@ -192,7 +192,7 @@ public class FlowsListCommand extends AbstractShellCommand {
if (!empty) {
for (FlowEntry f : flows) {
print(FMT, Long.toHexString(f.id().value()), f.state(),
f.bytes(), f.packets(), f.life(), f.priority(), f.type(),
f.bytes(), f.packets(), f.life(), f.priority(), f.tableId(),
coreService.getAppId(f.appId()).name());
print(SFMT, f.selector().criteria());
print(TFMT, f.treatment());
......
......@@ -42,7 +42,6 @@ public class DefaultFlowRule implements FlowRule {
private final boolean permanent;
private final GroupId groupId;
private final Type type;
private final Integer tableId;
......@@ -61,7 +60,6 @@ public class DefaultFlowRule implements FlowRule {
this.appId = (short) (flowId >>> 48);
this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
this.id = FlowId.valueOf(flowId);
this.type = Type.DEFAULT;
this.tableId = 0;
}
......@@ -80,8 +78,7 @@ public class DefaultFlowRule implements FlowRule {
this.appId = (short) (flowId >>> 48);
this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
this.id = FlowId.valueOf(flowId);
this.type = tableType;
this.tableId = 0;
this.tableId = tableType.ordinal();
}
......@@ -111,8 +108,7 @@ public class DefaultFlowRule implements FlowRule {
this.timeout = timeout;
this.permanent = permanent;
this.created = System.currentTimeMillis();
this.type = type;
this.tableId = 0;
this.tableId = type.ordinal();
/*
* id consists of the following.
......@@ -141,7 +137,6 @@ public class DefaultFlowRule implements FlowRule {
this.timeout = timeout;
this.permanent = permanent;
this.created = System.currentTimeMillis();
this.type = Type.DEFAULT;
this.tableId = 0;
/*
......@@ -163,7 +158,6 @@ public class DefaultFlowRule implements FlowRule {
this.timeout = rule.timeout();
this.permanent = rule.isPermanent();
this.created = System.currentTimeMillis();
this.type = rule.type();
this.tableId = rule.tableId();
}
......@@ -187,7 +181,6 @@ public class DefaultFlowRule implements FlowRule {
//FIXME: fields below will be removed.
this.groupId = null;
this.type = null;
}
......@@ -235,11 +228,11 @@ public class DefaultFlowRule implements FlowRule {
* @see java.lang.Object#equals(java.lang.Object)
*/
public int hashCode() {
return Objects.hash(deviceId, selector, priority, type, tableId);
return Objects.hash(deviceId, selector, priority, tableId);
}
public int hash() {
return Objects.hash(deviceId, selector, treatment, type);
return Objects.hash(deviceId, selector, treatment, tableId);
}
@Override
......@@ -258,8 +251,7 @@ public class DefaultFlowRule implements FlowRule {
return Objects.equals(deviceId, that.deviceId) &&
Objects.equals(priority, that.priority) &&
Objects.equals(selector, that.selector) &&
Objects.equals(tableId, that.tableId) &&
Objects.equals(type, that.type);
Objects.equals(tableId, that.tableId);
}
return false;
......@@ -273,7 +265,7 @@ public class DefaultFlowRule implements FlowRule {
.add("priority", priority)
.add("selector", selector.criteria())
.add("treatment", treatment == null ? "N/A" : treatment.allInstructions())
.add("table type", type)
.add("tableId", tableId)
.add("created", created)
.toString();
}
......@@ -289,11 +281,6 @@ public class DefaultFlowRule implements FlowRule {
}
@Override
public Type type() {
return type;
}
@Override
public int tableId() {
return tableId;
}
......
......@@ -127,14 +127,6 @@ public interface FlowRule {
boolean isPermanent();
/**
* Returns the flow rule type.
*
* @return flow rule type
*/
@Deprecated
Type type();
/**
* Returns the table id for this rule.
*
* @return an integer.
......
......@@ -333,13 +333,13 @@ public class IntentTestsMocks {
static int nextId = 0;
int priority;
Type type;
int tableId;
long timestamp;
int id;
public MockFlowRule(int priority) {
this.priority = priority;
this.type = Type.DEFAULT;
this.tableId = 0;
this.timestamp = System.currentTimeMillis();
this.id = nextId++;
}
......@@ -408,13 +408,8 @@ public class IntentTestsMocks {
}
@Override
public Type type() {
return type;
}
@Override
public int tableId() {
return 0;
return tableId;
}
}
......
......@@ -124,7 +124,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.setTableId(TableId.of(flowRule().type().ordinal()))
.setTableId(TableId.of(flowRule().tableId()))
.build();
return fm;
......@@ -161,7 +161,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.setTableId(TableId.of(flowRule().type().ordinal()))
.setTableId(TableId.of(flowRule().tableId()))
.build();
return fm;
......@@ -180,7 +180,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder {
.setMatch(match)
.setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM))
.setPriority(flowRule().priority())
.setTableId(TableId.of(flowRule().type().ordinal()))
.setTableId(TableId.of(flowRule().tableId()))
.build();
return fm;
......
......@@ -144,11 +144,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
private void applyRule(FlowRule flowRule) {
OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri()));
if (flowRule.type() == FlowRule.Type.DEFAULT) {
if (flowRule.tableId() == 0) {
sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
Optional.empty()).buildFlowAdd());
} else {
OpenFlowSwitch.TableType type = getTableType(flowRule.type());
OpenFlowSwitch.TableType type = getTableType(flowRule.tableId());
sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
Optional.empty()).buildFlowAdd(),
type);
......@@ -166,12 +166,12 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
private void removeRule(FlowRule flowRule) {
OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri()));
if (flowRule.type() == FlowRule.Type.DEFAULT) {
if (flowRule.tableId() == 0) {
sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
Optional.empty()).buildFlowDel());
} else {
sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
Optional.empty()).buildFlowDel(), getTableType(flowRule.type()));
Optional.empty()).buildFlowDel(), getTableType(flowRule.tableId()));
}
}
......@@ -211,10 +211,10 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
fbe.operator(), fbe);
continue;
}
if (fbe.target().type() == FlowRule.Type.DEFAULT) {
if (fbe.target().tableId() == 0) {
sw.sendMsg(mod);
} else {
sw.transformAndSendMsg(mod, getTableType(fbe.target().type()));
sw.transformAndSendMsg(mod, getTableType(fbe.target().tableId()));
}
}
OFBarrierRequest.Builder builder = sw.factory()
......@@ -223,8 +223,8 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
sw.sendMsg(builder.build());
}
private OpenFlowSwitch.TableType getTableType(FlowRule.Type type) {
switch (type) {
private OpenFlowSwitch.TableType getTableType(int type) {
switch (FlowRule.Type.values()[type]) {
case DEFAULT:
return OpenFlowSwitch.TableType.NONE;
......
......@@ -147,13 +147,13 @@ public class FlowsResourceTest extends ResourceTest {
}
@Override
public short appId() {
return 2;
public GroupId groupId() {
return new DefaultGroupId(3);
}
@Override
public GroupId groupId() {
return new DefaultGroupId(3);
public short appId() {
return 2;
}
@Override
......@@ -187,11 +187,6 @@ public class FlowsResourceTest extends ResourceTest {
}
@Override
public Type type() {
return Type.DEFAULT;
}
@Override
public int tableId() {
return 0;
}
......