Committed by
Gerrit Code Review
ONOS-3633 - Implementation of virtual network point to point intent provider.
Change-Id: Ie2c1e5ac278bc0dd6259479c44dd92b9b625e90b
Showing
29 changed files
with
818 additions
and
151 deletions
... | @@ -20,7 +20,6 @@ import org.apache.karaf.shell.commands.Argument; | ... | @@ -20,7 +20,6 @@ import org.apache.karaf.shell.commands.Argument; |
20 | import org.apache.karaf.shell.commands.Command; | 20 | import org.apache.karaf.shell.commands.Command; |
21 | import org.apache.karaf.shell.commands.Option; | 21 | import org.apache.karaf.shell.commands.Option; |
22 | import org.onosproject.cli.AbstractShellCommand; | 22 | import org.onosproject.cli.AbstractShellCommand; |
23 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
24 | import org.onosproject.incubator.net.virtual.NetworkId; | 23 | import org.onosproject.incubator.net.virtual.NetworkId; |
25 | import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService; | 24 | import org.onosproject.incubator.net.virtual.VirtualNetworkAdminService; |
26 | import org.onosproject.net.ConnectPoint; | 25 | import org.onosproject.net.ConnectPoint; |
... | @@ -65,12 +64,10 @@ public class VirtualLinkCreateCommand extends AbstractShellCommand { | ... | @@ -65,12 +64,10 @@ public class VirtualLinkCreateCommand extends AbstractShellCommand { |
65 | VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class); | 64 | VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class); |
66 | ConnectPoint src = new ConnectPoint(DeviceId.deviceId(srcDeviceId), PortNumber.portNumber(srcPortNum)); | 65 | ConnectPoint src = new ConnectPoint(DeviceId.deviceId(srcDeviceId), PortNumber.portNumber(srcPortNum)); |
67 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(dstDeviceId), PortNumber.portNumber(dstPortNum)); | 66 | ConnectPoint dst = new ConnectPoint(DeviceId.deviceId(dstDeviceId), PortNumber.portNumber(dstPortNum)); |
68 | - //TODO use a real/valid tunnel ID | ||
69 | - TunnelId tunnelId = TunnelId.valueOf(0); | ||
70 | 67 | ||
71 | - service.createVirtualLink(NetworkId.networkId(networkId), src, dst, tunnelId); | 68 | + service.createVirtualLink(NetworkId.networkId(networkId), src, dst); |
72 | if (bidirectional) { | 69 | if (bidirectional) { |
73 | - service.createVirtualLink(NetworkId.networkId(networkId), dst, src, tunnelId); | 70 | + service.createVirtualLink(NetworkId.networkId(networkId), dst, src); |
74 | } | 71 | } |
75 | print("Virtual link successfully created."); | 72 | print("Virtual link successfully created."); |
76 | } | 73 | } | ... | ... |
... | @@ -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"; | 37 | + "src=%s, dst=%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) |
... | @@ -65,6 +65,7 @@ public class VirtualLinkListCommand extends AbstractShellCommand { | ... | @@ -65,6 +65,7 @@ public class VirtualLinkListCommand extends AbstractShellCommand { |
65 | * @param virtualLink virtual link | 65 | * @param virtualLink virtual link |
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.tunnelId() == null ? null : virtualLink.tunnelId().toString()); | ||
69 | } | 70 | } |
70 | } | 71 | } | ... | ... |
... | @@ -148,7 +148,7 @@ public class DefaultLink extends AbstractProjectableModel implements Link { | ... | @@ -148,7 +148,7 @@ public class DefaultLink extends AbstractProjectableModel implements Link { |
148 | /** | 148 | /** |
149 | * Builder for DefaultLink objects. | 149 | * Builder for DefaultLink objects. |
150 | */ | 150 | */ |
151 | - public static final class Builder { | 151 | + public static class Builder { |
152 | private ProviderId providerId; | 152 | private ProviderId providerId; |
153 | private Annotations annotations = EMPTY; | 153 | private Annotations annotations = EMPTY; |
154 | private ConnectPoint src; | 154 | private ConnectPoint src; |
... | @@ -157,7 +157,7 @@ public class DefaultLink extends AbstractProjectableModel implements Link { | ... | @@ -157,7 +157,7 @@ public class DefaultLink extends AbstractProjectableModel implements Link { |
157 | private State state = ACTIVE; | 157 | private State state = ACTIVE; |
158 | private boolean isExpected = false; | 158 | private boolean isExpected = false; |
159 | 159 | ||
160 | - private Builder() { | 160 | + protected Builder() { |
161 | // Hide constructor | 161 | // Hide constructor |
162 | } | 162 | } |
163 | 163 | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
1 | package org.onosproject.codec.impl; | 17 | package org.onosproject.codec.impl; |
2 | 18 | ||
3 | import com.fasterxml.jackson.databind.node.ObjectNode; | 19 | import com.fasterxml.jackson.databind.node.ObjectNode; |
4 | import org.onosproject.codec.CodecContext; | 20 | import org.onosproject.codec.CodecContext; |
5 | import org.onosproject.codec.JsonCodec; | 21 | import org.onosproject.codec.JsonCodec; |
6 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
7 | import org.onosproject.incubator.net.virtual.DefaultVirtualLink; | 22 | import org.onosproject.incubator.net.virtual.DefaultVirtualLink; |
8 | import org.onosproject.incubator.net.virtual.NetworkId; | 23 | import org.onosproject.incubator.net.virtual.NetworkId; |
9 | import org.onosproject.incubator.net.virtual.VirtualLink; | 24 | import org.onosproject.incubator.net.virtual.VirtualLink; |
... | @@ -19,7 +34,6 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> { | ... | @@ -19,7 +34,6 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> { |
19 | 34 | ||
20 | // JSON field names | 35 | // JSON field names |
21 | private static final String NETWORK_ID = "networkId"; | 36 | private static final String NETWORK_ID = "networkId"; |
22 | - private static final String TUNNEL_ID = "tunnelId"; | ||
23 | 37 | ||
24 | private static final String NULL_OBJECT_MSG = "VirtualLink cannot be null"; | 38 | private static final String NULL_OBJECT_MSG = "VirtualLink cannot be null"; |
25 | private static final String MISSING_MEMBER_MSG = " member is required in VirtualLink"; | 39 | private static final String MISSING_MEMBER_MSG = " member is required in VirtualLink"; |
... | @@ -31,10 +45,6 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> { | ... | @@ -31,10 +45,6 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> { |
31 | JsonCodec<Link> codec = context.codec(Link.class); | 45 | JsonCodec<Link> codec = context.codec(Link.class); |
32 | ObjectNode result = codec.encode(vLink, context); | 46 | ObjectNode result = codec.encode(vLink, context); |
33 | result.put(NETWORK_ID, vLink.networkId().toString()); | 47 | result.put(NETWORK_ID, vLink.networkId().toString()); |
34 | - // TODO check if tunnelId needs to be part of VirtualLink interface. | ||
35 | - if (vLink instanceof DefaultVirtualLink) { | ||
36 | - result.put(TUNNEL_ID, ((DefaultVirtualLink) vLink).tunnelId().toString()); | ||
37 | - } | ||
38 | return result; | 48 | return result; |
39 | } | 49 | } |
40 | 50 | ||
... | @@ -46,16 +56,17 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> { | ... | @@ -46,16 +56,17 @@ public class VirtualLinkCodec extends JsonCodec<VirtualLink> { |
46 | JsonCodec<Link> codec = context.codec(Link.class); | 56 | JsonCodec<Link> codec = context.codec(Link.class); |
47 | Link link = codec.decode(json, context); | 57 | Link link = codec.decode(json, context); |
48 | NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json))); | 58 | NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json))); |
49 | - String tunnelIdStr = json.path(TUNNEL_ID).asText(); | 59 | + return DefaultVirtualLink.builder() |
50 | - TunnelId tunnelId = tunnelIdStr != null ? TunnelId.valueOf(tunnelIdStr) | 60 | + .networkId(nId) |
51 | - : TunnelId.valueOf(0); | 61 | + .src(link.src()) |
52 | - return new DefaultVirtualLink(nId, link.src(), link.dst(), tunnelId); | 62 | + .dst(link.dst()) |
63 | + .build(); | ||
53 | } | 64 | } |
54 | 65 | ||
55 | /** | 66 | /** |
56 | * Extract member from JSON ObjectNode. | 67 | * Extract member from JSON ObjectNode. |
57 | * | 68 | * |
58 | - * @param key key for which value is needed | 69 | + * @param key key for which value is needed |
59 | * @param json JSON ObjectNode | 70 | * @param json JSON ObjectNode |
60 | * @return member value | 71 | * @return member value |
61 | */ | 72 | */ | ... | ... |
... | @@ -23,39 +23,35 @@ import org.onlab.util.Identifier; | ... | @@ -23,39 +23,35 @@ import org.onlab.util.Identifier; |
23 | * Representation of a Tunnel Id. | 23 | * Representation of a Tunnel Id. |
24 | */ | 24 | */ |
25 | @Beta | 25 | @Beta |
26 | -public final class TunnelId extends Identifier<Long> { | 26 | +public final class TunnelId extends Identifier<String> { |
27 | /** | 27 | /** |
28 | * Creates an tunnel identifier from the specified tunnel. | 28 | * Creates an tunnel identifier from the specified tunnel. |
29 | * | 29 | * |
30 | - * @param value long value | 30 | + * @param value string value |
31 | * @return tunnel identifier | 31 | * @return tunnel identifier |
32 | */ | 32 | */ |
33 | - public static TunnelId valueOf(long value) { | ||
34 | - return new TunnelId(value); | ||
35 | - } | ||
36 | - | ||
37 | public static TunnelId valueOf(String value) { | 33 | public static TunnelId valueOf(String value) { |
38 | - return new TunnelId(Long.parseLong(value)); | 34 | + return new TunnelId(value); |
39 | } | 35 | } |
40 | 36 | ||
41 | /** | 37 | /** |
42 | * Constructor for serializer. | 38 | * Constructor for serializer. |
43 | */ | 39 | */ |
44 | TunnelId() { | 40 | TunnelId() { |
45 | - super(0L); | 41 | + super("0"); |
46 | } | 42 | } |
47 | 43 | ||
48 | /** | 44 | /** |
49 | - * Constructs the ID corresponding to a given long value. | 45 | + * Constructs the ID corresponding to a given string value. |
50 | * | 46 | * |
51 | * @param value the underlying value of this ID | 47 | * @param value the underlying value of this ID |
52 | */ | 48 | */ |
53 | - TunnelId(long value) { | 49 | + TunnelId(String value) { |
54 | super(value); | 50 | super(value); |
55 | } | 51 | } |
56 | 52 | ||
57 | @Override | 53 | @Override |
58 | public String toString() { | 54 | public String toString() { |
59 | - return "0x" + Long.toHexString(identifier); | 55 | + return id(); |
60 | } | 56 | } |
61 | } | 57 | } | ... | ... |
... | @@ -25,27 +25,28 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -25,27 +25,28 @@ import org.onosproject.net.provider.ProviderId; |
25 | import java.util.Objects; | 25 | import java.util.Objects; |
26 | 26 | ||
27 | import static com.google.common.base.MoreObjects.toStringHelper; | 27 | import static com.google.common.base.MoreObjects.toStringHelper; |
28 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
28 | 29 | ||
29 | /** | 30 | /** |
30 | * Default representation of a virtual link. | 31 | * Default representation of a virtual link. |
31 | */ | 32 | */ |
32 | public final class DefaultVirtualLink extends DefaultLink implements VirtualLink { | 33 | public final class DefaultVirtualLink extends DefaultLink implements VirtualLink { |
33 | 34 | ||
34 | - private static final String VIRTUAL = "virtual"; | 35 | + private static final String VIRTUAL = "virtualLink"; |
35 | - private static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL); | 36 | + public static final ProviderId PID = new ProviderId(VIRTUAL, VIRTUAL); |
36 | 37 | ||
37 | private final NetworkId networkId; | 38 | private final NetworkId networkId; |
38 | private final TunnelId tunnelId; | 39 | private final TunnelId tunnelId; |
39 | 40 | ||
40 | /** | 41 | /** |
41 | - * Constructor for a default virtual link. | 42 | + * Private constructor for a default virtual link. |
42 | * | 43 | * |
43 | * @param networkId network identifier | 44 | * @param networkId network identifier |
44 | * @param src source connection point | 45 | * @param src source connection point |
45 | * @param dst destination connection point | 46 | * @param dst destination connection point |
46 | * @param tunnelId tunnel identifier | 47 | * @param tunnelId tunnel identifier |
47 | */ | 48 | */ |
48 | - public DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { | 49 | + private DefaultVirtualLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId tunnelId) { |
49 | super(PID, src, dst, Type.VIRTUAL, DefaultAnnotations.builder().build()); | 50 | super(PID, src, dst, Type.VIRTUAL, DefaultAnnotations.builder().build()); |
50 | this.networkId = networkId; | 51 | this.networkId = networkId; |
51 | this.tunnelId = tunnelId; | 52 | this.tunnelId = tunnelId; |
... | @@ -88,4 +89,84 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink | ... | @@ -88,4 +89,84 @@ public final class DefaultVirtualLink extends DefaultLink implements VirtualLink |
88 | public String toString() { | 89 | public String toString() { |
89 | return toStringHelper(this).add("networkId", networkId).add("tunnelId", tunnelId).toString(); | 90 | return toStringHelper(this).add("networkId", networkId).add("tunnelId", tunnelId).toString(); |
90 | } | 91 | } |
92 | + | ||
93 | + /** | ||
94 | + * Creates a new default virtual link builder. | ||
95 | + * | ||
96 | + * @return default virtual link builder | ||
97 | + */ | ||
98 | + public static Builder builder() { | ||
99 | + return new Builder(); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Builder for DefaultVirtualLink objects. | ||
104 | + */ | ||
105 | + public static final class Builder extends DefaultLink.Builder { | ||
106 | + private NetworkId networkId; | ||
107 | + private ConnectPoint src; | ||
108 | + private ConnectPoint dst; | ||
109 | + private TunnelId tunnelId; | ||
110 | + | ||
111 | + private Builder() { | ||
112 | + // Hide constructor | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Sets the network identifier to be used by the builder. | ||
117 | + * | ||
118 | + * @param networkId network identifier | ||
119 | + * @return self | ||
120 | + */ | ||
121 | + public Builder networkId(NetworkId networkId) { | ||
122 | + this.networkId = networkId; | ||
123 | + return this; | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * Sets the source connect point to be used by the builder. | ||
128 | + * | ||
129 | + * @param src source connect point | ||
130 | + * @return self | ||
131 | + */ | ||
132 | + public Builder src(ConnectPoint src) { | ||
133 | + this.src = src; | ||
134 | + return this; | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * Sets the destination connect point to be used by the builder. | ||
139 | + * | ||
140 | + * @param dst new destination connect point | ||
141 | + * @return self | ||
142 | + */ | ||
143 | + public Builder dst(ConnectPoint dst) { | ||
144 | + this.dst = dst; | ||
145 | + return this; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Sets the tunnel identifier to be used by the builder. | ||
150 | + * | ||
151 | + * @param tunnelId tunnel identifier | ||
152 | + * @return self | ||
153 | + */ | ||
154 | + public Builder tunnelId(TunnelId tunnelId) { | ||
155 | + this.tunnelId = tunnelId; | ||
156 | + return this; | ||
157 | + } | ||
158 | + | ||
159 | + /** | ||
160 | + * Builds a default virtual link object from the accumulated parameters. | ||
161 | + * | ||
162 | + * @return default virtual link object | ||
163 | + */ | ||
164 | + public DefaultVirtualLink build() { | ||
165 | + checkNotNull(src, "Source connect point cannot be null"); | ||
166 | + checkNotNull(dst, "Destination connect point cannot be null"); | ||
167 | + checkNotNull(networkId, "Network Id cannot be null"); | ||
168 | + | ||
169 | + return new DefaultVirtualLink(networkId, src, dst, tunnelId); | ||
170 | + } | ||
171 | + } | ||
91 | } | 172 | } | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.incubator.net.virtual; | 16 | package org.onosproject.incubator.net.virtual; |
17 | 17 | ||
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
19 | import org.onosproject.net.Link; | 20 | import org.onosproject.net.Link; |
20 | 21 | ||
21 | /** | 22 | /** |
... | @@ -23,4 +24,10 @@ import org.onosproject.net.Link; | ... | @@ -23,4 +24,10 @@ import org.onosproject.net.Link; |
23 | */ | 24 | */ |
24 | @Beta | 25 | @Beta |
25 | public interface VirtualLink extends VirtualElement, Link { | 26 | public interface VirtualLink extends VirtualElement, Link { |
27 | + /** | ||
28 | + * Returns the tunnel identifier to which this virtual link belongs. | ||
29 | + * | ||
30 | + * @return tunnel identifier | ||
31 | + */ | ||
32 | + TunnelId tunnelId(); | ||
26 | } | 33 | } | ... | ... |
... | @@ -16,7 +16,6 @@ | ... | @@ -16,7 +16,6 @@ |
16 | package org.onosproject.incubator.net.virtual; | 16 | package org.onosproject.incubator.net.virtual; |
17 | 17 | ||
18 | import com.google.common.annotations.Beta; | 18 | import com.google.common.annotations.Beta; |
19 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
20 | import org.onosproject.net.ConnectPoint; | 19 | import org.onosproject.net.ConnectPoint; |
21 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
22 | import org.onosproject.net.Port; | 21 | import org.onosproject.net.Port; |
... | @@ -96,13 +95,11 @@ public interface VirtualNetworkAdminService extends VirtualNetworkService { | ... | @@ -96,13 +95,11 @@ public interface VirtualNetworkAdminService extends VirtualNetworkService { |
96 | * @param networkId network identifier | 95 | * @param networkId network identifier |
97 | * @param src source connection point | 96 | * @param src source connection point |
98 | * @param dst destination connection point | 97 | * @param dst destination connection point |
99 | - * @param realizedBy identifier of the tunnel using which this link is realized | ||
100 | * @return newly created virtual link | 98 | * @return newly created virtual link |
101 | * @throws org.onlab.util.ItemNotFoundException if no such network found | 99 | * @throws org.onlab.util.ItemNotFoundException if no such network found |
102 | */ | 100 | */ |
103 | VirtualLink createVirtualLink(NetworkId networkId, | 101 | VirtualLink createVirtualLink(NetworkId networkId, |
104 | - ConnectPoint src, ConnectPoint dst, | 102 | + ConnectPoint src, ConnectPoint dst); |
105 | - TunnelId realizedBy); | ||
106 | 103 | ||
107 | // TODO: Discuss whether we should provide an alternate createVirtualLink | 104 | // TODO: Discuss whether we should provide an alternate createVirtualLink |
108 | // which is backed by a Path instead; I'm leaning towards not doing that. | 105 | // which is backed by a Path instead; I'm leaning towards not doing that. |
... | @@ -121,11 +118,11 @@ public interface VirtualNetworkAdminService extends VirtualNetworkService { | ... | @@ -121,11 +118,11 @@ public interface VirtualNetworkAdminService extends VirtualNetworkService { |
121 | * Creates a new virtual port on the specified device. | 118 | * Creates a new virtual port on the specified device. |
122 | * | 119 | * |
123 | * @param networkId network identifier | 120 | * @param networkId network identifier |
124 | - * @param deviceId device identifier | 121 | + * @param deviceId virtual device identifier |
125 | - * @param portNumber port number | 122 | + * @param portNumber virtual port number |
126 | - * @param realizedBy underlying port using which this virtual port is realized | 123 | + * @param realizedBy underlying physical port using which this virtual port is realized |
127 | * @return newly created port | 124 | * @return newly created port |
128 | - * @throws org.onlab.util.ItemNotFoundException if no such network or device found | 125 | + * @throws org.onlab.util.ItemNotFoundException if no such network or device is found |
129 | */ | 126 | */ |
130 | VirtualPort createVirtualPort(NetworkId networkId, DeviceId deviceId, | 127 | VirtualPort createVirtualPort(NetworkId networkId, DeviceId deviceId, |
131 | PortNumber portNumber, Port realizedBy); | 128 | PortNumber portNumber, Port realizedBy); | ... | ... |
... | @@ -89,11 +89,18 @@ public interface VirtualNetworkStore | ... | @@ -89,11 +89,18 @@ public interface VirtualNetworkStore |
89 | * @param networkId network identifier | 89 | * @param networkId network identifier |
90 | * @param src source end-point of the link | 90 | * @param src source end-point of the link |
91 | * @param dst destination end-point of the link | 91 | * @param dst destination end-point of the link |
92 | - * @param realizedBy underlying tunnel using which this link is realized | 92 | + * @param realizedBy underlying tunnel identifier using which this link is realized |
93 | * @return the virtual link | 93 | * @return the virtual link |
94 | */ | 94 | */ |
95 | - VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, | 95 | + VirtualLink addLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst, TunnelId realizedBy); |
96 | - TunnelId realizedBy); | 96 | + |
97 | + /** | ||
98 | + * Updates the tunnelId in the virtual link. | ||
99 | + * | ||
100 | + * @param virtualLink virtual link | ||
101 | + * @param tunnelId tunnel identifier | ||
102 | + */ | ||
103 | + void updateLink(VirtualLink virtualLink, TunnelId tunnelId); | ||
97 | 104 | ||
98 | /** | 105 | /** |
99 | * Removes the specified link from the store. | 106 | * Removes the specified link from the store. |
... | @@ -101,8 +108,9 @@ public interface VirtualNetworkStore | ... | @@ -101,8 +108,9 @@ public interface VirtualNetworkStore |
101 | * @param networkId network identifier | 108 | * @param networkId network identifier |
102 | * @param src source connection point | 109 | * @param src source connection point |
103 | * @param dst destination connection point | 110 | * @param dst destination connection point |
111 | + * @return the virtual link | ||
104 | */ | 112 | */ |
105 | - void removeLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst); | 113 | + VirtualLink removeLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst); |
106 | 114 | ||
107 | /** | 115 | /** |
108 | * Adds a new virtual port to the network. | 116 | * Adds a new virtual port to the network. | ... | ... |
... | @@ -44,7 +44,7 @@ public class DefaultTunnelTest { | ... | @@ -44,7 +44,7 @@ public class DefaultTunnelTest { |
44 | .valueOf(32421)); | 44 | .valueOf(32421)); |
45 | DefaultGroupId groupId = new DefaultGroupId(92034); | 45 | DefaultGroupId groupId = new DefaultGroupId(92034); |
46 | TunnelName tunnelName = TunnelName.tunnelName("TunnelName"); | 46 | TunnelName tunnelName = TunnelName.tunnelName("TunnelName"); |
47 | - TunnelId tunnelId = TunnelId.valueOf(41654654); | 47 | + TunnelId tunnelId = TunnelId.valueOf("41654654"); |
48 | ProviderId producerName1 = new ProviderId("producer1", "13"); | 48 | ProviderId producerName1 = new ProviderId("producer1", "13"); |
49 | ProviderId producerName2 = new ProviderId("producer2", "13"); | 49 | ProviderId producerName2 = new ProviderId("producer2", "13"); |
50 | Tunnel p1 = new DefaultTunnel(producerName1, src, dst, Tunnel.Type.VXLAN, | 50 | Tunnel p1 = new DefaultTunnel(producerName1, src, dst, Tunnel.Type.VXLAN, | ... | ... |
... | @@ -48,7 +48,7 @@ public class TunnelEventTest { | ... | @@ -48,7 +48,7 @@ public class TunnelEventTest { |
48 | .valueOf(32421)); | 48 | .valueOf(32421)); |
49 | DefaultGroupId groupId = new DefaultGroupId(92034); | 49 | DefaultGroupId groupId = new DefaultGroupId(92034); |
50 | TunnelName tunnelName = TunnelName.tunnelName("TunnelName"); | 50 | TunnelName tunnelName = TunnelName.tunnelName("TunnelName"); |
51 | - TunnelId tunnelId = TunnelId.valueOf(41654654); | 51 | + TunnelId tunnelId = TunnelId.valueOf("41654654"); |
52 | ProviderId producerName1 = new ProviderId("producer1", "13"); | 52 | ProviderId producerName1 = new ProviderId("producer1", "13"); |
53 | Tunnel p1 = new DefaultTunnel(producerName1, src, dst, Tunnel.Type.VXLAN, | 53 | Tunnel p1 = new DefaultTunnel(producerName1, src, dst, Tunnel.Type.VXLAN, |
54 | Tunnel.State.ACTIVE, groupId, tunnelId, | 54 | Tunnel.State.ACTIVE, groupId, tunnelId, | ... | ... |
... | @@ -30,9 +30,9 @@ import com.google.common.testing.EqualsTester; | ... | @@ -30,9 +30,9 @@ import com.google.common.testing.EqualsTester; |
30 | */ | 30 | */ |
31 | public class TunnelIdTest { | 31 | public class TunnelIdTest { |
32 | 32 | ||
33 | - final TunnelId tunnelId1 = TunnelId.valueOf(1); | 33 | + final TunnelId tunnelId1 = TunnelId.valueOf("1"); |
34 | - final TunnelId sameAstunnelId1 = TunnelId.valueOf(1); | 34 | + final TunnelId sameAstunnelId1 = TunnelId.valueOf("1"); |
35 | - final TunnelId tunnelId2 = TunnelId.valueOf(2); | 35 | + final TunnelId tunnelId2 = TunnelId.valueOf("2"); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Checks that the TunnelId class is immutable. | 38 | * Checks that the TunnelId class is immutable. |
... | @@ -58,7 +58,7 @@ public class TunnelIdTest { | ... | @@ -58,7 +58,7 @@ public class TunnelIdTest { |
58 | */ | 58 | */ |
59 | @Test | 59 | @Test |
60 | public void testConstruction() { | 60 | public void testConstruction() { |
61 | - final long tunnelIdValue = 7777L; | 61 | + final String tunnelIdValue = "7777"; |
62 | final TunnelId tunnelId = TunnelId.valueOf(tunnelIdValue); | 62 | final TunnelId tunnelId = TunnelId.valueOf(tunnelIdValue); |
63 | assertThat(tunnelId, is(notNullValue())); | 63 | assertThat(tunnelId, is(notNullValue())); |
64 | assertThat(tunnelId.id(), is(tunnelIdValue)); | 64 | assertThat(tunnelId.id(), is(tunnelIdValue)); | ... | ... |
... | @@ -45,7 +45,7 @@ public class TunnelSubscriptionTest { | ... | @@ -45,7 +45,7 @@ public class TunnelSubscriptionTest { |
45 | TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421)); | 45 | TunnelEndPoint dst = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(32421)); |
46 | ApplicationId appId = new DefaultApplicationId(243, "test"); | 46 | ApplicationId appId = new DefaultApplicationId(243, "test"); |
47 | ApplicationId appId2 = new DefaultApplicationId(2431, "test1"); | 47 | ApplicationId appId2 = new DefaultApplicationId(2431, "test1"); |
48 | - TunnelId tunnelId = TunnelId.valueOf(41654654); | 48 | + TunnelId tunnelId = TunnelId.valueOf("41654654"); |
49 | TunnelSubscription p1 = new TunnelSubscription(appId, src, dst, tunnelId, Tunnel.Type.VXLAN, | 49 | TunnelSubscription p1 = new TunnelSubscription(appId, src, dst, tunnelId, Tunnel.Type.VXLAN, |
50 | null); | 50 | null); |
51 | TunnelSubscription p2 = new TunnelSubscription(appId, src, dst, tunnelId, Tunnel.Type.VXLAN, | 51 | TunnelSubscription p2 = new TunnelSubscription(appId, src, dst, tunnelId, Tunnel.Type.VXLAN, | ... | ... |
... | @@ -40,6 +40,60 @@ public class DefaultVirtualLinkTest { | ... | @@ -40,6 +40,60 @@ public class DefaultVirtualLinkTest { |
40 | assertThatClassIsImmutable(DefaultVirtualLink.class); | 40 | assertThatClassIsImmutable(DefaultVirtualLink.class); |
41 | } | 41 | } |
42 | 42 | ||
43 | + /** | ||
44 | + * Tests the DefaultVirtualLink Builder to ensure that the src cannot be null. | ||
45 | + */ | ||
46 | + @Test(expected = NullPointerException.class) | ||
47 | + public void testBuilderNullSrc() { | ||
48 | + DefaultVirtualDevice device1 = | ||
49 | + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1)); | ||
50 | + DefaultVirtualDevice device2 = | ||
51 | + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2)); | ||
52 | + ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1)); | ||
53 | + ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2)); | ||
54 | + | ||
55 | + DefaultVirtualLink.builder() | ||
56 | + .src(null) | ||
57 | + .build(); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Tests the DefaultVirtualLink Builder to ensure that the dst cannot be null. | ||
62 | + */ | ||
63 | + @Test(expected = NullPointerException.class) | ||
64 | + public void testBuilderNullDst() { | ||
65 | + DefaultVirtualDevice device1 = | ||
66 | + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1)); | ||
67 | + DefaultVirtualDevice device2 = | ||
68 | + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2)); | ||
69 | + ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1)); | ||
70 | + ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2)); | ||
71 | + | ||
72 | + DefaultVirtualLink.builder() | ||
73 | + .dst(null) | ||
74 | + .build(); | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * Tests the DefaultVirtualLink Builder to ensure that the networkId cannot be null. | ||
79 | + */ | ||
80 | + @Test(expected = NullPointerException.class) | ||
81 | + public void testBuilderNullNetworkId() { | ||
82 | + DefaultVirtualDevice device1 = | ||
83 | + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue1)); | ||
84 | + DefaultVirtualDevice device2 = | ||
85 | + new DefaultVirtualDevice(NetworkId.networkId(0), DeviceId.deviceId(deviceIdValue2)); | ||
86 | + ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1)); | ||
87 | + ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2)); | ||
88 | + | ||
89 | + DefaultVirtualLink.builder() | ||
90 | + .networkId(null) | ||
91 | + .build(); | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Tests the DefaultVirtualLink equality method. | ||
96 | + */ | ||
43 | @Test | 97 | @Test |
44 | public void testEquality() { | 98 | public void testEquality() { |
45 | DefaultVirtualDevice device1 = | 99 | DefaultVirtualDevice device1 = |
... | @@ -49,10 +103,30 @@ public class DefaultVirtualLinkTest { | ... | @@ -49,10 +103,30 @@ public class DefaultVirtualLinkTest { |
49 | ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1)); | 103 | ConnectPoint src = new ConnectPoint(device1.id(), PortNumber.portNumber(1)); |
50 | ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2)); | 104 | ConnectPoint dst = new ConnectPoint(device2.id(), PortNumber.portNumber(2)); |
51 | 105 | ||
52 | - DefaultVirtualLink link1 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(0)); | 106 | + VirtualLink link1 = DefaultVirtualLink.builder() |
53 | - DefaultVirtualLink link2 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(0)); | 107 | + .networkId(NetworkId.networkId(0)) |
54 | - DefaultVirtualLink link3 = new DefaultVirtualLink(NetworkId.networkId(0), src, dst, TunnelId.valueOf(1)); | 108 | + .src(src) |
55 | - DefaultVirtualLink link4 = new DefaultVirtualLink(NetworkId.networkId(1), src, dst, TunnelId.valueOf(0)); | 109 | + .dst(dst) |
110 | + .tunnelId(TunnelId.valueOf("1")) | ||
111 | + .build(); | ||
112 | + VirtualLink link2 = DefaultVirtualLink.builder() | ||
113 | + .networkId(NetworkId.networkId(0)) | ||
114 | + .src(src) | ||
115 | + .dst(dst) | ||
116 | + .tunnelId(TunnelId.valueOf("1")) | ||
117 | + .build(); | ||
118 | + VirtualLink link3 = DefaultVirtualLink.builder() | ||
119 | + .networkId(NetworkId.networkId(0)) | ||
120 | + .src(src) | ||
121 | + .dst(dst) | ||
122 | + .tunnelId(TunnelId.valueOf("2")) | ||
123 | + .build(); | ||
124 | + VirtualLink link4 = DefaultVirtualLink.builder() | ||
125 | + .networkId(NetworkId.networkId(1)) | ||
126 | + .src(src) | ||
127 | + .dst(dst) | ||
128 | + .tunnelId(TunnelId.valueOf("3")) | ||
129 | + .build(); | ||
56 | 130 | ||
57 | new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3) | 131 | new EqualsTester().addEqualityGroup(link1, link2).addEqualityGroup(link3) |
58 | .addEqualityGroup(link4).testEquals(); | 132 | .addEqualityGroup(link4).testEquals(); | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.incubator.net.virtual.impl; | ||
18 | + | ||
19 | + | ||
20 | +import org.apache.felix.scr.annotations.Activate; | ||
21 | +import org.apache.felix.scr.annotations.Component; | ||
22 | +import org.apache.felix.scr.annotations.Deactivate; | ||
23 | +import org.apache.felix.scr.annotations.Reference; | ||
24 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
25 | +import org.apache.felix.scr.annotations.Service; | ||
26 | +import org.onosproject.core.ApplicationId; | ||
27 | +import org.onosproject.core.CoreService; | ||
28 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
29 | +import org.onosproject.incubator.net.virtual.DefaultVirtualLink; | ||
30 | +import org.onosproject.incubator.net.virtual.NetworkId; | ||
31 | +import org.onosproject.incubator.net.virtual.VirtualNetworkProvider; | ||
32 | +import org.onosproject.incubator.net.virtual.VirtualNetworkProviderRegistry; | ||
33 | +import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService; | ||
34 | +import org.onosproject.net.ConnectPoint; | ||
35 | +import org.onosproject.net.EncapsulationType; | ||
36 | +import org.onosproject.net.intent.Constraint; | ||
37 | +import org.onosproject.net.intent.Intent; | ||
38 | +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.PointToPointIntent; | ||
42 | +import org.onosproject.net.intent.constraint.EncapsulationConstraint; | ||
43 | +import org.onosproject.net.provider.AbstractProvider; | ||
44 | +import org.slf4j.Logger; | ||
45 | + | ||
46 | +import java.util.ArrayList; | ||
47 | +import java.util.List; | ||
48 | + | ||
49 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
50 | +import static java.lang.Thread.sleep; | ||
51 | +import static org.slf4j.LoggerFactory.getLogger; | ||
52 | + | ||
53 | +/** | ||
54 | + * Point to point intent VirtualNetworkProvider implementation. | ||
55 | + */ | ||
56 | +@Component(immediate = true) | ||
57 | +@Service | ||
58 | +public class PtToPtIntentVirtualNetworkProvider extends AbstractProvider implements VirtualNetworkProvider { | ||
59 | + | ||
60 | + private final Logger log = getLogger(PtToPtIntentVirtualNetworkProvider.class); | ||
61 | + 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"; | ||
63 | + private static final String INTENT_NULL = "Intent cannot be null"; | ||
64 | + protected static final String KEY_FORMAT = "networkId=%s src=%s dst=%s"; | ||
65 | + private static final int MAX_WAIT_COUNT = 30; | ||
66 | + | ||
67 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
68 | + protected VirtualNetworkProviderRegistry providerRegistry; | ||
69 | + | ||
70 | + private VirtualNetworkProviderService providerService; | ||
71 | + | ||
72 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
73 | + protected IntentService intentService; | ||
74 | + | ||
75 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
76 | + protected CoreService coreService; | ||
77 | + | ||
78 | + protected static final String PTPT_INTENT_APPID = "org.onosproject.vnet.intent"; | ||
79 | + private ApplicationId appId; | ||
80 | + | ||
81 | + /** | ||
82 | + * Default constructor. | ||
83 | + */ | ||
84 | + public PtToPtIntentVirtualNetworkProvider() { | ||
85 | + super(DefaultVirtualLink.PID); | ||
86 | + } | ||
87 | + | ||
88 | + @Activate | ||
89 | + public void activate() { | ||
90 | + providerService = providerRegistry.register(this); | ||
91 | + appId = coreService.registerApplication(PTPT_INTENT_APPID); | ||
92 | + | ||
93 | + log.info("Started"); | ||
94 | + } | ||
95 | + | ||
96 | + @Deactivate | ||
97 | + public void deactivate() { | ||
98 | + providerRegistry.unregister(this); | ||
99 | + providerService = null; | ||
100 | + log.info("Stopped"); | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public TunnelId createTunnel(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | ||
105 | + checkNotNull(NETWORK_ID_NULL, networkId); | ||
106 | + checkNotNull(CONNECT_POINT_NULL, src); | ||
107 | + checkNotNull(CONNECT_POINT_NULL, dst); | ||
108 | + String key = String.format(KEY_FORMAT, networkId.toString(), src.toString(), dst.toString()); | ||
109 | + Key intentKey = Key.of(key, appId); | ||
110 | + | ||
111 | + List<Constraint> constraints = new ArrayList<>(); | ||
112 | + constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN)); | ||
113 | + | ||
114 | + // TODO Currently there can only be one tunnel/intent between the src and dst across | ||
115 | + // all virtual networks. We may want to support multiple intents between the same src/dst pairs. | ||
116 | + PointToPointIntent intent = PointToPointIntent.builder() | ||
117 | + .key(intentKey) | ||
118 | + .appId(appId) | ||
119 | + .ingressPoint(src) | ||
120 | + .egressPoint(dst) | ||
121 | + .constraints(constraints) | ||
122 | + .build(); | ||
123 | + intentService.submit(intent); | ||
124 | + | ||
125 | + // construct tunnelId from the key | ||
126 | + return TunnelId.valueOf(key); | ||
127 | + } | ||
128 | + | ||
129 | + @Override | ||
130 | + public void destroyTunnel(NetworkId networkId, TunnelId tunnelId) { | ||
131 | + String key = tunnelId.id(); | ||
132 | + Key intentKey = Key.of(key, appId); | ||
133 | + Intent intent = intentService.getIntent(intentKey); | ||
134 | + checkNotNull(intent, INTENT_NULL); | ||
135 | + intentService.withdraw(intent); | ||
136 | + try { | ||
137 | + int count = 0; | ||
138 | + // Loop waiting for the intent to go into a withdrawn or failed state | ||
139 | + // before attempting to purge it. | ||
140 | + while (++count <= MAX_WAIT_COUNT) { | ||
141 | + IntentState state = intentService.getIntentState(intentKey); | ||
142 | + if ((state == IntentState.FAILED) || (state == IntentState.WITHDRAWN)) { | ||
143 | + intentService.purge(intent); | ||
144 | + break; | ||
145 | + } | ||
146 | + sleep(1000); | ||
147 | + } | ||
148 | + } catch (Exception e) { | ||
149 | + log.error("Exception: " + e); | ||
150 | + } | ||
151 | + } | ||
152 | +} | ||
153 | + |
... | @@ -66,6 +66,7 @@ public class VirtualNetworkManager | ... | @@ -66,6 +66,7 @@ public class VirtualNetworkManager |
66 | private static final String NETWORK_NULL = "Network ID cannot be null"; | 66 | private static final String NETWORK_NULL = "Network ID cannot be null"; |
67 | private static final String DEVICE_NULL = "Device ID cannot be null"; | 67 | private static final String DEVICE_NULL = "Device ID cannot be null"; |
68 | private static final String LINK_POINT_NULL = "Link end-point cannot be null"; | 68 | private static final String LINK_POINT_NULL = "Link end-point cannot be null"; |
69 | + private static final String VIRTUAL_LINK_NULL = "Virtual Link cannot be null"; | ||
69 | 70 | ||
70 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 71 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
71 | protected VirtualNetworkStore store; | 72 | protected VirtualNetworkStore store; |
... | @@ -135,13 +136,41 @@ public class VirtualNetworkManager | ... | @@ -135,13 +136,41 @@ public class VirtualNetworkManager |
135 | 136 | ||
136 | @Override | 137 | @Override |
137 | public VirtualLink createVirtualLink(NetworkId networkId, | 138 | public VirtualLink createVirtualLink(NetworkId networkId, |
138 | - ConnectPoint src, ConnectPoint dst, | 139 | + ConnectPoint src, ConnectPoint dst) { |
139 | - TunnelId realizedBy) { | ||
140 | checkNotNull(networkId, NETWORK_NULL); | 140 | checkNotNull(networkId, NETWORK_NULL); |
141 | checkNotNull(src, LINK_POINT_NULL); | 141 | checkNotNull(src, LINK_POINT_NULL); |
142 | checkNotNull(dst, LINK_POINT_NULL); | 142 | checkNotNull(dst, LINK_POINT_NULL); |
143 | - checkNotNull(realizedBy, "Tunnel ID cannot be null"); | 143 | + VirtualLink virtualLink = store.addLink(networkId, src, dst, null); |
144 | - return store.addLink(networkId, src, dst, realizedBy); | 144 | + checkNotNull(virtualLink, VIRTUAL_LINK_NULL); |
145 | + | ||
146 | + if (virtualLink.providerId() != null) { | ||
147 | + VirtualNetworkProvider provider = getProvider(virtualLink.providerId()); | ||
148 | + if (provider != null) { | ||
149 | + TunnelId tunnelId = provider.createTunnel(networkId, mapVirtualToPhysicalPort(networkId, src), | ||
150 | + mapVirtualToPhysicalPort(networkId, dst)); | ||
151 | + store.updateLink(virtualLink, tunnelId); | ||
152 | + } | ||
153 | + } | ||
154 | + return virtualLink; | ||
155 | + } | ||
156 | + | ||
157 | + /** | ||
158 | + * Maps the virtual connect point to a physical connect point. | ||
159 | + * | ||
160 | + * @param networkId network identifier | ||
161 | + * @param virtualCp virtual connect point | ||
162 | + * @return physical connect point | ||
163 | + */ | ||
164 | + private ConnectPoint mapVirtualToPhysicalPort(NetworkId networkId, | ||
165 | + ConnectPoint virtualCp) { | ||
166 | + Set<VirtualPort> ports = store.getPorts(networkId, virtualCp.deviceId()); | ||
167 | + for (VirtualPort port : ports) { | ||
168 | + if (port.element().id().equals(virtualCp.elementId()) && | ||
169 | + port.number().equals(virtualCp.port())) { | ||
170 | + return new ConnectPoint(port.realizedBy().element().id(), port.realizedBy().number()); | ||
171 | + } | ||
172 | + } | ||
173 | + return null; | ||
145 | } | 174 | } |
146 | 175 | ||
147 | @Override | 176 | @Override |
... | @@ -149,7 +178,14 @@ public class VirtualNetworkManager | ... | @@ -149,7 +178,14 @@ public class VirtualNetworkManager |
149 | checkNotNull(networkId, NETWORK_NULL); | 178 | checkNotNull(networkId, NETWORK_NULL); |
150 | checkNotNull(src, LINK_POINT_NULL); | 179 | checkNotNull(src, LINK_POINT_NULL); |
151 | checkNotNull(dst, LINK_POINT_NULL); | 180 | checkNotNull(dst, LINK_POINT_NULL); |
152 | - store.removeLink(networkId, src, dst); | 181 | + VirtualLink virtualLink = store.removeLink(networkId, src, dst); |
182 | + | ||
183 | + if (virtualLink != null && virtualLink.providerId() != null) { | ||
184 | + VirtualNetworkProvider provider = getProvider(virtualLink.providerId()); | ||
185 | + if (provider != null) { | ||
186 | + provider.destroyTunnel(networkId, virtualLink.tunnelId()); | ||
187 | + } | ||
188 | + } | ||
153 | } | 189 | } |
154 | 190 | ||
155 | @Override | 191 | @Override | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +package org.onosproject.incubator.net.virtual.impl; | ||
18 | + | ||
19 | +import com.google.common.collect.Sets; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onosproject.TestApplicationId; | ||
24 | +import org.onosproject.core.ApplicationId; | ||
25 | +import org.onosproject.core.CoreService; | ||
26 | +import org.onosproject.core.CoreServiceAdapter; | ||
27 | +import org.onosproject.core.IdGenerator; | ||
28 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
29 | +import org.onosproject.incubator.net.virtual.NetworkId; | ||
30 | +import org.onosproject.incubator.net.virtual.VirtualNetworkProvider; | ||
31 | +import org.onosproject.incubator.net.virtual.VirtualNetworkProviderRegistry; | ||
32 | +import org.onosproject.incubator.net.virtual.VirtualNetworkProviderService; | ||
33 | +import org.onosproject.net.ConnectPoint; | ||
34 | +import org.onosproject.net.DeviceId; | ||
35 | +import org.onosproject.net.PortNumber; | ||
36 | +import org.onosproject.net.intent.Intent; | ||
37 | +import org.onosproject.net.intent.IntentService; | ||
38 | +import org.onosproject.net.intent.IntentServiceAdapter; | ||
39 | +import org.onosproject.net.intent.IntentState; | ||
40 | +import org.onosproject.net.intent.Key; | ||
41 | +import org.onosproject.net.intent.MockIdGenerator; | ||
42 | +import org.onosproject.net.provider.AbstractProviderService; | ||
43 | +import org.onosproject.net.provider.ProviderId; | ||
44 | + | ||
45 | +import java.util.Set; | ||
46 | +import java.util.concurrent.atomic.AtomicLong; | ||
47 | + | ||
48 | +import static org.easymock.EasyMock.*; | ||
49 | +import static org.junit.Assert.assertEquals; | ||
50 | +import static org.junit.Assert.assertNotNull; | ||
51 | + | ||
52 | +/** | ||
53 | + * Junit tests for PtToPtIntentVirtualNetworkProvider. | ||
54 | + */ | ||
55 | +public class PtToPtIntentVirtualNetworkProviderTest { | ||
56 | + | ||
57 | + private PtToPtIntentVirtualNetworkProvider provider; | ||
58 | + private VirtualNetworkProviderRegistry providerRegistry; | ||
59 | + | ||
60 | + private final VirtualNetworkRegistryAdapter virtualNetworkRegistry = new VirtualNetworkRegistryAdapter(); | ||
61 | + private IntentService intentService; | ||
62 | + | ||
63 | + private static final ApplicationId APP_ID = | ||
64 | + TestApplicationId.create(PtToPtIntentVirtualNetworkProvider.PTPT_INTENT_APPID); | ||
65 | + | ||
66 | + private IdGenerator idGenerator = new MockIdGenerator(); | ||
67 | + | ||
68 | + @Before | ||
69 | + public void setUp() { | ||
70 | + provider = new PtToPtIntentVirtualNetworkProvider(); | ||
71 | + provider.providerRegistry = virtualNetworkRegistry; | ||
72 | + final CoreService mockCoreService = createMock(CoreService.class); | ||
73 | + provider.coreService = mockCoreService; | ||
74 | + expect(mockCoreService.registerApplication(PtToPtIntentVirtualNetworkProvider.PTPT_INTENT_APPID)) | ||
75 | + .andReturn(APP_ID).anyTimes(); | ||
76 | + replay(mockCoreService); | ||
77 | + Intent.unbindIdGenerator(idGenerator); | ||
78 | + Intent.bindIdGenerator(idGenerator); | ||
79 | + | ||
80 | + intentService = new TestIntentService(); | ||
81 | + provider.intentService = intentService; | ||
82 | + provider.activate(); | ||
83 | + } | ||
84 | + | ||
85 | + @After | ||
86 | + public void tearDown() { | ||
87 | + provider.deactivate(); | ||
88 | + provider.providerRegistry = null; | ||
89 | + provider.coreService = null; | ||
90 | + provider.intentService = null; | ||
91 | + Intent.unbindIdGenerator(idGenerator); | ||
92 | + } | ||
93 | + | ||
94 | + @Test | ||
95 | + public void basics() { | ||
96 | + assertNotNull("registration expected", provider); | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Test a null network identifier. | ||
101 | + */ | ||
102 | + @Test(expected = NullPointerException.class) | ||
103 | + public void testCreateTunnelNullNetworkId() { | ||
104 | + provider.createTunnel(null, null, null); | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * Test a null source connect point. | ||
109 | + */ | ||
110 | + @Test(expected = NullPointerException.class) | ||
111 | + public void testCreateTunnelNullSrc() { | ||
112 | + ConnectPoint dst = new ConnectPoint(DeviceId.deviceId("device2"), PortNumber.portNumber(2)); | ||
113 | + | ||
114 | + provider.createTunnel(NetworkId.networkId(0), null, dst); | ||
115 | + } | ||
116 | + | ||
117 | + /** | ||
118 | + * Test a null destination connect point. | ||
119 | + */ | ||
120 | + @Test(expected = NullPointerException.class) | ||
121 | + public void testCreateTunnelNullDst() { | ||
122 | + ConnectPoint src = new ConnectPoint(DeviceId.deviceId("device1"), PortNumber.portNumber(1)); | ||
123 | + | ||
124 | + provider.createTunnel(NetworkId.networkId(0), src, null); | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Test creating/destroying a valid tunnel. | ||
129 | + */ | ||
130 | + @Test | ||
131 | + public void testCreateRemoveTunnel() { | ||
132 | + NetworkId networkId = NetworkId.networkId(0); | ||
133 | + ConnectPoint src = new ConnectPoint(DeviceId.deviceId("device1"), PortNumber.portNumber(1)); | ||
134 | + ConnectPoint dst = new ConnectPoint(DeviceId.deviceId("device2"), PortNumber.portNumber(2)); | ||
135 | + | ||
136 | + TunnelId tunnelId = provider.createTunnel(networkId, src, dst); | ||
137 | + String key = String.format(PtToPtIntentVirtualNetworkProvider.KEY_FORMAT, | ||
138 | + networkId.toString(), src.toString(), dst.toString()); | ||
139 | + | ||
140 | + assertEquals("TunnelId does not match as expected.", key, tunnelId.toString()); | ||
141 | + provider.destroyTunnel(networkId, tunnelId); | ||
142 | + } | ||
143 | + | ||
144 | + /** | ||
145 | + * Virtual network registry implementation for this test class. | ||
146 | + */ | ||
147 | + private class VirtualNetworkRegistryAdapter implements VirtualNetworkProviderRegistry { | ||
148 | + private VirtualNetworkProvider provider; | ||
149 | + | ||
150 | + @Override | ||
151 | + public VirtualNetworkProviderService register(VirtualNetworkProvider theProvider) { | ||
152 | + this.provider = theProvider; | ||
153 | + return new TestVirtualNetworkProviderService(theProvider); | ||
154 | + } | ||
155 | + | ||
156 | + @Override | ||
157 | + public void unregister(VirtualNetworkProvider theProvider) { | ||
158 | + this.provider = null; | ||
159 | + } | ||
160 | + | ||
161 | + @Override | ||
162 | + public Set<ProviderId> getProviders() { | ||
163 | + return null; | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * Virtual network provider service implementation for this test class. | ||
169 | + */ | ||
170 | + private class TestVirtualNetworkProviderService | ||
171 | + extends AbstractProviderService<VirtualNetworkProvider> | ||
172 | + implements VirtualNetworkProviderService { | ||
173 | + | ||
174 | + protected TestVirtualNetworkProviderService(VirtualNetworkProvider provider) { | ||
175 | + super(provider); | ||
176 | + } | ||
177 | + } | ||
178 | + | ||
179 | + | ||
180 | + /** | ||
181 | + * Core service test class. | ||
182 | + */ | ||
183 | + private class TestCoreService extends CoreServiceAdapter { | ||
184 | + | ||
185 | + @Override | ||
186 | + public IdGenerator getIdGenerator(String topic) { | ||
187 | + return new IdGenerator() { | ||
188 | + private AtomicLong counter = new AtomicLong(0); | ||
189 | + | ||
190 | + @Override | ||
191 | + public long getNewId() { | ||
192 | + return counter.getAndIncrement(); | ||
193 | + } | ||
194 | + }; | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | + /** | ||
199 | + * Represents a fake IntentService class that easily allows to store and | ||
200 | + * retrieve intents without implementing the IntentService logic. | ||
201 | + */ | ||
202 | + private class TestIntentService extends IntentServiceAdapter { | ||
203 | + | ||
204 | + private Set<Intent> intents; | ||
205 | + | ||
206 | + public TestIntentService() { | ||
207 | + intents = Sets.newHashSet(); | ||
208 | + } | ||
209 | + | ||
210 | + @Override | ||
211 | + public void submit(Intent intent) { | ||
212 | + intents.add(intent); | ||
213 | + } | ||
214 | + | ||
215 | + @Override | ||
216 | + public void withdraw(Intent intent) { | ||
217 | + } | ||
218 | + | ||
219 | + @Override | ||
220 | + public IntentState getIntentState(Key intentKey) { | ||
221 | + return IntentState.WITHDRAWN; | ||
222 | + } | ||
223 | + | ||
224 | + @Override | ||
225 | + public void purge(Intent intent) { | ||
226 | + intents.remove(intent); | ||
227 | + } | ||
228 | + | ||
229 | + @Override | ||
230 | + public long getIntentCount() { | ||
231 | + return intents.size(); | ||
232 | + } | ||
233 | + | ||
234 | + @Override | ||
235 | + public Iterable<Intent> getIntents() { | ||
236 | + return intents; | ||
237 | + } | ||
238 | + | ||
239 | + @Override | ||
240 | + public Intent getIntent(Key intentKey) { | ||
241 | + for (Intent intent : intents) { | ||
242 | + if (intent.key().equals(intentKey)) { | ||
243 | + return intent; | ||
244 | + } | ||
245 | + } | ||
246 | + return null; | ||
247 | + } | ||
248 | + } | ||
249 | +} |
... | @@ -27,7 +27,6 @@ import org.onosproject.core.CoreService; | ... | @@ -27,7 +27,6 @@ import org.onosproject.core.CoreService; |
27 | import org.onosproject.core.CoreServiceAdapter; | 27 | import org.onosproject.core.CoreServiceAdapter; |
28 | import org.onosproject.core.IdGenerator; | 28 | import org.onosproject.core.IdGenerator; |
29 | import org.onosproject.event.Event; | 29 | import org.onosproject.event.Event; |
30 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
31 | import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork; | 30 | import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork; |
32 | import org.onosproject.incubator.net.virtual.NetworkId; | 31 | import org.onosproject.incubator.net.virtual.NetworkId; |
33 | import org.onosproject.incubator.net.virtual.TenantId; | 32 | import org.onosproject.incubator.net.virtual.TenantId; |
... | @@ -247,8 +246,8 @@ public class VirtualNetworkManagerTest { | ... | @@ -247,8 +246,8 @@ public class VirtualNetworkManagerTest { |
247 | manager.createVirtualDevice(virtualNetwork1.id(), DeviceId.deviceId(deviceIdValue2)); | 246 | manager.createVirtualDevice(virtualNetwork1.id(), DeviceId.deviceId(deviceIdValue2)); |
248 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | 247 | ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); |
249 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); | 248 | ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); |
250 | - manager.createVirtualLink(virtualNetwork1.id(), src, dst, TunnelId.valueOf(0)); | 249 | + manager.createVirtualLink(virtualNetwork1.id(), src, dst); |
251 | - manager.createVirtualLink(virtualNetwork1.id(), dst, src, TunnelId.valueOf(1)); | 250 | + manager.createVirtualLink(virtualNetwork1.id(), dst, src); |
252 | 251 | ||
253 | Set<VirtualLink> virtualLinks = manager.getVirtualLinks(virtualNetwork1.id()); | 252 | Set<VirtualLink> virtualLinks = manager.getVirtualLinks(virtualNetwork1.id()); |
254 | assertNotNull("The virtual link set should not be null", virtualLinks); | 253 | assertNotNull("The virtual link set should not be null", virtualLinks); |
... | @@ -263,13 +262,30 @@ public class VirtualNetworkManagerTest { | ... | @@ -263,13 +262,30 @@ public class VirtualNetworkManagerTest { |
263 | assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty()); | 262 | assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty()); |
264 | 263 | ||
265 | // Add/remove the virtual link again. | 264 | // Add/remove the virtual link again. |
266 | - VirtualLink virtualLink = manager.createVirtualLink(virtualNetwork1.id(), src, dst, TunnelId.valueOf(0)); | 265 | + VirtualLink virtualLink = manager.createVirtualLink(virtualNetwork1.id(), src, dst); |
267 | manager.removeVirtualLink(virtualLink.networkId(), virtualLink.src(), virtualLink.dst()); | 266 | manager.removeVirtualLink(virtualLink.networkId(), virtualLink.src(), virtualLink.dst()); |
268 | virtualLinks = manager.getVirtualLinks(virtualNetwork1.id()); | 267 | virtualLinks = manager.getVirtualLinks(virtualNetwork1.id()); |
269 | assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty()); | 268 | assertTrue("The virtual link set should be empty.", virtualLinks.isEmpty()); |
270 | } | 269 | } |
271 | 270 | ||
272 | /** | 271 | /** |
272 | + * Tests adding the same virtual link twice. | ||
273 | + */ | ||
274 | + @Test(expected = IllegalStateException.class) | ||
275 | + public void testAddSameVirtualLink() { | ||
276 | + manager.registerTenantId(TenantId.tenantId(tenantIdValue1)); | ||
277 | + VirtualNetwork virtualNetwork1 = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1)); | ||
278 | + VirtualDevice srcVirtualDevice = | ||
279 | + manager.createVirtualDevice(virtualNetwork1.id(), DeviceId.deviceId(deviceIdValue1)); | ||
280 | + VirtualDevice dstVirtualDevice = | ||
281 | + manager.createVirtualDevice(virtualNetwork1.id(), DeviceId.deviceId(deviceIdValue2)); | ||
282 | + ConnectPoint src = new ConnectPoint(srcVirtualDevice.id(), PortNumber.portNumber(1)); | ||
283 | + ConnectPoint dst = new ConnectPoint(dstVirtualDevice.id(), PortNumber.portNumber(2)); | ||
284 | + manager.createVirtualLink(virtualNetwork1.id(), src, dst); | ||
285 | + manager.createVirtualLink(virtualNetwork1.id(), src, dst); | ||
286 | + } | ||
287 | + | ||
288 | + /** | ||
273 | * Tests add and remove of virtual ports. | 289 | * Tests add and remove of virtual ports. |
274 | */ | 290 | */ |
275 | @Test | 291 | @Test | ... | ... |
... | @@ -180,7 +180,7 @@ public class DistributedTunnelStore | ... | @@ -180,7 +180,7 @@ public class DistributedTunnelStore |
180 | notifyDelegate(event); | 180 | notifyDelegate(event); |
181 | return tunnel.tunnelId(); | 181 | return tunnel.tunnelId(); |
182 | } else { | 182 | } else { |
183 | - TunnelId tunnelId = TunnelId.valueOf(idGenerator.getNewId()); | 183 | + TunnelId tunnelId = TunnelId.valueOf(String.valueOf(idGenerator.getNewId())); |
184 | State tunnelState = (state != null) ? state : tunnel.state(); | 184 | State tunnelState = (state != null) ? state : tunnel.state(); |
185 | Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(), | 185 | Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(), |
186 | tunnel.dst(), tunnel.type(), | 186 | tunnel.dst(), tunnel.type(), | ... | ... |
... | @@ -134,9 +134,9 @@ public class DistributedVirtualNetworkStore | ... | @@ -134,9 +134,9 @@ public class DistributedVirtualNetworkStore |
134 | .register(DefaultVirtualPort.class) | 134 | .register(DefaultVirtualPort.class) |
135 | .register(DeviceId.class) | 135 | .register(DeviceId.class) |
136 | .register(Device.class) | 136 | .register(Device.class) |
137 | - .register(TunnelId.class) | ||
138 | .register(DefaultDevice.class) | 137 | .register(DefaultDevice.class) |
139 | .register(DefaultPort.class) | 138 | .register(DefaultPort.class) |
139 | + .register(TunnelId.class) | ||
140 | .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID).build()); | 140 | .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID).build()); |
141 | 141 | ||
142 | /** | 142 | /** |
... | @@ -349,22 +349,51 @@ public class DistributedVirtualNetworkStore | ... | @@ -349,22 +349,51 @@ public class DistributedVirtualNetworkStore |
349 | if (virtualLinkSet == null) { | 349 | if (virtualLinkSet == null) { |
350 | virtualLinkSet = new HashSet<>(); | 350 | virtualLinkSet = new HashSet<>(); |
351 | } | 351 | } |
352 | - VirtualLink virtualLink = new DefaultVirtualLink(networkId, src, dst, realizedBy); | 352 | + // validate that the link does not already exist in this network |
353 | + checkState(getLink(networkId, src, dst) == null, "The virtual link already exists"); | ||
354 | + | ||
355 | + VirtualLink virtualLink = DefaultVirtualLink.builder() | ||
356 | + .networkId(networkId) | ||
357 | + .src(src) | ||
358 | + .dst(dst) | ||
359 | + .tunnelId(realizedBy) | ||
360 | + .build(); | ||
361 | + | ||
353 | virtualLinkSet.add(virtualLink); | 362 | virtualLinkSet.add(virtualLink); |
354 | networkIdVirtualLinkSetMap.put(networkId, virtualLinkSet); | 363 | networkIdVirtualLinkSetMap.put(networkId, virtualLinkSet); |
355 | return virtualLink; | 364 | return virtualLink; |
356 | } | 365 | } |
357 | 366 | ||
358 | @Override | 367 | @Override |
359 | - public void removeLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | 368 | + public void updateLink(VirtualLink virtualLink, TunnelId tunnelId) { |
369 | + checkState(networkExists(virtualLink.networkId()), "The network has not been added."); | ||
370 | + Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(virtualLink.networkId()); | ||
371 | + if (virtualLinkSet == null) { | ||
372 | + virtualLinkSet = new HashSet<>(); | ||
373 | + } | ||
374 | + virtualLinkSet.remove(virtualLink); | ||
375 | + | ||
376 | + VirtualLink newVirtualLink = DefaultVirtualLink.builder() | ||
377 | + .networkId(virtualLink.networkId()) | ||
378 | + .src(virtualLink.src()) | ||
379 | + .dst(virtualLink.dst()) | ||
380 | + .tunnelId(tunnelId) | ||
381 | + .build(); | ||
382 | + | ||
383 | + virtualLinkSet.add(newVirtualLink); | ||
384 | + networkIdVirtualLinkSetMap.put(newVirtualLink.networkId(), virtualLinkSet); | ||
385 | + } | ||
386 | + | ||
387 | + @Override | ||
388 | + public VirtualLink removeLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | ||
360 | checkState(networkExists(networkId), "The network has not been added."); | 389 | checkState(networkExists(networkId), "The network has not been added."); |
361 | 390 | ||
391 | + final VirtualLink virtualLink = getLink(networkId, src, dst); | ||
392 | + if (virtualLink == null) { | ||
393 | + return null; | ||
394 | + } | ||
362 | Set<VirtualLink> virtualLinkSet = new HashSet<>(); | 395 | Set<VirtualLink> virtualLinkSet = new HashSet<>(); |
363 | - networkIdVirtualLinkSetMap.get(networkId).forEach(link -> { | 396 | + virtualLinkSet.add(virtualLink); |
364 | - if (link.src().equals(src) && link.dst().equals(dst)) { | ||
365 | - virtualLinkSet.add(link); | ||
366 | - } | ||
367 | - }); | ||
368 | 397 | ||
369 | if (virtualLinkSet != null) { | 398 | if (virtualLinkSet != null) { |
370 | networkIdVirtualLinkSetMap.compute(networkId, (id, existingVirtualLinks) -> { | 399 | networkIdVirtualLinkSetMap.compute(networkId, (id, existingVirtualLinks) -> { |
... | @@ -375,6 +404,7 @@ public class DistributedVirtualNetworkStore | ... | @@ -375,6 +404,7 @@ public class DistributedVirtualNetworkStore |
375 | } | 404 | } |
376 | }); | 405 | }); |
377 | } | 406 | } |
407 | + return virtualLink; | ||
378 | } | 408 | } |
379 | 409 | ||
380 | @Override | 410 | @Override |
... | @@ -445,6 +475,31 @@ public class DistributedVirtualNetworkStore | ... | @@ -445,6 +475,31 @@ public class DistributedVirtualNetworkStore |
445 | return ImmutableSet.copyOf(virtualLinkSet); | 475 | return ImmutableSet.copyOf(virtualLinkSet); |
446 | } | 476 | } |
447 | 477 | ||
478 | + /** | ||
479 | + * Returns the virtual link matching the network identifier, source connect point, | ||
480 | + * and destination connect point. | ||
481 | + * | ||
482 | + * @param networkId network identifier | ||
483 | + * @param src source connect point | ||
484 | + * @param dst destination connect point | ||
485 | + * @return virtual link | ||
486 | + */ | ||
487 | + private VirtualLink getLink(NetworkId networkId, ConnectPoint src, ConnectPoint dst) { | ||
488 | + Set<VirtualLink> virtualLinkSet = networkIdVirtualLinkSetMap.get(networkId); | ||
489 | + if (virtualLinkSet == null) { | ||
490 | + return null; | ||
491 | + } | ||
492 | + | ||
493 | + VirtualLink virtualLink = null; | ||
494 | + for (VirtualLink link : virtualLinkSet) { | ||
495 | + if (link.src().equals(src) && link.dst().equals(dst)) { | ||
496 | + virtualLink = link; | ||
497 | + break; | ||
498 | + } | ||
499 | + } | ||
500 | + return virtualLink; | ||
501 | + } | ||
502 | + | ||
448 | @Override | 503 | @Override |
449 | public Set<VirtualPort> getPorts(NetworkId networkId, DeviceId deviceId) { | 504 | public Set<VirtualPort> getPorts(NetworkId networkId, DeviceId deviceId) { |
450 | checkState(networkExists(networkId), "The network has not been added."); | 505 | checkState(networkExists(networkId), "The network has not been added."); | ... | ... |
... | @@ -152,7 +152,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid | ... | @@ -152,7 +152,7 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid |
152 | 152 | ||
153 | HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); | 153 | HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); |
154 | HashMap<TunnelId, TunnelStatistics> tunnelStatisticsMap = new HashMap<>(); | 154 | HashMap<TunnelId, TunnelStatistics> tunnelStatisticsMap = new HashMap<>(); |
155 | - private HashMap<Long, TunnelStatsCollector> collectors = Maps.newHashMap(); | 155 | + private HashMap<String, TunnelStatsCollector> collectors = Maps.newHashMap(); |
156 | 156 | ||
157 | private InnerTunnelProvider listener = new InnerTunnelProvider(); | 157 | private InnerTunnelProvider listener = new InnerTunnelProvider(); |
158 | 158 | ... | ... |
... | @@ -51,7 +51,7 @@ import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; | ... | @@ -51,7 +51,7 @@ import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; |
51 | */ | 51 | */ |
52 | public class PcepReleaseTunnelProviderTest { | 52 | public class PcepReleaseTunnelProviderTest { |
53 | 53 | ||
54 | - public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | 54 | + private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
55 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | 55 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
56 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | 56 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
57 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | 57 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
... | @@ -104,7 +104,7 @@ public class PcepReleaseTunnelProviderTest { | ... | @@ -104,7 +104,7 @@ public class PcepReleaseTunnelProviderTest { |
104 | path = new DefaultPath(pid, links, 20, EMPTY); | 104 | path = new DefaultPath(pid, links, 20, EMPTY); |
105 | 105 | ||
106 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | 106 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
107 | - new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | 107 | + new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
108 | path, EMPTY); | 108 | path, EMPTY); |
109 | 109 | ||
110 | // for releasing tunnel tunnel should exist in db | 110 | // for releasing tunnel tunnel should exist in db |
... | @@ -154,7 +154,7 @@ public class PcepReleaseTunnelProviderTest { | ... | @@ -154,7 +154,7 @@ public class PcepReleaseTunnelProviderTest { |
154 | path = new DefaultPath(pid, links, 20, EMPTY); | 154 | path = new DefaultPath(pid, links, 20, EMPTY); |
155 | 155 | ||
156 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | 156 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
157 | - new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | 157 | + new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
158 | path, EMPTY); | 158 | path, EMPTY); |
159 | 159 | ||
160 | // for releasing tunnel tunnel should exist in db | 160 | // for releasing tunnel tunnel should exist in db | ... | ... |
... | @@ -50,7 +50,7 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -50,7 +50,7 @@ import org.onosproject.net.provider.ProviderId; |
50 | */ | 50 | */ |
51 | public class PcepSetupTunnelProviderTest { | 51 | public class PcepSetupTunnelProviderTest { |
52 | 52 | ||
53 | - public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | 53 | + private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
54 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | 54 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
55 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | 55 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
56 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | 56 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
... | @@ -99,7 +99,7 @@ public class PcepSetupTunnelProviderTest { | ... | @@ -99,7 +99,7 @@ public class PcepSetupTunnelProviderTest { |
99 | path = new DefaultPath(pid, links, 10, EMPTY); | 99 | path = new DefaultPath(pid, links, 10, EMPTY); |
100 | 100 | ||
101 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | 101 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
102 | - new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | 102 | + new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
103 | path, EMPTY); | 103 | path, EMPTY); |
104 | 104 | ||
105 | tunnelProvider.setupTunnel(tunnel, path); | 105 | tunnelProvider.setupTunnel(tunnel, path); |
... | @@ -138,7 +138,7 @@ public class PcepSetupTunnelProviderTest { | ... | @@ -138,7 +138,7 @@ public class PcepSetupTunnelProviderTest { |
138 | path = new DefaultPath(pid, links, 10, EMPTY); | 138 | path = new DefaultPath(pid, links, 10, EMPTY); |
139 | 139 | ||
140 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | 140 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
141 | - new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | 141 | + new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
142 | path, EMPTY); | 142 | path, EMPTY); |
143 | 143 | ||
144 | tunnelProvider.setupTunnel(tunnel, path); | 144 | tunnelProvider.setupTunnel(tunnel, path); | ... | ... |
... | @@ -42,7 +42,7 @@ import org.onosproject.cfg.ComponentConfigAdapter; | ... | @@ -42,7 +42,7 @@ import org.onosproject.cfg.ComponentConfigAdapter; |
42 | 42 | ||
43 | public class PcepTunnelProviderTest { | 43 | public class PcepTunnelProviderTest { |
44 | 44 | ||
45 | - public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | 45 | + private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
46 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | 46 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
47 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | 47 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
48 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | 48 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
... | @@ -86,7 +86,7 @@ public class PcepTunnelProviderTest { | ... | @@ -86,7 +86,7 @@ public class PcepTunnelProviderTest { |
86 | path = new DefaultPath(pid, links, 10, EMPTY); | 86 | path = new DefaultPath(pid, links, 10, EMPTY); |
87 | 87 | ||
88 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | 88 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
89 | - new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | 89 | + new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
90 | path, EMPTY); | 90 | path, EMPTY); |
91 | 91 | ||
92 | tunnelProvider.setupTunnel(tunnel, path); | 92 | tunnelProvider.setupTunnel(tunnel, path); | ... | ... |
... | @@ -51,7 +51,7 @@ import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; | ... | @@ -51,7 +51,7 @@ import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; |
51 | */ | 51 | */ |
52 | public class PcepUpdateTunnelProviderTest { | 52 | public class PcepUpdateTunnelProviderTest { |
53 | 53 | ||
54 | - public static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; | 54 | + private static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; |
55 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); | 55 | private PcepTunnelProvider tunnelProvider = new PcepTunnelProvider(); |
56 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); | 56 | private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); |
57 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); | 57 | private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); |
... | @@ -102,7 +102,7 @@ public class PcepUpdateTunnelProviderTest { | ... | @@ -102,7 +102,7 @@ public class PcepUpdateTunnelProviderTest { |
102 | path = new DefaultPath(pid, links, 20, EMPTY); | 102 | path = new DefaultPath(pid, links, 20, EMPTY); |
103 | 103 | ||
104 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | 104 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
105 | - new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | 105 | + new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
106 | path, EMPTY); | 106 | path, EMPTY); |
107 | 107 | ||
108 | // for updating tunnel tunnel should exist in db | 108 | // for updating tunnel tunnel should exist in db |
... | @@ -150,7 +150,7 @@ public class PcepUpdateTunnelProviderTest { | ... | @@ -150,7 +150,7 @@ public class PcepUpdateTunnelProviderTest { |
150 | path = new DefaultPath(pid, links, 20, EMPTY); | 150 | path = new DefaultPath(pid, links, 20, EMPTY); |
151 | 151 | ||
152 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, | 152 | tunnel = new DefaultTunnel(pid, ipTunnelEndPointSrc, ipTunnelEndPointDst, Tunnel.Type.MPLS, |
153 | - new DefaultGroupId(0), TunnelId.valueOf(1), TunnelName.tunnelName("T123"), | 153 | + new DefaultGroupId(0), TunnelId.valueOf("1"), TunnelName.tunnelName("T123"), |
154 | path, EMPTY); | 154 | path, EMPTY); |
155 | 155 | ||
156 | // for updating tunnel tunnel should exist in db | 156 | // for updating tunnel tunnel should exist in db | ... | ... |
... | @@ -18,8 +18,6 @@ package org.onosproject.rest.resources; | ... | @@ -18,8 +18,6 @@ package org.onosproject.rest.resources; |
18 | 18 | ||
19 | import com.fasterxml.jackson.databind.JsonNode; | 19 | import com.fasterxml.jackson.databind.JsonNode; |
20 | import com.fasterxml.jackson.databind.node.ObjectNode; | 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
21 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
22 | -import org.onosproject.incubator.net.virtual.DefaultVirtualLink; | ||
23 | import org.onosproject.incubator.net.virtual.NetworkId; | 21 | import org.onosproject.incubator.net.virtual.NetworkId; |
24 | import org.onosproject.incubator.net.virtual.TenantId; | 22 | import org.onosproject.incubator.net.virtual.TenantId; |
25 | import org.onosproject.incubator.net.virtual.VirtualDevice; | 23 | import org.onosproject.incubator.net.virtual.VirtualDevice; |
... | @@ -100,7 +98,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -100,7 +98,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
100 | @Path("{tenantId}") | 98 | @Path("{tenantId}") |
101 | public Response getVirtualNetworkById(@PathParam("tenantId") String tenantId) { | 99 | public Response getVirtualNetworkById(@PathParam("tenantId") String tenantId) { |
102 | final TenantId existingTid = TenantWebResource.getExistingTenantId(vnetAdminService, | 100 | final TenantId existingTid = TenantWebResource.getExistingTenantId(vnetAdminService, |
103 | - TenantId.tenantId(tenantId)); | 101 | + TenantId.tenantId(tenantId)); |
104 | Set<VirtualNetwork> vnets = vnetService.getVirtualNetworks(existingTid); | 102 | Set<VirtualNetwork> vnets = vnetService.getVirtualNetworks(existingTid); |
105 | return ok(encodeArray(VirtualNetwork.class, "vnets", vnets)).build(); | 103 | return ok(encodeArray(VirtualNetwork.class, "vnets", vnets)).build(); |
106 | } | 104 | } |
... | @@ -158,7 +156,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -158,7 +156,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
158 | @Path("{networkId}/devices") | 156 | @Path("{networkId}/devices") |
159 | public Response getVirtualDevices(@PathParam("networkId") long networkId) { | 157 | public Response getVirtualDevices(@PathParam("networkId") long networkId) { |
160 | NetworkId nid = NetworkId.networkId(networkId); | 158 | NetworkId nid = NetworkId.networkId(networkId); |
161 | - Set<VirtualDevice> vdevs = vnetService.getVirtualDevices(nid); | 159 | + Set<VirtualDevice> vdevs = vnetService.getVirtualDevices(nid); |
162 | return ok(encodeArray(VirtualDevice.class, "devices", vdevs)).build(); | 160 | return ok(encodeArray(VirtualDevice.class, "devices", vdevs)).build(); |
163 | } | 161 | } |
164 | 162 | ||
... | @@ -166,7 +164,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -166,7 +164,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
166 | * Creates a virtual device from the JSON input stream. | 164 | * Creates a virtual device from the JSON input stream. |
167 | * | 165 | * |
168 | * @param networkId network identifier | 166 | * @param networkId network identifier |
169 | - * @param stream Virtual device JSON stream | 167 | + * @param stream Virtual device JSON stream |
170 | * @return status of the request - CREATED if the JSON is correct, | 168 | * @return status of the request - CREATED if the JSON is correct, |
171 | * BAD_REQUEST if the JSON is invalid | 169 | * BAD_REQUEST if the JSON is invalid |
172 | * @onos.rsModel VirtualDevice | 170 | * @onos.rsModel VirtualDevice |
... | @@ -201,13 +199,13 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -201,13 +199,13 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
201 | * Removes the virtual network device from the virtual network. | 199 | * Removes the virtual network device from the virtual network. |
202 | * | 200 | * |
203 | * @param networkId network identifier | 201 | * @param networkId network identifier |
204 | - * @param deviceId device identifier | 202 | + * @param deviceId device identifier |
205 | * @return 200 OK, 404 not found | 203 | * @return 200 OK, 404 not found |
206 | */ | 204 | */ |
207 | @DELETE | 205 | @DELETE |
208 | @Path("{networkId}/devices/{deviceId}") | 206 | @Path("{networkId}/devices/{deviceId}") |
209 | public Response removeVirtualDevice(@PathParam("networkId") long networkId, | 207 | public Response removeVirtualDevice(@PathParam("networkId") long networkId, |
210 | - @PathParam("deviceId") String deviceId) { | 208 | + @PathParam("deviceId") String deviceId) { |
211 | NetworkId nid = NetworkId.networkId(networkId); | 209 | NetworkId nid = NetworkId.networkId(networkId); |
212 | DeviceId did = DeviceId.deviceId(deviceId); | 210 | DeviceId did = DeviceId.deviceId(deviceId); |
213 | vnetAdminService.removeVirtualDevice(nid, did); | 211 | vnetAdminService.removeVirtualDevice(nid, did); |
... | @@ -220,25 +218,25 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -220,25 +218,25 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
220 | * Returns all virtual network ports in a virtual device in a virtual network. | 218 | * Returns all virtual network ports in a virtual device in a virtual network. |
221 | * | 219 | * |
222 | * @param networkId network identifier | 220 | * @param networkId network identifier |
223 | - * @param deviceId virtual device identifier | 221 | + * @param deviceId virtual device identifier |
224 | * @return 200 OK | 222 | * @return 200 OK |
225 | */ | 223 | */ |
226 | @GET | 224 | @GET |
227 | @Produces(MediaType.APPLICATION_JSON) | 225 | @Produces(MediaType.APPLICATION_JSON) |
228 | @Path("{networkId}/devices/{deviceId}/ports") | 226 | @Path("{networkId}/devices/{deviceId}/ports") |
229 | public Response getVirtualPorts(@PathParam("networkId") long networkId, | 227 | public Response getVirtualPorts(@PathParam("networkId") long networkId, |
230 | - @PathParam("deviceId") String deviceId) { | 228 | + @PathParam("deviceId") String deviceId) { |
231 | NetworkId nid = NetworkId.networkId(networkId); | 229 | NetworkId nid = NetworkId.networkId(networkId); |
232 | - Iterable<VirtualPort> vports = vnetService.getVirtualPorts(nid, DeviceId.deviceId(deviceId)); | 230 | + Iterable<VirtualPort> vports = vnetService.getVirtualPorts(nid, DeviceId.deviceId(deviceId)); |
233 | return ok(encodeArray(VirtualPort.class, "ports", vports)).build(); | 231 | return ok(encodeArray(VirtualPort.class, "ports", vports)).build(); |
234 | } | 232 | } |
235 | 233 | ||
236 | /** | 234 | /** |
237 | * Creates a virtual network port in a virtual device in a virtual network. | 235 | * Creates a virtual network port in a virtual device in a virtual network. |
238 | * | 236 | * |
239 | - * @param networkId network identifier | 237 | + * @param networkId network identifier |
240 | * @param virtDeviceId virtual device identifier | 238 | * @param virtDeviceId virtual device identifier |
241 | - * @param stream Virtual device JSON stream | 239 | + * @param stream Virtual device JSON stream |
242 | * @return status of the request - CREATED if the JSON is correct, | 240 | * @return status of the request - CREATED if the JSON is correct, |
243 | * BAD_REQUEST if the JSON is invalid | 241 | * BAD_REQUEST if the JSON is invalid |
244 | * @onos.rsModel VirtualPort | 242 | * @onos.rsModel VirtualPort |
... | @@ -248,8 +246,8 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -248,8 +246,8 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
248 | @Produces(MediaType.APPLICATION_JSON) | 246 | @Produces(MediaType.APPLICATION_JSON) |
249 | @Path("{networkId}/devices/{deviceId}/ports") | 247 | @Path("{networkId}/devices/{deviceId}/ports") |
250 | public Response createVirtualPort(@PathParam("networkId") long networkId, | 248 | public Response createVirtualPort(@PathParam("networkId") long networkId, |
251 | - @PathParam("deviceId") String virtDeviceId, | 249 | + @PathParam("deviceId") String virtDeviceId, |
252 | - InputStream stream) { | 250 | + InputStream stream) { |
253 | try { | 251 | try { |
254 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | 252 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
255 | // final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this); | 253 | // final VirtualPort vportReq = codec(VirtualPort.class).decode(jsonTree, this); |
... | @@ -268,11 +266,11 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -268,11 +266,11 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
268 | DeviceId vdevId = DeviceId.deviceId(virtDeviceId); | 266 | DeviceId vdevId = DeviceId.deviceId(virtDeviceId); |
269 | DefaultAnnotations annotations = DefaultAnnotations.builder().build(); | 267 | DefaultAnnotations annotations = DefaultAnnotations.builder().build(); |
270 | Device physDevice = new DefaultDevice(null, DeviceId.deviceId(specifiedPhysDeviceId.asText()), | 268 | Device physDevice = new DefaultDevice(null, DeviceId.deviceId(specifiedPhysDeviceId.asText()), |
271 | - null, null, null, null, null, null, annotations); | 269 | + null, null, null, null, null, null, annotations); |
272 | Port realizedBy = new DefaultPort(physDevice, | 270 | Port realizedBy = new DefaultPort(physDevice, |
273 | - PortNumber.portNumber(specifiedPhysPortNum.asText()), true); | 271 | + PortNumber.portNumber(specifiedPhysPortNum.asText()), true); |
274 | VirtualPort vport = vnetAdminService.createVirtualPort(nid, vdevId, | 272 | VirtualPort vport = vnetAdminService.createVirtualPort(nid, vdevId, |
275 | - PortNumber.portNumber(specifiedPortNum.asText()), realizedBy); | 273 | + PortNumber.portNumber(specifiedPortNum.asText()), realizedBy); |
276 | UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() | 274 | UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() |
277 | .path("vnets").path(specifiedNetworkId.asText()) | 275 | .path("vnets").path(specifiedNetworkId.asText()) |
278 | .path("devices").path(specifiedDeviceId.asText()) | 276 | .path("devices").path(specifiedDeviceId.asText()) |
... | @@ -289,18 +287,18 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -289,18 +287,18 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
289 | * Removes the virtual network port from the virtual device in a virtual network. | 287 | * Removes the virtual network port from the virtual device in a virtual network. |
290 | * | 288 | * |
291 | * @param networkId network identifier | 289 | * @param networkId network identifier |
292 | - * @param deviceId virtual device identifier | 290 | + * @param deviceId virtual device identifier |
293 | - * @param portNum virtual port number | 291 | + * @param portNum virtual port number |
294 | * @return 200 OK, 404 not found | 292 | * @return 200 OK, 404 not found |
295 | */ | 293 | */ |
296 | @DELETE | 294 | @DELETE |
297 | @Path("{networkId}/devices/{deviceId}/ports/{portNum}") | 295 | @Path("{networkId}/devices/{deviceId}/ports/{portNum}") |
298 | public Response removeVirtualPort(@PathParam("networkId") long networkId, | 296 | public Response removeVirtualPort(@PathParam("networkId") long networkId, |
299 | - @PathParam("deviceId") String deviceId, | 297 | + @PathParam("deviceId") String deviceId, |
300 | - @PathParam("portNum") long portNum) { | 298 | + @PathParam("portNum") long portNum) { |
301 | NetworkId nid = NetworkId.networkId(networkId); | 299 | NetworkId nid = NetworkId.networkId(networkId); |
302 | vnetAdminService.removeVirtualPort(nid, DeviceId.deviceId(deviceId), | 300 | vnetAdminService.removeVirtualPort(nid, DeviceId.deviceId(deviceId), |
303 | - PortNumber.portNumber(portNum)); | 301 | + PortNumber.portNumber(portNum)); |
304 | return Response.ok().build(); | 302 | return Response.ok().build(); |
305 | } | 303 | } |
306 | 304 | ||
... | @@ -317,15 +315,15 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -317,15 +315,15 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
317 | @Path("{networkId}/links") | 315 | @Path("{networkId}/links") |
318 | public Response getVirtualLinks(@PathParam("networkId") long networkId) { | 316 | public Response getVirtualLinks(@PathParam("networkId") long networkId) { |
319 | NetworkId nid = NetworkId.networkId(networkId); | 317 | NetworkId nid = NetworkId.networkId(networkId); |
320 | - Set<VirtualLink> vlinks = vnetService.getVirtualLinks(nid); | 318 | + Set<VirtualLink> vlinks = vnetService.getVirtualLinks(nid); |
321 | return ok(encodeArray(VirtualLink.class, "links", vlinks)).build(); | 319 | return ok(encodeArray(VirtualLink.class, "links", vlinks)).build(); |
322 | } | 320 | } |
323 | 321 | ||
324 | - /** | 322 | + /** |
325 | * Creates a virtual network link from the JSON input stream. | 323 | * Creates a virtual network link from the JSON input stream. |
326 | * | 324 | * |
327 | * @param networkId network identifier | 325 | * @param networkId network identifier |
328 | - * @param stream Virtual device JSON stream | 326 | + * @param stream Virtual device JSON stream |
329 | * @return status of the request - CREATED if the JSON is correct, | 327 | * @return status of the request - CREATED if the JSON is correct, |
330 | * BAD_REQUEST if the JSON is invalid | 328 | * BAD_REQUEST if the JSON is invalid |
331 | * @onos.rsModel VirtualLink | 329 | * @onos.rsModel VirtualLink |
... | @@ -343,12 +341,8 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -343,12 +341,8 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
343 | throw new IllegalArgumentException(INVALID_FIELD + "networkId"); | 341 | throw new IllegalArgumentException(INVALID_FIELD + "networkId"); |
344 | } | 342 | } |
345 | final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this); | 343 | final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this); |
346 | - TunnelId tunnelId = TunnelId.valueOf(0); | ||
347 | - if (vlinkReq instanceof DefaultVirtualLink) { | ||
348 | - tunnelId = ((DefaultVirtualLink) vlinkReq).tunnelId(); | ||
349 | - } | ||
350 | vnetAdminService.createVirtualLink(vlinkReq.networkId(), | 344 | vnetAdminService.createVirtualLink(vlinkReq.networkId(), |
351 | - vlinkReq.src(), vlinkReq.dst(), tunnelId); | 345 | + vlinkReq.src(), vlinkReq.dst()); |
352 | UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() | 346 | UriBuilder locationBuilder = uriInfo.getBaseUriBuilder() |
353 | .path("vnets").path(specifiedNetworkId.asText()) | 347 | .path("vnets").path(specifiedNetworkId.asText()) |
354 | .path("links"); | 348 | .path("links"); |
... | @@ -364,7 +358,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -364,7 +358,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
364 | * Removes the virtual network link from the JSON input stream. | 358 | * Removes the virtual network link from the JSON input stream. |
365 | * | 359 | * |
366 | * @param networkId network identifier | 360 | * @param networkId network identifier |
367 | - * @param stream deviceIds JSON stream | 361 | + * @param stream deviceIds JSON stream |
368 | * @return 200 OK, 404 not found | 362 | * @return 200 OK, 404 not found |
369 | * @onos.rsModel VirtualLink | 363 | * @onos.rsModel VirtualLink |
370 | */ | 364 | */ |
... | @@ -372,7 +366,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -372,7 +366,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
372 | @Path("{networkId}/links") | 366 | @Path("{networkId}/links") |
373 | @Consumes(MediaType.APPLICATION_JSON) | 367 | @Consumes(MediaType.APPLICATION_JSON) |
374 | public Response removeVirtualLink(@PathParam("networkId") long networkId, | 368 | public Response removeVirtualLink(@PathParam("networkId") long networkId, |
375 | - InputStream stream) { | 369 | + InputStream stream) { |
376 | try { | 370 | try { |
377 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); | 371 | ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); |
378 | JsonNode specifiedNetworkId = jsonTree.get("networkId"); | 372 | JsonNode specifiedNetworkId = jsonTree.get("networkId"); |
... | @@ -382,7 +376,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -382,7 +376,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
382 | } | 376 | } |
383 | final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this); | 377 | final VirtualLink vlinkReq = codec(VirtualLink.class).decode(jsonTree, this); |
384 | vnetAdminService.removeVirtualLink(vlinkReq.networkId(), | 378 | vnetAdminService.removeVirtualLink(vlinkReq.networkId(), |
385 | - vlinkReq.src(), vlinkReq.dst()); | 379 | + vlinkReq.src(), vlinkReq.dst()); |
386 | } catch (IOException e) { | 380 | } catch (IOException e) { |
387 | throw new IllegalArgumentException(e); | 381 | throw new IllegalArgumentException(e); |
388 | } | 382 | } |
... | @@ -393,7 +387,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { | ... | @@ -393,7 +387,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource { |
393 | /** | 387 | /** |
394 | * Get the tenant identifier from the JSON stream. | 388 | * Get the tenant identifier from the JSON stream. |
395 | * | 389 | * |
396 | - * @param stream TenantId JSON stream | 390 | + * @param stream TenantId JSON stream |
397 | * @param jsonFieldName field name | 391 | * @param jsonFieldName field name |
398 | * @return JsonNode | 392 | * @return JsonNode |
399 | * @throws IOException if unable to parse the request | 393 | * @throws IOException if unable to parse the request | ... | ... |
... | @@ -32,7 +32,6 @@ import org.onlab.osgi.TestServiceDirectory; | ... | @@ -32,7 +32,6 @@ import org.onlab.osgi.TestServiceDirectory; |
32 | import org.onlab.rest.BaseResource; | 32 | import org.onlab.rest.BaseResource; |
33 | import org.onosproject.codec.CodecService; | 33 | import org.onosproject.codec.CodecService; |
34 | import org.onosproject.codec.impl.CodecManager; | 34 | import org.onosproject.codec.impl.CodecManager; |
35 | -import org.onosproject.incubator.net.tunnel.TunnelId; | ||
36 | import org.onosproject.incubator.net.virtual.DefaultVirtualDevice; | 35 | import org.onosproject.incubator.net.virtual.DefaultVirtualDevice; |
37 | import org.onosproject.incubator.net.virtual.DefaultVirtualLink; | 36 | import org.onosproject.incubator.net.virtual.DefaultVirtualLink; |
38 | import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork; | 37 | import org.onosproject.incubator.net.virtual.DefaultVirtualNetwork; |
... | @@ -104,7 +103,6 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -104,7 +103,6 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
104 | private static final String PORT_NUM = "portNum"; | 103 | private static final String PORT_NUM = "portNum"; |
105 | private static final String PHYS_DEVICE_ID = "physDeviceId"; | 104 | private static final String PHYS_DEVICE_ID = "physDeviceId"; |
106 | private static final String PHYS_PORT_NUM = "physPortNum"; | 105 | private static final String PHYS_PORT_NUM = "physPortNum"; |
107 | - private static final String TUNNEL_ID = "tunnelId"; | ||
108 | 106 | ||
109 | private final TenantId tenantId1 = TenantId.tenantId("TenantId1"); | 107 | private final TenantId tenantId1 = TenantId.tenantId("TenantId1"); |
110 | private final TenantId tenantId2 = TenantId.tenantId("TenantId2"); | 108 | private final TenantId tenantId2 = TenantId.tenantId("TenantId2"); |
... | @@ -137,18 +135,26 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -137,18 +135,26 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
137 | Port port2 = new DefaultPort(dev2, portNumber(2), true); | 135 | Port port2 = new DefaultPort(dev2, portNumber(2), true); |
138 | 136 | ||
139 | private final VirtualPort vport22 = new DefaultVirtualPort(networkId3, | 137 | private final VirtualPort vport22 = new DefaultVirtualPort(networkId3, |
140 | - dev22, portNumber(22), port1); | 138 | + dev22, portNumber(22), port1); |
141 | private final VirtualPort vport23 = new DefaultVirtualPort(networkId3, | 139 | private final VirtualPort vport23 = new DefaultVirtualPort(networkId3, |
142 | - dev22, portNumber(23), port2); | 140 | + dev22, portNumber(23), port2); |
143 | 141 | ||
144 | private final ConnectPoint cp11 = NetTestTools.connectPoint(devId1.toString(), 21); | 142 | private final ConnectPoint cp11 = NetTestTools.connectPoint(devId1.toString(), 21); |
145 | private final ConnectPoint cp21 = NetTestTools.connectPoint(devId2.toString(), 22); | 143 | private final ConnectPoint cp21 = NetTestTools.connectPoint(devId2.toString(), 22); |
146 | private final ConnectPoint cp12 = NetTestTools.connectPoint(devId1.toString(), 2); | 144 | private final ConnectPoint cp12 = NetTestTools.connectPoint(devId1.toString(), 2); |
147 | private final ConnectPoint cp22 = NetTestTools.connectPoint(devId2.toString(), 22); | 145 | private final ConnectPoint cp22 = NetTestTools.connectPoint(devId2.toString(), 22); |
148 | 146 | ||
149 | - private final TunnelId tunnelId = TunnelId.valueOf(31); | 147 | + private final VirtualLink vlink1 = DefaultVirtualLink.builder() |
150 | - private final VirtualLink vlink1 = new DefaultVirtualLink(networkId3, cp22, cp11, tunnelId); | 148 | + .networkId(networkId3) |
151 | - private final VirtualLink vlink2 = new DefaultVirtualLink(networkId3, cp12, cp21, tunnelId); | 149 | + .src(cp22) |
150 | + .dst(cp11) | ||
151 | + .build(); | ||
152 | + | ||
153 | + private final VirtualLink vlink2 = DefaultVirtualLink.builder() | ||
154 | + .networkId(networkId3) | ||
155 | + .src(cp12) | ||
156 | + .dst(cp21) | ||
157 | + .build(); | ||
152 | 158 | ||
153 | /** | 159 | /** |
154 | * Sets up the global values for all the tests. | 160 | * Sets up the global values for all the tests. |
... | @@ -217,14 +223,14 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -217,14 +223,14 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
217 | /** | 223 | /** |
218 | * Factory to allocate a virtual network entity matcher. | 224 | * Factory to allocate a virtual network entity matcher. |
219 | * | 225 | * |
220 | - * @param obj virtual network object we are looking for | 226 | + * @param obj virtual network object we are looking for |
221 | * @param jsonFieldNames JSON field names to check against | 227 | * @param jsonFieldNames JSON field names to check against |
222 | - * @param getValue function to retrieve value from virtual network object | 228 | + * @param getValue function to retrieve value from virtual network object |
223 | * @param <T> | 229 | * @param <T> |
224 | * @return JsonObjectMatcher | 230 | * @return JsonObjectMatcher |
225 | */ | 231 | */ |
226 | private static <T> JsonObjectMatcher matchesVnetEntity(T obj, List<String> jsonFieldNames, | 232 | private static <T> JsonObjectMatcher matchesVnetEntity(T obj, List<String> jsonFieldNames, |
227 | - BiFunction<T, String, String> getValue) { | 233 | + BiFunction<T, String, String> getValue) { |
228 | return new JsonObjectMatcher(obj, jsonFieldNames, getValue); | 234 | return new JsonObjectMatcher(obj, jsonFieldNames, getValue); |
229 | } | 235 | } |
230 | 236 | ||
... | @@ -710,7 +716,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -710,7 +716,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
710 | final JsonArray vnetJsonArray = result.get("ports").asArray(); | 716 | final JsonArray vnetJsonArray = result.get("ports").asArray(); |
711 | assertThat(vnetJsonArray, notNullValue()); | 717 | assertThat(vnetJsonArray, notNullValue()); |
712 | assertEquals("Virtual ports array is not the correct size.", | 718 | assertEquals("Virtual ports array is not the correct size.", |
713 | - vportSet.size(), vnetJsonArray.size()); | 719 | + vportSet.size(), vnetJsonArray.size()); |
714 | 720 | ||
715 | vportSet.forEach(vport -> assertThat(vnetJsonArray, hasVport(vport))); | 721 | vportSet.forEach(vport -> assertThat(vnetJsonArray, hasVport(vport))); |
716 | 722 | ||
... | @@ -759,7 +765,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -759,7 +765,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
759 | DeviceId deviceId = devId22; | 765 | DeviceId deviceId = devId22; |
760 | DefaultAnnotations annotations = DefaultAnnotations.builder().build(); | 766 | DefaultAnnotations annotations = DefaultAnnotations.builder().build(); |
761 | Device physDevice = new DefaultDevice(null, DeviceId.deviceId("dev1"), | 767 | Device physDevice = new DefaultDevice(null, DeviceId.deviceId("dev1"), |
762 | - null, null, null, null, null, null, annotations); | 768 | + null, null, null, null, null, null, annotations); |
763 | Port port1 = new DefaultPort(physDevice, portNumber(1), true); | 769 | Port port1 = new DefaultPort(physDevice, portNumber(1), true); |
764 | expect(mockVnetAdminService.createVirtualPort(networkId, deviceId, portNumber(22), port1)) | 770 | expect(mockVnetAdminService.createVirtualPort(networkId, deviceId, portNumber(22), port1)) |
765 | .andReturn(vport22); | 771 | .andReturn(vport22); |
... | @@ -817,7 +823,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -817,7 +823,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
817 | WebTarget wt = target() | 823 | WebTarget wt = target() |
818 | .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); | 824 | .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); |
819 | String reqLocation = "vnets/" + networkId.toString() | 825 | String reqLocation = "vnets/" + networkId.toString() |
820 | - + "/devices/" + deviceId.toString() + "/ports/" + portNum.toLong(); | 826 | + + "/devices/" + deviceId.toString() + "/ports/" + portNum.toLong(); |
821 | Response response = wt.path(reqLocation) | 827 | Response response = wt.path(reqLocation) |
822 | .request(MediaType.APPLICATION_JSON_TYPE) | 828 | .request(MediaType.APPLICATION_JSON_TYPE) |
823 | .delete(); | 829 | .delete(); |
... | @@ -902,15 +908,6 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -902,15 +908,6 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
902 | reason = ID + " was " + jsonNetworkId; | 908 | reason = ID + " was " + jsonNetworkId; |
903 | return false; | 909 | return false; |
904 | } | 910 | } |
905 | - // check TunnelId | ||
906 | - String jsonTunnelId = jsonLink.get(TUNNEL_ID).asString(); | ||
907 | - if (jsonTunnelId != null && vlink instanceof DefaultVirtualLink) { | ||
908 | - String tunnelId = ((DefaultVirtualLink) vlink).tunnelId().toString(); | ||
909 | - if (!jsonTunnelId.equals(tunnelId)) { | ||
910 | - reason = TUNNEL_ID + " was " + jsonTunnelId; | ||
911 | - return false; | ||
912 | - } | ||
913 | - } | ||
914 | return true; | 911 | return true; |
915 | } | 912 | } |
916 | 913 | ||
... | @@ -980,7 +977,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { | ... | @@ -980,7 +977,7 @@ public class VirtualNetworkWebResourceTest extends ResourceTest { |
980 | @Test | 977 | @Test |
981 | public void testPostVirtualLink() { | 978 | public void testPostVirtualLink() { |
982 | NetworkId networkId = networkId3; | 979 | NetworkId networkId = networkId3; |
983 | - expect(mockVnetAdminService.createVirtualLink(networkId, cp22, cp11, tunnelId)) | 980 | + expect(mockVnetAdminService.createVirtualLink(networkId, cp22, cp11)) |
984 | .andReturn(vlink1); | 981 | .andReturn(vlink1); |
985 | replay(mockVnetAdminService); | 982 | replay(mockVnetAdminService); |
986 | 983 | ... | ... |
-
Please register or login to post a comment