Marc De Leenheer
Committed by Gerrit Code Review

Release resources when intent is withdrawn (ONOS-2048).

Create optical circuits using CLI (ONOS-2049).

Change-Id: I8e52e698a897b869147afffdc0294956df76aa0c
...@@ -140,7 +140,6 @@ public class OpticalPathProvisioner { ...@@ -140,7 +140,6 @@ public class OpticalPathProvisioner {
140 case INSTALL_REQ: 140 case INSTALL_REQ:
141 break; 141 break;
142 case INSTALLED: 142 case INSTALLED:
143 - // track h2h & p2p intents using our connectivity
144 break; 143 break;
145 case FAILED: 144 case FAILED:
146 log.info("Intent {} failed, calling optical path provisioning app.", event.subject()); 145 log.info("Intent {} failed, calling optical path provisioning app.", event.subject());
...@@ -407,8 +406,10 @@ public class OpticalPathProvisioner { ...@@ -407,8 +406,10 @@ public class OpticalPathProvisioner {
407 if (intent instanceof OpticalConnectivityIntent) { 406 if (intent instanceof OpticalConnectivityIntent) {
408 deviceResourceService.releasePorts(intent.id()); 407 deviceResourceService.releasePorts(intent.id());
409 linkResourceService.releaseResources(linkResourceService.getAllocations(intent.id())); 408 linkResourceService.releaseResources(linkResourceService.getAllocations(intent.id()));
409 + } else if (intent instanceof OpticalCircuitIntent) {
410 + deviceResourceService.releasePorts(intent.id());
411 + deviceResourceService.releaseMapping(intent.id());
410 } 412 }
411 - // TODO: add other layers
412 } 413 }
413 } 414 }
414 415
......
...@@ -18,13 +18,18 @@ package org.onosproject.cli.net; ...@@ -18,13 +18,18 @@ package org.onosproject.cli.net;
18 import org.apache.karaf.shell.commands.Argument; 18 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 import org.onosproject.net.ConnectPoint; 20 import org.onosproject.net.ConnectPoint;
21 +import org.onosproject.net.OchPort;
22 +import org.onosproject.net.OduCltPort;
21 import org.onosproject.net.OduSignalType; 23 import org.onosproject.net.OduSignalType;
24 +import org.onosproject.net.Port;
25 +import org.onosproject.net.device.DeviceService;
22 import org.onosproject.net.intent.Intent; 26 import org.onosproject.net.intent.Intent;
23 import org.onosproject.net.intent.IntentService; 27 import org.onosproject.net.intent.IntentService;
28 +import org.onosproject.net.intent.OpticalCircuitIntent;
24 import org.onosproject.net.intent.OpticalConnectivityIntent; 29 import org.onosproject.net.intent.OpticalConnectivityIntent;
25 30
26 /** 31 /**
27 - * Installs optical connectivity intents. 32 + * Installs optical connectivity or circuit intents, depending on given port types.
28 */ 33 */
29 @Command(scope = "onos", name = "add-optical-intent", 34 @Command(scope = "onos", name = "add-optical-intent",
30 description = "Installs optical connectivity intent") 35 description = "Installs optical connectivity intent")
...@@ -48,14 +53,33 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand { ...@@ -48,14 +53,33 @@ public class AddOpticalIntentCommand extends ConnectivityIntentCommand {
48 53
49 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString); 54 ConnectPoint egress = ConnectPoint.deviceConnectPoint(egressDeviceString);
50 55
51 - // FIXME: Hardcoded ODU signal type 56 + DeviceService deviceService = get(DeviceService.class);
52 - Intent intent = OpticalConnectivityIntent.builder() 57 + Port srcPort = deviceService.getPort(ingress.deviceId(), ingress.port());
58 + Port dstPort = deviceService.getPort(egress.deviceId(), egress.port());
59 +
60 + Intent intent;
61 + // FIXME: Hardcoded signal types
62 + if (srcPort instanceof OduCltPort && dstPort instanceof OduCltPort) {
63 + intent = OpticalCircuitIntent.builder()
64 + .appId(appId())
65 + .key(key())
66 + .src(ingress)
67 + .dst(egress)
68 + .signalType(OduCltPort.SignalType.CLT_10GBE)
69 + .build();
70 + } else if (srcPort instanceof OchPort && dstPort instanceof OchPort) {
71 + intent = OpticalConnectivityIntent.builder()
53 .appId(appId()) 72 .appId(appId())
54 .key(key()) 73 .key(key())
55 .src(ingress) 74 .src(ingress)
56 .dst(egress) 75 .dst(egress)
57 .signalType(OduSignalType.ODU4) 76 .signalType(OduSignalType.ODU4)
58 .build(); 77 .build();
78 + } else {
79 + print("Unable to create optical intent between connect points {} and {}", ingress, egress);
80 + return;
81 + }
82 +
59 service.submit(intent); 83 service.submit(intent);
60 print("Optical intent submitted:\n%s", intent.toString()); 84 print("Optical intent submitted:\n%s", intent.toString());
61 } 85 }
......
...@@ -67,7 +67,12 @@ public interface DeviceResourceService { ...@@ -67,7 +67,12 @@ public interface DeviceResourceService {
67 */ 67 */
68 Set<IntentId> getMapping(IntentId intentId); 68 Set<IntentId> getMapping(IntentId intentId);
69 69
70 - void releaseMapping(IntentId keyIntentId, IntentId valIntentId); 70 + /**
71 + * Release mapping of given intent.
72 + *
73 + * @param intentId intent ID
74 + */
75 + void releaseMapping(IntentId intentId);
71 76
72 /** 77 /**
73 * Release ports associated with given intent ID. 78 * Release ports associated with given intent ID.
......
...@@ -66,12 +66,11 @@ public interface DeviceResourceStore { ...@@ -66,12 +66,11 @@ public interface DeviceResourceStore {
66 Set<IntentId> getMapping(IntentId intentId); 66 Set<IntentId> getMapping(IntentId intentId);
67 67
68 /** 68 /**
69 - * Releases the mapping between the given intents. 69 + * Releases the mapping of the given intent.
70 * 70 *
71 - * @param keyIntentId key intent ID 71 + * @param intentId intent ID
72 - * @param valIntentId value intent ID
73 */ 72 */
74 - void releaseMapping(IntentId keyIntentId, IntentId valIntentId); 73 + void releaseMapping(IntentId intentId);
75 74
76 /** 75 /**
77 * Releases the ports allocated to the given intent. 76 * Releases the ports allocated to the given intent.
......
...@@ -73,8 +73,8 @@ public class DeviceResourceManager implements DeviceResourceService { ...@@ -73,8 +73,8 @@ public class DeviceResourceManager implements DeviceResourceService {
73 } 73 }
74 74
75 @Override 75 @Override
76 - public void releaseMapping(IntentId keyIntentId, IntentId valIntentId) { 76 + public void releaseMapping(IntentId intentId) {
77 - store.releaseMapping(keyIntentId, valIntentId); 77 + store.releaseMapping(intentId);
78 } 78 }
79 79
80 @Override 80 @Override
......
...@@ -168,21 +168,6 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { ...@@ -168,21 +168,6 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore {
168 } 168 }
169 169
170 @Override 170 @Override
171 - public void releaseMapping(IntentId keyIntentId, IntentId valIntentId) {
172 - if (!intentMapping.containsKey(keyIntentId)) {
173 - return;
174 - }
175 -
176 - Set<IntentId> intents = intentMapping.get(keyIntentId).value();
177 -
178 - try {
179 - intents.remove(valIntentId);
180 - } catch (Exception e) {
181 - log.error("Trying to remove non-existing mapping {} {}", keyIntentId, valIntentId);
182 - }
183 - }
184 -
185 - @Override
186 public boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId) { 171 public boolean allocateMapping(IntentId keyIntentId, IntentId valIntentId) {
187 Set<IntentId> intents = intentMapping.get(keyIntentId).value(); 172 Set<IntentId> intents = intentMapping.get(keyIntentId).value();
188 173
...@@ -198,6 +183,17 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore { ...@@ -198,6 +183,17 @@ public class ConsistentDeviceResourceStore implements DeviceResourceStore {
198 } 183 }
199 184
200 @Override 185 @Override
186 + public void releaseMapping(IntentId intentId) {
187 + for (IntentId intent : intentMapping.keySet()) {
188 + // TODO: optimize by checking for identical src & dst
189 + Set<IntentId> mapping = intentMapping.get(intent).value();
190 + if (mapping.remove(intentId)) {
191 + return;
192 + }
193 + }
194 + }
195 +
196 + @Override
201 public boolean releasePorts(IntentId intentId) { 197 public boolean releasePorts(IntentId intentId) {
202 checkNotNull(intentId); 198 checkNotNull(intentId);
203 199
......