Brian O'Connor
Committed by Gerrit Code Review

Some fixes for the optical app

Change-Id: Ib3e317ad080d822ac41b1cf113ba388a7ce78316
...@@ -15,13 +15,7 @@ ...@@ -15,13 +15,7 @@
15 */ 15 */
16 package org.onlab.onos.optical; 16 package org.onlab.onos.optical;
17 17
18 -import java.util.ArrayList; 18 +import com.google.common.collect.Lists;
19 -import java.util.HashMap;
20 -import java.util.Iterator;
21 -import java.util.Map;
22 -import java.util.Map.Entry;
23 -import java.util.Set;
24 -
25 import org.apache.felix.scr.annotations.Activate; 19 import org.apache.felix.scr.annotations.Activate;
26 import org.apache.felix.scr.annotations.Component; 20 import org.apache.felix.scr.annotations.Component;
27 import org.apache.felix.scr.annotations.Deactivate; 21 import org.apache.felix.scr.annotations.Deactivate;
...@@ -33,31 +27,25 @@ import org.onlab.onos.net.ConnectPoint; ...@@ -33,31 +27,25 @@ import org.onlab.onos.net.ConnectPoint;
33 import org.onlab.onos.net.Host; 27 import org.onlab.onos.net.Host;
34 import org.onlab.onos.net.Link; 28 import org.onlab.onos.net.Link;
35 import org.onlab.onos.net.Path; 29 import org.onlab.onos.net.Path;
36 -import org.onlab.onos.net.device.DeviceService;
37 -import org.onlab.onos.net.flow.DefaultTrafficSelector;
38 -import org.onlab.onos.net.flow.TrafficSelector;
39 -import org.onlab.onos.net.flow.TrafficTreatment;
40 import org.onlab.onos.net.host.HostService; 30 import org.onlab.onos.net.host.HostService;
41 import org.onlab.onos.net.intent.HostToHostIntent; 31 import org.onlab.onos.net.intent.HostToHostIntent;
42 import org.onlab.onos.net.intent.Intent; 32 import org.onlab.onos.net.intent.Intent;
43 import org.onlab.onos.net.intent.IntentEvent; 33 import org.onlab.onos.net.intent.IntentEvent;
44 -import org.onlab.onos.net.intent.IntentExtensionService;
45 import org.onlab.onos.net.intent.IntentListener; 34 import org.onlab.onos.net.intent.IntentListener;
35 +import org.onlab.onos.net.intent.IntentOperations;
46 import org.onlab.onos.net.intent.IntentService; 36 import org.onlab.onos.net.intent.IntentService;
37 +import org.onlab.onos.net.intent.IntentState;
47 import org.onlab.onos.net.intent.OpticalConnectivityIntent; 38 import org.onlab.onos.net.intent.OpticalConnectivityIntent;
48 import org.onlab.onos.net.intent.PointToPointIntent; 39 import org.onlab.onos.net.intent.PointToPointIntent;
49 -import org.onlab.onos.net.link.LinkService;
50 -import org.onlab.onos.net.resource.LinkResourceService;
51 import org.onlab.onos.net.topology.LinkWeight; 40 import org.onlab.onos.net.topology.LinkWeight;
52 -import org.onlab.onos.net.topology.Topology; 41 +import org.onlab.onos.net.topology.PathService;
53 import org.onlab.onos.net.topology.TopologyEdge; 42 import org.onlab.onos.net.topology.TopologyEdge;
54 -
55 -import org.onlab.onos.net.topology.TopologyService;
56 -import org.onlab.packet.Ethernet;
57 import org.slf4j.Logger; 43 import org.slf4j.Logger;
58 import org.slf4j.LoggerFactory; 44 import org.slf4j.LoggerFactory;
59 45
60 -import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder; 46 +import java.util.Iterator;
47 +import java.util.List;
48 +import java.util.Set;
61 49
62 /** 50 /**
63 * OpticalPathProvisioner listens event notifications from the Intent F/W. 51 * OpticalPathProvisioner listens event notifications from the Intent F/W.
...@@ -76,24 +64,12 @@ public class OpticalPathProvisioner { ...@@ -76,24 +64,12 @@ public class OpticalPathProvisioner {
76 private IntentService intentService; 64 private IntentService intentService;
77 65
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 66 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 - private IntentExtensionService intentExtensionService; 67 + protected PathService pathService;
80 -
81 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
82 - protected LinkService linkService;
83 -
84 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
85 - protected DeviceService deviceService;
86 -
87 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
88 - protected TopologyService topologyService;
89 68
90 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 69 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 protected CoreService coreService; 70 protected CoreService coreService;
92 71
93 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
94 - protected LinkResourceService resourceService;
95 -
96 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
97 protected HostService hostService; 73 protected HostService hostService;
98 74
99 private ApplicationId appId; 75 private ApplicationId appId;
...@@ -124,7 +100,7 @@ public class OpticalPathProvisioner { ...@@ -124,7 +100,7 @@ public class OpticalPathProvisioner {
124 break; 100 break;
125 case FAILED: 101 case FAILED:
126 log.info("packet intent {} failed, calling optical path provisioning APP.", event.subject()); 102 log.info("packet intent {} failed, calling optical path provisioning APP.", event.subject());
127 - setuplightpath(event.subject()); 103 + setupLightpath(event.subject());
128 break; 104 break;
129 case WITHDRAWN: 105 case WITHDRAWN:
130 log.info("intent {} withdrawn.", event.subject()); 106 log.info("intent {} withdrawn.", event.subject());
...@@ -135,58 +111,44 @@ public class OpticalPathProvisioner { ...@@ -135,58 +111,44 @@ public class OpticalPathProvisioner {
135 } 111 }
136 } 112 }
137 113
138 - private void setuplightpath(Intent intent) { 114 + private void setupLightpath(Intent intent) {
139 // TODO support more packet intent types 115 // TODO support more packet intent types
140 - 116 + List<Intent> intents = Lists.newArrayList();
141 if (intent instanceof HostToHostIntent) { 117 if (intent instanceof HostToHostIntent) {
142 HostToHostIntent hostToHostIntent = (HostToHostIntent) intent; 118 HostToHostIntent hostToHostIntent = (HostToHostIntent) intent;
143 Host one = hostService.getHost(hostToHostIntent.one()); 119 Host one = hostService.getHost(hostToHostIntent.one());
144 Host two = hostService.getHost(hostToHostIntent.two()); 120 Host two = hostService.getHost(hostToHostIntent.two());
145 - 121 + // provision both directions
146 - TrafficSelector selector = buildTrafficSelector(); 122 + intents.addAll(getOpticalPaths(one.location(), two.location()));
147 - TrafficTreatment treatment = builder().build(); 123 + intents.addAll(getOpticalPaths(two.location(), one.location()));
148 - 124 + } else if (intent instanceof PointToPointIntent) {
149 - PointToPointIntent intentOneToTwo = 125 + PointToPointIntent p2pIntent = (PointToPointIntent) intent;
150 - new PointToPointIntent(appId, selector, treatment, 126 + intents.addAll(getOpticalPaths(p2pIntent.ingressPoint(), p2pIntent.egressPoint()));
151 - one.location(), two.location()); 127 + } else {
152 - intentService.submit(intentOneToTwo); 128 + log.info("Unsupported intent type: {}", intent.getClass());
153 - log.info("Submitting P2P intent {} ", intentOneToTwo);
154 -
155 - PointToPointIntent intentTwoToOne =
156 - new PointToPointIntent(appId, selector, treatment,
157 - two.location(), one.location());
158 - intentService.submit(intentTwoToOne);
159 - log.info("Submitting P2P intent for {} ", intentTwoToOne);
160 - return;
161 - } else if (!intent.getClass().equals(PointToPointIntent.class)) {
162 - return;
163 } 129 }
164 130
165 - PointToPointIntent pktIntent = (PointToPointIntent) intent; 131 + // Build the intent batch
166 - if (pktIntent.ingressPoint() == null || pktIntent.egressPoint() == null) { 132 + IntentOperations.Builder ops = IntentOperations.builder();
167 - return; 133 + for (Intent i : intents) {
134 + // TODO: don't allow duplicate intents between the same points for now
135 + // we may want to allow this carefully in future to increase capacity
136 + Intent existing = intentService.getIntent(i.id());
137 + if (existing == null ||
138 + !IntentState.WITHDRAWN.equals(intentService.getIntentState(i.id()))) {
139 + ops.addSubmitOperation(i);
168 } 140 }
169 -
170 - Topology topology = topologyService.currentTopology();
171 -
172 - LinkWeight weight = new LinkWeight() {
173 - @Override
174 - public double weight(TopologyEdge edge) {
175 - if (isOpticalLink(edge.link())) {
176 - return 1000.0; // optical links
177 - } else {
178 - return 1.0; // packet links
179 } 141 }
142 + intentService.execute(ops.build());
180 } 143 }
181 - };
182 144
183 - Set<Path> paths = topologyService.getPaths(topology, 145 + private List<Intent> getOpticalPaths(ConnectPoint ingress, ConnectPoint egress) {
184 - pktIntent.ingressPoint().deviceId(), 146 + Set<Path> paths = pathService.getPaths(ingress.deviceId(),
185 - pktIntent.egressPoint().deviceId(), 147 + egress.deviceId(),
186 - weight); 148 + new OpticalLinkWeight());
187 149
188 if (paths.isEmpty()) { 150 if (paths.isEmpty()) {
189 - return; 151 + return Lists.newArrayList();
190 } 152 }
191 153
192 ConnectPoint srcWdmPoint = null; 154 ConnectPoint srcWdmPoint = null;
...@@ -195,9 +157,7 @@ public class OpticalPathProvisioner { ...@@ -195,9 +157,7 @@ public class OpticalPathProvisioner {
195 Path firstPath = itrPath.next(); 157 Path firstPath = itrPath.next();
196 log.info(firstPath.links().toString()); 158 log.info(firstPath.links().toString());
197 159
198 - ArrayList<Map<ConnectPoint, ConnectPoint>> connectionList = 160 + List<Intent> connectionList = Lists.newArrayList();
199 - new ArrayList<>();
200 -
201 161
202 Iterator<Link> itrLink = firstPath.links().iterator(); 162 Iterator<Link> itrLink = firstPath.links().iterator();
203 while (itrLink.hasNext()) { 163 while (itrLink.hasNext()) {
...@@ -216,46 +176,25 @@ public class OpticalPathProvisioner { ...@@ -216,46 +176,25 @@ public class OpticalPathProvisioner {
216 } else { 176 } else {
217 break; 177 break;
218 } 178 }
219 -
220 - /*
221 - if (itrLink.hasNext()) {
222 - Link link3 = itrLink.next();
223 - if (isOpticalLink(link3)) {
224 - break;
225 - }
226 - } else {
227 - break;
228 - }*/
229 -
230 - }
231 -
232 - Map<ConnectPoint, ConnectPoint> pair =
233 - new HashMap<ConnectPoint, ConnectPoint>();
234 - pair.put(srcWdmPoint, dstWdmPoint);
235 -
236 - connectionList.add(pair);
237 } 179 }
238 180
239 - for (Map<ConnectPoint, ConnectPoint> map : connectionList) {
240 - for (Entry<ConnectPoint, ConnectPoint> entry : map.entrySet()) {
241 -
242 - ConnectPoint src = entry.getKey();
243 - ConnectPoint dst = entry.getValue();
244 -
245 Intent opticalIntent = new OpticalConnectivityIntent(appId, 181 Intent opticalIntent = new OpticalConnectivityIntent(appId,
246 srcWdmPoint, 182 srcWdmPoint,
247 dstWdmPoint); 183 dstWdmPoint);
248 - 184 + log.info("Creating optical intent from {} to {}", srcWdmPoint, dstWdmPoint);
249 - intentService.submit(opticalIntent); 185 + connectionList.add(opticalIntent);
250 -
251 - log.info(srcWdmPoint.toString());
252 - log.info(dstWdmPoint.toString());
253 } 186 }
187 + return connectionList;
254 } 188 }
255 189
190 +
191 +
192 + private void teardownLightpath(Intent intent) {
193 + // TODO: tear down the idle lightpath if the utilization is close to zero.
194 + }
256 } 195 }
257 196
258 - private boolean isOpticalLink(Link link) { 197 + private static boolean isOpticalLink(Link link) {
259 boolean isOptical = false; 198 boolean isOptical = false;
260 Link.Type lt = link.type(); 199 Link.Type lt = link.type();
261 if (lt == Link.Type.OPTICAL) { 200 if (lt == Link.Type.OPTICAL) {
...@@ -264,19 +203,15 @@ public class OpticalPathProvisioner { ...@@ -264,19 +203,15 @@ public class OpticalPathProvisioner {
264 return isOptical; 203 return isOptical;
265 } 204 }
266 205
267 - private void teardownLightpath(Intent intent) { 206 + private static class OpticalLinkWeight implements LinkWeight {
268 - // TODO: tear down the idle lightpath if the utilization is close to zero. 207 + @Override
208 + public double weight(TopologyEdge edge) {
209 + if (isOpticalLink(edge.link())) {
210 + return 1000.0; // optical links
211 + } else {
212 + return 1.0; // packet links
269 } 213 }
270 -
271 - private TrafficSelector buildTrafficSelector() {
272 - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
273 - Short ethType = Ethernet.TYPE_IPV4;
274 -
275 - selectorBuilder.matchEthType(ethType);
276 -
277 - return selectorBuilder.build();
278 } 214 }
279 -
280 } 215 }
281 216
282 } 217 }
......
...@@ -101,14 +101,19 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn ...@@ -101,14 +101,19 @@ public class OpticalPathIntentInstaller implements IntentInstaller<OpticalPathIn
101 @Override 101 @Override
102 public List<FlowRuleBatchOperation> uninstall(OpticalPathIntent intent) { 102 public List<FlowRuleBatchOperation> uninstall(OpticalPathIntent intent) {
103 LinkResourceAllocations allocations = resourceService.getAllocations(intent.id()); 103 LinkResourceAllocations allocations = resourceService.getAllocations(intent.id());
104 - return generateRules(intent, allocations, FlowRuleOperation.REMOVE); 104 + List<FlowRuleBatchOperation> rules = generateRules(intent, allocations, FlowRuleOperation.REMOVE);
105 + log.info("uninstall rules: {}", rules);
106 + return rules;
105 } 107 }
106 108
107 @Override 109 @Override
108 - public List<FlowRuleBatchOperation> replace(OpticalPathIntent intent, 110 + public List<FlowRuleBatchOperation> replace(OpticalPathIntent oldIntent,
109 OpticalPathIntent newIntent) { 111 OpticalPathIntent newIntent) {
110 // FIXME: implement this 112 // FIXME: implement this
111 - return null; 113 + List<FlowRuleBatchOperation> batches = Lists.newArrayList();
114 + batches.addAll(uninstall(oldIntent));
115 + batches.addAll(install(newIntent));
116 + return batches;
112 } 117 }
113 118
114 private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) { 119 private LinkResourceAllocations assignWavelength(OpticalPathIntent intent) {
......