Committed by
Gerrit Code Review
ONOS-3633 - Adding intent event listener to PointToPointIntent virtual network
provider. Intent events will either set the virtual link state to ACTIVE or INACTIVE. Change-Id: I34b65b2bfff29b791e7b2eb4d7cefb2ec4e88672
Showing
14 changed files
with
268 additions
and
118 deletions
... | @@ -34,7 +34,7 @@ import java.util.List; | ... | @@ -34,7 +34,7 @@ import java.util.List; |
34 | public class VirtualLinkListCommand extends AbstractShellCommand { | 34 | public class VirtualLinkListCommand extends AbstractShellCommand { |
35 | 35 | ||
36 | private static final String FMT_VIRTUAL_LINK = | 36 | private static final String FMT_VIRTUAL_LINK = |
37 | - "src=%s, dst=%s, tunnelId=%s"; | 37 | + "src=%s, dst=%s, state=%s, tunnelId=%s"; |
38 | 38 | ||
39 | @Argument(index = 0, name = "networkId", description = "Network ID", | 39 | @Argument(index = 0, name = "networkId", description = "Network ID", |
40 | required = true, multiValued = false) | 40 | required = true, multiValued = false) |
... | @@ -66,6 +66,7 @@ public class VirtualLinkListCommand extends AbstractShellCommand { | ... | @@ -66,6 +66,7 @@ public class VirtualLinkListCommand extends AbstractShellCommand { |
66 | */ | 66 | */ |
67 | private void printVirtualLink(VirtualLink virtualLink) { | 67 | private void printVirtualLink(VirtualLink virtualLink) { |
68 | print(FMT_VIRTUAL_LINK, virtualLink.src().toString(), virtualLink.dst().toString(), | 68 | print(FMT_VIRTUAL_LINK, virtualLink.src().toString(), virtualLink.dst().toString(), |
69 | + virtualLink.state(), | ||
69 | virtualLink.tunnelId() == null ? null : virtualLink.tunnelId().toString()); | 70 | virtualLink.tunnelId() == null ? null : virtualLink.tunnelId().toString()); |
70 | } | 71 | } |
71 | } | 72 | } | ... | ... |
... | @@ -42,7 +42,7 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink { | ... | @@ -42,7 +42,7 @@ public class DefaultEdgeLink extends DefaultLink implements EdgeLink { |
42 | HostLocation hostLocation, boolean isIngress, | 42 | HostLocation hostLocation, boolean isIngress, |
43 | Annotations... annotations) { | 43 | Annotations... annotations) { |
44 | super(providerId, isIngress ? hostPoint : hostLocation, | 44 | super(providerId, isIngress ? hostPoint : hostLocation, |
45 | - isIngress ? hostLocation : hostPoint, Type.EDGE, annotations); | 45 | + isIngress ? hostLocation : hostPoint, Type.EDGE, State.ACTIVE, annotations); |
46 | checkArgument(hostPoint.elementId() instanceof HostId, | 46 | checkArgument(hostPoint.elementId() instanceof HostId, |
47 | "Host point does not refer to a host ID"); | 47 | "Host point does not refer to a host ID"); |
48 | this.hostId = (HostId) hostPoint.elementId(); | 48 | this.hostId = (HostId) hostPoint.elementId(); | ... | ... |
... | @@ -36,17 +36,18 @@ public class DefaultLink extends AbstractProjectableModel implements Link { | ... | @@ -36,17 +36,18 @@ public class DefaultLink extends AbstractProjectableModel implements Link { |
36 | private final boolean isExpected; | 36 | private final boolean isExpected; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | - * Creates an active infrastructure link using the supplied information. | 39 | + * Creates an infrastructure link using the supplied information. |
40 | * | 40 | * |
41 | * @param providerId provider identity | 41 | * @param providerId provider identity |
42 | * @param src link source | 42 | * @param src link source |
43 | * @param dst link destination | 43 | * @param dst link destination |
44 | * @param type link type | 44 | * @param type link type |
45 | + * @param state link state | ||
45 | * @param annotations optional key/value annotations | 46 | * @param annotations optional key/value annotations |
46 | */ | 47 | */ |
47 | protected DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, | 48 | protected DefaultLink(ProviderId providerId, ConnectPoint src, ConnectPoint dst, |
48 | - Type type, Annotations... annotations) { | 49 | + Type type, State state, Annotations... annotations) { |
49 | - this(providerId, src, dst, type, ACTIVE, false, annotations); | 50 | + this(providerId, src, dst, type, state, false, annotations); |
50 | } | 51 | } |
51 | 52 | ||
52 | /** | 53 | /** | ... | ... |
... | @@ -44,7 +44,7 @@ public class DefaultPath extends DefaultLink implements Path { | ... | @@ -44,7 +44,7 @@ public class DefaultPath extends DefaultLink implements Path { |
44 | */ | 44 | */ |
45 | public DefaultPath(ProviderId providerId, List<Link> links, double cost, | 45 | public DefaultPath(ProviderId providerId, List<Link> links, double cost, |
46 | Annotations... annotations) { | 46 | Annotations... annotations) { |
47 | - super(providerId, source(links), destination(links), Type.INDIRECT, annotations); | 47 | + super(providerId, source(links), destination(links), Type.INDIRECT, State.ACTIVE, annotations); |
48 | this.links = ImmutableList.copyOf(links); | 48 | this.links = ImmutableList.copyOf(links); |
49 | this.cost = cost; | 49 | this.cost = cost; |
50 | } | 50 | } | ... | ... |
... | @@ -42,11 +42,11 @@ public class DefaultLinkTest { | ... | @@ -42,11 +42,11 @@ public class DefaultLinkTest { |
42 | 42 | ||
43 | @Test | 43 | @Test |
44 | public void testEquality() { | 44 | public void testEquality() { |
45 | - Link l1 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT); | 45 | + Link l1 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
46 | - Link l2 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT); | 46 | + Link l2 = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
47 | - Link l3 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT); | 47 | + Link l3 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
48 | - Link l4 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT); | 48 | + Link l4 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
49 | - Link l5 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), INDIRECT); | 49 | + Link l5 = new DefaultLink(PID, cp(DID1, P2), cp(DID2, P2), INDIRECT, Link.State.ACTIVE); |
50 | 50 | ||
51 | new EqualsTester().addEqualityGroup(l1, l2) | 51 | new EqualsTester().addEqualityGroup(l1, l2) |
52 | .addEqualityGroup(l3, l4) | 52 | .addEqualityGroup(l3, l4) |
... | @@ -56,7 +56,7 @@ public class DefaultLinkTest { | ... | @@ -56,7 +56,7 @@ public class DefaultLinkTest { |
56 | 56 | ||
57 | @Test | 57 | @Test |
58 | public void basics() { | 58 | public void basics() { |
59 | - Link link = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT); | 59 | + Link link = new DefaultLink(PID, cp(DID1, P1), cp(DID2, P2), DIRECT, Link.State.ACTIVE); |
60 | assertEquals("incorrect src", cp(DID1, P1), link.src()); | 60 | assertEquals("incorrect src", cp(DID1, P1), link.src()); |
61 | assertEquals("incorrect dst", cp(DID2, P2), link.dst()); | 61 | assertEquals("incorrect dst", cp(DID2, P2), link.dst()); |
62 | assertEquals("incorrect type", DIRECT, link.type()); | 62 | assertEquals("incorrect type", DIRECT, link.type()); | ... | ... |
... | @@ -81,7 +81,7 @@ public final class NetTestTools { | ... | @@ -81,7 +81,7 @@ public final class NetTestTools { |
81 | return new DefaultLink(PID, | 81 | return new DefaultLink(PID, |
82 | connectPoint(src, sp), | 82 | connectPoint(src, sp), |
83 | connectPoint(dst, dp), | 83 | connectPoint(dst, dp), |
84 | - Link.Type.DIRECT); | 84 | + Link.Type.DIRECT, Link.State.ACTIVE); |
85 | } | 85 | } |
86 | 86 | ||
87 | // Creates a path that leads through the given devices. | 87 | // Creates a path that leads through the given devices. | ... | ... |
... | @@ -44,10 +44,12 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink | ... | @@ -44,10 +44,12 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink |
44 | * @param networkId network identifier | 44 | * @param networkId network identifier |
45 | * @param src source connection point | 45 | * @param src source connection point |
46 | * @param dst destination connection point | 46 | * @param dst destination connection point |
47 | + * @param state link state | ||
47 | * @param tunnelId tunnel identifier | 48 | * @param tunnelId tunnel identifier |
48 | */ | 49 | */ |
49 | - private DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { | 50 | + private DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, |
50 | - super(PID, src, dst, Type.VIRTUAL, DefaultAnnotations.builder().build()); | 51 | + State state, TunnelId tunnelId) { |
52 | + super(PID, src, dst, Type.VIRTUAL, state, DefaultAnnotations.builder().build()); | ||
51 | this.networkId = networkId; | 53 | this.networkId = networkId; |
52 | this.tunnelId = tunnelId; | 54 | this.tunnelId = tunnelId; |
53 | } | 55 | } |
... | @@ -107,6 +109,7 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink | ... | @@ -107,6 +109,7 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink |
107 | private ConnectPoint src; | 109 | private ConnectPoint src; |
108 | private ConnectPoint dst; | 110 | private ConnectPoint dst; |
109 | private TunnelId tunnelId; | 111 | private TunnelId tunnelId; |
112 | + private State state; | ||
110 | 113 | ||
111 | private Builder() { | 114 | private Builder() { |
112 | // Hide constructor | 115 | // Hide constructor |
... | @@ -157,6 +160,17 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink | ... | @@ -157,6 +160,17 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink |
157 | } | 160 | } |
158 | 161 | ||
159 | /** | 162 | /** |
163 | + * Sets the link state to be used by the builder. | ||
164 | + * | ||
165 | + * @param state link state | ||
166 | + * @return self | ||
167 | + */ | ||
168 | + public Builder state(State state) { | ||
169 | + this.state = state; | ||
170 | + return this; | ||
171 | + } | ||
172 | + | ||
173 | + /** | ||
160 | * Builds a default virtual link object from the accumulated parameters. | 174 | * Builds a default virtual link object from the accumulated parameters. |
161 | * | 175 | * |
162 | * @return default virtual link object | 176 | * @return default virtual link object |
... | @@ -166,7 +180,7 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink | ... | @@ -166,7 +180,7 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink |
166 | checkNotNull(dst, "Destination connect point cannot be null"); | 180 | checkNotNull(dst, "Destination connect point cannot be null"); |
167 | checkNotNull(networkId, "Network Id cannot be null"); | 181 | checkNotNull(networkId, "Network Id cannot be null"); |
168 | 182 | ||
169 | - return new DefaultVirtualLink(networkId, src, dst, tunnelId); | 183 | + return new DefaultVirtualLink(networkId, src, dst, state, tunnelId); |
170 | } | 184 | } |
171 | } | 185 | } |
172 | } | 186 | } | ... | ... |
incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkProviderService.java
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.incubator.net.virtual; | 16 | package org.onosproject.incubator.net.virtual; |
17 | 17 | ||
18 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
18 | import org.onosproject.net.ConnectPoint; | 19 | import org.onosproject.net.ConnectPoint; |
19 | import org.onosproject.net.provider.ProviderService; | 20 | import org.onosproject.net.provider.ProviderService; |
20 | 21 | ||
... | @@ -30,8 +31,9 @@ public interface VirtualNetworkProviderService extends ProviderService<VirtualNe | ... | @@ -30,8 +31,9 @@ public interface VirtualNetworkProviderService extends ProviderService<VirtualNe |
30 | * @param networkId network identifier | 31 | * @param networkId network identifier |
31 | * @param src source connection point | 32 | * @param src source connection point |
32 | * @param dst destination connection point | 33 | * @param dst destination connection point |
34 | + * @param tunnelId tunnel identifier | ||
33 | */ | 35 | */ |
34 | - void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst); | 36 | + void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId); |
35 | 37 | ||
36 | /** | 38 | /** |
37 | * This method is used to notify the VirtualNetwork service that a tunnel is now | 39 | * This method is used to notify the VirtualNetwork service that a tunnel is now |
... | @@ -40,7 +42,8 @@ public interface VirtualNetworkProviderService extends ProviderService<VirtualNe | ... | @@ -40,7 +42,8 @@ public interface VirtualNetworkProviderService extends ProviderService<VirtualNe |
40 | * @param networkId network identifier | 42 | * @param networkId network identifier |
41 | * @param src source connection point | 43 | * @param src source connection point |
42 | * @param dst destination connection point | 44 | * @param dst destination connection point |
45 | + * @param tunnelId tunnel identifier | ||
43 | */ | 46 | */ |
44 | - void tunnelDown(NetworkId networkId, ConnectPoint src, ConnectPoint dst); | 47 | + void tunnelDown(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId); |
45 | 48 | ||
46 | } | 49 | } | ... | ... |
... | @@ -60,7 +60,9 @@ public interface VirtualNetworkService { | ... | @@ -60,7 +60,9 @@ public interface VirtualNetworkService { |
60 | Set<VirtualLink> getVirtualLinks(NetworkId networkId); | 60 | Set<VirtualLink> getVirtualLinks(NetworkId networkId); |
61 | 61 | ||
62 | /** | 62 | /** |
63 | - * Returns list of all virtual ports of the specified device. | 63 | + * Returns list of all virtual ports of the specified device. If the |
64 | + * device identifier is null then all of the virtual ports in the specified | ||
65 | + * network will be returned. | ||
64 | * | 66 | * |
65 | * @param networkId network identifier | 67 | * @param networkId network identifier |
66 | * @param deviceId device identifier | 68 | * @param deviceId device identifier | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.incubator.net.virtual; | ... | @@ -18,6 +18,7 @@ package org.onosproject.incubator.net.virtual; |
18 | import org.onosproject.incubator.net.tunnel.TunnelId; | 18 | import org.onosproject.incubator.net.tunnel.TunnelId; |
19 | import org.onosproject.net.ConnectPoint; | 19 | import org.onosproject.net.ConnectPoint; |
20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
21 | +import org.onosproject.net.Link; | ||
21 | import org.onosproject.net.Port; | 22 | import org.onosproject.net.Port; |
22 | import org.onosproject.net.PortNumber; | 23 | import org.onosproject.net.PortNumber; |
23 | import org.onosproject.store.Store; | 24 | import org.onosproject.store.Store; |
... | @@ -89,18 +90,20 @@ public interface VirtualNetworkStore | ... | @@ -89,18 +90,20 @@ public interface VirtualNetworkStore |
89 | * @param networkId network identifier | 90 | * @param networkId network identifier |
90 | * @param src source end-point of the link | 91 | * @param src source end-point of the link |
91 | * @param dst destination end-point of the link | 92 | * @param dst destination end-point of the link |
93 | + * @param state link state | ||
92 | * @param realizedBy underlying tunnel identifier using which this link is realized | 94 | * @param realizedBy underlying tunnel identifier using which this link is realized |
93 | * @return the virtual link | 95 | * @return the virtual link |
94 | */ | 96 | */ |
95 | - VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId realizedBy); | 97 | + VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, Link.State state, TunnelId realizedBy); |
96 | 98 | ||
97 | /** | 99 | /** |
98 | * Updates the tunnelId in the virtual link. | 100 | * Updates the tunnelId in the virtual link. |
99 | * | 101 | * |
100 | - * @param virtualLink virtual link | 102 | + * @param virtualLink virtual link |
101 | - * @param tunnelId tunnel identifier | 103 | + * @param tunnelId tunnel identifier |
104 | + * @param state link state | ||
102 | */ | 105 | */ |
103 | - void updateLink(VirtualLink virtualLink, TunnelId tunnelId); | 106 | + void updateLink(VirtualLink virtualLink, TunnelId tunnelId, Link.State state); |
104 | 107 | ||
105 | /** | 108 | /** |
106 | * Removes the specified link from the store. | 109 | * Removes the specified link from the store. |
... | @@ -158,10 +161,21 @@ public interface VirtualNetworkStore | ... | @@ -158,10 +161,21 @@ public interface VirtualNetworkStore |
158 | Set<VirtualLink> getLinks(NetworkId networkId); | 161 | Set<VirtualLink> getLinks(NetworkId networkId); |
159 | 162 | ||
160 | /** | 163 | /** |
164 | + * Returns the virtual link matching the network identifier, source connect point, | ||
165 | + * and destination connect point. | ||
166 | + * | ||
167 | + * @param networkId network identifier | ||
168 | + * @param src source connect point | ||
169 | + * @param dst destination connect point | ||
170 | + * @return virtual link | ||
171 | + */ | ||
172 | + VirtualLink getLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst); | ||
173 | + | ||
174 | + /** | ||
161 | * Returns the list of ports of the specified virtual device. | 175 | * Returns the list of ports of the specified virtual device. |
162 | * | 176 | * |
163 | * @param networkId network identifier | 177 | * @param networkId network identifier |
164 | - * @param deviceId device identifier | 178 | + * @param deviceId device identifier |
165 | * @return set of virtual networks | 179 | * @return set of virtual networks |
166 | */ | 180 | */ |
167 | Set<VirtualPort> getPorts(NetworkId networkId, DeviceId deviceId); | 181 | Set<VirtualPort> getPorts(NetworkId networkId, DeviceId deviceId); | ... | ... |
... | @@ -35,8 +35,9 @@ import org.onosproject.net.ConnectPoint; | ... | @@ -35,8 +35,9 @@ import org.onosproject.net.ConnectPoint; |
35 | import org.onosproject.net.EncapsulationType; | 35 | import org.onosproject.net.EncapsulationType; |
36 | import org.onosproject.net.intent.Constraint; | 36 | import org.onosproject.net.intent.Constraint; |
37 | import org.onosproject.net.intent.Intent; | 37 | import org.onosproject.net.intent.Intent; |
38 | +import org.onosproject.net.intent.IntentEvent; | ||
39 | +import org.onosproject.net.intent.IntentListener; | ||
38 | import org.onosproject.net.intent.IntentService; | 40 | import org.onosproject.net.intent.IntentService; |
39 | -import org.onosproject.net.intent.IntentState; | ||
40 | import org.onosproject.net.intent.Key; | 41 | import org.onosproject.net.intent.Key; |
41 | import org.onosproject.net.intent.PointToPointIntent; | 42 | import org.onosproject.net.intent.PointToPointIntent; |
42 | import org.onosproject.net.intent.constraint.EncapsulationConstraint; | 43 | import org.onosproject.net.intent.constraint.EncapsulationConstraint; |
... | @@ -45,9 +46,9 @@ import org.slf4j.Logger; | ... | @@ -45,9 +46,9 @@ import org.slf4j.Logger; |
45 | 46 | ||
46 | import java.util.ArrayList; | 47 | import java.util.ArrayList; |
47 | import java.util.List; | 48 | import java.util.List; |
49 | +import java.util.StringTokenizer; | ||
48 | 50 | ||
49 | import static com.google.common.base.Preconditions.checkNotNull; | 51 | import static com.google.common.base.Preconditions.checkNotNull; |
50 | -import static java.lang.Thread.sleep; | ||
51 | import static org.slf4j.LoggerFactory.getLogger; | 52 | import static org.slf4j.LoggerFactory.getLogger; |
52 | 53 | ||
53 | /** | 54 | /** |
... | @@ -55,13 +56,15 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -55,13 +56,15 @@ import static org.slf4j.LoggerFactory.getLogger; |
55 | */ | 56 | */ |
56 | @Component(immediate = true) | 57 | @Component(immediate = true) |
57 | @Service | 58 | @Service |
58 | -public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider implements VirtualNetworkProvider { | 59 | +public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider |
60 | + implements VirtualNetworkProvider { | ||
59 | 61 | ||
60 | private final Logger log = getLogger(PtToPtIntentVirtualNetworkProvider.class); | 62 | private final Logger log = getLogger(PtToPtIntentVirtualNetworkProvider.class); |
61 | private static final String NETWORK_ID_NULL = "Network ID cannot be null"; | 63 | private static final String NETWORK_ID_NULL = "Network ID cannot be null"; |
62 | private static final String CONNECT_POINT_NULL = "Connect Point cannot be null"; | 64 | private static final String CONNECT_POINT_NULL = "Connect Point cannot be null"; |
63 | private static final String INTENT_NULL = "Intent cannot be null"; | 65 | private static final String INTENT_NULL = "Intent cannot be null"; |
64 | - protected static final String KEY_FORMAT = "networkId=%s src=%s dst=%s"; | 66 | + private static final String NETWORK_ID = "networkId="; |
67 | + protected static final String KEY_FORMAT = NETWORK_ID + "%s, src=%s, dst=%s"; | ||
65 | private static final int MAX_WAIT_COUNT = 30; | 68 | private static final int MAX_WAIT_COUNT = 30; |
66 | 69 | ||
67 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 70 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
... | @@ -72,6 +75,8 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme | ... | @@ -72,6 +75,8 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme |
72 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 75 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
73 | protected IntentService intentService; | 76 | protected IntentService intentService; |
74 | 77 | ||
78 | + private final InternalPtPtIntentListener intentListener = new InternalPtPtIntentListener(); | ||
79 | + | ||
75 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 80 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
76 | protected CoreService coreService; | 81 | protected CoreService coreService; |
77 | 82 | ||
... | @@ -90,11 +95,13 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme | ... | @@ -90,11 +95,13 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme |
90 | providerService = providerRegistry.register(this); | 95 | providerService = providerRegistry.register(this); |
91 | appId = coreService.registerApplication(PTPT_INTENT_APPID); | 96 | appId = coreService.registerApplication(PTPT_INTENT_APPID); |
92 | 97 | ||
98 | + intentService.addListener(intentListener); | ||
93 | log.info("Started"); | 99 | log.info("Started"); |
94 | } | 100 | } |
95 | 101 | ||
96 | @Deactivate | 102 | @Deactivate |
97 | public void deactivate() { | 103 | public void deactivate() { |
104 | + intentService.removeListener(intentListener); | ||
98 | providerRegistry.unregister(this); | 105 | providerRegistry.unregister(this); |
99 | providerService = null; | 106 | providerService = null; |
100 | log.info("Stopped"); | 107 | log.info("Stopped"); |
... | @@ -105,8 +112,7 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme | ... | @@ -105,8 +112,7 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme |
105 | checkNotNull(networkId, NETWORK_ID_NULL); | 112 | checkNotNull(networkId, NETWORK_ID_NULL); |
106 | checkNotNull(src, CONNECT_POINT_NULL); | 113 | checkNotNull(src, CONNECT_POINT_NULL); |
107 | checkNotNull(dst, CONNECT_POINT_NULL); | 114 | checkNotNull(dst, CONNECT_POINT_NULL); |
108 | - String key = String.format(KEY_FORMAT, networkId.toString(), src.toString(), dst.toString()); | 115 | + Key intentKey = encodeKey(networkId, src, dst); |
109 | - Key intentKey = Key.of(key, appId); | ||
110 | 116 | ||
111 | List<Constraint> constraints = new ArrayList<>(); | 117 | List<Constraint> constraints = new ArrayList<>(); |
112 | constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN)); | 118 | constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN)); |
... | @@ -123,7 +129,7 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme | ... | @@ -123,7 +129,7 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme |
123 | intentService.submit(intent); | 129 | intentService.submit(intent); |
124 | 130 | ||
125 | // construct tunnelId from the key | 131 | // construct tunnelId from the key |
126 | - return TunnelId.valueOf(key); | 132 | + return TunnelId.valueOf(intentKey.toString()); |
127 | } | 133 | } |
128 | 134 | ||
129 | @Override | 135 | @Override |
... | @@ -133,20 +139,64 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme | ... | @@ -133,20 +139,64 @@ public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider impleme |
133 | Intent intent = intentService.getIntent(intentKey); | 139 | Intent intent = intentService.getIntent(intentKey); |
134 | checkNotNull(intent, INTENT_NULL); | 140 | checkNotNull(intent, INTENT_NULL); |
135 | intentService.withdraw(intent); | 141 | intentService.withdraw(intent); |
136 | - try { | 142 | + } |
137 | - int count = 0; | 143 | + |
138 | - // Loop waiting for the intent to go into a withdrawn or failed state | 144 | + private NetworkId decodeNetworkIdFromKey(Key intentKey) { |
139 | - // before attempting to purge it. | 145 | + // Extract the network identifier from the intent key |
140 | - while (++count <= MAX_WAIT_COUNT) { | 146 | + StringTokenizer tokenizer = new StringTokenizer(intentKey.toString(), ","); |
141 | - IntentState state = intentService.getIntentState(intentKey); | 147 | + String networkIdString = tokenizer.nextToken().substring(NETWORK_ID.length()); |
142 | - if ((state == IntentState.FAILED) || (state == IntentState.WITHDRAWN)) { | 148 | + return NetworkId.networkId(Integer.valueOf(networkIdString)); |
149 | + } | ||
150 | + | ||
151 | + private Key encodeKey(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | ||
152 | + String key = String.format(KEY_FORMAT, networkId, src, dst); | ||
153 | + return Key.of(key, appId); | ||
154 | + } | ||
155 | + | ||
156 | + private class InternalPtPtIntentListener implements IntentListener { | ||
157 | + @Override | ||
158 | + public void event(IntentEvent event) { | ||
159 | + PointToPointIntent intent = (PointToPointIntent) event.subject(); | ||
160 | + Key intentKey = intent.key(); | ||
161 | + | ||
162 | + // Ignore intent events that are not relevant. | ||
163 | + if (!isRelevant(event)) { | ||
164 | + return; | ||
165 | + } | ||
166 | + | ||
167 | + NetworkId networkId = decodeNetworkIdFromKey(intentKey); | ||
168 | + ConnectPoint src = intent.ingressPoint(); | ||
169 | + ConnectPoint dst = intent.egressPoint(); | ||
170 | + | ||
171 | + switch (event.type()) { | ||
172 | + case INSTALLED: | ||
173 | + providerService.tunnelUp(networkId, src, dst, TunnelId.valueOf(intentKey.toString())); | ||
174 | + break; | ||
175 | + case WITHDRAWN: | ||
143 | intentService.purge(intent); | 176 | intentService.purge(intent); |
177 | + // Fall through and notify the provider service that the tunnel is down | ||
178 | + // for both WITHDRAWN and FAILED intent event types. | ||
179 | + case FAILED: | ||
180 | + providerService.tunnelDown(networkId, src, dst, TunnelId.valueOf(intentKey.toString())); | ||
181 | + break; | ||
182 | + case INSTALL_REQ: | ||
183 | + case CORRUPT: | ||
184 | + case PURGED: | ||
185 | + break; // Not sure what do with these events, ignore for now. | ||
186 | + default: | ||
144 | break; | 187 | break; |
145 | - } | ||
146 | - sleep(1000); | ||
147 | } | 188 | } |
148 | - } catch (Exception e) { | 189 | + } |
149 | - log.error("Exception: " + e); | 190 | + |
191 | + @Override | ||
192 | + public boolean isRelevant(IntentEvent event) { | ||
193 | + PointToPointIntent intent = (PointToPointIntent) event.subject(); | ||
194 | + | ||
195 | + // Only events that are for this appId are relevent. | ||
196 | + if (intent.appId().equals(appId)) { | ||
197 | + return true; | ||
198 | + } | ||
199 | + return false; | ||
150 | } | 200 | } |
151 | } | 201 | } |
152 | } | 202 | } | ... | ... |
... | @@ -39,6 +39,7 @@ import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate; | ... | @@ -39,6 +39,7 @@ import org.onosproject.incubator.net.virtual.VirtualNetworkStoreDelegate; |
39 | import org.onosproject.incubator.net.virtual.VirtualPort; | 39 | import org.onosproject.incubator.net.virtual.VirtualPort; |
40 | import org.onosproject.net.ConnectPoint; | 40 | import org.onosproject.net.ConnectPoint; |
41 | import org.onosproject.net.DeviceId; | 41 | import org.onosproject.net.DeviceId; |
42 | +import org.onosproject.net.Link; | ||
42 | import org.onosproject.net.Port; | 43 | import org.onosproject.net.Port; |
43 | import org.onosproject.net.PortNumber; | 44 | import org.onosproject.net.PortNumber; |
44 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; | 45 | import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
... | @@ -140,7 +141,7 @@ public class VirtualNetworkManager | ... | @@ -140,7 +141,7 @@ public class VirtualNetworkManager |
140 | checkNotNull(networkId, NETWORK_NULL); | 141 | checkNotNull(networkId, NETWORK_NULL); |
141 | checkNotNull(src, LINK_POINT_NULL); | 142 | checkNotNull(src, LINK_POINT_NULL); |
142 | checkNotNull(dst, LINK_POINT_NULL); | 143 | checkNotNull(dst, LINK_POINT_NULL); |
143 | - VirtualLink virtualLink = store.addLink(networkId, src, dst, null); | 144 | + VirtualLink virtualLink = store.addLink(networkId, src, dst, Link.State.INACTIVE, null); |
144 | checkNotNull(virtualLink, VIRTUAL_LINK_NULL); | 145 | checkNotNull(virtualLink, VIRTUAL_LINK_NULL); |
145 | 146 | ||
146 | if (virtualLink.providerId() != null) { | 147 | if (virtualLink.providerId() != null) { |
... | @@ -148,7 +149,7 @@ public class VirtualNetworkManager | ... | @@ -148,7 +149,7 @@ public class VirtualNetworkManager |
148 | if (provider != null) { | 149 | if (provider != null) { |
149 | TunnelId tunnelId = provider.createTunnel(networkId, mapVirtualToPhysicalPort(networkId, src), | 150 | TunnelId tunnelId = provider.createTunnel(networkId, mapVirtualToPhysicalPort(networkId, src), |
150 | mapVirtualToPhysicalPort(networkId, dst)); | 151 | mapVirtualToPhysicalPort(networkId, dst)); |
151 | - store.updateLink(virtualLink, tunnelId); | 152 | + store.updateLink(virtualLink, tunnelId, Link.State.INACTIVE); |
152 | } | 153 | } |
153 | } | 154 | } |
154 | return virtualLink; | 155 | return virtualLink; |
... | @@ -173,6 +174,25 @@ public class VirtualNetworkManager | ... | @@ -173,6 +174,25 @@ public class VirtualNetworkManager |
173 | return null; | 174 | return null; |
174 | } | 175 | } |
175 | 176 | ||
177 | + /** | ||
178 | + * Maps the physical connect point to a virtual connect point. | ||
179 | + * | ||
180 | + * @param networkId network identifier | ||
181 | + * @param physicalCp physical connect point | ||
182 | + * @return virtual connect point | ||
183 | + */ | ||
184 | + private ConnectPoint mapPhysicalToVirtualToPort(NetworkId networkId, | ||
185 | + ConnectPoint physicalCp) { | ||
186 | + Set<VirtualPort> ports = store.getPorts(networkId, null); | ||
187 | + for (VirtualPort port : ports) { | ||
188 | + if (port.realizedBy().element().id().equals(physicalCp.elementId()) && | ||
189 | + port.realizedBy().number().equals(physicalCp.port())) { | ||
190 | + return new ConnectPoint(port.element().id(), port.number()); | ||
191 | + } | ||
192 | + } | ||
193 | + return null; | ||
194 | + } | ||
195 | + | ||
176 | @Override | 196 | @Override |
177 | public void removeVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | 197 | public void removeVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { |
178 | checkNotNull(networkId, NETWORK_NULL); | 198 | checkNotNull(networkId, NETWORK_NULL); |
... | @@ -226,7 +246,6 @@ public class VirtualNetworkManager | ... | @@ -226,7 +246,6 @@ public class VirtualNetworkManager |
226 | @Override | 246 | @Override |
227 | public Set<VirtualPort> getVirtualPorts(NetworkId networkId, DeviceId deviceId) { | 247 | public Set<VirtualPort> getVirtualPorts(NetworkId networkId, DeviceId deviceId) { |
228 | checkNotNull(networkId, NETWORK_NULL); | 248 | checkNotNull(networkId, NETWORK_NULL); |
229 | - checkNotNull(deviceId, DEVICE_NULL); | ||
230 | return store.getPorts(networkId, deviceId); | 249 | return store.getPorts(networkId, deviceId); |
231 | } | 250 | } |
232 | 251 | ||
... | @@ -251,13 +270,32 @@ public class VirtualNetworkManager | ... | @@ -251,13 +270,32 @@ public class VirtualNetworkManager |
251 | } | 270 | } |
252 | 271 | ||
253 | @Override | 272 | @Override |
254 | - public void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | 273 | + public void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { |
274 | + | ||
275 | + ConnectPoint srcVirtualCp = mapPhysicalToVirtualToPort(networkId, src); | ||
276 | + ConnectPoint dstVirtualCp = mapPhysicalToVirtualToPort(networkId, dst); | ||
277 | + if ((srcVirtualCp == null) || (dstVirtualCp == null)) { | ||
278 | + log.error("Src or dst virtual connection point was not found."); | ||
279 | + } | ||
255 | 280 | ||
281 | + VirtualLink virtualLink = store.getLink(networkId, srcVirtualCp, dstVirtualCp); | ||
282 | + if (virtualLink != null) { | ||
283 | + store.updateLink(virtualLink, tunnelId, Link.State.ACTIVE); | ||
284 | + } | ||
256 | } | 285 | } |
257 | 286 | ||
258 | @Override | 287 | @Override |
259 | - public void tunnelDown(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | 288 | + public void tunnelDown(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { |
289 | + ConnectPoint srcVirtualCp = mapPhysicalToVirtualToPort(networkId, src); | ||
290 | + ConnectPoint dstVirtualCp = mapPhysicalToVirtualToPort(networkId, dst); | ||
291 | + if ((srcVirtualCp == null) || (dstVirtualCp == null)) { | ||
292 | + log.error("Src or dst virtual connection point was not found."); | ||
293 | + } | ||
260 | 294 | ||
295 | + VirtualLink virtualLink = store.getLink(networkId, srcVirtualCp, dstVirtualCp); | ||
296 | + if (virtualLink != null) { | ||
297 | + store.updateLink(virtualLink, tunnelId, Link.State.INACTIVE); | ||
298 | + } | ||
261 | } | 299 | } |
262 | } | 300 | } |
263 | 301 | ... | ... |
... | @@ -16,7 +16,7 @@ | ... | @@ -16,7 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.incubator.net.virtual.impl; | 17 | package org.onosproject.incubator.net.virtual.impl; |
18 | 18 | ||
19 | -import com.google.common.collect.Sets; | 19 | +import com.google.common.collect.Lists; |
20 | import org.junit.After; | 20 | import org.junit.After; |
21 | import org.junit.Before; | 21 | import org.junit.Before; |
22 | import org.junit.Test; | 22 | import org.junit.Test; |
... | @@ -33,21 +33,29 @@ import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService; | ... | @@ -33,21 +33,29 @@ import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService; |
33 | import org.onosproject.net.ConnectPoint; | 33 | import org.onosproject.net.ConnectPoint; |
34 | import org.onosproject.net.DeviceId; | 34 | import org.onosproject.net.DeviceId; |
35 | import org.onosproject.net.PortNumber; | 35 | import org.onosproject.net.PortNumber; |
36 | +import org.onosproject.net.intent.FakeIntentManager; | ||
37 | +import org.onosproject.net.intent.FlowRuleIntent; | ||
36 | import org.onosproject.net.intent.Intent; | 38 | import org.onosproject.net.intent.Intent; |
37 | -import org.onosproject.net.intent.IntentService; | 39 | +import org.onosproject.net.intent.IntentCompiler; |
38 | -import org.onosproject.net.intent.IntentServiceAdapter; | 40 | +import org.onosproject.net.intent.IntentEvent; |
39 | -import org.onosproject.net.intent.IntentState; | 41 | +import org.onosproject.net.intent.IntentExtensionService; |
40 | -import org.onosproject.net.intent.Key; | 42 | +import org.onosproject.net.intent.IntentListener; |
43 | +import org.onosproject.net.intent.IntentTestsMocks; | ||
41 | import org.onosproject.net.intent.MockIdGenerator; | 44 | import org.onosproject.net.intent.MockIdGenerator; |
45 | +import org.onosproject.net.intent.PointToPointIntent; | ||
46 | +import org.onosproject.net.intent.TestableIntentService; | ||
42 | import org.onosproject.net.provider.AbstractProviderService; | 47 | import org.onosproject.net.provider.AbstractProviderService; |
43 | import org.onosproject.net.provider.ProviderId; | 48 | import org.onosproject.net.provider.ProviderId; |
44 | 49 | ||
50 | +import java.util.Collections; | ||
51 | +import java.util.List; | ||
45 | import java.util.Set; | 52 | import java.util.Set; |
53 | +import java.util.concurrent.Semaphore; | ||
54 | +import java.util.concurrent.TimeUnit; | ||
46 | import java.util.concurrent.atomic.AtomicLong; | 55 | import java.util.concurrent.atomic.AtomicLong; |
47 | 56 | ||
48 | import static org.easymock.EasyMock.*; | 57 | import static org.easymock.EasyMock.*; |
49 | -import static org.junit.Assert.assertEquals; | 58 | +import static org.junit.Assert.*; |
50 | -import static org.junit.Assert.assertNotNull; | ||
51 | 59 | ||
52 | /** | 60 | /** |
53 | * Junit tests for PtToPtIntentVirtualNetworkProvider. | 61 | * Junit tests for PtToPtIntentVirtualNetworkProvider. |
... | @@ -58,12 +66,19 @@ public class PtToPtIntentVirtualNetworkProviderTest { | ... | @@ -58,12 +66,19 @@ public class PtToPtIntentVirtualNetworkProviderTest { |
58 | private VirtualNetworkProviderRegistry providerRegistry; | 66 | private VirtualNetworkProviderRegistry providerRegistry; |
59 | 67 | ||
60 | private final VirtualNetworkRegistryAdapter virtualNetworkRegistry = new VirtualNetworkRegistryAdapter(); | 68 | private final VirtualNetworkRegistryAdapter virtualNetworkRegistry = new VirtualNetworkRegistryAdapter(); |
61 | - private IntentService intentService; | 69 | + private TestableIntentService intentService = new FakeIntentManager(); |
70 | + private TestListener listener = new TestListener(); | ||
71 | + protected TestIntentCompiler compiler = new TestIntentCompiler(); | ||
72 | + private IntentExtensionService intentExtensionService; | ||
62 | 73 | ||
63 | private static final ApplicationId APP_ID = | 74 | private static final ApplicationId APP_ID = |
64 | TestApplicationId.create(PtToPtIntentVirtualNetworkProvider.PTPT_INTENT_APPID); | 75 | TestApplicationId.create(PtToPtIntentVirtualNetworkProvider.PTPT_INTENT_APPID); |
65 | 76 | ||
66 | private IdGenerator idGenerator = new MockIdGenerator(); | 77 | private IdGenerator idGenerator = new MockIdGenerator(); |
78 | + private static final int MAX_WAIT_TIME = 5; | ||
79 | + private static final int MAX_PERMITS = 2; | ||
80 | + private static Semaphore created; | ||
81 | + private static Semaphore removed; | ||
67 | 82 | ||
68 | @Before | 83 | @Before |
69 | public void setUp() { | 84 | public void setUp() { |
... | @@ -77,18 +92,28 @@ public class PtToPtIntentVirtualNetworkProviderTest { | ... | @@ -77,18 +92,28 @@ public class PtToPtIntentVirtualNetworkProviderTest { |
77 | Intent.unbindIdGenerator(idGenerator); | 92 | Intent.unbindIdGenerator(idGenerator); |
78 | Intent.bindIdGenerator(idGenerator); | 93 | Intent.bindIdGenerator(idGenerator); |
79 | 94 | ||
80 | - intentService = new TestIntentService(); | 95 | + intentService.addListener(listener); |
81 | provider.intentService = intentService; | 96 | provider.intentService = intentService; |
97 | + | ||
98 | + // Register a compiler and an installer both setup for success. | ||
99 | + intentExtensionService = intentService; | ||
100 | + intentExtensionService.registerCompiler(PointToPointIntent.class, compiler); | ||
101 | + | ||
82 | provider.activate(); | 102 | provider.activate(); |
103 | + created = new Semaphore(0, true); | ||
104 | + removed = new Semaphore(0, true); | ||
83 | } | 105 | } |
84 | 106 | ||
85 | @After | 107 | @After |
86 | public void tearDown() { | 108 | public void tearDown() { |
109 | + Intent.unbindIdGenerator(idGenerator); | ||
110 | + intentService.removeListener(listener); | ||
87 | provider.deactivate(); | 111 | provider.deactivate(); |
88 | provider.providerRegistry = null; | 112 | provider.providerRegistry = null; |
89 | provider.coreService = null; | 113 | provider.coreService = null; |
90 | provider.intentService = null; | 114 | provider.intentService = null; |
91 | - Intent.unbindIdGenerator(idGenerator); | 115 | + created = null; |
116 | + removed = null; | ||
92 | } | 117 | } |
93 | 118 | ||
94 | @Test | 119 | @Test |
... | @@ -134,11 +159,30 @@ public class PtToPtIntentVirtualNetworkProviderTest { | ... | @@ -134,11 +159,30 @@ public class PtToPtIntentVirtualNetworkProviderTest { |
134 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId("device2"), PortNumber.portNumber(2)); | 159 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId("device2"), PortNumber.portNumber(2)); |
135 | 160 | ||
136 | TunnelId tunnelId = provider.createTunnel(networkId, src, dst); | 161 | TunnelId tunnelId = provider.createTunnel(networkId, src, dst); |
162 | + | ||
163 | + // Wait for the tunnel to go into an INSTALLED state, and that the tunnelUp method was called. | ||
164 | + try { | ||
165 | + if (!created.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) { | ||
166 | + fail("Failed to wait for tunnel to get installed."); | ||
167 | + } | ||
168 | + } catch (InterruptedException e) { | ||
169 | + fail("Semaphore exception during tunnel installation." + e.getMessage()); | ||
170 | + } | ||
171 | + | ||
137 | String key = String.format(PtToPtIntentVirtualNetworkProvider.KEY_FORMAT, | 172 | String key = String.format(PtToPtIntentVirtualNetworkProvider.KEY_FORMAT, |
138 | networkId.toString(), src.toString(), dst.toString()); | 173 | networkId.toString(), src.toString(), dst.toString()); |
139 | 174 | ||
140 | assertEquals("TunnelId does not match as expected.", key, tunnelId.toString()); | 175 | assertEquals("TunnelId does not match as expected.", key, tunnelId.toString()); |
141 | provider.destroyTunnel(networkId, tunnelId); | 176 | provider.destroyTunnel(networkId, tunnelId); |
177 | + | ||
178 | + // Wait for the tunnel to go into a WITHDRAWN state, and that the tunnelDown method was called. | ||
179 | + try { | ||
180 | + if (!removed.tryAcquire(MAX_PERMITS, MAX_WAIT_TIME, TimeUnit.SECONDS)) { | ||
181 | + fail("Failed to wait for tunnel to get removed."); | ||
182 | + } | ||
183 | + } catch (InterruptedException e) { | ||
184 | + fail("Semaphore exception during tunnel removal." + e.getMessage()); | ||
185 | + } | ||
142 | } | 186 | } |
143 | 187 | ||
144 | /** | 188 | /** |
... | @@ -176,16 +220,36 @@ public class PtToPtIntentVirtualNetworkProviderTest { | ... | @@ -176,16 +220,36 @@ public class PtToPtIntentVirtualNetworkProviderTest { |
176 | } | 220 | } |
177 | 221 | ||
178 | @Override | 222 | @Override |
179 | - public void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | 223 | + public void tunnelUp(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { |
180 | - | 224 | + // Release one permit on the created semaphore since the tunnelUp method was called. |
225 | + created.release(); | ||
181 | } | 226 | } |
182 | 227 | ||
183 | @Override | 228 | @Override |
184 | - public void tunnelDown(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | 229 | + public void tunnelDown(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { |
185 | - | 230 | + // Release one permit on the removed semaphore since the tunnelDown method was called. |
231 | + removed.release(); | ||
186 | } | 232 | } |
187 | } | 233 | } |
188 | 234 | ||
235 | + private static class TestListener implements IntentListener { | ||
236 | + | ||
237 | + @Override | ||
238 | + public void event(IntentEvent event) { | ||
239 | + switch (event.type()) { | ||
240 | + case INSTALLED: | ||
241 | + // Release one permit on the created semaphore since the Intent event was received. | ||
242 | + created.release(); | ||
243 | + break; | ||
244 | + case WITHDRAWN: | ||
245 | + // Release one permit on the removed semaphore since the Intent event was received. | ||
246 | + removed.release(); | ||
247 | + break; | ||
248 | + default: | ||
249 | + break; | ||
250 | + } | ||
251 | + } | ||
252 | + } | ||
189 | 253 | ||
190 | /** | 254 | /** |
191 | * Core service test class. | 255 | * Core service test class. |
... | @@ -205,55 +269,17 @@ public class PtToPtIntentVirtualNetworkProviderTest { | ... | @@ -205,55 +269,17 @@ public class PtToPtIntentVirtualNetworkProviderTest { |
205 | } | 269 | } |
206 | } | 270 | } |
207 | 271 | ||
208 | - /** | 272 | + private static class TestIntentCompiler implements IntentCompiler<PointToPointIntent> { |
209 | - * Represents a fake IntentService class that easily allows to store and | ||
210 | - * retrieve intents without implementing the IntentService logic. | ||
211 | - */ | ||
212 | - private class TestIntentService extends IntentServiceAdapter { | ||
213 | - | ||
214 | - private Set<Intent> intents; | ||
215 | - | ||
216 | - public TestIntentService() { | ||
217 | - intents = Sets.newHashSet(); | ||
218 | - } | ||
219 | - | ||
220 | - @Override | ||
221 | - public void submit(Intent intent) { | ||
222 | - intents.add(intent); | ||
223 | - } | ||
224 | - | ||
225 | - @Override | ||
226 | - public void withdraw(Intent intent) { | ||
227 | - } | ||
228 | - | ||
229 | - @Override | ||
230 | - public IntentState getIntentState(Key intentKey) { | ||
231 | - return IntentState.WITHDRAWN; | ||
232 | - } | ||
233 | - | ||
234 | @Override | 273 | @Override |
235 | - public void purge(Intent intent) { | 274 | + public List<Intent> compile(PointToPointIntent intent, List<Intent> installable) { |
236 | - intents.remove(intent); | 275 | + return Lists.newArrayList(new MockInstallableIntent()); |
237 | - } | ||
238 | - | ||
239 | - @Override | ||
240 | - public long getIntentCount() { | ||
241 | - return intents.size(); | ||
242 | } | 276 | } |
277 | + } | ||
243 | 278 | ||
244 | - @Override | 279 | + private static class MockInstallableIntent extends FlowRuleIntent { |
245 | - public Iterable<Intent> getIntents() { | ||
246 | - return intents; | ||
247 | - } | ||
248 | 280 | ||
249 | - @Override | 281 | + public MockInstallableIntent() { |
250 | - public Intent getIntent(Key intentKey) { | 282 | + super(APP_ID, Collections.singletonList(new IntentTestsMocks.MockFlowRule(100)), Collections.emptyList()); |
251 | - for (Intent intent : intents) { | ||
252 | - if (intent.key().equals(intentKey)) { | ||
253 | - return intent; | ||
254 | - } | ||
255 | - } | ||
256 | - return null; | ||
257 | } | 283 | } |
258 | } | 284 | } |
259 | } | 285 | } | ... | ... |
... | @@ -44,6 +44,7 @@ import org.onosproject.incubator.net.virtual.VirtualPort; | ... | @@ -44,6 +44,7 @@ import org.onosproject.incubator.net.virtual.VirtualPort; |
44 | import org.onosproject.net.ConnectPoint; | 44 | import org.onosproject.net.ConnectPoint; |
45 | import org.onosproject.net.Device; | 45 | import org.onosproject.net.Device; |
46 | import org.onosproject.net.DeviceId; | 46 | import org.onosproject.net.DeviceId; |
47 | +import org.onosproject.net.Link; | ||
47 | import org.onosproject.net.Port; | 48 | import org.onosproject.net.Port; |
48 | import org.onosproject.net.PortNumber; | 49 | import org.onosproject.net.PortNumber; |
49 | import org.onosproject.store.AbstractStore; | 50 | import org.onosproject.store.AbstractStore; |
... | @@ -295,6 +296,7 @@ public class DistributedVirtualNetworkStore | ... | @@ -295,6 +296,7 @@ public class DistributedVirtualNetworkStore |
295 | * @return true if the network identifier exists, false otherwise. | 296 | * @return true if the network identifier exists, false otherwise. |
296 | */ | 297 | */ |
297 | private boolean networkExists(NetworkId networkId) { | 298 | private boolean networkExists(NetworkId networkId) { |
299 | + checkNotNull(networkId, "The network identifier cannot be null."); | ||
298 | return (networkIdVirtualNetworkMap.containsKey(networkId)); | 300 | return (networkIdVirtualNetworkMap.containsKey(networkId)); |
299 | } | 301 | } |
300 | 302 | ||
... | @@ -339,7 +341,8 @@ public class DistributedVirtualNetworkStore | ... | @@ -339,7 +341,8 @@ public class DistributedVirtualNetworkStore |
339 | } | 341 | } |
340 | 342 | ||
341 | @Override | 343 | @Override |
342 | - public VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId realizedBy) { | 344 | + public VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, |
345 | + Link.State state, TunnelId realizedBy) { | ||
343 | checkState(networkExists(networkId), "The network has not been added."); | 346 | checkState(networkExists(networkId), "The network has not been added."); |
344 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); | 347 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); |
345 | if (virtualLinkSet == null) { | 348 | if (virtualLinkSet == null) { |
... | @@ -352,6 +355,7 @@ public class DistributedVirtualNetworkStore | ... | @@ -352,6 +355,7 @@ public class DistributedVirtualNetworkStore |
352 | .networkId(networkId) | 355 | .networkId(networkId) |
353 | .src(src) | 356 | .src(src) |
354 | .dst(dst) | 357 | .dst(dst) |
358 | + .state(state) | ||
355 | .tunnelId(realizedBy) | 359 | .tunnelId(realizedBy) |
356 | .build(); | 360 | .build(); |
357 | 361 | ||
... | @@ -361,7 +365,7 @@ public class DistributedVirtualNetworkStore | ... | @@ -361,7 +365,7 @@ public class DistributedVirtualNetworkStore |
361 | } | 365 | } |
362 | 366 | ||
363 | @Override | 367 | @Override |
364 | - public void updateLink(VirtualLink virtualLink, TunnelId tunnelId) { | 368 | + public void updateLink(VirtualLink virtualLink, TunnelId tunnelId, Link.State state) { |
365 | checkState(networkExists(virtualLink.networkId()), "The network has not been added."); | 369 | checkState(networkExists(virtualLink.networkId()), "The network has not been added."); |
366 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(virtualLink.networkId()); | 370 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(virtualLink.networkId()); |
367 | if (virtualLinkSet == null) { | 371 | if (virtualLinkSet == null) { |
... | @@ -374,6 +378,7 @@ public class DistributedVirtualNetworkStore | ... | @@ -374,6 +378,7 @@ public class DistributedVirtualNetworkStore |
374 | .src(virtualLink.src()) | 378 | .src(virtualLink.src()) |
375 | .dst(virtualLink.dst()) | 379 | .dst(virtualLink.dst()) |
376 | .tunnelId(tunnelId) | 380 | .tunnelId(tunnelId) |
381 | + .state(state) | ||
377 | .build(); | 382 | .build(); |
378 | 383 | ||
379 | virtualLinkSet.add(newVirtualLink); | 384 | virtualLinkSet.add(newVirtualLink); |
... | @@ -471,16 +476,8 @@ public class DistributedVirtualNetworkStore | ... | @@ -471,16 +476,8 @@ public class DistributedVirtualNetworkStore |
471 | return ImmutableSet.copyOf(virtualLinkSet); | 476 | return ImmutableSet.copyOf(virtualLinkSet); |
472 | } | 477 | } |
473 | 478 | ||
474 | - /** | 479 | + @Override |
475 | - * Returns the virtual link matching the network identifier, source connect point, | 480 | + public VirtualLink getLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { |
476 | - * and destination connect point. | ||
477 | - * | ||
478 | - * @param networkId network identifier | ||
479 | - * @param src source connect point | ||
480 | - * @param dst destination connect point | ||
481 | - * @return virtual link | ||
482 | - */ | ||
483 | - private VirtualLink getLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | ||
484 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); | 481 | Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); |
485 | if (virtualLinkSet == null) { | 482 | if (virtualLinkSet == null) { |
486 | return null; | 483 | return null; |
... | @@ -504,6 +501,10 @@ public class DistributedVirtualNetworkStore | ... | @@ -504,6 +501,10 @@ public class DistributedVirtualNetworkStore |
504 | virtualPortSet = new HashSet<>(); | 501 | virtualPortSet = new HashSet<>(); |
505 | } | 502 | } |
506 | 503 | ||
504 | + if (deviceId == null) { | ||
505 | + return ImmutableSet.copyOf(virtualPortSet); | ||
506 | + } | ||
507 | + | ||
507 | Set<VirtualPort> portSet = new HashSet<>(); | 508 | Set<VirtualPort> portSet = new HashSet<>(); |
508 | virtualPortSet.forEach(virtualPort -> { | 509 | virtualPortSet.forEach(virtualPort -> { |
509 | if (virtualPort.element().id().equals(deviceId)) { | 510 | if (virtualPort.element().id().equals(deviceId)) { | ... | ... |
-
Please register or login to post a comment