alshabib

fixed FlowEntry parsing to take table ids

Change-Id: I1dc6716ee299f1de7608663135a83346800068bf
...@@ -33,7 +33,6 @@ import org.onosproject.net.flow.DefaultTrafficTreatment; ...@@ -33,7 +33,6 @@ import org.onosproject.net.flow.DefaultTrafficTreatment;
33 import org.onosproject.net.flow.FlowEntry; 33 import org.onosproject.net.flow.FlowEntry;
34 import org.onosproject.net.flow.FlowEntry.FlowEntryState; 34 import org.onosproject.net.flow.FlowEntry.FlowEntryState;
35 import org.onosproject.net.flow.FlowRule; 35 import org.onosproject.net.flow.FlowRule;
36 -import org.onosproject.net.flow.FlowRule.Type;
37 import org.onosproject.net.flow.TrafficSelector; 36 import org.onosproject.net.flow.TrafficSelector;
38 import org.onosproject.net.flow.TrafficTreatment; 37 import org.onosproject.net.flow.TrafficTreatment;
39 import org.onosproject.openflow.controller.Dpid; 38 import org.onosproject.openflow.controller.Dpid;
...@@ -55,6 +54,7 @@ import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp; ...@@ -55,6 +54,7 @@ import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanPcp;
55 import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid; 54 import org.projectfloodlight.openflow.protocol.action.OFActionSetVlanVid;
56 import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; 55 import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
57 import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions; 56 import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions;
57 +import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable;
58 import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions; 58 import org.projectfloodlight.openflow.protocol.instruction.OFInstructionWriteActions;
59 import org.projectfloodlight.openflow.protocol.match.Match; 59 import org.projectfloodlight.openflow.protocol.match.Match;
60 import org.projectfloodlight.openflow.protocol.match.MatchField; 60 import org.projectfloodlight.openflow.protocol.match.MatchField;
...@@ -92,9 +92,8 @@ public class FlowEntryBuilder { ...@@ -92,9 +92,8 @@ public class FlowEntryBuilder {
92 public enum FlowType { STAT, REMOVED, MOD } 92 public enum FlowType { STAT, REMOVED, MOD }
93 93
94 private final FlowType type; 94 private final FlowType type;
95 - private Type tableType = FlowRule.Type.DEFAULT;
96 95
97 - public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry, Type tableType) { 96 + public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) {
98 this.stat = entry; 97 this.stat = entry;
99 this.match = entry.getMatch(); 98 this.match = entry.getMatch();
100 this.instructions = getInstructions(entry); 99 this.instructions = getInstructions(entry);
...@@ -102,10 +101,9 @@ public class FlowEntryBuilder { ...@@ -102,10 +101,9 @@ public class FlowEntryBuilder {
102 this.removed = null; 101 this.removed = null;
103 this.flowMod = null; 102 this.flowMod = null;
104 this.type = FlowType.STAT; 103 this.type = FlowType.STAT;
105 - this.tableType = tableType;
106 } 104 }
107 105
108 - public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed, Type tableType) { 106 + public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) {
109 this.match = removed.getMatch(); 107 this.match = removed.getMatch();
110 this.removed = removed; 108 this.removed = removed;
111 109
...@@ -114,11 +112,10 @@ public class FlowEntryBuilder { ...@@ -114,11 +112,10 @@ public class FlowEntryBuilder {
114 this.stat = null; 112 this.stat = null;
115 this.flowMod = null; 113 this.flowMod = null;
116 this.type = FlowType.REMOVED; 114 this.type = FlowType.REMOVED;
117 - this.tableType = tableType;
118 115
119 } 116 }
120 117
121 - public FlowEntryBuilder(Dpid dpid, OFFlowMod fm, Type tableType) { 118 + public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) {
122 this.match = fm.getMatch(); 119 this.match = fm.getMatch();
123 this.dpid = dpid; 120 this.dpid = dpid;
124 this.instructions = getInstructions(fm); 121 this.instructions = getInstructions(fm);
...@@ -126,33 +123,49 @@ public class FlowEntryBuilder { ...@@ -126,33 +123,49 @@ public class FlowEntryBuilder {
126 this.flowMod = fm; 123 this.flowMod = fm;
127 this.stat = null; 124 this.stat = null;
128 this.removed = null; 125 this.removed = null;
129 - this.tableType = tableType;
130 } 126 }
131 127
132 public FlowEntry build(FlowEntryState... state) { 128 public FlowEntry build(FlowEntryState... state) {
133 FlowRule rule; 129 FlowRule rule;
134 switch (this.type) { 130 switch (this.type) {
135 case STAT: 131 case STAT:
136 - rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), 132 + rule = DefaultFlowRule.builder()
137 - buildSelector(), buildTreatment(), stat.getPriority(), 133 + .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
138 - stat.getCookie().getValue(), stat.getIdleTimeout(), false, 134 + .withSelector(buildSelector())
139 - tableType); 135 + .withTreatment(buildTreatment())
136 + .withPriority(stat.getPriority())
137 + .makeTemporary(stat.getIdleTimeout())
138 + .withCookie(stat.getCookie().getValue())
139 + .forTable(stat.getTableId().getValue())
140 + .build();
141 +
140 return new DefaultFlowEntry(rule, FlowEntryState.ADDED, 142 return new DefaultFlowEntry(rule, FlowEntryState.ADDED,
141 stat.getDurationSec(), stat.getPacketCount().getValue(), 143 stat.getDurationSec(), stat.getPacketCount().getValue(),
142 stat.getByteCount().getValue()); 144 stat.getByteCount().getValue());
143 case REMOVED: 145 case REMOVED:
144 - rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), 146 + rule = DefaultFlowRule.builder()
145 - buildSelector(), null, removed.getPriority(), 147 + .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
146 - removed.getCookie().getValue(), removed.getIdleTimeout(), false, 148 + .withSelector(buildSelector())
147 - tableType); 149 + .withPriority(removed.getPriority())
150 + .makeTemporary(removed.getIdleTimeout())
151 + .withCookie(removed.getCookie().getValue())
152 + .forTable(removed.getTableId().getValue())
153 + .build();
154 +
148 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), 155 return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(),
149 removed.getPacketCount().getValue(), removed.getByteCount().getValue()); 156 removed.getPacketCount().getValue(), removed.getByteCount().getValue());
150 case MOD: 157 case MOD:
151 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED; 158 FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
152 - rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), 159 + rule = DefaultFlowRule.builder()
153 - buildSelector(), buildTreatment(), flowMod.getPriority(), 160 + .forDevice(DeviceId.deviceId(Dpid.uri(dpid)))
154 - flowMod.getCookie().getValue(), flowMod.getIdleTimeout(), false, 161 + .withSelector(buildSelector())
155 - tableType); 162 + .withTreatment(buildTreatment())
163 + .withPriority(flowMod.getPriority())
164 + .makeTemporary(flowMod.getIdleTimeout())
165 + .withCookie(flowMod.getCookie().getValue())
166 + .forTable(flowMod.getTableId().getValue())
167 + .build();
168 +
156 return new DefaultFlowEntry(rule, flowState, 0, 0, 0); 169 return new DefaultFlowEntry(rule, flowState, 0, 0, 0);
157 default: 170 default:
158 log.error("Unknown flow type : {}", this.type); 171 log.error("Unknown flow type : {}", this.type);
...@@ -202,7 +215,8 @@ public class FlowEntryBuilder { ...@@ -202,7 +215,8 @@ public class FlowEntryBuilder {
202 for (OFInstruction in : instructions) { 215 for (OFInstruction in : instructions) {
203 switch (in.getType()) { 216 switch (in.getType()) {
204 case GOTO_TABLE: 217 case GOTO_TABLE:
205 - builder.transition(tableType); 218 + builder.transition(((int) ((OFInstructionGotoTable) in)
219 + .getTableId().getValue()));
206 break; 220 break;
207 case WRITE_METADATA: 221 case WRITE_METADATA:
208 break; 222 break;
......
...@@ -144,15 +144,9 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -144,15 +144,9 @@ 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.tableId() == 0) { 147 + sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
148 - sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
149 Optional.empty()).buildFlowAdd()); 148 Optional.empty()).buildFlowAdd());
150 - } else { 149 +
151 - OpenFlowSwitch.TableType type = getTableType(flowRule.tableId());
152 - sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
153 - Optional.empty()).buildFlowAdd(),
154 - type);
155 - }
156 } 150 }
157 151
158 152
...@@ -166,13 +160,9 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -166,13 +160,9 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
166 160
167 private void removeRule(FlowRule flowRule) { 161 private void removeRule(FlowRule flowRule) {
168 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); 162 OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri()));
169 - if (flowRule.tableId() == 0) { 163 +
170 - sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), 164 + sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
171 Optional.empty()).buildFlowDel()); 165 Optional.empty()).buildFlowDel());
172 - } else {
173 - sw.transformAndSendMsg(FlowModBuilder.builder(flowRule, sw.factory(),
174 - Optional.empty()).buildFlowDel(), getTableType(flowRule.tableId()));
175 - }
176 } 166 }
177 167
178 @Override 168 @Override
...@@ -211,11 +201,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -211,11 +201,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
211 fbe.operator(), fbe); 201 fbe.operator(), fbe);
212 continue; 202 continue;
213 } 203 }
214 - /*if (fbe.target().tableId() == 0) {
215 - sw.sendMsg(mod);
216 - } else {
217 - sw.transformAndSendMsg(mod, getTableType(fbe.target().tableId()));
218 - }*/
219 sw.sendMsg(mod); 204 sw.sendMsg(mod);
220 } 205 }
221 OFBarrierRequest.Builder builder = sw.factory() 206 OFBarrierRequest.Builder builder = sw.factory()
...@@ -224,58 +209,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -224,58 +209,6 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
224 sw.sendMsg(builder.build()); 209 sw.sendMsg(builder.build());
225 } 210 }
226 211
227 - private OpenFlowSwitch.TableType getTableType(int type) {
228 - switch (FlowRule.Type.values()[type]) {
229 -
230 - case DEFAULT:
231 - return OpenFlowSwitch.TableType.NONE;
232 - case IP:
233 - return OpenFlowSwitch.TableType.IP;
234 - case MPLS:
235 - return OpenFlowSwitch.TableType.MPLS;
236 - case ACL:
237 - return OpenFlowSwitch.TableType.ACL;
238 - case VLAN_MPLS:
239 - return OpenFlowSwitch.TableType.VLAN_MPLS;
240 - case VLAN:
241 - return OpenFlowSwitch.TableType.VLAN;
242 - case ETHER:
243 - return OpenFlowSwitch.TableType.ETHER;
244 - case COS:
245 - return OpenFlowSwitch.TableType.COS;
246 - case FIRST:
247 - return OpenFlowSwitch.TableType.FIRST;
248 - default:
249 - return OpenFlowSwitch.TableType.NONE;
250 - }
251 - }
252 -
253 - private FlowRule.Type getType(OpenFlowSwitch.TableType tableType) {
254 - switch (tableType) {
255 -
256 - case NONE:
257 - return FlowRule.Type.DEFAULT;
258 - case IP:
259 - return FlowRule.Type.IP;
260 - case MPLS:
261 - return FlowRule.Type.MPLS;
262 - case ACL:
263 - return FlowRule.Type.ACL;
264 - case VLAN_MPLS:
265 - return FlowRule.Type.VLAN_MPLS;
266 - case VLAN:
267 - return FlowRule.Type.VLAN;
268 - case ETHER:
269 - return FlowRule.Type.ETHER;
270 - case COS:
271 - return FlowRule.Type.COS;
272 - case FIRST:
273 - return FlowRule.Type.FIRST;
274 - default:
275 - return FlowRule.Type.DEFAULT;
276 - }
277 - }
278 -
279 212
280 private class InternalFlowProvider 213 private class InternalFlowProvider
281 implements OpenFlowSwitchListener, OpenFlowEventListener { 214 implements OpenFlowSwitchListener, OpenFlowEventListener {
...@@ -311,8 +244,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -311,8 +244,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
311 case FLOW_REMOVED: 244 case FLOW_REMOVED:
312 OFFlowRemoved removed = (OFFlowRemoved) msg; 245 OFFlowRemoved removed = (OFFlowRemoved) msg;
313 246
314 - FlowEntry fr = new FlowEntryBuilder(dpid, removed, 247 + FlowEntry fr = new FlowEntryBuilder(dpid, removed).build();
315 - getType(sw.getTableType(removed.getTableId()))).build();
316 providerService.flowRemoved(fr); 248 providerService.flowRemoved(fr);
317 break; 249 break;
318 case STATS_REPLY: 250 case STATS_REPLY:
...@@ -343,8 +275,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -343,8 +275,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
343 OFFlowMod fm = (OFFlowMod) m; 275 OFFlowMod fm = (OFFlowMod) m;
344 InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid()); 276 InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid());
345 if (entry != null) { 277 if (entry != null) {
346 - entry.appendFailure(new FlowEntryBuilder(dpid, fm, 278 + entry.appendFailure(new FlowEntryBuilder(dpid, fm)
347 - getType(sw.getTableType(fm.getTableId())))
348 .build()); 279 .build());
349 } else { 280 } else {
350 log.error("No matching batch for this error: {}", error); 281 log.error("No matching batch for this error: {}", error);
...@@ -377,9 +308,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr ...@@ -377,9 +308,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
377 OpenFlowSwitch sw = controller.getSwitch(dpid); 308 OpenFlowSwitch sw = controller.getSwitch(dpid);
378 309
379 List<FlowEntry> flowEntries = replies.getEntries().stream() 310 List<FlowEntry> flowEntries = replies.getEntries().stream()
380 - .map(entry -> new FlowEntryBuilder(dpid, entry, 311 + .map(entry -> new FlowEntryBuilder(dpid, entry).build())
381 - getType(sw.getTableType(entry.getTableId())))
382 - .build())
383 .collect(Collectors.toList()); 312 .collect(Collectors.toList());
384 313
385 providerService.pushFlowMetrics(did, flowEntries); 314 providerService.pushFlowMetrics(did, flowEntries);
......