tom

Reworked intent states to the new set of states.

Separate intent state from intent event type.
Implemented new state transitions in IntentManager.
Implemented ObjectiveTracker.
Re-route now works.
Showing 28 changed files with 296 additions and 304 deletions
...@@ -24,7 +24,7 @@ public class IntentIdCompleter implements Completer { ...@@ -24,7 +24,7 @@ public class IntentIdCompleter implements Completer {
24 Iterator<Intent> it = service.getIntents().iterator(); 24 Iterator<Intent> it = service.getIntents().iterator();
25 SortedSet<String> strings = delegate.getStrings(); 25 SortedSet<String> strings = delegate.getStrings();
26 while (it.hasNext()) { 26 while (it.hasNext()) {
27 - strings.add(it.next().getId().toString()); 27 + strings.add(it.next().id().toString());
28 } 28 }
29 29
30 // Now let the completer do the work for figuring out what to offer. 30 // Now let the completer do the work for figuring out what to offer.
......
...@@ -17,8 +17,8 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -17,8 +17,8 @@ public class IntentsListCommand extends AbstractShellCommand {
17 protected void execute() { 17 protected void execute() {
18 IntentService service = get(IntentService.class); 18 IntentService service = get(IntentService.class);
19 for (Intent intent : service.getIntents()) { 19 for (Intent intent : service.getIntents()) {
20 - IntentState state = service.getIntentState(intent.getId()); 20 + IntentState state = service.getIntentState(intent.id());
21 - print("%s %s %s", intent.getId(), state, intent); 21 + print("%s %s %s", intent.id(), state, intent);
22 } 22 }
23 } 23 }
24 24
......
...@@ -34,7 +34,7 @@ public class WipeOutCommand extends ClustersListCommand { ...@@ -34,7 +34,7 @@ public class WipeOutCommand extends ClustersListCommand {
34 34
35 IntentService intentService = get(IntentService.class); 35 IntentService intentService = get(IntentService.class);
36 for (Intent intent : intentService.getIntents()) { 36 for (Intent intent : intentService.getIntents()) {
37 - if (intentService.getIntentState(intent.getId()) == IntentState.INSTALLED) { 37 + if (intentService.getIntentState(intent.id()) == IntentState.INSTALLED) {
38 intentService.withdraw(intent); 38 intentService.withdraw(intent);
39 } 39 }
40 } 40 }
......
...@@ -24,7 +24,7 @@ public abstract class AbstractIntent implements Intent { ...@@ -24,7 +24,7 @@ public abstract class AbstractIntent implements Intent {
24 } 24 }
25 25
26 @Override 26 @Override
27 - public IntentId getId() { 27 + public IntentId id() {
28 return id; 28 return id;
29 } 29 }
30 30
......
...@@ -53,7 +53,7 @@ public abstract class ConnectivityIntent extends AbstractIntent { ...@@ -53,7 +53,7 @@ public abstract class ConnectivityIntent extends AbstractIntent {
53 * 53 *
54 * @return traffic match 54 * @return traffic match
55 */ 55 */
56 - public TrafficSelector getTrafficSelector() { 56 + public TrafficSelector selector() {
57 return selector; 57 return selector;
58 } 58 }
59 59
...@@ -62,7 +62,7 @@ public abstract class ConnectivityIntent extends AbstractIntent { ...@@ -62,7 +62,7 @@ public abstract class ConnectivityIntent extends AbstractIntent {
62 * 62 *
63 * @return applied action 63 * @return applied action
64 */ 64 */
65 - public TrafficTreatment getTrafficTreatment() { 65 + public TrafficTreatment treatment() {
66 return treatment; 66 return treatment;
67 } 67 }
68 68
......
...@@ -80,9 +80,9 @@ public class HostToHostIntent extends ConnectivityIntent { ...@@ -80,9 +80,9 @@ public class HostToHostIntent extends ConnectivityIntent {
80 @Override 80 @Override
81 public String toString() { 81 public String toString() {
82 return MoreObjects.toStringHelper(getClass()) 82 return MoreObjects.toStringHelper(getClass())
83 - .add("id", getId()) 83 + .add("id", id())
84 - .add("selector", getTrafficSelector()) 84 + .add("selector", selector())
85 - .add("treatment", getTrafficTreatment()) 85 + .add("treatment", treatment())
86 .add("one", one) 86 .add("one", one)
87 .add("two", two) 87 .add("two", two)
88 .toString(); 88 .toString();
......
...@@ -11,5 +11,5 @@ public interface Intent extends BatchOperationTarget { ...@@ -11,5 +11,5 @@ public interface Intent extends BatchOperationTarget {
11 * 11 *
12 * @return intent identifier 12 * @return intent identifier
13 */ 13 */
14 - IntentId getId(); 14 + IntentId id();
15 } 15 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 -import com.google.common.base.MoreObjects;
4 import org.onlab.onos.event.AbstractEvent; 3 import org.onlab.onos.event.AbstractEvent;
5 4
6 -import java.util.Objects;
7 -
8 -import static com.google.common.base.Preconditions.checkNotNull;
9 -
10 /** 5 /**
11 * A class to represent an intent related event. 6 * A class to represent an intent related event.
12 */ 7 */
13 -public class IntentEvent extends AbstractEvent<IntentState, Intent> { 8 +public class IntentEvent extends AbstractEvent<IntentEvent.Type, Intent> {
14 -
15 - // TODO: determine a suitable parent class; if one does not exist, consider
16 - // introducing one
17 9
18 - private final long time; 10 + public enum Type {
19 - private final Intent intent; 11 + /**
20 - private final IntentState state; 12 + * Signifies that a new intent has been submitted to the system.
21 - private final IntentState previous; 13 + */
14 + SUBMITTED,
22 15
23 /** 16 /**
24 - * Creates an event describing a state change of an intent. 17 + * Signifies that an intent has been successfully installed.
25 - *
26 - * @param intent subject intent
27 - * @param state new intent state
28 - * @param previous previous intent state
29 - * @param time time the event created in milliseconds since start of epoch
30 - * @throws NullPointerException if the intent or state is null
31 */ 18 */
32 - public IntentEvent(Intent intent, IntentState state, IntentState previous, long time) { 19 + INSTALLED,
33 - super(state, intent);
34 - this.intent = checkNotNull(intent);
35 - this.state = checkNotNull(state);
36 - this.previous = previous;
37 - this.time = time;
38 - }
39 20
40 /** 21 /**
41 - * Returns the state of the intent which caused the event. 22 + * Signifies that an intent has failed compilation or installation.
42 - *
43 - * @return the state of the intent
44 */ 23 */
45 - public IntentState getState() { 24 + FAILED,
46 - return state;
47 - }
48 25
49 /** 26 /**
50 - * Returns the previous state of the intent which caused the event. 27 + * Signifies that an intent has been withdrawn from the system.
51 - *
52 - * @return the previous state of the intent
53 */ 28 */
54 - public IntentState getPreviousState() { 29 + WITHDRAWN
55 - return previous;
56 } 30 }
57 31
58 /** 32 /**
59 - * Returns the intent associated with the event. 33 + * Creates an event of a given type and for the specified intent and the
34 + * current time.
60 * 35 *
61 - * @return the intent 36 + * @param type event type
37 + * @param intent subject intent
38 + * @param time time the event created in milliseconds since start of epoch
62 */ 39 */
63 - public Intent getIntent() { 40 + public IntentEvent(Type type, Intent intent, long time) {
64 - return intent; 41 + super(type, intent, time);
65 } 42 }
66 43
67 /** 44 /**
68 - * Returns the time at which the event was created. 45 + * Creates an event of a given type and for the specified intent and the
46 + * current time.
69 * 47 *
70 - * @return the time in milliseconds since start of epoch 48 + * @param type event type
49 + * @param intent subject intent
71 */ 50 */
72 - public long getTime() { 51 + public IntentEvent(Type type, Intent intent) {
73 - return time; 52 + super(type, intent);
74 - }
75 -
76 - @Override
77 - public boolean equals(Object o) {
78 - if (this == o) {
79 - return true;
80 - }
81 - if (o == null || getClass() != o.getClass()) {
82 - return false;
83 } 53 }
84 54
85 - IntentEvent that = (IntentEvent) o;
86 - return Objects.equals(this.intent, that.intent)
87 - && Objects.equals(this.state, that.state)
88 - && Objects.equals(this.previous, that.previous)
89 - && Objects.equals(this.time, that.time);
90 - }
91 -
92 - @Override
93 - public int hashCode() {
94 - return Objects.hash(intent, state, previous, time);
95 - }
96 -
97 - @Override
98 - public String toString() {
99 - return MoreObjects.toStringHelper(getClass())
100 - .add("intent", intent)
101 - .add("state", state)
102 - .add("previous", previous)
103 - .add("time", time)
104 - .toString();
105 - }
106 } 55 }
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 /** 3 /**
4 - * This class represents the states of an intent. 4 + * Representation of the phases an intent may attain during its lifecycle.
5 - *
6 - * <p>
7 - * Note: The state is expressed as enum, but there is possibility
8 - * in the future that we define specific class instead of enum to improve
9 - * the extensibility of state definition.
10 - * </p>
11 */ 5 */
12 public enum IntentState { 6 public enum IntentState {
13 - // FIXME: requires discussion on State vs. EventType and a solid state-transition diagram 7 +
14 - // TODO: consider the impact of conflict detection
15 - // TODO: consider the impact that external events affect an installed intent
16 /** 8 /**
17 - * The beginning state. 9 + * Signifies that the intent has been submitted and will start compiling
18 - * 10 + * shortly. However, this compilation may not necessarily occur on the
11 + * local controller instance.
12 + * <p/>
19 * All intent in the runtime take this state first. 13 * All intent in the runtime take this state first.
20 */ 14 */
21 SUBMITTED, 15 SUBMITTED,
22 16
23 /** 17 /**
24 - * The intent compilation has been completed. 18 + * Signifies that the intent is being compiled into installable intents.
25 - * 19 + * This is a transitional state after which the intent will enter either
26 - * An intent translation graph (tree) is completely created. 20 + * {@link #FAILED} state or {@link #INSTALLING} state.
27 - * Leaves of the graph are installable intent type. 21 + */
22 + COMPILING,
23 +
24 + /**
25 + * Signifies that the resulting installable intents are being installed
26 + * into the network environment. This is a transitional state after which
27 + * the intent will enter either {@link #INSTALLED} state or
28 + * {@link #RECOMPILING} state.
28 */ 29 */
29 - COMPILED, 30 + INSTALLING,
30 31
31 /** 32 /**
32 - * The intent has been successfully installed. 33 + * The intent has been successfully installed. This is a state where the
34 + * intent may remain parked until it is withdrawn by the application or
35 + * until the network environment changes in some way to make the original
36 + * set of installable intents untenable.
33 */ 37 */
34 INSTALLED, 38 INSTALLED,
35 39
36 /** 40 /**
37 - * The intent is being withdrawn. 41 + * Signifies that the intent is being recompiled into installable intents
38 - * 42 + * as an attempt to adapt to an anomaly in the network environment.
39 - * When {@link IntentService#withdraw(Intent)} is called, 43 + * This is a transitional state after which the intent will enter either
40 - * the intent takes this state first. 44 + * {@link #FAILED} state or {@link #INSTALLING} state.
45 + * <p/>
46 + * Exit to the {@link #FAILED} state may be caused by failure to compile
47 + * or by compiling into the same set of installable intents which have
48 + * previously failed to be installed.
49 + */
50 + RECOMPILING,
51 +
52 + /**
53 + * Indicates that the intent is being withdrawn. This is a transitional
54 + * state, triggered by invocation of the
55 + * {@link IntentService#withdraw(Intent)} but one with only one outcome,
56 + * which is the the intent being placed in the {@link #WITHDRAWN} state.
41 */ 57 */
42 WITHDRAWING, 58 WITHDRAWING,
43 59
44 /** 60 /**
45 - * The intent has been successfully withdrawn. 61 + * Indicates that the intent has been successfully withdrawn.
46 */ 62 */
47 WITHDRAWN, 63 WITHDRAWN,
48 64
49 /** 65 /**
50 - * The intent has failed to be compiled, installed, or withdrawn. 66 + * Signifies that the intent has failed compiling, installing or
51 - * 67 + * recompiling states.
52 - * When the intent failed to be withdrawn, it is still, at least partially installed.
53 */ 68 */
54 - FAILED, 69 + FAILED
55 } 70 }
......
...@@ -10,10 +10,16 @@ import java.util.List; ...@@ -10,10 +10,16 @@ import java.util.List;
10 public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { 10 public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
11 11
12 /** 12 /**
13 - * Creates a new intent. 13 + * Submits a new intent into the store. If the returned event is not
14 + * null, the manager is expected to dispatch the event and then to kick
15 + * off intent compilation process. Otherwise, another node has been elected
16 + * to perform the compilation process and the node will learn about
17 + * the submittal and results of the intent compilation via the delegate
18 + * mechanism.
14 * 19 *
15 - * @param intent intent 20 + * @param intent intent to be submitted
16 - * @return appropriate event or null if no change resulted 21 + * @return event indicating the intent was submitted or null if no
22 + * change resulted, e.g. duplicate intent
17 */ 23 */
18 IntentEvent createIntent(Intent intent); 24 IntentEvent createIntent(Intent intent);
19 25
...@@ -68,9 +74,8 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { ...@@ -68,9 +74,8 @@ public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> {
68 * 74 *
69 * @param intentId original intent identifier 75 * @param intentId original intent identifier
70 * @param installableIntents compiled installable intents 76 * @param installableIntents compiled installable intents
71 - * @return compiled state transition event
72 */ 77 */
73 - IntentEvent addInstallableIntents(IntentId intentId, 78 + void addInstallableIntents(IntentId intentId,
74 List<InstallableIntent> installableIntents); 79 List<InstallableIntent> installableIntents);
75 80
76 /** 81 /**
......
1 package org.onlab.onos.net.intent; 1 package org.onlab.onos.net.intent;
2 2
3 -import static com.google.common.base.Preconditions.checkArgument; 3 +import com.google.common.base.MoreObjects;
4 -import static com.google.common.base.Preconditions.checkNotNull; 4 +import com.google.common.collect.Sets;
5 -
6 -import java.util.Objects;
7 -import java.util.Set;
8 -
9 import org.onlab.onos.net.ConnectPoint; 5 import org.onlab.onos.net.ConnectPoint;
10 import org.onlab.onos.net.flow.TrafficSelector; 6 import org.onlab.onos.net.flow.TrafficSelector;
11 import org.onlab.onos.net.flow.TrafficTreatment; 7 import org.onlab.onos.net.flow.TrafficTreatment;
12 8
13 -import com.google.common.base.MoreObjects; 9 +import java.util.Objects;
14 -import com.google.common.collect.Sets; 10 +import java.util.Set;
11 +
12 +import static com.google.common.base.Preconditions.checkArgument;
13 +import static com.google.common.base.Preconditions.checkNotNull;
15 14
16 /** 15 /**
17 * Abstraction of multiple source to single destination connectivity intent. 16 * Abstraction of multiple source to single destination connectivity intent.
18 */ 17 */
19 public class MultiPointToSinglePointIntent extends ConnectivityIntent { 18 public class MultiPointToSinglePointIntent extends ConnectivityIntent {
20 19
21 - private final Set<ConnectPoint> ingressPorts; 20 + private final Set<ConnectPoint> ingressPoints;
22 - private final ConnectPoint egressPort; 21 + private final ConnectPoint egressPoint;
23 22
24 /** 23 /**
25 * Creates a new multi-to-single point connectivity intent for the specified 24 * Creates a new multi-to-single point connectivity intent for the specified
...@@ -28,25 +27,25 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -28,25 +27,25 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent {
28 * @param id intent identifier 27 * @param id intent identifier
29 * @param match traffic match 28 * @param match traffic match
30 * @param action action 29 * @param action action
31 - * @param ingressPorts set of ports from which ingress traffic originates 30 + * @param ingressPoints set of ports from which ingress traffic originates
32 - * @param egressPort port to which traffic will egress 31 + * @param egressPoint port to which traffic will egress
33 - * @throws NullPointerException if {@code ingressPorts} or 32 + * @throws NullPointerException if {@code ingressPoints} or
34 - * {@code egressPort} is null. 33 + * {@code egressPoint} is null.
35 - * @throws IllegalArgumentException if the size of {@code ingressPorts} is 34 + * @throws IllegalArgumentException if the size of {@code ingressPoints} is
36 * not more than 1 35 * not more than 1
37 */ 36 */
38 public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match, 37 public MultiPointToSinglePointIntent(IntentId id, TrafficSelector match,
39 TrafficTreatment action, 38 TrafficTreatment action,
40 - Set<ConnectPoint> ingressPorts, 39 + Set<ConnectPoint> ingressPoints,
41 - ConnectPoint egressPort) { 40 + ConnectPoint egressPoint) {
42 super(id, match, action); 41 super(id, match, action);
43 42
44 - checkNotNull(ingressPorts); 43 + checkNotNull(ingressPoints);
45 - checkArgument(!ingressPorts.isEmpty(), 44 + checkArgument(!ingressPoints.isEmpty(),
46 "there should be at least one ingress port"); 45 "there should be at least one ingress port");
47 46
48 - this.ingressPorts = Sets.newHashSet(ingressPorts); 47 + this.ingressPoints = Sets.newHashSet(ingressPoints);
49 - this.egressPort = checkNotNull(egressPort); 48 + this.egressPoint = checkNotNull(egressPoint);
50 } 49 }
51 50
52 /** 51 /**
...@@ -54,8 +53,8 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -54,8 +53,8 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent {
54 */ 53 */
55 protected MultiPointToSinglePointIntent() { 54 protected MultiPointToSinglePointIntent() {
56 super(); 55 super();
57 - this.ingressPorts = null; 56 + this.ingressPoints = null;
58 - this.egressPort = null; 57 + this.egressPoint = null;
59 } 58 }
60 59
61 /** 60 /**
...@@ -64,8 +63,8 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -64,8 +63,8 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent {
64 * 63 *
65 * @return set of ingress ports 64 * @return set of ingress ports
66 */ 65 */
67 - public Set<ConnectPoint> getIngressPorts() { 66 + public Set<ConnectPoint> ingressPoints() {
68 - return ingressPorts; 67 + return ingressPoints;
69 } 68 }
70 69
71 /** 70 /**
...@@ -73,8 +72,8 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -73,8 +72,8 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent {
73 * 72 *
74 * @return egress port 73 * @return egress port
75 */ 74 */
76 - public ConnectPoint getEgressPort() { 75 + public ConnectPoint egressPoint() {
77 - return egressPort; 76 + return egressPoint;
78 } 77 }
79 78
80 @Override 79 @Override
...@@ -90,23 +89,23 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -90,23 +89,23 @@ public class MultiPointToSinglePointIntent extends ConnectivityIntent {
90 } 89 }
91 90
92 MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o; 91 MultiPointToSinglePointIntent that = (MultiPointToSinglePointIntent) o;
93 - return Objects.equals(this.ingressPorts, that.ingressPorts) 92 + return Objects.equals(this.ingressPoints, that.ingressPoints)
94 - && Objects.equals(this.egressPort, that.egressPort); 93 + && Objects.equals(this.egressPoint, that.egressPoint);
95 } 94 }
96 95
97 @Override 96 @Override
98 public int hashCode() { 97 public int hashCode() {
99 - return Objects.hash(super.hashCode(), ingressPorts, egressPort); 98 + return Objects.hash(super.hashCode(), ingressPoints, egressPoint);
100 } 99 }
101 100
102 @Override 101 @Override
103 public String toString() { 102 public String toString() {
104 return MoreObjects.toStringHelper(getClass()) 103 return MoreObjects.toStringHelper(getClass())
105 - .add("id", getId()) 104 + .add("id", id())
106 - .add("match", getTrafficSelector()) 105 + .add("match", selector())
107 - .add("action", getTrafficTreatment()) 106 + .add("action", treatment())
108 - .add("ingressPorts", getIngressPorts()) 107 + .add("ingressPoints", ingressPoints())
109 - .add("egressPort", getEgressPort()) 108 + .add("egressPoint", egressPoint())
110 .toString(); 109 .toString();
111 } 110 }
112 } 111 }
......
...@@ -46,7 +46,7 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent ...@@ -46,7 +46,7 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent
46 * 46 *
47 * @return traversed links 47 * @return traversed links
48 */ 48 */
49 - public Path getPath() { 49 + public Path path() {
50 return path; 50 return path;
51 } 51 }
52 52
...@@ -79,11 +79,11 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent ...@@ -79,11 +79,11 @@ public class PathIntent extends PointToPointIntent implements InstallableIntent
79 @Override 79 @Override
80 public String toString() { 80 public String toString() {
81 return MoreObjects.toStringHelper(getClass()) 81 return MoreObjects.toStringHelper(getClass())
82 - .add("id", getId()) 82 + .add("id", id())
83 - .add("match", getTrafficSelector()) 83 + .add("match", selector())
84 - .add("action", getTrafficTreatment()) 84 + .add("action", treatment())
85 - .add("ingressPort", getIngressPort()) 85 + .add("ingressPort", ingressPoint())
86 - .add("egressPort", getEgressPort()) 86 + .add("egressPort", egressPoint())
87 .add("path", path) 87 .add("path", path)
88 .toString(); 88 .toString();
89 } 89 }
......
...@@ -14,8 +14,8 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -14,8 +14,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
14 */ 14 */
15 public class PointToPointIntent extends ConnectivityIntent { 15 public class PointToPointIntent extends ConnectivityIntent {
16 16
17 - private final ConnectPoint ingressPort; 17 + private final ConnectPoint ingressPoint;
18 - private final ConnectPoint egressPort; 18 + private final ConnectPoint egressPoint;
19 19
20 /** 20 /**
21 * Creates a new point-to-point intent with the supplied ingress/egress 21 * Creates a new point-to-point intent with the supplied ingress/egress
...@@ -24,17 +24,17 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -24,17 +24,17 @@ public class PointToPointIntent extends ConnectivityIntent {
24 * @param id intent identifier 24 * @param id intent identifier
25 * @param selector traffic selector 25 * @param selector traffic selector
26 * @param treatment treatment 26 * @param treatment treatment
27 - * @param ingressPort ingress port 27 + * @param ingressPoint ingress port
28 - * @param egressPort egress port 28 + * @param egressPoint egress port
29 - * @throws NullPointerException if {@code ingressPort} or {@code egressPort} is null. 29 + * @throws NullPointerException if {@code ingressPoint} or {@code egressPoints} is null.
30 */ 30 */
31 public PointToPointIntent(IntentId id, TrafficSelector selector, 31 public PointToPointIntent(IntentId id, TrafficSelector selector,
32 TrafficTreatment treatment, 32 TrafficTreatment treatment,
33 - ConnectPoint ingressPort, 33 + ConnectPoint ingressPoint,
34 - ConnectPoint egressPort) { 34 + ConnectPoint egressPoint) {
35 super(id, selector, treatment); 35 super(id, selector, treatment);
36 - this.ingressPort = checkNotNull(ingressPort); 36 + this.ingressPoint = checkNotNull(ingressPoint);
37 - this.egressPort = checkNotNull(egressPort); 37 + this.egressPoint = checkNotNull(egressPoint);
38 } 38 }
39 39
40 /** 40 /**
...@@ -42,8 +42,8 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -42,8 +42,8 @@ public class PointToPointIntent extends ConnectivityIntent {
42 */ 42 */
43 protected PointToPointIntent() { 43 protected PointToPointIntent() {
44 super(); 44 super();
45 - this.ingressPort = null; 45 + this.ingressPoint = null;
46 - this.egressPort = null; 46 + this.egressPoint = null;
47 } 47 }
48 48
49 /** 49 /**
...@@ -52,8 +52,8 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -52,8 +52,8 @@ public class PointToPointIntent extends ConnectivityIntent {
52 * 52 *
53 * @return ingress port 53 * @return ingress port
54 */ 54 */
55 - public ConnectPoint getIngressPort() { 55 + public ConnectPoint ingressPoint() {
56 - return ingressPort; 56 + return ingressPoint;
57 } 57 }
58 58
59 /** 59 /**
...@@ -61,8 +61,8 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -61,8 +61,8 @@ public class PointToPointIntent extends ConnectivityIntent {
61 * 61 *
62 * @return egress port 62 * @return egress port
63 */ 63 */
64 - public ConnectPoint getEgressPort() { 64 + public ConnectPoint egressPoint() {
65 - return egressPort; 65 + return egressPoint;
66 } 66 }
67 67
68 @Override 68 @Override
...@@ -78,23 +78,23 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -78,23 +78,23 @@ public class PointToPointIntent extends ConnectivityIntent {
78 } 78 }
79 79
80 PointToPointIntent that = (PointToPointIntent) o; 80 PointToPointIntent that = (PointToPointIntent) o;
81 - return Objects.equals(this.ingressPort, that.ingressPort) 81 + return Objects.equals(this.ingressPoint, that.ingressPoint)
82 - && Objects.equals(this.egressPort, that.egressPort); 82 + && Objects.equals(this.egressPoint, that.egressPoint);
83 } 83 }
84 84
85 @Override 85 @Override
86 public int hashCode() { 86 public int hashCode() {
87 - return Objects.hash(super.hashCode(), ingressPort, egressPort); 87 + return Objects.hash(super.hashCode(), ingressPoint, egressPoint);
88 } 88 }
89 89
90 @Override 90 @Override
91 public String toString() { 91 public String toString() {
92 return MoreObjects.toStringHelper(getClass()) 92 return MoreObjects.toStringHelper(getClass())
93 - .add("id", getId()) 93 + .add("id", id())
94 - .add("match", getTrafficSelector()) 94 + .add("match", selector())
95 - .add("action", getTrafficTreatment()) 95 + .add("action", treatment())
96 - .add("ingressPort", ingressPort) 96 + .add("ingressPoint", ingressPoint)
97 - .add("egressPort", egressPort) 97 + .add("egressPoints", egressPoint)
98 .toString(); 98 .toString();
99 } 99 }
100 100
......
...@@ -17,8 +17,8 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -17,8 +17,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
17 */ 17 */
18 public class SinglePointToMultiPointIntent extends ConnectivityIntent { 18 public class SinglePointToMultiPointIntent extends ConnectivityIntent {
19 19
20 - private final ConnectPoint ingressPort; 20 + private final ConnectPoint ingressPoint;
21 - private final Set<ConnectPoint> egressPorts; 21 + private final Set<ConnectPoint> egressPoints;
22 22
23 /** 23 /**
24 * Creates a new single-to-multi point connectivity intent. 24 * Creates a new single-to-multi point connectivity intent.
...@@ -26,25 +26,25 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -26,25 +26,25 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
26 * @param id intent identifier 26 * @param id intent identifier
27 * @param selector traffic selector 27 * @param selector traffic selector
28 * @param treatment treatment 28 * @param treatment treatment
29 - * @param ingressPort port on which traffic will ingress 29 + * @param ingressPoint port on which traffic will ingress
30 - * @param egressPorts set of ports on which traffic will egress 30 + * @param egressPoints set of ports on which traffic will egress
31 - * @throws NullPointerException if {@code ingressPort} or 31 + * @throws NullPointerException if {@code ingressPoint} or
32 - * {@code egressPorts} is null 32 + * {@code egressPoints} is null
33 - * @throws IllegalArgumentException if the size of {@code egressPorts} is 33 + * @throws IllegalArgumentException if the size of {@code egressPoints} is
34 * not more than 1 34 * not more than 1
35 */ 35 */
36 public SinglePointToMultiPointIntent(IntentId id, TrafficSelector selector, 36 public SinglePointToMultiPointIntent(IntentId id, TrafficSelector selector,
37 TrafficTreatment treatment, 37 TrafficTreatment treatment,
38 - ConnectPoint ingressPort, 38 + ConnectPoint ingressPoint,
39 - Set<ConnectPoint> egressPorts) { 39 + Set<ConnectPoint> egressPoints) {
40 super(id, selector, treatment); 40 super(id, selector, treatment);
41 41
42 - checkNotNull(egressPorts); 42 + checkNotNull(egressPoints);
43 - checkArgument(!egressPorts.isEmpty(), 43 + checkArgument(!egressPoints.isEmpty(),
44 "there should be at least one egress port"); 44 "there should be at least one egress port");
45 45
46 - this.ingressPort = checkNotNull(ingressPort); 46 + this.ingressPoint = checkNotNull(ingressPoint);
47 - this.egressPorts = Sets.newHashSet(egressPorts); 47 + this.egressPoints = Sets.newHashSet(egressPoints);
48 } 48 }
49 49
50 /** 50 /**
...@@ -52,8 +52,8 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -52,8 +52,8 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
52 */ 52 */
53 protected SinglePointToMultiPointIntent() { 53 protected SinglePointToMultiPointIntent() {
54 super(); 54 super();
55 - this.ingressPort = null; 55 + this.ingressPoint = null;
56 - this.egressPorts = null; 56 + this.egressPoints = null;
57 } 57 }
58 58
59 /** 59 /**
...@@ -61,8 +61,8 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -61,8 +61,8 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
61 * 61 *
62 * @return ingress port 62 * @return ingress port
63 */ 63 */
64 - public ConnectPoint getIngressPort() { 64 + public ConnectPoint ingressPoint() {
65 - return ingressPort; 65 + return ingressPoint;
66 } 66 }
67 67
68 /** 68 /**
...@@ -70,8 +70,8 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -70,8 +70,8 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
70 * 70 *
71 * @return set of egress ports 71 * @return set of egress ports
72 */ 72 */
73 - public Set<ConnectPoint> getEgressPorts() { 73 + public Set<ConnectPoint> egressPoints() {
74 - return egressPorts; 74 + return egressPoints;
75 } 75 }
76 76
77 @Override 77 @Override
...@@ -87,23 +87,23 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -87,23 +87,23 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
87 } 87 }
88 88
89 SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o; 89 SinglePointToMultiPointIntent that = (SinglePointToMultiPointIntent) o;
90 - return Objects.equals(this.ingressPort, that.ingressPort) 90 + return Objects.equals(this.ingressPoint, that.ingressPoint)
91 - && Objects.equals(this.egressPorts, that.egressPorts); 91 + && Objects.equals(this.egressPoints, that.egressPoints);
92 } 92 }
93 93
94 @Override 94 @Override
95 public int hashCode() { 95 public int hashCode() {
96 - return Objects.hash(super.hashCode(), ingressPort, egressPorts); 96 + return Objects.hash(super.hashCode(), ingressPoint, egressPoints);
97 } 97 }
98 98
99 @Override 99 @Override
100 public String toString() { 100 public String toString() {
101 return MoreObjects.toStringHelper(getClass()) 101 return MoreObjects.toStringHelper(getClass())
102 - .add("id", getId()) 102 + .add("id", id())
103 - .add("match", getTrafficSelector()) 103 + .add("match", selector())
104 - .add("action", getTrafficTreatment()) 104 + .add("action", treatment())
105 - .add("ingressPort", ingressPort) 105 + .add("ingressPoint", ingressPoint)
106 - .add("egressPort", egressPorts) 106 + .add("egressPort", egressPoints)
107 .toString(); 107 .toString();
108 } 108 }
109 109
......
...@@ -40,8 +40,7 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -40,8 +40,7 @@ public class FakeIntentManager implements TestableIntentService {
40 @Override 40 @Override
41 public void run() { 41 public void run() {
42 try { 42 try {
43 - List<InstallableIntent> installable = compileIntent(intent); 43 + executeCompilingPhase(intent);
44 - installIntents(intent, installable);
45 } catch (IntentException e) { 44 } catch (IntentException e) {
46 exceptions.add(e); 45 exceptions.add(e);
47 } 46 }
...@@ -55,8 +54,8 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -55,8 +54,8 @@ public class FakeIntentManager implements TestableIntentService {
55 @Override 54 @Override
56 public void run() { 55 public void run() {
57 try { 56 try {
58 - List<InstallableIntent> installable = getInstallable(intent.getId()); 57 + List<InstallableIntent> installable = getInstallable(intent.id());
59 - uninstallIntents(intent, installable); 58 + executeWithdrawingPhase(intent, installable);
60 } catch (IntentException e) { 59 } catch (IntentException e) {
61 exceptions.add(e); 60 exceptions.add(e);
62 } 61 }
...@@ -84,53 +83,60 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -84,53 +83,60 @@ public class FakeIntentManager implements TestableIntentService {
84 return installer; 83 return installer;
85 } 84 }
86 85
87 - private <T extends Intent> List<InstallableIntent> compileIntent(T intent) { 86 + private <T extends Intent> void executeCompilingPhase(T intent) {
87 + setState(intent, IntentState.COMPILING);
88 try { 88 try {
89 // For the fake, we compile using a single level pass 89 // For the fake, we compile using a single level pass
90 List<InstallableIntent> installable = new ArrayList<>(); 90 List<InstallableIntent> installable = new ArrayList<>();
91 for (Intent compiled : getCompiler(intent).compile(intent)) { 91 for (Intent compiled : getCompiler(intent).compile(intent)) {
92 installable.add((InstallableIntent) compiled); 92 installable.add((InstallableIntent) compiled);
93 } 93 }
94 - setState(intent, IntentState.COMPILED); 94 + executeInstallingPhase(intent, installable);
95 - return installable; 95 +
96 } catch (IntentException e) { 96 } catch (IntentException e) {
97 setState(intent, IntentState.FAILED); 97 setState(intent, IntentState.FAILED);
98 - throw e; 98 + dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent));
99 } 99 }
100 } 100 }
101 101
102 - private void installIntents(Intent intent, List<InstallableIntent> installable) { 102 + private void executeInstallingPhase(Intent intent,
103 + List<InstallableIntent> installable) {
104 + setState(intent, IntentState.INSTALLING);
103 try { 105 try {
104 for (InstallableIntent ii : installable) { 106 for (InstallableIntent ii : installable) {
105 registerSubclassInstallerIfNeeded(ii); 107 registerSubclassInstallerIfNeeded(ii);
106 getInstaller(ii).install(ii); 108 getInstaller(ii).install(ii);
107 } 109 }
108 setState(intent, IntentState.INSTALLED); 110 setState(intent, IntentState.INSTALLED);
109 - putInstallable(intent.getId(), installable); 111 + putInstallable(intent.id(), installable);
112 + dispatch(new IntentEvent(IntentEvent.Type.INSTALLED, intent));
113 +
110 } catch (IntentException e) { 114 } catch (IntentException e) {
111 setState(intent, IntentState.FAILED); 115 setState(intent, IntentState.FAILED);
112 - throw e; 116 + dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent));
113 } 117 }
114 } 118 }
115 119
116 - private void uninstallIntents(Intent intent, List<InstallableIntent> installable) { 120 + private void executeWithdrawingPhase(Intent intent,
121 + List<InstallableIntent> installable) {
122 + setState(intent, IntentState.WITHDRAWING);
117 try { 123 try {
118 for (InstallableIntent ii : installable) { 124 for (InstallableIntent ii : installable) {
119 getInstaller(ii).uninstall(ii); 125 getInstaller(ii).uninstall(ii);
120 } 126 }
127 + removeInstallable(intent.id());
121 setState(intent, IntentState.WITHDRAWN); 128 setState(intent, IntentState.WITHDRAWN);
122 - removeInstallable(intent.getId()); 129 + dispatch(new IntentEvent(IntentEvent.Type.WITHDRAWN, intent));
123 } catch (IntentException e) { 130 } catch (IntentException e) {
131 + // FIXME: Do we really want to do this?
124 setState(intent, IntentState.FAILED); 132 setState(intent, IntentState.FAILED);
125 - throw e; 133 + dispatch(new IntentEvent(IntentEvent.Type.FAILED, intent));
126 } 134 }
127 } 135 }
128 136
129 // Sets the internal state for the given intent and dispatches an event 137 // Sets the internal state for the given intent and dispatches an event
130 private void setState(Intent intent, IntentState state) { 138 private void setState(Intent intent, IntentState state) {
131 - IntentState previous = intentStates.get(intent.getId()); 139 + intentStates.put(intent.id(), state);
132 - intentStates.put(intent.getId(), state);
133 - dispatch(new IntentEvent(intent, state, previous, System.currentTimeMillis()));
134 } 140 }
135 141
136 private void putInstallable(IntentId id, List<InstallableIntent> installable) { 142 private void putInstallable(IntentId id, List<InstallableIntent> installable) {
...@@ -152,15 +158,15 @@ public class FakeIntentManager implements TestableIntentService { ...@@ -152,15 +158,15 @@ public class FakeIntentManager implements TestableIntentService {
152 158
153 @Override 159 @Override
154 public void submit(Intent intent) { 160 public void submit(Intent intent) {
155 - intents.put(intent.getId(), intent); 161 + intents.put(intent.id(), intent);
156 setState(intent, IntentState.SUBMITTED); 162 setState(intent, IntentState.SUBMITTED);
163 + dispatch(new IntentEvent(IntentEvent.Type.SUBMITTED, intent));
157 executeSubmit(intent); 164 executeSubmit(intent);
158 } 165 }
159 166
160 @Override 167 @Override
161 public void withdraw(Intent intent) { 168 public void withdraw(Intent intent) {
162 - intents.remove(intent.getId()); 169 + intents.remove(intent.id());
163 - setState(intent, IntentState.WITHDRAWING);
164 executeWithdraw(intent); 170 executeWithdraw(intent);
165 } 171 }
166 172
......
...@@ -10,11 +10,9 @@ import java.util.Collections; ...@@ -10,11 +10,9 @@ import java.util.Collections;
10 import java.util.Iterator; 10 import java.util.Iterator;
11 import java.util.List; 11 import java.util.List;
12 12
13 -import static org.onlab.onos.net.intent.IntentState.*;
14 import static org.junit.Assert.*; 13 import static org.junit.Assert.*;
14 +import static org.onlab.onos.net.intent.IntentEvent.Type.*;
15 15
16 -// TODO: consider make it categorized as integration test when it become
17 -// slow test or fragile test
18 /** 16 /**
19 * Suite of tests for the intent service contract. 17 * Suite of tests for the intent service contract.
20 */ 18 */
...@@ -64,13 +62,13 @@ public class IntentServiceTest { ...@@ -64,13 +62,13 @@ public class IntentServiceTest {
64 TestTools.assertAfter(GRACE_MS, new Runnable() { 62 TestTools.assertAfter(GRACE_MS, new Runnable() {
65 @Override 63 @Override
66 public void run() { 64 public void run() {
67 - assertEquals("incorrect intent state", INSTALLED, 65 + assertEquals("incorrect intent state", IntentState.INSTALLED,
68 - service.getIntentState(intent.getId())); 66 + service.getIntentState(intent.id()));
69 } 67 }
70 }); 68 });
71 69
72 // Make sure that all expected events have been emitted 70 // Make sure that all expected events have been emitted
73 - validateEvents(intent, SUBMITTED, COMPILED, INSTALLED); 71 + validateEvents(intent, SUBMITTED, INSTALLED);
74 72
75 // Make sure there is just one intent (and is ours) 73 // Make sure there is just one intent (and is ours)
76 assertEquals("incorrect intent count", 1, service.getIntentCount()); 74 assertEquals("incorrect intent count", 1, service.getIntentCount());
...@@ -85,19 +83,19 @@ public class IntentServiceTest { ...@@ -85,19 +83,19 @@ public class IntentServiceTest {
85 TestTools.assertAfter(GRACE_MS, new Runnable() { 83 TestTools.assertAfter(GRACE_MS, new Runnable() {
86 @Override 84 @Override
87 public void run() { 85 public void run() {
88 - assertEquals("incorrect intent state", WITHDRAWN, 86 + assertEquals("incorrect intent state", IntentState.WITHDRAWN,
89 - service.getIntentState(intent.getId())); 87 + service.getIntentState(intent.id()));
90 } 88 }
91 }); 89 });
92 90
93 // Make sure that all expected events have been emitted 91 // Make sure that all expected events have been emitted
94 - validateEvents(intent, WITHDRAWING, WITHDRAWN); 92 + validateEvents(intent, WITHDRAWN);
95 93
96 // TODO: discuss what is the fate of intents after they have been withdrawn 94 // TODO: discuss what is the fate of intents after they have been withdrawn
97 // Make sure that the intent is no longer in the system 95 // Make sure that the intent is no longer in the system
98 // assertEquals("incorrect intent count", 0, service.getIntents().size()); 96 // assertEquals("incorrect intent count", 0, service.getIntents().size());
99 -// assertNull("intent should not be found", service.getIntent(intent.getId())); 97 +// assertNull("intent should not be found", service.getIntent(intent.id()));
100 -// assertNull("intent state should not be found", service.getIntentState(intent.getId())); 98 +// assertNull("intent state should not be found", service.getIntentState(intent.id()));
101 } 99 }
102 100
103 @Test 101 @Test
...@@ -113,8 +111,8 @@ public class IntentServiceTest { ...@@ -113,8 +111,8 @@ public class IntentServiceTest {
113 TestTools.assertAfter(GRACE_MS, new Runnable() { 111 TestTools.assertAfter(GRACE_MS, new Runnable() {
114 @Override 112 @Override
115 public void run() { 113 public void run() {
116 - assertEquals("incorrect intent state", FAILED, 114 + assertEquals("incorrect intent state", IntentState.FAILED,
117 - service.getIntentState(intent.getId())); 115 + service.getIntentState(intent.id()));
118 } 116 }
119 }); 117 });
120 118
...@@ -136,13 +134,13 @@ public class IntentServiceTest { ...@@ -136,13 +134,13 @@ public class IntentServiceTest {
136 TestTools.assertAfter(GRACE_MS, new Runnable() { 134 TestTools.assertAfter(GRACE_MS, new Runnable() {
137 @Override 135 @Override
138 public void run() { 136 public void run() {
139 - assertEquals("incorrect intent state", FAILED, 137 + assertEquals("incorrect intent state", IntentState.FAILED,
140 - service.getIntentState(intent.getId())); 138 + service.getIntentState(intent.id()));
141 } 139 }
142 }); 140 });
143 141
144 // Make sure that all expected events have been emitted 142 // Make sure that all expected events have been emitted
145 - validateEvents(intent, SUBMITTED, COMPILED, FAILED); 143 + validateEvents(intent, SUBMITTED, FAILED);
146 } 144 }
147 145
148 /** 146 /**
...@@ -151,23 +149,23 @@ public class IntentServiceTest { ...@@ -151,23 +149,23 @@ public class IntentServiceTest {
151 * considered. 149 * considered.
152 * 150 *
153 * @param intent intent subject 151 * @param intent intent subject
154 - * @param states list of states for which events are expected 152 + * @param types list of event types for which events are expected
155 */ 153 */
156 - protected void validateEvents(Intent intent, IntentState... states) { 154 + protected void validateEvents(Intent intent, IntentEvent.Type... types) {
157 Iterator<IntentEvent> events = listener.events.iterator(); 155 Iterator<IntentEvent> events = listener.events.iterator();
158 - for (IntentState state : states) { 156 + for (IntentEvent.Type type : types) {
159 IntentEvent event = events.hasNext() ? events.next() : null; 157 IntentEvent event = events.hasNext() ? events.next() : null;
160 if (event == null) { 158 if (event == null) {
161 - fail("expected event not found: " + state); 159 + fail("expected event not found: " + type);
162 - } else if (intent.equals(event.getIntent())) { 160 + } else if (intent.equals(event.subject())) {
163 - assertEquals("incorrect state", state, event.getState()); 161 + assertEquals("incorrect state", type, event.type());
164 } 162 }
165 } 163 }
166 164
167 // Remainder of events should not apply to this intent; make sure. 165 // Remainder of events should not apply to this intent; make sure.
168 while (events.hasNext()) { 166 while (events.hasNext()) {
169 assertFalse("unexpected event for intent", 167 assertFalse("unexpected event for intent",
170 - intent.equals(events.next().getIntent())); 168 + intent.equals(events.next().subject()));
171 } 169 }
172 } 170 }
173 171
...@@ -228,8 +226,8 @@ public class IntentServiceTest { ...@@ -228,8 +226,8 @@ public class IntentServiceTest {
228 TestTools.assertAfter(GRACE_MS, new Runnable() { 226 TestTools.assertAfter(GRACE_MS, new Runnable() {
229 @Override 227 @Override
230 public void run() { 228 public void run() {
231 - assertEquals("incorrect intent state", INSTALLED, 229 + assertEquals("incorrect intent state", IntentState.INSTALLED,
232 - service.getIntentState(intent.getId())); 230 + service.getIntentState(intent.id()));
233 } 231 }
234 }); 232 });
235 233
......
...@@ -12,10 +12,10 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest { ...@@ -12,10 +12,10 @@ public class MultiPointToSinglePointIntentTest extends ConnectivityIntentTest {
12 @Test 12 @Test
13 public void basics() { 13 public void basics() {
14 MultiPointToSinglePointIntent intent = createOne(); 14 MultiPointToSinglePointIntent intent = createOne();
15 - assertEquals("incorrect id", IID, intent.getId()); 15 + assertEquals("incorrect id", IID, intent.id());
16 - assertEquals("incorrect match", MATCH, intent.getTrafficSelector()); 16 + assertEquals("incorrect match", MATCH, intent.selector());
17 - assertEquals("incorrect ingress", PS1, intent.getIngressPorts()); 17 + assertEquals("incorrect ingress", PS1, intent.ingressPoints());
18 - assertEquals("incorrect egress", P2, intent.getEgressPort()); 18 + assertEquals("incorrect egress", P2, intent.egressPoint());
19 } 19 }
20 20
21 @Override 21 @Override
......
...@@ -16,12 +16,12 @@ public class PathIntentTest extends ConnectivityIntentTest { ...@@ -16,12 +16,12 @@ public class PathIntentTest extends ConnectivityIntentTest {
16 @Test 16 @Test
17 public void basics() { 17 public void basics() {
18 PathIntent intent = createOne(); 18 PathIntent intent = createOne();
19 - assertEquals("incorrect id", IID, intent.getId()); 19 + assertEquals("incorrect id", IID, intent.id());
20 - assertEquals("incorrect match", MATCH, intent.getTrafficSelector()); 20 + assertEquals("incorrect match", MATCH, intent.selector());
21 - assertEquals("incorrect action", NOP, intent.getTrafficTreatment()); 21 + assertEquals("incorrect action", NOP, intent.treatment());
22 - assertEquals("incorrect ingress", P1, intent.getIngressPort()); 22 + assertEquals("incorrect ingress", P1, intent.ingressPoint());
23 - assertEquals("incorrect egress", P2, intent.getEgressPort()); 23 + assertEquals("incorrect egress", P2, intent.egressPoint());
24 - assertEquals("incorrect path", PATH1, intent.getPath()); 24 + assertEquals("incorrect path", PATH1, intent.path());
25 } 25 }
26 26
27 @Override 27 @Override
......
...@@ -12,10 +12,10 @@ public class PointToPointIntentTest extends ConnectivityIntentTest { ...@@ -12,10 +12,10 @@ public class PointToPointIntentTest extends ConnectivityIntentTest {
12 @Test 12 @Test
13 public void basics() { 13 public void basics() {
14 PointToPointIntent intent = createOne(); 14 PointToPointIntent intent = createOne();
15 - assertEquals("incorrect id", IID, intent.getId()); 15 + assertEquals("incorrect id", IID, intent.id());
16 - assertEquals("incorrect match", MATCH, intent.getTrafficSelector()); 16 + assertEquals("incorrect match", MATCH, intent.selector());
17 - assertEquals("incorrect ingress", P1, intent.getIngressPort()); 17 + assertEquals("incorrect ingress", P1, intent.ingressPoint());
18 - assertEquals("incorrect egress", P2, intent.getEgressPort()); 18 + assertEquals("incorrect egress", P2, intent.egressPoint());
19 } 19 }
20 20
21 @Override 21 @Override
......
...@@ -12,10 +12,10 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest { ...@@ -12,10 +12,10 @@ public class SinglePointToMultiPointIntentTest extends ConnectivityIntentTest {
12 @Test 12 @Test
13 public void basics() { 13 public void basics() {
14 SinglePointToMultiPointIntent intent = createOne(); 14 SinglePointToMultiPointIntent intent = createOne();
15 - assertEquals("incorrect id", IID, intent.getId()); 15 + assertEquals("incorrect id", IID, intent.id());
16 - assertEquals("incorrect match", MATCH, intent.getTrafficSelector()); 16 + assertEquals("incorrect match", MATCH, intent.selector());
17 - assertEquals("incorrect ingress", P1, intent.getIngressPort()); 17 + assertEquals("incorrect ingress", P1, intent.ingressPoint());
18 - assertEquals("incorrect egress", PS2, intent.getEgressPorts()); 18 + assertEquals("incorrect egress", PS2, intent.egressPoints());
19 } 19 }
20 20
21 @Override 21 @Override
......
...@@ -71,11 +71,11 @@ public class HostToHostIntentCompiler ...@@ -71,11 +71,11 @@ public class HostToHostIntentCompiler
71 private Intent createPathIntent(Path path, Host src, Host dst, 71 private Intent createPathIntent(Path path, Host src, Host dst,
72 HostToHostIntent intent) { 72 HostToHostIntent intent) {
73 73
74 - TrafficSelector selector = builder(intent.getTrafficSelector()) 74 + TrafficSelector selector = builder(intent.selector())
75 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build(); 75 .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
76 76
77 return new PathIntent(intentIdGenerator.getNewId(), 77 return new PathIntent(intentIdGenerator.getNewId(),
78 - selector, intent.getTrafficTreatment(), 78 + selector, intent.treatment(),
79 path.src(), path.dst(), path); 79 path.src(), path.dst(), path);
80 } 80 }
81 81
......
...@@ -19,12 +19,15 @@ import org.onlab.onos.net.topology.TopologyService; ...@@ -19,12 +19,15 @@ import org.onlab.onos.net.topology.TopologyService;
19 import org.slf4j.Logger; 19 import org.slf4j.Logger;
20 20
21 import java.util.Collection; 21 import java.util.Collection;
22 +import java.util.HashSet;
23 +import java.util.Set;
22 import java.util.concurrent.ExecutorService; 24 import java.util.concurrent.ExecutorService;
23 25
24 import static com.google.common.base.Preconditions.checkArgument; 26 import static com.google.common.base.Preconditions.checkArgument;
25 import static com.google.common.base.Preconditions.checkNotNull; 27 import static com.google.common.base.Preconditions.checkNotNull;
26 import static com.google.common.collect.Multimaps.synchronizedSetMultimap; 28 import static com.google.common.collect.Multimaps.synchronizedSetMultimap;
27 import static java.util.concurrent.Executors.newSingleThreadExecutor; 29 import static java.util.concurrent.Executors.newSingleThreadExecutor;
30 +import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
28 import static org.onlab.util.Tools.namedThreads; 31 import static org.onlab.util.Tools.namedThreads;
29 import static org.slf4j.LoggerFactory.getLogger; 32 import static org.slf4j.LoggerFactory.getLogger;
30 33
...@@ -34,7 +37,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -34,7 +37,7 @@ import static org.slf4j.LoggerFactory.getLogger;
34 */ 37 */
35 @Component 38 @Component
36 @Service 39 @Service
37 -public class FlowTracker implements FlowTrackerService { 40 +public class ObjectiveTracker implements ObjectiveTrackerService {
38 41
39 private final Logger log = getLogger(getClass()); 42 private final Logger log = getLogger(getClass());
40 43
...@@ -110,15 +113,27 @@ public class FlowTracker implements FlowTrackerService { ...@@ -110,15 +113,27 @@ public class FlowTracker implements FlowTrackerService {
110 @Override 113 @Override
111 public void run() { 114 public void run() {
112 if (event.reasons() == null) { 115 if (event.reasons() == null) {
113 - delegate.bumpIntents(intentsByLink.values()); 116 + delegate.triggerCompile(null, false);
117 +
114 } else { 118 } else {
119 + Set<IntentId> toBeRecompiled = new HashSet<>();
120 + boolean recompileOnly = true;
121 +
122 + // Scan through the list of reasons and keep accruing all
123 + // intents that need to be recompiled.
115 for (Event reason : event.reasons()) { 124 for (Event reason : event.reasons()) {
116 if (reason instanceof LinkEvent) { 125 if (reason instanceof LinkEvent) {
117 LinkEvent linkEvent = (LinkEvent) reason; 126 LinkEvent linkEvent = (LinkEvent) reason;
118 - delegate.bumpIntents(intentsByLink.get(new LinkKey(linkEvent.subject()))); 127 + if (linkEvent.type() == LINK_REMOVED) {
128 + Set<IntentId> intentIds = intentsByLink.get(new LinkKey(linkEvent.subject()));
129 + toBeRecompiled.addAll(intentIds);
119 } 130 }
131 + recompileOnly = recompileOnly && linkEvent.type() == LINK_REMOVED;
120 } 132 }
121 } 133 }
134 +
135 + delegate.triggerCompile(toBeRecompiled, !recompileOnly);
136 + }
122 } 137 }
123 } 138 }
124 139
......
...@@ -9,7 +9,7 @@ import java.util.Collection; ...@@ -9,7 +9,7 @@ import java.util.Collection;
9 * Auxiliary service for tracking intent path flows and for notifying the 9 * Auxiliary service for tracking intent path flows and for notifying the
10 * intent service of environment changes via topology change delegate. 10 * intent service of environment changes via topology change delegate.
11 */ 11 */
12 -public interface FlowTrackerService { 12 +public interface ObjectiveTrackerService {
13 13
14 /** 14 /**
15 * Sets a topology change delegate. 15 * Sets a topology change delegate.
......
...@@ -49,8 +49,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -49,8 +49,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
49 @Override 49 @Override
50 public void install(PathIntent intent) { 50 public void install(PathIntent intent) {
51 TrafficSelector.Builder builder = 51 TrafficSelector.Builder builder =
52 - DefaultTrafficSelector.builder(intent.getTrafficSelector()); 52 + DefaultTrafficSelector.builder(intent.selector());
53 - Iterator<Link> links = intent.getPath().links().iterator(); 53 + Iterator<Link> links = intent.path().links().iterator();
54 ConnectPoint prev = links.next().dst(); 54 ConnectPoint prev = links.next().dst();
55 55
56 while (links.hasNext()) { 56 while (links.hasNext()) {
...@@ -70,8 +70,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> { ...@@ -70,8 +70,8 @@ public class PathIntentInstaller implements IntentInstaller<PathIntent> {
70 @Override 70 @Override
71 public void uninstall(PathIntent intent) { 71 public void uninstall(PathIntent intent) {
72 TrafficSelector.Builder builder = 72 TrafficSelector.Builder builder =
73 - DefaultTrafficSelector.builder(intent.getTrafficSelector()); 73 + DefaultTrafficSelector.builder(intent.selector());
74 - Iterator<Link> links = intent.getPath().links().iterator(); 74 + Iterator<Link> links = intent.path().links().iterator();
75 ConnectPoint prev = links.next().dst(); 75 ConnectPoint prev = links.next().dst();
76 76
77 while (links.hasNext()) { 77 while (links.hasNext()) {
......
...@@ -9,10 +9,14 @@ public interface TopologyChangeDelegate { ...@@ -9,10 +9,14 @@ public interface TopologyChangeDelegate {
9 9
10 /** 10 /**
11 * Notifies that topology has changed in such a way that the specified 11 * Notifies that topology has changed in such a way that the specified
12 - * intents should be recompiled. 12 + * intents should be recompiled. If the {@code compileAllFailed} parameter
13 + * is true, the all intents in {@link org.onlab.onos.net.intent.IntentState#FAILED}
14 + * state should be compiled as well.
13 * 15 *
14 * @param intentIds intents that should be recompiled 16 * @param intentIds intents that should be recompiled
17 + * @param compileAllFailed true implies full compile is required; false for
18 + * selective recompile only
15 */ 19 */
16 - void bumpIntents(Iterable<IntentId> intentIds); 20 + void triggerCompile(Iterable<IntentId> intentIds, boolean compileAllFailed);
17 21
18 } 22 }
......
1 package org.onlab.onos.store.trivial.impl; 1 package org.onlab.onos.store.trivial.impl;
2 2
3 -import static org.onlab.onos.net.intent.IntentState.COMPILED; 3 +import com.google.common.collect.ImmutableSet;
4 -import static org.slf4j.LoggerFactory.getLogger;
5 -
6 -import java.util.HashMap;
7 -import java.util.List;
8 -import java.util.Map;
9 -
10 import org.apache.felix.scr.annotations.Activate; 4 import org.apache.felix.scr.annotations.Activate;
11 import org.apache.felix.scr.annotations.Component; 5 import org.apache.felix.scr.annotations.Component;
12 import org.apache.felix.scr.annotations.Deactivate; 6 import org.apache.felix.scr.annotations.Deactivate;
...@@ -21,7 +15,12 @@ import org.onlab.onos.net.intent.IntentStoreDelegate; ...@@ -21,7 +15,12 @@ import org.onlab.onos.net.intent.IntentStoreDelegate;
21 import org.onlab.onos.store.AbstractStore; 15 import org.onlab.onos.store.AbstractStore;
22 import org.slf4j.Logger; 16 import org.slf4j.Logger;
23 17
24 -import com.google.common.collect.ImmutableSet; 18 +import java.util.HashMap;
19 +import java.util.List;
20 +import java.util.Map;
21 +
22 +import static org.onlab.onos.net.intent.IntentState.*;
23 +import static org.slf4j.LoggerFactory.getLogger;
25 24
26 @Component(immediate = true) 25 @Component(immediate = true)
27 @Service 26 @Service
...@@ -46,7 +45,7 @@ public class SimpleIntentStore ...@@ -46,7 +45,7 @@ public class SimpleIntentStore
46 45
47 @Override 46 @Override
48 public IntentEvent createIntent(Intent intent) { 47 public IntentEvent createIntent(Intent intent) {
49 - intents.put(intent.getId(), intent); 48 + intents.put(intent.id(), intent);
50 return this.setState(intent, IntentState.SUBMITTED); 49 return this.setState(intent, IntentState.SUBMITTED);
51 } 50 }
52 51
...@@ -54,7 +53,7 @@ public class SimpleIntentStore ...@@ -54,7 +53,7 @@ public class SimpleIntentStore
54 public IntentEvent removeIntent(IntentId intentId) { 53 public IntentEvent removeIntent(IntentId intentId) {
55 Intent intent = intents.remove(intentId); 54 Intent intent = intents.remove(intentId);
56 installable.remove(intentId); 55 installable.remove(intentId);
57 - IntentEvent event = this.setState(intent, IntentState.WITHDRAWN); 56 + IntentEvent event = this.setState(intent, WITHDRAWN);
58 states.remove(intentId); 57 states.remove(intentId);
59 return event; 58 return event;
60 } 59 }
...@@ -79,19 +78,21 @@ public class SimpleIntentStore ...@@ -79,19 +78,21 @@ public class SimpleIntentStore
79 return states.get(id); 78 return states.get(id);
80 } 79 }
81 80
82 - // TODO return dispatch event here... replace with state transition methods
83 @Override 81 @Override
84 - public IntentEvent setState(Intent intent, IntentState newState) { 82 + public IntentEvent setState(Intent intent, IntentState state) {
85 - IntentId id = intent.getId(); 83 + IntentId id = intent.id();
86 - IntentState oldState = states.get(id); 84 + states.put(id, state);
87 - states.put(id, newState); 85 + IntentEvent.Type type = (state == SUBMITTED ? IntentEvent.Type.SUBMITTED :
88 - return new IntentEvent(intent, newState, oldState, System.currentTimeMillis()); 86 + (state == INSTALLED ? IntentEvent.Type.INSTALLED :
87 + (state == FAILED ? IntentEvent.Type.FAILED :
88 + state == WITHDRAWN ? IntentEvent.Type.WITHDRAWN :
89 + null)));
90 + return type == null ? null : new IntentEvent(type, intent);
89 } 91 }
90 92
91 @Override 93 @Override
92 - public IntentEvent addInstallableIntents(IntentId intentId, List<InstallableIntent> result) { 94 + public void addInstallableIntents(IntentId intentId, List<InstallableIntent> result) {
93 installable.put(intentId, result); 95 installable.put(intentId, result);
94 - return this.setState(intents.get(intentId), COMPILED);
95 } 96 }
96 97
97 @Override 98 @Override
......
...@@ -89,5 +89,5 @@ function spy { ...@@ -89,5 +89,5 @@ function spy {
89 } 89 }
90 90
91 function nuke { 91 function nuke {
92 - spy | cut -c7-11 | xargs kill 92 + spy "$@" | cut -c7-11 | xargs kill
93 } 93 }
......