Brian O'Connor

Remove Path Intent

...@@ -4,6 +4,7 @@ import org.apache.karaf.shell.commands.Command; ...@@ -4,6 +4,7 @@ import org.apache.karaf.shell.commands.Command;
4 import org.onlab.onos.cli.AbstractShellCommand; 4 import org.onlab.onos.cli.AbstractShellCommand;
5 import org.onlab.onos.net.intent.Intent; 5 import org.onlab.onos.net.intent.Intent;
6 import org.onlab.onos.net.intent.IntentService; 6 import org.onlab.onos.net.intent.IntentService;
7 +import org.onlab.onos.net.intent.IntentState;
7 8
8 /** 9 /**
9 * Lists the inventory of intents and their states. 10 * Lists the inventory of intents and their states.
...@@ -16,7 +17,8 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -16,7 +17,8 @@ public class IntentsListCommand extends AbstractShellCommand {
16 protected void execute() { 17 protected void execute() {
17 IntentService service = get(IntentService.class); 18 IntentService service = get(IntentService.class);
18 for (Intent intent : service.getIntents()) { 19 for (Intent intent : service.getIntents()) {
19 - print("%s", intent); 20 + IntentState state = service.getIntentState(intent.getId());
21 + print("%s %s %s", intent.getId(), state, intent);
20 } 22 }
21 } 23 }
22 24
......
1 +package org.onlab.onos.cli.net;
2 +
3 +import org.apache.karaf.shell.commands.Argument;
4 +import org.apache.karaf.shell.commands.Command;
5 +import org.onlab.onos.cli.AbstractShellCommand;
6 +import org.onlab.onos.net.intent.Intent;
7 +import org.onlab.onos.net.intent.IntentId;
8 +import org.onlab.onos.net.intent.IntentService;
9 +
10 +/**
11 + * Removes host-to-host connectivity intent.
12 + */
13 +@Command(scope = "onos", name = "remove-host-intent",
14 + description = "Removes host-to-host connectivity intent")
15 +public class RemoveHostToHostIntentCommand extends AbstractShellCommand {
16 +
17 + @Argument(index = 0, name = "id", description = "Intent ID",
18 + required = true, multiValued = false)
19 + String id = null;
20 +
21 + @Override
22 + protected void execute() {
23 + IntentService service = get(IntentService.class);
24 +
25 + int radix = id.startsWith("0x") ? 16 : 10;
26 + if (radix == 16) {
27 + id = id.replaceFirst("0x", "");
28 + }
29 + IntentId intentId = new IntentId(Long.parseLong(id, radix));
30 +
31 +
32 + Intent intent = service.getIntent(intentId);
33 + if (intent != null) {
34 + service.withdraw(intent);
35 + }
36 + }
37 +}
...@@ -64,6 +64,9 @@ ...@@ -64,6 +64,9 @@
64 </completers> 64 </completers>
65 </command> 65 </command>
66 <command> 66 <command>
67 + <action class="org.onlab.onos.cli.net.RemoveHostToHostIntentCommand"/>
68 + </command>
69 + <command>
67 <action class="org.onlab.onos.cli.net.IntentsListCommand"/> 70 <action class="org.onlab.onos.cli.net.IntentsListCommand"/>
68 </command> 71 </command>
69 72
......
1 package org.onlab.onos.net.intent.impl; 1 package org.onlab.onos.net.intent.impl;
2 2
3 +import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
4 +
5 +import java.util.Iterator;
6 +
3 import org.apache.felix.scr.annotations.Activate; 7 import org.apache.felix.scr.annotations.Activate;
4 import org.apache.felix.scr.annotations.Component; 8 import org.apache.felix.scr.annotations.Component;
5 import org.apache.felix.scr.annotations.Deactivate; 9 import org.apache.felix.scr.annotations.Deactivate;
...@@ -18,10 +22,6 @@ import org.onlab.onos.net.intent.IntentExtensionService; ...@@ -18,10 +22,6 @@ import org.onlab.onos.net.intent.IntentExtensionService;
18 import org.onlab.onos.net.intent.IntentInstaller; 22 import org.onlab.onos.net.intent.IntentInstaller;
19 import org.onlab.onos.net.intent.PathIntent; 23 import org.onlab.onos.net.intent.PathIntent;
20 24
21 -import java.util.Iterator;
22 -
23 -import static org.onlab.onos.net.flow.DefaultTrafficTreatment.builder;
24 -
25 /** 25 /**
26 * Installer for {@link PathIntent path connectivity intents}. 26 * Installer for {@link PathIntent path connectivity intents}.
27 */ 27 */
...@@ -59,8 +59,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -59,8 +59,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
59 TrafficTreatment treatment = builder() 59 TrafficTreatment treatment = builder()
60 .setOutput(link.src().port()).build(); 60 .setOutput(link.src().port()).build();
61 FlowRule rule = new DefaultFlowRule(link.src().deviceId(), 61 FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
62 - builder.build(), treatment, 62 + builder.build(), treatment,
63 - 123, appId, 600); 63 + 123, appId, 600);
64 flowRuleService.applyFlowRules(rule); 64 flowRuleService.applyFlowRules(rule);
65 prev = link.dst(); 65 prev = link.dst();
66 } 66 }
...@@ -69,6 +69,21 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -69,6 +69,21 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
69 69
70 @Override 70 @Override
71 public void uninstall(PathIntent intent) { 71 public void uninstall(PathIntent intent) {
72 - //TODO 72 + TrafficSelector.Builder builder =
73 + DefaultTrafficSelector.builder(intent.getTrafficSelector());
74 + Iterator<Link> links = intent.getPath().links().iterator();
75 + ConnectPoint prev = links.next().dst();
76 +
77 + while (links.hasNext()) {
78 + builder.matchInport(prev.port());
79 + Link link = links.next();
80 + TrafficTreatment treatment = builder()
81 + .setOutput(link.src().port()).build();
82 + FlowRule rule = new DefaultFlowRule(link.src().deviceId(),
83 + builder.build(), treatment,
84 + 123, appId, 600);
85 + flowRuleService.removeFlowRules(rule);
86 + prev = link.dst();
87 + }
73 } 88 }
74 } 89 }
......