Committed by
Gerrit Code Review
Some fixes for the optical app
Change-Id: Ib3e317ad080d822ac41b1cf113ba388a7ce78316
Showing
2 changed files
with
105 additions
and
165 deletions
... | @@ -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,148 +111,107 @@ public class OpticalPathProvisioner { | ... | @@ -135,148 +111,107 @@ 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); | 129 | + } |
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 | - } | ||
164 | - | ||
165 | - PointToPointIntent pktIntent = (PointToPointIntent) intent; | ||
166 | - if (pktIntent.ingressPoint() == null || pktIntent.egressPoint() == null) { | ||
167 | - return; | ||
168 | - } | ||
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 | - } | ||
180 | - } | ||
181 | - }; | ||
182 | - | ||
183 | - Set<Path> paths = topologyService.getPaths(topology, | ||
184 | - pktIntent.ingressPoint().deviceId(), | ||
185 | - pktIntent.egressPoint().deviceId(), | ||
186 | - weight); | ||
187 | - | ||
188 | - if (paths.isEmpty()) { | ||
189 | - return; | ||
190 | - } | ||
191 | - | ||
192 | - ConnectPoint srcWdmPoint = null; | ||
193 | - ConnectPoint dstWdmPoint = null; | ||
194 | - Iterator<Path> itrPath = paths.iterator(); | ||
195 | - Path firstPath = itrPath.next(); | ||
196 | - log.info(firstPath.links().toString()); | ||
197 | - | ||
198 | - ArrayList<Map<ConnectPoint, ConnectPoint>> connectionList = | ||
199 | - new ArrayList<>(); | ||
200 | - | ||
201 | - | ||
202 | - Iterator<Link> itrLink = firstPath.links().iterator(); | ||
203 | - while (itrLink.hasNext()) { | ||
204 | - Link link1 = itrLink.next(); | ||
205 | - if (!isOpticalLink(link1)) { | ||
206 | - continue; | ||
207 | - } else { | ||
208 | - srcWdmPoint = link1.dst(); | ||
209 | - dstWdmPoint = srcWdmPoint; | ||
210 | - } | ||
211 | - | ||
212 | - while (true) { | ||
213 | - if (itrLink.hasNext()) { | ||
214 | - Link link2 = itrLink.next(); | ||
215 | - dstWdmPoint = link2.src(); | ||
216 | - } else { | ||
217 | - break; | ||
218 | - } | ||
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 | - } | ||
238 | - | ||
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 | 130 | ||
245 | - Intent opticalIntent = new OpticalConnectivityIntent(appId, | 131 | + // Build the intent batch |
246 | - srcWdmPoint, | 132 | + IntentOperations.Builder ops = IntentOperations.builder(); |
247 | - dstWdmPoint); | 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); | ||
140 | + } | ||
141 | + } | ||
142 | + intentService.execute(ops.build()); | ||
143 | + } | ||
248 | 144 | ||
249 | - intentService.submit(opticalIntent); | 145 | + private List<Intent> getOpticalPaths(ConnectPoint ingress, ConnectPoint egress) { |
146 | + Set<Path> paths = pathService.getPaths(ingress.deviceId(), | ||
147 | + egress.deviceId(), | ||
148 | + new OpticalLinkWeight()); | ||
250 | 149 | ||
251 | - log.info(srcWdmPoint.toString()); | 150 | + if (paths.isEmpty()) { |
252 | - log.info(dstWdmPoint.toString()); | 151 | + return Lists.newArrayList(); |
253 | - } | 152 | + } |
254 | - } | ||
255 | 153 | ||
154 | + ConnectPoint srcWdmPoint = null; | ||
155 | + ConnectPoint dstWdmPoint = null; | ||
156 | + Iterator<Path> itrPath = paths.iterator(); | ||
157 | + Path firstPath = itrPath.next(); | ||
158 | + log.info(firstPath.links().toString()); | ||
159 | + | ||
160 | + List<Intent> connectionList = Lists.newArrayList(); | ||
161 | + | ||
162 | + Iterator<Link> itrLink = firstPath.links().iterator(); | ||
163 | + while (itrLink.hasNext()) { | ||
164 | + Link link1 = itrLink.next(); | ||
165 | + if (!isOpticalLink(link1)) { | ||
166 | + continue; | ||
167 | + } else { | ||
168 | + srcWdmPoint = link1.dst(); | ||
169 | + dstWdmPoint = srcWdmPoint; | ||
170 | + } | ||
171 | + | ||
172 | + while (true) { | ||
173 | + if (itrLink.hasNext()) { | ||
174 | + Link link2 = itrLink.next(); | ||
175 | + dstWdmPoint = link2.src(); | ||
176 | + } else { | ||
177 | + break; | ||
178 | + } | ||
179 | + } | ||
180 | + | ||
181 | + Intent opticalIntent = new OpticalConnectivityIntent(appId, | ||
182 | + srcWdmPoint, | ||
183 | + dstWdmPoint); | ||
184 | + log.info("Creating optical intent from {} to {}", srcWdmPoint, dstWdmPoint); | ||
185 | + connectionList.add(opticalIntent); | ||
186 | + } | ||
187 | + return connectionList; | ||
256 | } | 188 | } |
257 | 189 | ||
258 | - private boolean isOpticalLink(Link link) { | 190 | + |
259 | - boolean isOptical = false; | ||
260 | - Link.Type lt = link.type(); | ||
261 | - if (lt == Link.Type.OPTICAL) { | ||
262 | - isOptical = true; | ||
263 | - } | ||
264 | - return isOptical; | ||
265 | - } | ||
266 | 191 | ||
267 | private void teardownLightpath(Intent intent) { | 192 | private void teardownLightpath(Intent intent) { |
268 | // TODO: tear down the idle lightpath if the utilization is close to zero. | 193 | // TODO: tear down the idle lightpath if the utilization is close to zero. |
269 | } | 194 | } |
195 | + } | ||
270 | 196 | ||
271 | - private TrafficSelector buildTrafficSelector() { | 197 | + private static boolean isOpticalLink(Link link) { |
272 | - TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); | 198 | + boolean isOptical = false; |
273 | - Short ethType = Ethernet.TYPE_IPV4; | 199 | + Link.Type lt = link.type(); |
274 | - | 200 | + if (lt == Link.Type.OPTICAL) { |
275 | - selectorBuilder.matchEthType(ethType); | 201 | + isOptical = true; |
276 | - | ||
277 | - return selectorBuilder.build(); | ||
278 | } | 202 | } |
203 | + return isOptical; | ||
204 | + } | ||
279 | 205 | ||
206 | + private static class OpticalLinkWeight implements LinkWeight { | ||
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 | ||
213 | + } | ||
214 | + } | ||
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) { | ... | ... |
-
Please register or login to post a comment