Added delete all flow rules during Corsa switch handshake
Change-Id: I885dad9453754bf86f12d4a86541fe7bfe7efd72 added delete all rules in corsa switch handshake Change-Id: I7905a754653f6fc7eb8643023372e6dfa779cf26
Showing
4 changed files
with
62 additions
and
21 deletions
... | @@ -298,6 +298,7 @@ public class BgpRouter { | ... | @@ -298,6 +298,7 @@ public class BgpRouter { |
298 | .setEthDst(nextHop.mac()) | 298 | .setEthDst(nextHop.mac()) |
299 | .pushVlan() | 299 | .pushVlan() |
300 | .setVlanId(egressIntf.vlan()) | 300 | .setVlanId(egressIntf.vlan()) |
301 | + .setVlanPcp((byte) 0) | ||
301 | .setOutput(egressIntf.connectPoint().port()) | 302 | .setOutput(egressIntf.connectPoint().port()) |
302 | .build(); | 303 | .build(); |
303 | 304 | ... | ... |
... | @@ -16,25 +16,31 @@ | ... | @@ -16,25 +16,31 @@ |
16 | package org.onosproject.openflow.drivers; | 16 | package org.onosproject.openflow.drivers; |
17 | 17 | ||
18 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
19 | - | ||
20 | import org.onosproject.openflow.controller.Dpid; | 19 | import org.onosproject.openflow.controller.Dpid; |
21 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; | 20 | import org.onosproject.openflow.controller.driver.AbstractOpenFlowSwitch; |
21 | +import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeAlreadyStarted; | ||
22 | +import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeCompleted; | ||
23 | +import org.onosproject.openflow.controller.driver.SwitchDriverSubHandshakeNotStarted; | ||
24 | +import org.projectfloodlight.openflow.protocol.OFBarrierRequest; | ||
22 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; | 25 | import org.projectfloodlight.openflow.protocol.OFDescStatsReply; |
23 | import org.projectfloodlight.openflow.protocol.OFFlowMod; | 26 | import org.projectfloodlight.openflow.protocol.OFFlowMod; |
24 | import org.projectfloodlight.openflow.protocol.OFMessage; | 27 | import org.projectfloodlight.openflow.protocol.OFMessage; |
25 | import org.projectfloodlight.openflow.protocol.OFType; | 28 | import org.projectfloodlight.openflow.protocol.OFType; |
26 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; | 29 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
27 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable; | 30 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionGotoTable; |
31 | +import org.projectfloodlight.openflow.types.OFGroup; | ||
28 | import org.projectfloodlight.openflow.types.TableId; | 32 | import org.projectfloodlight.openflow.types.TableId; |
29 | 33 | ||
30 | import java.util.ArrayList; | 34 | import java.util.ArrayList; |
31 | import java.util.Collections; | 35 | import java.util.Collections; |
32 | import java.util.List; | 36 | import java.util.List; |
37 | +import java.util.concurrent.atomic.AtomicBoolean; | ||
33 | 38 | ||
34 | /** | 39 | /** |
35 | * Corsa switch driver for BGP Router deployment. | 40 | * Corsa switch driver for BGP Router deployment. |
36 | */ | 41 | */ |
37 | public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch { | 42 | public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch { |
43 | + | ||
38 | private static final int FIRST_TABLE = 0; | 44 | private static final int FIRST_TABLE = 0; |
39 | private static final int VLAN_MPLS_TABLE = 1; | 45 | private static final int VLAN_MPLS_TABLE = 1; |
40 | private static final int VLAN_TABLE = 2; | 46 | private static final int VLAN_TABLE = 2; |
... | @@ -44,6 +50,10 @@ public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch { | ... | @@ -44,6 +50,10 @@ public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch { |
44 | private static final int FIB_TABLE = 6; | 50 | private static final int FIB_TABLE = 6; |
45 | private static final int LOCAL_TABLE = 9; | 51 | private static final int LOCAL_TABLE = 9; |
46 | 52 | ||
53 | + private AtomicBoolean handShakeComplete = new AtomicBoolean(false); | ||
54 | + | ||
55 | + private int barrierXid; | ||
56 | + | ||
47 | OFCorsaSwitchDriver(Dpid dpid, OFDescStatsReply desc) { | 57 | OFCorsaSwitchDriver(Dpid dpid, OFDescStatsReply desc) { |
48 | super(dpid); | 58 | super(dpid); |
49 | 59 | ||
... | @@ -222,13 +232,46 @@ public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch { | ... | @@ -222,13 +232,46 @@ public class OFCorsaSwitchDriver extends AbstractOpenFlowSwitch { |
222 | } | 232 | } |
223 | 233 | ||
224 | @Override | 234 | @Override |
225 | - public void startDriverHandshake() {} | 235 | + public void startDriverHandshake() { |
236 | + if (startDriverHandshakeCalled) { | ||
237 | + throw new SwitchDriverSubHandshakeAlreadyStarted(); | ||
238 | + } | ||
239 | + startDriverHandshakeCalled = true; | ||
240 | + OFFlowMod fm = factory().buildFlowDelete() | ||
241 | + .setTableId(TableId.ALL) | ||
242 | + .setOutGroup(OFGroup.ANY) | ||
243 | + .build(); | ||
244 | + | ||
245 | + channel.write(Collections.singletonList(fm)); | ||
246 | + | ||
247 | + barrierXid = getNextTransactionId(); | ||
248 | + OFBarrierRequest barrier = factory().buildBarrierRequest() | ||
249 | + .setXid(barrierXid).build(); | ||
250 | + | ||
251 | + | ||
252 | + channel.write(Collections.singletonList(barrier)); | ||
253 | + | ||
254 | + } | ||
226 | 255 | ||
227 | @Override | 256 | @Override |
228 | public boolean isDriverHandshakeComplete() { | 257 | public boolean isDriverHandshakeComplete() { |
229 | - return true; | 258 | + if (!startDriverHandshakeCalled) { |
259 | + throw new SwitchDriverSubHandshakeAlreadyStarted(); | ||
260 | + } | ||
261 | + return handShakeComplete.get(); | ||
230 | } | 262 | } |
231 | 263 | ||
232 | @Override | 264 | @Override |
233 | - public void processDriverHandshakeMessage(OFMessage m) {} | 265 | + public void processDriverHandshakeMessage(OFMessage m) { |
266 | + if (!startDriverHandshakeCalled) { | ||
267 | + throw new SwitchDriverSubHandshakeNotStarted(); | ||
268 | + } | ||
269 | + if (handShakeComplete.get()) { | ||
270 | + throw new SwitchDriverSubHandshakeCompleted(m); | ||
271 | + } | ||
272 | + if (m.getType() == OFType.BARRIER_REPLY && | ||
273 | + m.getXid() == barrierXid) { | ||
274 | + handShakeComplete.set(true); | ||
275 | + } | ||
276 | + } | ||
234 | } | 277 | } | ... | ... |
... | @@ -95,17 +95,6 @@ public class FlowEntryBuilder { | ... | @@ -95,17 +95,6 @@ public class FlowEntryBuilder { |
95 | private final FlowType type; | 95 | private final FlowType type; |
96 | private Type tableType = FlowRule.Type.DEFAULT; | 96 | private Type tableType = FlowRule.Type.DEFAULT; |
97 | 97 | ||
98 | - | ||
99 | - public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry) { | ||
100 | - this.stat = entry; | ||
101 | - this.match = entry.getMatch(); | ||
102 | - this.instructions = getInstructions(entry); | ||
103 | - this.dpid = dpid; | ||
104 | - this.removed = null; | ||
105 | - this.flowMod = null; | ||
106 | - this.type = FlowType.STAT; | ||
107 | - } | ||
108 | - | ||
109 | public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry, Type tableType) { | 98 | public FlowEntryBuilder(Dpid dpid, OFFlowStatsEntry entry, Type tableType) { |
110 | this.stat = entry; | 99 | this.stat = entry; |
111 | this.match = entry.getMatch(); | 100 | this.match = entry.getMatch(); |
... | @@ -117,7 +106,7 @@ public class FlowEntryBuilder { | ... | @@ -117,7 +106,7 @@ public class FlowEntryBuilder { |
117 | this.tableType = tableType; | 106 | this.tableType = tableType; |
118 | } | 107 | } |
119 | 108 | ||
120 | - public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed) { | 109 | + public FlowEntryBuilder(Dpid dpid, OFFlowRemoved removed, Type tableType) { |
121 | this.match = removed.getMatch(); | 110 | this.match = removed.getMatch(); |
122 | this.removed = removed; | 111 | this.removed = removed; |
123 | 112 | ||
... | @@ -126,10 +115,11 @@ public class FlowEntryBuilder { | ... | @@ -126,10 +115,11 @@ public class FlowEntryBuilder { |
126 | this.stat = null; | 115 | this.stat = null; |
127 | this.flowMod = null; | 116 | this.flowMod = null; |
128 | this.type = FlowType.REMOVED; | 117 | this.type = FlowType.REMOVED; |
118 | + this.tableType = tableType; | ||
129 | 119 | ||
130 | } | 120 | } |
131 | 121 | ||
132 | - public FlowEntryBuilder(Dpid dpid, OFFlowMod fm) { | 122 | + public FlowEntryBuilder(Dpid dpid, OFFlowMod fm, Type tableType) { |
133 | this.match = fm.getMatch(); | 123 | this.match = fm.getMatch(); |
134 | this.dpid = dpid; | 124 | this.dpid = dpid; |
135 | this.instructions = getInstructions(fm); | 125 | this.instructions = getInstructions(fm); |
... | @@ -137,6 +127,7 @@ public class FlowEntryBuilder { | ... | @@ -137,6 +127,7 @@ public class FlowEntryBuilder { |
137 | this.flowMod = fm; | 127 | this.flowMod = fm; |
138 | this.stat = null; | 128 | this.stat = null; |
139 | this.removed = null; | 129 | this.removed = null; |
130 | + this.tableType = tableType; | ||
140 | } | 131 | } |
141 | 132 | ||
142 | public FlowEntry build(FlowEntryState... state) { | 133 | public FlowEntry build(FlowEntryState... state) { |
... | @@ -153,14 +144,16 @@ public class FlowEntryBuilder { | ... | @@ -153,14 +144,16 @@ public class FlowEntryBuilder { |
153 | case REMOVED: | 144 | case REMOVED: |
154 | rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), | 145 | rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
155 | buildSelector(), null, removed.getPriority(), | 146 | buildSelector(), null, removed.getPriority(), |
156 | - removed.getCookie().getValue(), removed.getIdleTimeout(), false); | 147 | + removed.getCookie().getValue(), removed.getIdleTimeout(), false, |
148 | + tableType); | ||
157 | return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), | 149 | return new DefaultFlowEntry(rule, FlowEntryState.REMOVED, removed.getDurationSec(), |
158 | removed.getPacketCount().getValue(), removed.getByteCount().getValue()); | 150 | removed.getPacketCount().getValue(), removed.getByteCount().getValue()); |
159 | case MOD: | 151 | case MOD: |
160 | FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED; | 152 | FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED; |
161 | rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), | 153 | rule = new DefaultFlowRule(DeviceId.deviceId(Dpid.uri(dpid)), |
162 | buildSelector(), buildTreatment(), flowMod.getPriority(), | 154 | buildSelector(), buildTreatment(), flowMod.getPriority(), |
163 | - flowMod.getCookie().getValue(), flowMod.getIdleTimeout(), false); | 155 | + flowMod.getCookie().getValue(), flowMod.getIdleTimeout(), false, |
156 | + tableType); | ||
164 | return new DefaultFlowEntry(rule, flowState, 0, 0, 0); | 157 | return new DefaultFlowEntry(rule, flowState, 0, 0, 0); |
165 | default: | 158 | default: |
166 | log.error("Unknown flow type : {}", this.type); | 159 | log.error("Unknown flow type : {}", this.type); | ... | ... |
... | @@ -305,11 +305,13 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -305,11 +305,13 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
305 | 305 | ||
306 | @Override | 306 | @Override |
307 | public void handleMessage(Dpid dpid, OFMessage msg) { | 307 | public void handleMessage(Dpid dpid, OFMessage msg) { |
308 | + OpenFlowSwitch sw = controller.getSwitch(dpid); | ||
308 | switch (msg.getType()) { | 309 | switch (msg.getType()) { |
309 | case FLOW_REMOVED: | 310 | case FLOW_REMOVED: |
310 | OFFlowRemoved removed = (OFFlowRemoved) msg; | 311 | OFFlowRemoved removed = (OFFlowRemoved) msg; |
311 | 312 | ||
312 | - FlowEntry fr = new FlowEntryBuilder(dpid, removed).build(); | 313 | + FlowEntry fr = new FlowEntryBuilder(dpid, removed, |
314 | + getType(sw.getTableType(removed.getTableId()))).build(); | ||
313 | providerService.flowRemoved(fr); | 315 | providerService.flowRemoved(fr); |
314 | break; | 316 | break; |
315 | case STATS_REPLY: | 317 | case STATS_REPLY: |
... | @@ -340,7 +342,9 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr | ... | @@ -340,7 +342,9 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr |
340 | OFFlowMod fm = (OFFlowMod) m; | 342 | OFFlowMod fm = (OFFlowMod) m; |
341 | InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid()); | 343 | InternalCacheEntry entry = pendingBatches.getIfPresent(msg.getXid()); |
342 | if (entry != null) { | 344 | if (entry != null) { |
343 | - entry.appendFailure(new FlowEntryBuilder(dpid, fm).build()); | 345 | + entry.appendFailure(new FlowEntryBuilder(dpid, fm, |
346 | + getType(sw.getTableType(fm.getTableId()))) | ||
347 | + .build()); | ||
344 | } else { | 348 | } else { |
345 | log.error("No matching batch for this error: {}", error); | 349 | log.error("No matching batch for this error: {}", error); |
346 | } | 350 | } | ... | ... |
-
Please register or login to post a comment