Marc De Leenheer
Committed by Gerrit Code Review

Bidirectional optical intents (ONOS-2055).

Removed dead code.
Bugfix in device resource store.

Change-Id: Ic81e0b6985813d8dd696440610bee967a9fc2fc7
...@@ -58,9 +58,7 @@ import java.util.Collections; ...@@ -58,9 +58,7 @@ import java.util.Collections;
58 import java.util.Iterator; 58 import java.util.Iterator;
59 import java.util.LinkedList; 59 import java.util.LinkedList;
60 import java.util.List; 60 import java.util.List;
61 -import java.util.Map;
62 import java.util.Set; 61 import java.util.Set;
63 -import java.util.concurrent.ConcurrentHashMap;
64 62
65 import static com.google.common.base.Preconditions.checkArgument; 63 import static com.google.common.base.Preconditions.checkArgument;
66 import static com.google.common.base.Preconditions.checkNotNull; 64 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -106,9 +104,6 @@ public class OpticalPathProvisioner { ...@@ -106,9 +104,6 @@ public class OpticalPathProvisioner {
106 104
107 private ApplicationId appId; 105 private ApplicationId appId;
108 106
109 - private final Map<ConnectPoint, Map<ConnectPoint, Intent>> intentMap =
110 - new ConcurrentHashMap<>();
111 -
112 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner(); 107 private final InternalOpticalPathProvisioner pathProvisioner = new InternalOpticalPathProvisioner();
113 108
114 @Activate 109 @Activate
...@@ -147,35 +142,13 @@ public class OpticalPathProvisioner { ...@@ -147,35 +142,13 @@ public class OpticalPathProvisioner {
147 break; 142 break;
148 case WITHDRAWN: 143 case WITHDRAWN:
149 log.info("Intent {} withdrawn.", event.subject()); 144 log.info("Intent {} withdrawn.", event.subject());
150 - withdrawIntent(event.subject()); 145 + releaseResources(event.subject());
151 break; 146 break;
152 default: 147 default:
153 break; 148 break;
154 } 149 }
155 } 150 }
156 151
157 - /**
158 - * Registers an intent from src to dst.
159 - *
160 - * @param src source point
161 - * @param dst destination point
162 - * @param intent intent to be registered
163 - * @return true if intent has not been previously added, false otherwise
164 - */
165 - private boolean addIntent(ConnectPoint src, ConnectPoint dst, Intent intent) {
166 - Map<ConnectPoint, Intent> srcMap = intentMap.get(src);
167 - if (srcMap == null) {
168 - srcMap = new ConcurrentHashMap<>();
169 - intentMap.put(src, srcMap);
170 - }
171 - if (srcMap.containsKey(dst)) {
172 - return false;
173 - } else {
174 - srcMap.put(dst, intent);
175 - return true;
176 - }
177 - }
178 -
179 private void setupLightpath(Intent intent) { 152 private void setupLightpath(Intent intent) {
180 checkNotNull(intent); 153 checkNotNull(intent);
181 154
...@@ -310,14 +283,13 @@ public class OpticalPathProvisioner { ...@@ -310,14 +283,13 @@ public class OpticalPathProvisioner {
310 Port dstPort = deviceService.getPort(dst.deviceId(), dst.port()); 283 Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
311 284
312 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) { 285 if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
313 - // TODO: Check availability of ports
314 -
315 // Create OTN circuit 286 // Create OTN circuit
316 Intent circuitIntent = OpticalCircuitIntent.builder() 287 Intent circuitIntent = OpticalCircuitIntent.builder()
317 .appId(appId) 288 .appId(appId)
318 .src(src) 289 .src(src)
319 .dst(dst) 290 .dst(dst)
320 .signalType(OduCltPort.SignalType.CLT_10GBE) 291 .signalType(OduCltPort.SignalType.CLT_10GBE)
292 + .bidirectional(true)
321 .build(); 293 .build();
322 intents.add(circuitIntent); 294 intents.add(circuitIntent);
323 continue; 295 continue;
...@@ -329,6 +301,7 @@ public class OpticalPathProvisioner { ...@@ -329,6 +301,7 @@ public class OpticalPathProvisioner {
329 .src(src) 301 .src(src)
330 .dst(dst) 302 .dst(dst)
331 .signalType(OduSignalType.ODU4) 303 .signalType(OduSignalType.ODU4)
304 + .bidirectional(true)
332 .build(); 305 .build();
333 intents.add(opticalIntent); 306 intents.add(opticalIntent);
334 continue; 307 continue;
...@@ -397,11 +370,11 @@ public class OpticalPathProvisioner { ...@@ -397,11 +370,11 @@ public class OpticalPathProvisioner {
397 } 370 }
398 371
399 /** 372 /**
400 - * Handle withdrawn intent on each network layer. 373 + * Release resources associated to the given intent.
401 * 374 *
402 - * @param intent the withdrawn intent 375 + * @param intent the intent
403 */ 376 */
404 - private void withdrawIntent(Intent intent) { 377 + private void releaseResources(Intent intent) {
405 LinkResourceAllocations lra = linkResourceService.getAllocations(intent.id()); 378 LinkResourceAllocations lra = linkResourceService.getAllocations(intent.id());
406 if (intent instanceof OpticalConnectivityIntent) { 379 if (intent instanceof OpticalConnectivityIntent) {
407 deviceResourceService.releasePorts(intent.id()); 380 deviceResourceService.releasePorts(intent.id());
......
...@@ -49,6 +49,7 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand { ...@@ -49,6 +49,7 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
49 description = "Egress Device/Port Description", 49 description = "Egress Device/Port Description",
50 required = true, multiValued = false) 50 required = true, multiValued = false)
51 String egressDeviceString = null; 51 String egressDeviceString = null;
52 + // TODO: add parameter for uni/bidirectional intents
52 53
53 private ConnectPoint createConnectPoint(String devicePortString) { 54 private ConnectPoint createConnectPoint(String devicePortString) {
54 String[] splitted = devicePortString.split("/"); 55 String[] splitted = devicePortString.split("/");
......
...@@ -32,6 +32,7 @@ public class OpticalCircuitIntent extends Intent { ...@@ -32,6 +32,7 @@ public class OpticalCircuitIntent extends Intent {
32 private final ConnectPoint src; 32 private final ConnectPoint src;
33 private final ConnectPoint dst; 33 private final ConnectPoint dst;
34 private final OduCltPort.SignalType signalType; 34 private final OduCltPort.SignalType signalType;
35 + private final boolean isBidirectional;
35 36
36 /** 37 /**
37 * Creates an optical circuit intent between the specified 38 * Creates an optical circuit intent between the specified
...@@ -45,11 +46,12 @@ public class OpticalCircuitIntent extends Intent { ...@@ -45,11 +46,12 @@ public class OpticalCircuitIntent extends Intent {
45 * @param priority priority to use for flows from this intent 46 * @param priority priority to use for flows from this intent
46 */ 47 */
47 protected OpticalCircuitIntent(ApplicationId appId, Key key, ConnectPoint src, ConnectPoint dst, 48 protected OpticalCircuitIntent(ApplicationId appId, Key key, ConnectPoint src, ConnectPoint dst,
48 - OduCltPort.SignalType signalType, int priority) { 49 + OduCltPort.SignalType signalType, boolean isBidirectional, int priority) {
49 super(appId, key, Collections.emptyList(), priority); 50 super(appId, key, Collections.emptyList(), priority);
50 this.src = checkNotNull(src); 51 this.src = checkNotNull(src);
51 this.dst = checkNotNull(dst); 52 this.dst = checkNotNull(dst);
52 this.signalType = checkNotNull(signalType); 53 this.signalType = checkNotNull(signalType);
54 + this.isBidirectional = isBidirectional;
53 } 55 }
54 56
55 /** 57 /**
...@@ -69,6 +71,7 @@ public class OpticalCircuitIntent extends Intent { ...@@ -69,6 +71,7 @@ public class OpticalCircuitIntent extends Intent {
69 private ConnectPoint src; 71 private ConnectPoint src;
70 private ConnectPoint dst; 72 private ConnectPoint dst;
71 private OduCltPort.SignalType signalType; 73 private OduCltPort.SignalType signalType;
74 + private boolean isBidirectional;
72 75
73 @Override 76 @Override
74 public Builder appId(ApplicationId appId) { 77 public Builder appId(ApplicationId appId) {
...@@ -119,6 +122,17 @@ public class OpticalCircuitIntent extends Intent { ...@@ -119,6 +122,17 @@ public class OpticalCircuitIntent extends Intent {
119 } 122 }
120 123
121 /** 124 /**
125 + * Sets the directionality of the intent.
126 + *
127 + * @param isBidirectional true if bidirectional, false if unidirectional
128 + * @return this builder
129 + */
130 + public Builder bidirectional(boolean isBidirectional) {
131 + this.isBidirectional = isBidirectional;
132 + return this;
133 + }
134 +
135 + /**
122 * Builds an optical circuit intent from the accumulated parameters. 136 * Builds an optical circuit intent from the accumulated parameters.
123 * 137 *
124 * @return point to point intent 138 * @return point to point intent
...@@ -131,6 +145,7 @@ public class OpticalCircuitIntent extends Intent { ...@@ -131,6 +145,7 @@ public class OpticalCircuitIntent extends Intent {
131 src, 145 src,
132 dst, 146 dst,
133 signalType, 147 signalType,
148 + isBidirectional,
134 priority 149 priority
135 ); 150 );
136 } 151 }
...@@ -144,6 +159,7 @@ public class OpticalCircuitIntent extends Intent { ...@@ -144,6 +159,7 @@ public class OpticalCircuitIntent extends Intent {
144 this.src = null; 159 this.src = null;
145 this.dst = null; 160 this.dst = null;
146 this.signalType = null; 161 this.signalType = null;
162 + this.isBidirectional = false;
147 } 163 }
148 164
149 /** 165 /**
...@@ -173,6 +189,15 @@ public class OpticalCircuitIntent extends Intent { ...@@ -173,6 +189,15 @@ public class OpticalCircuitIntent extends Intent {
173 return signalType; 189 return signalType;
174 } 190 }
175 191
192 + /**
193 + * Returns the directionality of the intent.
194 + *
195 + * @return true if bidirectional, false if unidirectional
196 + */
197 + public boolean isBidirectional() {
198 + return isBidirectional;
199 + }
200 +
176 @Override 201 @Override
177 public String toString() { 202 public String toString() {
178 return MoreObjects.toStringHelper(this) 203 return MoreObjects.toStringHelper(this)
...@@ -184,6 +209,7 @@ public class OpticalCircuitIntent extends Intent { ...@@ -184,6 +209,7 @@ public class OpticalCircuitIntent extends Intent {
184 .add("src", src) 209 .add("src", src)
185 .add("dst", dst) 210 .add("dst", dst)
186 .add("signalType", signalType) 211 .add("signalType", signalType)
212 + .add("isBidirectional", isBidirectional)
187 .toString(); 213 .toString();
188 } 214 }
189 215
......
...@@ -32,6 +32,7 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -32,6 +32,7 @@ public final class OpticalConnectivityIntent extends Intent {
32 private final ConnectPoint src; 32 private final ConnectPoint src;
33 private final ConnectPoint dst; 33 private final ConnectPoint dst;
34 private final OduSignalType signalType; 34 private final OduSignalType signalType;
35 + private final boolean isBidirectional;
35 36
36 /** 37 /**
37 * Creates an optical connectivity intent between the specified 38 * Creates an optical connectivity intent between the specified
...@@ -41,6 +42,7 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -41,6 +42,7 @@ public final class OpticalConnectivityIntent extends Intent {
41 * @param key intent key 42 * @param key intent key
42 * @param src the source transponder port 43 * @param src the source transponder port
43 * @param dst the destination transponder port 44 * @param dst the destination transponder port
45 + * @param isBidirectional indicates if intent is unidirectional
44 * @param priority priority to use for flows from this intent 46 * @param priority priority to use for flows from this intent
45 */ 47 */
46 protected OpticalConnectivityIntent(ApplicationId appId, 48 protected OpticalConnectivityIntent(ApplicationId appId,
...@@ -48,11 +50,13 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -48,11 +50,13 @@ public final class OpticalConnectivityIntent extends Intent {
48 ConnectPoint src, 50 ConnectPoint src,
49 ConnectPoint dst, 51 ConnectPoint dst,
50 OduSignalType signalType, 52 OduSignalType signalType,
53 + boolean isBidirectional,
51 int priority) { 54 int priority) {
52 super(appId, key, Collections.emptyList(), priority); 55 super(appId, key, Collections.emptyList(), priority);
53 this.src = checkNotNull(src); 56 this.src = checkNotNull(src);
54 this.dst = checkNotNull(dst); 57 this.dst = checkNotNull(dst);
55 this.signalType = checkNotNull(signalType); 58 this.signalType = checkNotNull(signalType);
59 + this.isBidirectional = isBidirectional;
56 } 60 }
57 61
58 /** 62 /**
...@@ -72,6 +76,7 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -72,6 +76,7 @@ public final class OpticalConnectivityIntent extends Intent {
72 private ConnectPoint src; 76 private ConnectPoint src;
73 private ConnectPoint dst; 77 private ConnectPoint dst;
74 private OduSignalType signalType; 78 private OduSignalType signalType;
79 + private boolean isBidirectional;
75 80
76 @Override 81 @Override
77 public Builder appId(ApplicationId appId) { 82 public Builder appId(ApplicationId appId) {
...@@ -122,6 +127,17 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -122,6 +127,17 @@ public final class OpticalConnectivityIntent extends Intent {
122 } 127 }
123 128
124 /** 129 /**
130 + * Sets the directionality of the intent.
131 + *
132 + * @param isBidirectional true if bidirectional, false if unidirectional
133 + * @return this builder
134 + */
135 + public Builder bidirectional(boolean isBidirectional) {
136 + this.isBidirectional = isBidirectional;
137 + return this;
138 + }
139 +
140 + /**
125 * Builds an optical connectivity intent from the accumulated parameters. 141 * Builds an optical connectivity intent from the accumulated parameters.
126 * 142 *
127 * @return point to point intent 143 * @return point to point intent
...@@ -134,6 +150,7 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -134,6 +150,7 @@ public final class OpticalConnectivityIntent extends Intent {
134 src, 150 src,
135 dst, 151 dst,
136 signalType, 152 signalType,
153 + isBidirectional,
137 priority 154 priority
138 ); 155 );
139 } 156 }
...@@ -147,6 +164,7 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -147,6 +164,7 @@ public final class OpticalConnectivityIntent extends Intent {
147 this.src = null; 164 this.src = null;
148 this.dst = null; 165 this.dst = null;
149 this.signalType = null; 166 this.signalType = null;
167 + this.isBidirectional = false;
150 } 168 }
151 169
152 /** 170 /**
...@@ -176,6 +194,15 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -176,6 +194,15 @@ public final class OpticalConnectivityIntent extends Intent {
176 return signalType; 194 return signalType;
177 } 195 }
178 196
197 + /**
198 + * Returns the directionality of the intent.
199 + *
200 + * @return true if bidirectional, false if unidirectional
201 + */
202 + public boolean isBidirectional() {
203 + return isBidirectional;
204 + }
205 +
179 @Override 206 @Override
180 public String toString() { 207 public String toString() {
181 return MoreObjects.toStringHelper(this) 208 return MoreObjects.toStringHelper(this)
...@@ -187,6 +214,7 @@ public final class OpticalConnectivityIntent extends Intent { ...@@ -187,6 +214,7 @@ public final class OpticalConnectivityIntent extends Intent {
187 .add("src", src) 214 .add("src", src)
188 .add("dst", dst) 215 .add("dst", dst)
189 .add("signalType", signalType) 216 .add("signalType", signalType)
217 + .add("isBidirectional", isBidirectional)
190 .toString(); 218 .toString();
191 } 219 }
192 } 220 }
......
...@@ -33,6 +33,7 @@ public final class OpticalPathIntent extends Intent { ...@@ -33,6 +33,7 @@ public final class OpticalPathIntent extends Intent {
33 private final Path path; 33 private final Path path;
34 private final OchSignal lambda; 34 private final OchSignal lambda;
35 private final OchSignalType signalType; 35 private final OchSignalType signalType;
36 + private final boolean isBidirectional;
36 37
37 private OpticalPathIntent(ApplicationId appId, 38 private OpticalPathIntent(ApplicationId appId,
38 Key key, 39 Key key,
...@@ -41,6 +42,7 @@ public final class OpticalPathIntent extends Intent { ...@@ -41,6 +42,7 @@ public final class OpticalPathIntent extends Intent {
41 Path path, 42 Path path,
42 OchSignal lambda, 43 OchSignal lambda,
43 OchSignalType signalType, 44 OchSignalType signalType,
45 + boolean isBidirectional,
44 int priority) { 46 int priority) {
45 super(appId, key, ImmutableSet.copyOf(path.links()), priority); 47 super(appId, key, ImmutableSet.copyOf(path.links()), priority);
46 this.src = checkNotNull(src); 48 this.src = checkNotNull(src);
...@@ -48,6 +50,7 @@ public final class OpticalPathIntent extends Intent { ...@@ -48,6 +50,7 @@ public final class OpticalPathIntent extends Intent {
48 this.path = checkNotNull(path); 50 this.path = checkNotNull(path);
49 this.lambda = checkNotNull(lambda); 51 this.lambda = checkNotNull(lambda);
50 this.signalType = checkNotNull(signalType); 52 this.signalType = checkNotNull(signalType);
53 + this.isBidirectional = isBidirectional;
51 } 54 }
52 55
53 protected OpticalPathIntent() { 56 protected OpticalPathIntent() {
...@@ -56,6 +59,7 @@ public final class OpticalPathIntent extends Intent { ...@@ -56,6 +59,7 @@ public final class OpticalPathIntent extends Intent {
56 this.path = null; 59 this.path = null;
57 this.lambda = null; 60 this.lambda = null;
58 this.signalType = null; 61 this.signalType = null;
62 + this.isBidirectional = true;
59 } 63 }
60 64
61 /** 65 /**
...@@ -77,6 +81,7 @@ public final class OpticalPathIntent extends Intent { ...@@ -77,6 +81,7 @@ public final class OpticalPathIntent extends Intent {
77 private Path path; 81 private Path path;
78 private OchSignal lambda; 82 private OchSignal lambda;
79 private OchSignalType signalType; 83 private OchSignalType signalType;
84 + private boolean isBidirectional;
80 Key key; 85 Key key;
81 86
82 @Override 87 @Override
...@@ -150,6 +155,15 @@ public final class OpticalPathIntent extends Intent { ...@@ -150,6 +155,15 @@ public final class OpticalPathIntent extends Intent {
150 } 155 }
151 156
152 /** 157 /**
158 + * Sets the intent's direction.
159 + * @return this builder
160 + */
161 + public Builder bidirectional(boolean isBidirectional) {
162 + this.isBidirectional = isBidirectional;
163 + return this;
164 + }
165 +
166 + /**
153 * Builds an optical path intent from the accumulated parameters. 167 * Builds an optical path intent from the accumulated parameters.
154 * 168 *
155 * @return optical path intent 169 * @return optical path intent
...@@ -164,6 +178,7 @@ public final class OpticalPathIntent extends Intent { ...@@ -164,6 +178,7 @@ public final class OpticalPathIntent extends Intent {
164 path, 178 path,
165 lambda, 179 lambda,
166 signalType, 180 signalType,
181 + isBidirectional,
167 priority 182 priority
168 ); 183 );
169 } 184 }
...@@ -190,6 +205,10 @@ public final class OpticalPathIntent extends Intent { ...@@ -190,6 +205,10 @@ public final class OpticalPathIntent extends Intent {
190 return signalType; 205 return signalType;
191 } 206 }
192 207
208 + public boolean isBidirectional() {
209 + return isBidirectional;
210 + }
211 +
193 @Override 212 @Override
194 public String toString() { 213 public String toString() {
195 return MoreObjects.toStringHelper(getClass()) 214 return MoreObjects.toStringHelper(getClass())
...@@ -202,6 +221,7 @@ public final class OpticalPathIntent extends Intent { ...@@ -202,6 +221,7 @@ public final class OpticalPathIntent extends Intent {
202 .add("path", path) 221 .add("path", path)
203 .add("lambda", lambda) 222 .add("lambda", lambda)
204 .add("signalType", signalType) 223 .add("signalType", signalType)
224 + .add("isBidirectional", isBidirectional)
205 .toString(); 225 .toString();
206 } 226 }
207 } 227 }
......
...@@ -136,15 +136,23 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -136,15 +136,23 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
136 .src(srcCP) 136 .src(srcCP)
137 .dst(dstCP) 137 .dst(dstCP)
138 .signalType(OduSignalType.ODU4) 138 .signalType(OduSignalType.ODU4)
139 + .bidirectional(intent.isBidirectional())
139 .build(); 140 .build();
140 intents.add(connIntent); 141 intents.add(connIntent);
141 } 142 }
142 143
143 // Create optical circuit intent 144 // Create optical circuit intent
144 - circuitIntent = new FlowRuleIntent( 145 + List<FlowRule> rules = new LinkedList<>();
145 - appId, 146 + rules.add(connectPorts(src, connIntent.getSrc()));
146 - createRules(src, connIntent.getSrc(), dst, connIntent.getDst()), 147 + rules.add(connectPorts(connIntent.getDst(), dst));
147 - intent.resources()); 148 +
149 + // Create flow rules for reverse path
150 + if (intent.isBidirectional()) {
151 + rules.add(connectPorts(connIntent.getSrc(), src));
152 + rules.add(connectPorts(dst, connIntent.getDst()));
153 + }
154 +
155 + circuitIntent = new FlowRuleIntent(appId, rules, intent.resources());
148 156
149 // Save circuit to connectivity intent mapping 157 // Save circuit to connectivity intent mapping
150 deviceResourceService.requestMapping(connIntent.id(), circuitIntent.id()); 158 deviceResourceService.requestMapping(connIntent.id(), circuitIntent.id());
...@@ -236,40 +244,25 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -236,40 +244,25 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
236 } 244 }
237 245
238 /** 246 /**
239 - * Builds flow rules for mapping between ODU and OCh ports. 247 + * Builds flow rule for mapping between two ports.
240 * 248 *
241 - * @param srcOdu 249 + * @param src source port
242 - * @param dstOdu 250 + * @param dst destination port
243 - * @return 251 + * @return flow rules
244 */ 252 */
245 - private List<FlowRule> createRules(ConnectPoint srcOdu, ConnectPoint srcOch, 253 + private FlowRule connectPorts(ConnectPoint src, ConnectPoint dst) {
246 - ConnectPoint dstOdu, ConnectPoint dstOch) { 254 + checkArgument(src.deviceId().equals(dst.deviceId()));
255 +
247 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); 256 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
248 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder(); 257 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
249 258
250 - // Source flow rule 259 + selectorBuilder.matchInPort(src.port());
251 - selectorBuilder.matchInPort(srcOdu.port());
252 //selectorBuilder.add(Criteria.matchCltSignalType) 260 //selectorBuilder.add(Criteria.matchCltSignalType)
253 - treatmentBuilder.setOutput(srcOch.port()); 261 + treatmentBuilder.setOutput(dst.port());
254 //treatmentBuilder.add(Instructions.modL1OduSignalType) 262 //treatmentBuilder.add(Instructions.modL1OduSignalType)
255 263
256 - FlowRule srcRule = DefaultFlowRule.builder() 264 + FlowRule flowRule = DefaultFlowRule.builder()
257 - .forDevice(srcOdu.deviceId()) 265 + .forDevice(src.deviceId())
258 - .withSelector(selectorBuilder.build())
259 - .withTreatment(treatmentBuilder.build())
260 - .withPriority(100)
261 - .fromApp(appId)
262 - .makePermanent()
263 - .build();
264 -
265 - // Destination flow rule
266 - selectorBuilder.matchInPort(dstOch.port());
267 - //selectorBuilder.add(Criteria.matchOduSignalType)
268 - treatmentBuilder.setOutput(dstOdu.port());
269 - //treatmentBuilder.add(Instructions.modL1CltSignalType)
270 -
271 - FlowRule dstRule = DefaultFlowRule.builder()
272 - .forDevice(dstOdu.deviceId())
273 .withSelector(selectorBuilder.build()) 266 .withSelector(selectorBuilder.build())
274 .withTreatment(treatmentBuilder.build()) 267 .withTreatment(treatmentBuilder.build())
275 .withPriority(100) 268 .withPriority(100)
...@@ -277,6 +270,6 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -277,6 +270,6 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
277 .makePermanent() 270 .makePermanent()
278 .build(); 271 .build();
279 272
280 - return Arrays.<FlowRule>asList(srcRule, dstRule); 273 + return flowRule;
281 } 274 }
282 } 275 }
......
...@@ -144,6 +144,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -144,6 +144,7 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
144 .path(path) 144 .path(path)
145 .lambda(ochSignal) 145 .lambda(ochSignal)
146 .signalType(signalType) 146 .signalType(signalType)
147 + .bidirectional(intent.isBidirectional())
147 .build(); 148 .build();
148 149
149 return ImmutableList.of(newIntent); 150 return ImmutableList.of(newIntent);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.net.intent.impl.compiler; 16 package org.onosproject.net.intent.impl.compiler;
17 17
18 +import com.google.common.collect.Lists;
18 import org.apache.felix.scr.annotations.Activate; 19 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 20 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 21 import org.apache.felix.scr.annotations.Deactivate;
...@@ -79,10 +80,21 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte ...@@ -79,10 +80,21 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte
79 Set<LinkResourceAllocations> resources) { 80 Set<LinkResourceAllocations> resources) {
80 log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst()); 81 log.debug("Compiling optical path intent between {} and {}", intent.src(), intent.dst());
81 82
82 - return Collections.singletonList( 83 + // Create rules for forward and reverse path
83 - new FlowRuleIntent(appId, createRules(intent), intent.resources())); 84 + List<FlowRule> rules = createRules(intent);
85 + if (intent.isBidirectional()) {
86 + rules.addAll(createReverseRules(intent));
84 } 87 }
85 88
89 + return Collections.singletonList(new FlowRuleIntent(appId, createRules(intent), intent.resources()));
90 + }
91 +
92 + /**
93 + * Create rules for the forward path of the intent.
94 + *
95 + * @param intent the intent
96 + * @return list of flow rules
97 + */
86 private List<FlowRule> createRules(OpticalPathIntent intent) { 98 private List<FlowRule> createRules(OpticalPathIntent intent) {
87 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder(); 99 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
88 selectorBuilder.matchInPort(intent.src().port()); 100 selectorBuilder.matchInPort(intent.src().port());
...@@ -128,4 +140,56 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte ...@@ -128,4 +140,56 @@ public class OpticalPathIntentCompiler implements IntentCompiler<OpticalPathInte
128 140
129 return rules; 141 return rules;
130 } 142 }
143 +
144 + /**
145 + * Create rules for the reverse path of the intent.
146 + *
147 + * @param intent the intent
148 + * @return list of flow rules
149 + */
150 + private List<FlowRule> createReverseRules(OpticalPathIntent intent) {
151 + TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
152 + selectorBuilder.matchInPort(intent.dst().port());
153 +
154 + List<FlowRule> rules = new LinkedList<>();
155 + ConnectPoint current = intent.dst();
156 +
157 + for (Link link : Lists.reverse(intent.path().links())) {
158 + TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
159 + treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
160 + treatmentBuilder.setOutput(link.dst().port());
161 +
162 + FlowRule rule = DefaultFlowRule.builder()
163 + .forDevice(current.deviceId())
164 + .withSelector(selectorBuilder.build())
165 + .withTreatment(treatmentBuilder.build())
166 + .withPriority(100)
167 + .fromApp(appId)
168 + .makePermanent()
169 + .build();
170 +
171 + rules.add(rule);
172 +
173 + current = link.src();
174 + selectorBuilder.matchInPort(link.src().port());
175 + selectorBuilder.add(Criteria.matchLambda(intent.lambda()));
176 + selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType()));
177 + }
178 +
179 + // Build the egress ROADM rule
180 + TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder();
181 + treatmentLast.setOutput(intent.src().port());
182 +
183 + FlowRule rule = new DefaultFlowRule.Builder()
184 + .forDevice(intent.src().deviceId())
185 + .withSelector(selectorBuilder.build())
186 + .withTreatment(treatmentLast.build())
187 + .withPriority(100)
188 + .fromApp(appId)
189 + .makePermanent()
190 + .build();
191 + rules.add(rule);
192 +
193 + return rules;
194 + }
131 } 195 }
......
...@@ -33,6 +33,7 @@ import org.onosproject.store.service.Serializer; ...@@ -33,6 +33,7 @@ import org.onosproject.store.service.Serializer;
33 import org.onosproject.store.service.StorageService; 33 import org.onosproject.store.service.StorageService;
34 import org.onosproject.store.service.TransactionContext; 34 import org.onosproject.store.service.TransactionContext;
35 import org.onosproject.store.service.TransactionalMap; 35 import org.onosproject.store.service.TransactionalMap;
36 +import org.onosproject.store.service.Versioned;
36 import org.slf4j.Logger; 37 import org.slf4j.Logger;
37 38
38 import java.util.Collections; 39 import java.util.Collections;
...@@ -169,16 +170,16 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { ...@@ -169,16 +170,16 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore {
169 170
170 @Override 171 @Override
171 public boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId) { 172 public boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId) {
172 - Set<IntentId> intents = intentMapping.get(keyIntentId).value(); 173 + Versioned<Set<IntentId>> versionedIntents = intentMapping.get(keyIntentId);
173 174
174 - if (intents == null) { 175 +
175 - intents = Collections.singleton(valIntentId); 176 + if (versionedIntents == null) {
177 + intentMapping.put(keyIntentId, Collections.singleton(valIntentId));
176 } else { 178 } else {
177 - intents.add(valIntentId); 179 + versionedIntents.value().add(valIntentId);
180 + intentMapping.put(keyIntentId, versionedIntents.value());
178 } 181 }
179 182
180 - intentMapping.put(keyIntentId, intents);
181 -
182 return true; 183 return true;
183 } 184 }
184 185
......
...@@ -217,6 +217,7 @@ public final class KryoNamespaces { ...@@ -217,6 +217,7 @@ public final class KryoNamespaces {
217 .register(Optional.class) 217 .register(Optional.class)
218 .register(Collections.emptyList().getClass()) 218 .register(Collections.emptyList().getClass())
219 .register(Collections.unmodifiableSet(Collections.emptySet()).getClass()) 219 .register(Collections.unmodifiableSet(Collections.emptySet()).getClass())
220 + .register(Collections.singleton(Object.class).getClass())
220 .build(); 221 .build();
221 222
222 /** 223 /**
......