alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 1 | package org.onlab.onos.provider.of.flow.impl; |
| 2 | |
| 3 | import static org.slf4j.LoggerFactory.getLogger; |
| 4 | |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 5 | import java.util.HashSet; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 6 | import java.util.List; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 7 | import java.util.Map; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 8 | import java.util.Set; |
| 9 | import java.util.concurrent.ConcurrentHashMap; |
| 10 | import java.util.concurrent.CountDownLatch; |
| 11 | import java.util.concurrent.ExecutionException; |
| 12 | import java.util.concurrent.Future; |
| 13 | import java.util.concurrent.TimeUnit; |
| 14 | import java.util.concurrent.TimeoutException; |
| 15 | import java.util.concurrent.atomic.AtomicBoolean; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 16 | |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 17 | import org.apache.felix.scr.annotations.Activate; |
| 18 | import org.apache.felix.scr.annotations.Component; |
| 19 | import org.apache.felix.scr.annotations.Deactivate; |
| 20 | import org.apache.felix.scr.annotations.Reference; |
| 21 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 22 | import org.onlab.onos.ApplicationId; |
alshabib | a7f7ca8 | 2014-09-22 11:41:23 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.DeviceId; |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 24 | import org.onlab.onos.net.flow.FlowEntry; |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 25 | import org.onlab.onos.net.flow.FlowRule; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 26 | import org.onlab.onos.net.flow.FlowRuleBatchEntry; |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 27 | import org.onlab.onos.net.flow.FlowRuleProvider; |
| 28 | import org.onlab.onos.net.flow.FlowRuleProviderRegistry; |
| 29 | import org.onlab.onos.net.flow.FlowRuleProviderService; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 30 | import org.onlab.onos.net.intent.BatchOperation; |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 31 | import org.onlab.onos.net.provider.AbstractProvider; |
| 32 | import org.onlab.onos.net.provider.ProviderId; |
| 33 | import org.onlab.onos.net.topology.TopologyService; |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 34 | import org.onlab.onos.openflow.controller.Dpid; |
| 35 | import org.onlab.onos.openflow.controller.OpenFlowController; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 36 | import org.onlab.onos.openflow.controller.OpenFlowEventListener; |
tom | 9c94c5b | 2014-09-17 13:14:42 -0700 | [diff] [blame] | 37 | import org.onlab.onos.openflow.controller.OpenFlowSwitch; |
alshabib | ce4e578 | 2014-09-17 14:56:42 -0700 | [diff] [blame] | 38 | import org.onlab.onos.openflow.controller.OpenFlowSwitchListener; |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 39 | import org.onlab.onos.openflow.controller.RoleState; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 40 | import org.projectfloodlight.openflow.protocol.OFActionType; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 41 | import org.projectfloodlight.openflow.protocol.OFBarrierRequest; |
| 42 | import org.projectfloodlight.openflow.protocol.OFErrorMsg; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 43 | import org.projectfloodlight.openflow.protocol.OFFlowRemoved; |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 44 | import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; |
| 45 | import org.projectfloodlight.openflow.protocol.OFFlowStatsReply; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 46 | import org.projectfloodlight.openflow.protocol.OFInstructionType; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 47 | import org.projectfloodlight.openflow.protocol.OFMessage; |
| 48 | import org.projectfloodlight.openflow.protocol.OFPortStatus; |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 49 | import org.projectfloodlight.openflow.protocol.OFStatsReply; |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 50 | import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 51 | import org.projectfloodlight.openflow.protocol.OFStatsType; |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 52 | import org.projectfloodlight.openflow.protocol.OFVersion; |
| 53 | import org.projectfloodlight.openflow.protocol.action.OFAction; |
| 54 | import org.projectfloodlight.openflow.protocol.action.OFActionOutput; |
| 55 | import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; |
| 56 | import org.projectfloodlight.openflow.protocol.instruction.OFInstructionApplyActions; |
| 57 | import org.projectfloodlight.openflow.types.OFPort; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 58 | import org.projectfloodlight.openflow.types.U32; |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 59 | import org.slf4j.Logger; |
| 60 | |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 61 | import com.google.common.collect.ArrayListMultimap; |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 62 | import com.google.common.collect.Lists; |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 63 | import com.google.common.collect.Maps; |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 64 | import com.google.common.collect.Multimap; |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 65 | |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 66 | /** |
| 67 | * Provider which uses an OpenFlow controller to detect network |
| 68 | * end-station hosts. |
| 69 | */ |
| 70 | @Component(immediate = true) |
| 71 | public class OpenFlowRuleProvider extends AbstractProvider implements FlowRuleProvider { |
| 72 | |
| 73 | private final Logger log = getLogger(getClass()); |
| 74 | |
| 75 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 76 | protected FlowRuleProviderRegistry providerRegistry; |
| 77 | |
| 78 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 79 | protected OpenFlowController controller; |
| 80 | |
| 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 82 | protected TopologyService topologyService; |
| 83 | |
| 84 | private FlowRuleProviderService providerService; |
| 85 | |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 86 | private final InternalFlowProvider listener = new InternalFlowProvider(); |
| 87 | |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 88 | private final Map<Long, InstallationFuture> pendingFutures = |
| 89 | new ConcurrentHashMap<Long, InstallationFuture>(); |
| 90 | |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 91 | /** |
| 92 | * Creates an OpenFlow host provider. |
| 93 | */ |
| 94 | public OpenFlowRuleProvider() { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 95 | super(new ProviderId("of", "org.onlab.onos.provider.openflow")); |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Activate |
| 99 | public void activate() { |
| 100 | providerService = providerRegistry.register(this); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 101 | controller.addListener(listener); |
| 102 | controller.addEventListener(listener); |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 103 | log.info("Started"); |
| 104 | } |
| 105 | |
| 106 | @Deactivate |
| 107 | public void deactivate() { |
| 108 | providerRegistry.unregister(this); |
| 109 | providerService = null; |
| 110 | |
| 111 | log.info("Stopped"); |
| 112 | } |
| 113 | @Override |
| 114 | public void applyFlowRule(FlowRule... flowRules) { |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 115 | for (int i = 0; i < flowRules.length; i++) { |
| 116 | applyRule(flowRules[i]); |
| 117 | } |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 118 | } |
| 119 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 120 | private void applyRule(FlowRule flowRule) { |
| 121 | OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 122 | sw.sendMsg(new FlowModBuilder(flowRule, sw.factory()).buildFlowAdd()); |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 123 | } |
| 124 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 125 | |
alshabib | 35edb1a | 2014-09-16 17:44:44 -0700 | [diff] [blame] | 126 | |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 127 | @Override |
| 128 | public void removeFlowRule(FlowRule... flowRules) { |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 129 | for (int i = 0; i < flowRules.length; i++) { |
| 130 | removeRule(flowRules[i]); |
| 131 | } |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 132 | |
| 133 | } |
| 134 | |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 135 | private void removeRule(FlowRule flowRule) { |
| 136 | OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); |
| 137 | sw.sendMsg(new FlowModBuilder(flowRule, sw.factory()).buildFlowDel()); |
| 138 | } |
| 139 | |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 140 | @Override |
| 141 | public void removeRulesById(ApplicationId id, FlowRule... flowRules) { |
| 142 | // TODO: optimize using the ApplicationId |
| 143 | removeFlowRule(flowRules); |
| 144 | } |
| 145 | |
alshabib | 219ebaa | 2014-09-22 15:41:24 -0700 | [diff] [blame] | 146 | |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 147 | //TODO: InternalFlowRuleProvider listening to stats and error and flowremoved. |
| 148 | // possibly barriers as well. May not be internal at all... |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 149 | private class InternalFlowProvider |
| 150 | implements OpenFlowSwitchListener, OpenFlowEventListener { |
| 151 | |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 152 | private final Map<Dpid, FlowStatsCollector> collectors = Maps.newHashMap(); |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 153 | private final Multimap<DeviceId, FlowEntry> completeEntries = |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 154 | ArrayListMultimap.create(); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 155 | |
| 156 | @Override |
| 157 | public void switchAdded(Dpid dpid) { |
alshabib | ba5ac48 | 2014-10-02 17:15:20 -0700 | [diff] [blame] | 158 | FlowStatsCollector fsc = new FlowStatsCollector(controller.getSwitch(dpid), POLL_INTERVAL); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 159 | fsc.start(); |
| 160 | collectors.put(dpid, fsc); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void switchRemoved(Dpid dpid) { |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 165 | collectors.remove(dpid).stop(); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void portChanged(Dpid dpid, OFPortStatus status) { |
| 170 | //TODO: Decide whether to evict flows internal store. |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public void handleMessage(Dpid dpid, OFMessage msg) { |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 175 | InstallationFuture future = null; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 176 | switch (msg.getType()) { |
| 177 | case FLOW_REMOVED: |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 178 | //TODO: make this better |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 179 | OFFlowRemoved removed = (OFFlowRemoved) msg; |
alshabib | 6b5cfec | 2014-09-18 17:42:18 -0700 | [diff] [blame] | 180 | |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 181 | FlowEntry fr = new FlowEntryBuilder(dpid, removed).build(); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 182 | providerService.flowRemoved(fr); |
| 183 | break; |
| 184 | case STATS_REPLY: |
alshabib | 9704490 | 2014-09-18 14:52:16 -0700 | [diff] [blame] | 185 | pushFlowMetrics(dpid, (OFStatsReply) msg); |
alshabib | eec3a06 | 2014-09-17 18:01:26 -0700 | [diff] [blame] | 186 | break; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 187 | case BARRIER_REPLY: |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 188 | future = pendingFutures.get(msg.getXid()); |
| 189 | if (future != null) { |
| 190 | future.satisfyRequirement(dpid); |
| 191 | } |
| 192 | break; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 193 | case ERROR: |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 194 | future = pendingFutures.get(msg.getXid()); |
| 195 | if (future != null) { |
| 196 | future.fail((OFErrorMsg) msg, dpid); |
| 197 | } |
| 198 | break; |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 199 | default: |
alshabib | 6eb438a | 2014-10-01 16:39:37 -0700 | [diff] [blame] | 200 | log.debug("Unhandled message type: {}", msg.getType()); |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | } |
| 204 | |
Ayaka Koshibe | ab91cc4 | 2014-09-25 10:20:52 -0700 | [diff] [blame] | 205 | @Override |
| 206 | public void roleAssertFailed(Dpid dpid, RoleState role) { |
| 207 | // TODO Auto-generated method stub |
| 208 | |
| 209 | } |
| 210 | |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 211 | private synchronized void pushFlowMetrics(Dpid dpid, OFStatsReply stats) { |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 212 | if (stats.getStatsType() != OFStatsType.FLOW) { |
| 213 | return; |
| 214 | } |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 215 | DeviceId did = DeviceId.deviceId(Dpid.uri(dpid)); |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 216 | final OFFlowStatsReply replies = (OFFlowStatsReply) stats; |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 217 | //final List<FlowRule> entries = Lists.newLinkedList(); |
| 218 | |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 219 | for (OFFlowStatsEntry reply : replies.getEntries()) { |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 220 | if (!tableMissRule(dpid, reply)) { |
alshabib | 1c319ff | 2014-10-04 20:29:09 -0700 | [diff] [blame] | 221 | completeEntries.put(did, new FlowEntryBuilder(dpid, reply).build()); |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 222 | } |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 223 | } |
alshabib | 54ce589 | 2014-09-23 17:50:51 -0700 | [diff] [blame] | 224 | |
| 225 | if (!stats.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { |
| 226 | log.debug("sending flowstats to core {}", completeEntries.get(did)); |
| 227 | providerService.pushFlowMetrics(did, completeEntries.get(did)); |
| 228 | completeEntries.removeAll(did); |
| 229 | } |
alshabib | 5c370ff | 2014-09-18 10:12:14 -0700 | [diff] [blame] | 230 | } |
| 231 | |
alshabib | 19fdc12 | 2014-10-03 11:38:19 -0700 | [diff] [blame] | 232 | private boolean tableMissRule(Dpid dpid, OFFlowStatsEntry reply) { |
| 233 | // TODO NEED TO FIND A BETTER WAY TO AVOID DOING THIS |
| 234 | if (reply.getVersion().equals(OFVersion.OF_10) || |
| 235 | reply.getMatch().getMatchFields().iterator().hasNext()) { |
| 236 | return false; |
| 237 | } |
| 238 | for (OFInstruction ins : reply.getInstructions()) { |
| 239 | if (ins.getType() == OFInstructionType.APPLY_ACTIONS) { |
| 240 | OFInstructionApplyActions apply = (OFInstructionApplyActions) ins; |
| 241 | List<OFAction> acts = apply.getActions(); |
| 242 | for (OFAction act : acts) { |
| 243 | if (act.getType() == OFActionType.OUTPUT) { |
| 244 | OFActionOutput out = (OFActionOutput) act; |
| 245 | if (out.getPort() == OFPort.CONTROLLER) { |
| 246 | return true; |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | return false; |
| 253 | } |
| 254 | |
alshabib | 8f1cf4a | 2014-09-17 14:44:48 -0700 | [diff] [blame] | 255 | } |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 256 | |
| 257 | |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 258 | @Override |
| 259 | public Future<Void> executeBatch(BatchOperation<FlowRuleBatchEntry> batch) { |
| 260 | final Set<Dpid> sws = new HashSet<Dpid>(); |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 261 | |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 262 | for (FlowRuleBatchEntry fbe : batch.getOperations()) { |
| 263 | FlowRule flowRule = fbe.getTarget(); |
| 264 | OpenFlowSwitch sw = controller.getSwitch(Dpid.dpid(flowRule.deviceId().uri())); |
| 265 | sws.add(new Dpid(sw.getId())); |
| 266 | switch (fbe.getOperator()) { |
| 267 | case ADD: |
| 268 | //TODO: Track XID for each flowmod |
| 269 | sw.sendMsg(new FlowModBuilder(flowRule, sw.factory()).buildFlowAdd()); |
| 270 | break; |
| 271 | case REMOVE: |
| 272 | //TODO: Track XID for each flowmod |
| 273 | sw.sendMsg(new FlowModBuilder(flowRule, sw.factory()).buildFlowDel()); |
| 274 | break; |
| 275 | case MODIFY: |
| 276 | //TODO: Track XID for each flowmod |
| 277 | sw.sendMsg(new FlowModBuilder(flowRule, sw.factory()).buildFlowMod()); |
| 278 | break; |
| 279 | default: |
| 280 | log.error("Unsupported batch operation {}", fbe.getOperator()); |
| 281 | } |
| 282 | } |
| 283 | InstallationFuture installation = new InstallationFuture(sws); |
| 284 | pendingFutures.put(U32.f(batch.hashCode()), installation); |
| 285 | installation.verify(batch.hashCode()); |
| 286 | return installation; |
| 287 | } |
| 288 | |
| 289 | private class InstallationFuture implements Future<Void> { |
| 290 | |
| 291 | private final Set<Dpid> sws; |
| 292 | private final AtomicBoolean ok = new AtomicBoolean(true); |
| 293 | private final List<FlowEntry> offendingFlowMods = Lists.newLinkedList(); |
| 294 | |
| 295 | private final CountDownLatch countDownLatch; |
| 296 | |
| 297 | public InstallationFuture(Set<Dpid> sws) { |
| 298 | this.sws = sws; |
| 299 | countDownLatch = new CountDownLatch(sws.size()); |
| 300 | } |
| 301 | |
| 302 | public void fail(OFErrorMsg msg, Dpid dpid) { |
| 303 | ok.set(false); |
| 304 | //TODO add reason to flowentry |
| 305 | //TODO handle specific error msgs |
| 306 | //offendingFlowMods.add(new FlowEntryBuilder(dpid, msg.)); |
| 307 | switch (msg.getErrType()) { |
| 308 | case BAD_ACTION: |
| 309 | break; |
| 310 | case BAD_INSTRUCTION: |
| 311 | break; |
| 312 | case BAD_MATCH: |
| 313 | break; |
| 314 | case BAD_REQUEST: |
| 315 | break; |
| 316 | case EXPERIMENTER: |
| 317 | break; |
| 318 | case FLOW_MOD_FAILED: |
| 319 | break; |
| 320 | case GROUP_MOD_FAILED: |
| 321 | break; |
| 322 | case HELLO_FAILED: |
| 323 | break; |
| 324 | case METER_MOD_FAILED: |
| 325 | break; |
| 326 | case PORT_MOD_FAILED: |
| 327 | break; |
| 328 | case QUEUE_OP_FAILED: |
| 329 | break; |
| 330 | case ROLE_REQUEST_FAILED: |
| 331 | break; |
| 332 | case SWITCH_CONFIG_FAILED: |
| 333 | break; |
| 334 | case TABLE_FEATURES_FAILED: |
| 335 | break; |
| 336 | case TABLE_MOD_FAILED: |
| 337 | break; |
| 338 | default: |
| 339 | break; |
| 340 | |
| 341 | } |
| 342 | |
| 343 | } |
| 344 | |
| 345 | public void satisfyRequirement(Dpid dpid) { |
| 346 | log.warn("Satisfaction from switch {}", dpid); |
Brian O'Connor | f10fcf6 | 2014-10-08 15:35:59 -0700 | [diff] [blame^] | 347 | sws.remove(dpid); |
alshabib | 902d41b | 2014-10-07 16:52:05 -0700 | [diff] [blame] | 348 | countDownLatch.countDown(); |
| 349 | } |
| 350 | |
| 351 | public void verify(Integer id) { |
| 352 | for (Dpid dpid : sws) { |
| 353 | OpenFlowSwitch sw = controller.getSwitch(dpid); |
| 354 | OFBarrierRequest.Builder builder = sw.factory() |
| 355 | .buildBarrierRequest() |
| 356 | .setXid(id); |
| 357 | sw.sendMsg(builder.build()); |
| 358 | } |
| 359 | |
| 360 | |
| 361 | } |
| 362 | |
| 363 | @Override |
| 364 | public boolean cancel(boolean mayInterruptIfRunning) { |
| 365 | // TODO Auto-generated method stub |
| 366 | return false; |
| 367 | } |
| 368 | |
| 369 | @Override |
| 370 | public boolean isCancelled() { |
| 371 | // TODO Auto-generated method stub |
| 372 | return false; |
| 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public boolean isDone() { |
| 377 | return sws.isEmpty(); |
| 378 | } |
| 379 | |
| 380 | @Override |
| 381 | public Void get() throws InterruptedException, ExecutionException { |
| 382 | countDownLatch.await(); |
| 383 | //return offendingFlowMods; |
| 384 | return null; |
| 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public Void get(long timeout, TimeUnit unit) |
| 389 | throws InterruptedException, ExecutionException, |
| 390 | TimeoutException { |
| 391 | countDownLatch.await(timeout, unit); |
| 392 | //return offendingFlowMods; |
| 393 | return null; |
| 394 | } |
| 395 | |
| 396 | } |
alshabib | a68eb96 | 2014-09-24 20:34:13 -0700 | [diff] [blame] | 397 | |
alshabib | 1cc04f7 | 2014-09-16 16:09:58 -0700 | [diff] [blame] | 398 | } |