change to LF line-endings; not CRLF.
Change-Id: I0991704fcfe9abdd64989509c2cf53ae8aa67ae4
Showing
5 changed files
with
1576 additions
and
1576 deletions
1 | -/* | 1 | +/* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | - * | 3 | + * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | - * you may not use this file except in compliance with 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 | 6 | + * You may obtain a copy of the License at |
7 | - * | 7 | + * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | - * | 9 | + * |
10 | - * Unless required by applicable law or agreed to in writing, software | 10 | + * Unless required by applicable law or agreed to in writing, software |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | - * See the License for the specific language governing permissions and | 13 | + * See the License for the specific language governing permissions and |
14 | - * limitations under the License. | 14 | + * limitations under the License. |
15 | - */ | 15 | + */ |
16 | -package org.onosproject.vtnweb.resources; | 16 | +package org.onosproject.vtnweb.resources; |
17 | - | 17 | + |
18 | -import static com.google.common.base.Preconditions.checkArgument; | 18 | +import static com.google.common.base.Preconditions.checkArgument; |
19 | -import static com.google.common.base.Preconditions.checkNotNull; | 19 | +import static com.google.common.base.Preconditions.checkNotNull; |
20 | -import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; | 20 | +import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
21 | - | 21 | + |
22 | -import java.io.IOException; | 22 | +import java.io.IOException; |
23 | -import java.io.InputStream; | 23 | +import java.io.InputStream; |
24 | -import java.util.Collections; | 24 | +import java.util.Collections; |
25 | -import java.util.HashMap; | 25 | +import java.util.HashMap; |
26 | -import java.util.HashSet; | 26 | +import java.util.HashSet; |
27 | -import java.util.Map; | 27 | +import java.util.Map; |
28 | -import java.util.Set; | 28 | +import java.util.Set; |
29 | -import java.util.concurrent.ConcurrentMap; | 29 | +import java.util.concurrent.ConcurrentMap; |
30 | - | 30 | + |
31 | -import javax.ws.rs.Consumes; | 31 | +import javax.ws.rs.Consumes; |
32 | -import javax.ws.rs.DELETE; | 32 | +import javax.ws.rs.DELETE; |
33 | -import javax.ws.rs.GET; | 33 | +import javax.ws.rs.GET; |
34 | -import javax.ws.rs.POST; | 34 | +import javax.ws.rs.POST; |
35 | -import javax.ws.rs.PUT; | 35 | +import javax.ws.rs.PUT; |
36 | -import javax.ws.rs.Path; | 36 | +import javax.ws.rs.Path; |
37 | -import javax.ws.rs.PathParam; | 37 | +import javax.ws.rs.PathParam; |
38 | -import javax.ws.rs.Produces; | 38 | +import javax.ws.rs.Produces; |
39 | -import javax.ws.rs.core.MediaType; | 39 | +import javax.ws.rs.core.MediaType; |
40 | -import javax.ws.rs.core.Response; | 40 | +import javax.ws.rs.core.Response; |
41 | - | 41 | + |
42 | -import org.onlab.packet.IpAddress; | 42 | +import org.onlab.packet.IpAddress; |
43 | -import org.onlab.packet.IpAddress.Version; | 43 | +import org.onlab.packet.IpAddress.Version; |
44 | -import org.onlab.packet.IpPrefix; | 44 | +import org.onlab.packet.IpPrefix; |
45 | -import org.onlab.util.ItemNotFoundException; | 45 | +import org.onlab.util.ItemNotFoundException; |
46 | -import org.onosproject.rest.AbstractWebResource; | 46 | +import org.onosproject.rest.AbstractWebResource; |
47 | -import org.onosproject.vtnrsc.AllocationPool; | 47 | +import org.onosproject.vtnrsc.AllocationPool; |
48 | -import org.onosproject.vtnrsc.DefaultAllocationPool; | 48 | +import org.onosproject.vtnrsc.DefaultAllocationPool; |
49 | -import org.onosproject.vtnrsc.DefaultHostRoute; | 49 | +import org.onosproject.vtnrsc.DefaultHostRoute; |
50 | -import org.onosproject.vtnrsc.DefaultSubnet; | 50 | +import org.onosproject.vtnrsc.DefaultSubnet; |
51 | -import org.onosproject.vtnrsc.HostRoute; | 51 | +import org.onosproject.vtnrsc.HostRoute; |
52 | -import org.onosproject.vtnrsc.Subnet; | 52 | +import org.onosproject.vtnrsc.Subnet; |
53 | -import org.onosproject.vtnrsc.SubnetId; | 53 | +import org.onosproject.vtnrsc.SubnetId; |
54 | -import org.onosproject.vtnrsc.TenantId; | 54 | +import org.onosproject.vtnrsc.TenantId; |
55 | -import org.onosproject.vtnrsc.TenantNetworkId; | 55 | +import org.onosproject.vtnrsc.TenantNetworkId; |
56 | -import org.onosproject.vtnrsc.Subnet.Mode; | 56 | +import org.onosproject.vtnrsc.Subnet.Mode; |
57 | -import org.onosproject.vtnrsc.subnet.SubnetService; | 57 | +import org.onosproject.vtnrsc.subnet.SubnetService; |
58 | -import org.onosproject.vtnrsc.web.SubnetCodec; | 58 | +import org.onosproject.vtnrsc.web.SubnetCodec; |
59 | -import org.slf4j.Logger; | 59 | +import org.slf4j.Logger; |
60 | -import org.slf4j.LoggerFactory; | 60 | +import org.slf4j.LoggerFactory; |
61 | - | 61 | + |
62 | -import com.fasterxml.jackson.databind.JsonNode; | 62 | +import com.fasterxml.jackson.databind.JsonNode; |
63 | -import com.fasterxml.jackson.databind.ObjectMapper; | 63 | +import com.fasterxml.jackson.databind.ObjectMapper; |
64 | -import com.fasterxml.jackson.databind.node.ObjectNode; | 64 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
65 | -import com.google.common.collect.Maps; | 65 | +import com.google.common.collect.Maps; |
66 | -import com.google.common.collect.Sets; | 66 | +import com.google.common.collect.Sets; |
67 | - | 67 | + |
68 | -@Path("subnets") | 68 | +@Path("subnets") |
69 | -public class SubnetWebResource extends AbstractWebResource { | 69 | +public class SubnetWebResource extends AbstractWebResource { |
70 | - private final Logger log = LoggerFactory.getLogger(SubnetWebResource.class); | 70 | + private final Logger log = LoggerFactory.getLogger(SubnetWebResource.class); |
71 | - public static final String SUBNET_NOT_CREATE = "Subnets is failed to create!"; | 71 | + public static final String SUBNET_NOT_CREATE = "Subnets is failed to create!"; |
72 | - public static final String SUBNET_NOT_FOUND = "Subnets is failed to update!"; | 72 | + public static final String SUBNET_NOT_FOUND = "Subnets is failed to update!"; |
73 | - public static final String JSON_NOT_NULL = "JsonNode can not be null"; | 73 | + public static final String JSON_NOT_NULL = "JsonNode can not be null"; |
74 | - | 74 | + |
75 | - @GET | 75 | + @GET |
76 | - @Produces(MediaType.APPLICATION_JSON) | 76 | + @Produces(MediaType.APPLICATION_JSON) |
77 | - public Response listSubnets() { | 77 | + public Response listSubnets() { |
78 | - Iterable<Subnet> subnets = get(SubnetService.class).getSubnets(); | 78 | + Iterable<Subnet> subnets = get(SubnetService.class).getSubnets(); |
79 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 79 | + ObjectNode result = new ObjectMapper().createObjectNode(); |
80 | - result.set("subnets", new SubnetCodec().encode(subnets, this)); | 80 | + result.set("subnets", new SubnetCodec().encode(subnets, this)); |
81 | - return ok(result.toString()).build(); | 81 | + return ok(result.toString()).build(); |
82 | - } | 82 | + } |
83 | - | 83 | + |
84 | - @GET | 84 | + @GET |
85 | - @Path("{subnetUUID}") | 85 | + @Path("{subnetUUID}") |
86 | - @Produces(MediaType.APPLICATION_JSON) | 86 | + @Produces(MediaType.APPLICATION_JSON) |
87 | - public Response getSubnet(@PathParam("subnetUUID") String id) { | 87 | + public Response getSubnet(@PathParam("subnetUUID") String id) { |
88 | - | 88 | + |
89 | - if (!get(SubnetService.class).exists(SubnetId.subnetId(id))) { | 89 | + if (!get(SubnetService.class).exists(SubnetId.subnetId(id))) { |
90 | - return ok("The subnet does not exists").build(); | 90 | + return ok("The subnet does not exists").build(); |
91 | - } | 91 | + } |
92 | - Subnet sub = nullIsNotFound(get(SubnetService.class) | 92 | + Subnet sub = nullIsNotFound(get(SubnetService.class) |
93 | - .getSubnet(SubnetId.subnetId(id)), | 93 | + .getSubnet(SubnetId.subnetId(id)), |
94 | - SUBNET_NOT_FOUND); | 94 | + SUBNET_NOT_FOUND); |
95 | - | 95 | + |
96 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 96 | + ObjectNode result = new ObjectMapper().createObjectNode(); |
97 | - result.set("subnet", new SubnetCodec().encode(sub, this)); | 97 | + result.set("subnet", new SubnetCodec().encode(sub, this)); |
98 | - return ok(result.toString()).build(); | 98 | + return ok(result.toString()).build(); |
99 | - } | 99 | + } |
100 | - | 100 | + |
101 | - @POST | 101 | + @POST |
102 | - @Produces(MediaType.APPLICATION_JSON) | 102 | + @Produces(MediaType.APPLICATION_JSON) |
103 | - @Consumes(MediaType.APPLICATION_JSON) | 103 | + @Consumes(MediaType.APPLICATION_JSON) |
104 | - public Response createSubnet(final InputStream input) { | 104 | + public Response createSubnet(final InputStream input) { |
105 | - | 105 | + |
106 | - try { | 106 | + try { |
107 | - ObjectMapper mapper = new ObjectMapper(); | 107 | + ObjectMapper mapper = new ObjectMapper(); |
108 | - JsonNode subnode = mapper.readTree(input); | 108 | + JsonNode subnode = mapper.readTree(input); |
109 | - Iterable<Subnet> subnets = createOrUpdateByInputStream(subnode); | 109 | + Iterable<Subnet> subnets = createOrUpdateByInputStream(subnode); |
110 | - Boolean result = nullIsNotFound((get(SubnetService.class) | 110 | + Boolean result = nullIsNotFound((get(SubnetService.class) |
111 | - .createSubnets(subnets)), | 111 | + .createSubnets(subnets)), |
112 | - SUBNET_NOT_CREATE); | 112 | + SUBNET_NOT_CREATE); |
113 | - | 113 | + |
114 | - if (!result) { | 114 | + if (!result) { |
115 | - return Response.status(204).entity(SUBNET_NOT_CREATE).build(); | 115 | + return Response.status(204).entity(SUBNET_NOT_CREATE).build(); |
116 | - } | 116 | + } |
117 | - return Response.status(202).entity(result.toString()).build(); | 117 | + return Response.status(202).entity(result.toString()).build(); |
118 | - } catch (Exception e) { | 118 | + } catch (Exception e) { |
119 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 119 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
120 | - .build(); | 120 | + .build(); |
121 | - } | 121 | + } |
122 | - } | 122 | + } |
123 | - | 123 | + |
124 | - @PUT | 124 | + @PUT |
125 | - @Path("{subnetUUID}") | 125 | + @Path("{subnetUUID}") |
126 | - @Produces(MediaType.APPLICATION_JSON) | 126 | + @Produces(MediaType.APPLICATION_JSON) |
127 | - @Consumes(MediaType.APPLICATION_JSON) | 127 | + @Consumes(MediaType.APPLICATION_JSON) |
128 | - public Response updateSubnet(@PathParam("id") String id, | 128 | + public Response updateSubnet(@PathParam("id") String id, |
129 | - final InputStream input) { | 129 | + final InputStream input) { |
130 | - try { | 130 | + try { |
131 | - ObjectMapper mapper = new ObjectMapper(); | 131 | + ObjectMapper mapper = new ObjectMapper(); |
132 | - JsonNode subnode = mapper.readTree(input); | 132 | + JsonNode subnode = mapper.readTree(input); |
133 | - Iterable<Subnet> subnets = createOrUpdateByInputStream(subnode); | 133 | + Iterable<Subnet> subnets = createOrUpdateByInputStream(subnode); |
134 | - Boolean result = nullIsNotFound(get(SubnetService.class) | 134 | + Boolean result = nullIsNotFound(get(SubnetService.class) |
135 | - .updateSubnets(subnets), SUBNET_NOT_FOUND); | 135 | + .updateSubnets(subnets), SUBNET_NOT_FOUND); |
136 | - if (!result) { | 136 | + if (!result) { |
137 | - return Response.status(204).entity(SUBNET_NOT_FOUND).build(); | 137 | + return Response.status(204).entity(SUBNET_NOT_FOUND).build(); |
138 | - } | 138 | + } |
139 | - return Response.status(203).entity(result.toString()).build(); | 139 | + return Response.status(203).entity(result.toString()).build(); |
140 | - } catch (Exception e) { | 140 | + } catch (Exception e) { |
141 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 141 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
142 | - .build(); | 142 | + .build(); |
143 | - } | 143 | + } |
144 | - } | 144 | + } |
145 | - | 145 | + |
146 | - @Path("{subnetUUID}") | 146 | + @Path("{subnetUUID}") |
147 | - @DELETE | 147 | + @DELETE |
148 | - public Response deleteSingleSubnet(@PathParam("subnetUUID") String id) | 148 | + public Response deleteSingleSubnet(@PathParam("subnetUUID") String id) |
149 | - throws IOException { | 149 | + throws IOException { |
150 | - try { | 150 | + try { |
151 | - SubnetId subId = SubnetId.subnetId(id); | 151 | + SubnetId subId = SubnetId.subnetId(id); |
152 | - Set<SubnetId> subIds = new HashSet<>(); | 152 | + Set<SubnetId> subIds = new HashSet<>(); |
153 | - subIds.add(subId); | 153 | + subIds.add(subId); |
154 | - get(SubnetService.class).removeSubnets(subIds); | 154 | + get(SubnetService.class).removeSubnets(subIds); |
155 | - return Response.status(201).entity("SUCCESS").build(); | 155 | + return Response.status(201).entity("SUCCESS").build(); |
156 | - } catch (Exception e) { | 156 | + } catch (Exception e) { |
157 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 157 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
158 | - .build(); | 158 | + .build(); |
159 | - } | 159 | + } |
160 | - } | 160 | + } |
161 | - | 161 | + |
162 | - private Iterable<Subnet> createOrUpdateByInputStream(JsonNode subnode) { | 162 | + private Iterable<Subnet> createOrUpdateByInputStream(JsonNode subnode) { |
163 | - checkNotNull(subnode, JSON_NOT_NULL); | 163 | + checkNotNull(subnode, JSON_NOT_NULL); |
164 | - Iterable<Subnet> subnets = null; | 164 | + Iterable<Subnet> subnets = null; |
165 | - JsonNode subnetNodes = subnode.get("subnets"); | 165 | + JsonNode subnetNodes = subnode.get("subnets"); |
166 | - if (subnetNodes == null) { | 166 | + if (subnetNodes == null) { |
167 | - subnetNodes = subnode.get("subnet"); | 167 | + subnetNodes = subnode.get("subnet"); |
168 | - } | 168 | + } |
169 | - log.debug("subnetNodes is {}", subnetNodes.toString()); | 169 | + log.debug("subnetNodes is {}", subnetNodes.toString()); |
170 | - if (subnetNodes.isArray()) { | 170 | + if (subnetNodes.isArray()) { |
171 | - subnets = changeJsonToSubs(subnetNodes); | 171 | + subnets = changeJsonToSubs(subnetNodes); |
172 | - } else { | 172 | + } else { |
173 | - subnets = changeJsonToSub(subnetNodes); | 173 | + subnets = changeJsonToSub(subnetNodes); |
174 | - } | 174 | + } |
175 | - return subnets; | 175 | + return subnets; |
176 | - } | 176 | + } |
177 | - | 177 | + |
178 | - /** | 178 | + /** |
179 | - * Returns a collection of subnets from subnetNodes. | 179 | + * Returns a collection of subnets from subnetNodes. |
180 | - * | 180 | + * |
181 | - * @param subnetNodes the subnet json node | 181 | + * @param subnetNodes the subnet json node |
182 | - * @return subnets a collection of subnets | 182 | + * @return subnets a collection of subnets |
183 | - */ | 183 | + */ |
184 | - public Iterable<Subnet> changeJsonToSubs(JsonNode subnetNodes) { | 184 | + public Iterable<Subnet> changeJsonToSubs(JsonNode subnetNodes) { |
185 | - checkNotNull(subnetNodes, JSON_NOT_NULL); | 185 | + checkNotNull(subnetNodes, JSON_NOT_NULL); |
186 | - Map<SubnetId, Subnet> subMap = new HashMap<>(); | 186 | + Map<SubnetId, Subnet> subMap = new HashMap<>(); |
187 | - for (JsonNode subnetNode : subnetNodes) { | 187 | + for (JsonNode subnetNode : subnetNodes) { |
188 | - if (!subnetNode.hasNonNull("id")) { | 188 | + if (!subnetNode.hasNonNull("id")) { |
189 | - return null; | 189 | + return null; |
190 | - } | 190 | + } |
191 | - SubnetId id = SubnetId.subnetId(subnetNode.get("id").asText()); | 191 | + SubnetId id = SubnetId.subnetId(subnetNode.get("id").asText()); |
192 | - String subnetName = subnetNode.get("name").asText(); | 192 | + String subnetName = subnetNode.get("name").asText(); |
193 | - TenantId tenantId = TenantId | 193 | + TenantId tenantId = TenantId |
194 | - .tenantId(subnetNode.get("tenant_id").asText()); | 194 | + .tenantId(subnetNode.get("tenant_id").asText()); |
195 | - TenantNetworkId networkId = TenantNetworkId | 195 | + TenantNetworkId networkId = TenantNetworkId |
196 | - .networkId(subnetNode.get("network_id").asText()); | 196 | + .networkId(subnetNode.get("network_id").asText()); |
197 | - Version ipVersion = Version | 197 | + Version ipVersion = Version |
198 | - .valueOf(subnetNode.get("ip_version").asText()); | 198 | + .valueOf(subnetNode.get("ip_version").asText()); |
199 | - IpPrefix cidr = IpPrefix.valueOf(subnetNode.get("cidr").asText()); | 199 | + IpPrefix cidr = IpPrefix.valueOf(subnetNode.get("cidr").asText()); |
200 | - IpAddress gatewayIp = IpAddress | 200 | + IpAddress gatewayIp = IpAddress |
201 | - .valueOf(subnetNode.get("gateway_ip").asText()); | 201 | + .valueOf(subnetNode.get("gateway_ip").asText()); |
202 | - Boolean dhcpEnabled = subnetNode.get("enable_dhcp").asBoolean(); | 202 | + Boolean dhcpEnabled = subnetNode.get("enable_dhcp").asBoolean(); |
203 | - Boolean shared = subnetNode.get("shared").asBoolean(); | 203 | + Boolean shared = subnetNode.get("shared").asBoolean(); |
204 | - JsonNode hostRoutes = subnetNode.get("host_routes"); | 204 | + JsonNode hostRoutes = subnetNode.get("host_routes"); |
205 | - Iterable<HostRoute> hostRoutesIt = jsonNodeToHostRoutes(hostRoutes); | 205 | + Iterable<HostRoute> hostRoutesIt = jsonNodeToHostRoutes(hostRoutes); |
206 | - JsonNode allocationPools = subnetNode.get("allocation_pools"); | 206 | + JsonNode allocationPools = subnetNode.get("allocation_pools"); |
207 | - Iterable<AllocationPool> allocationPoolsIt = jsonNodeToAllocationPools(allocationPools); | 207 | + Iterable<AllocationPool> allocationPoolsIt = jsonNodeToAllocationPools(allocationPools); |
208 | - Mode ipV6AddressMode = Mode | 208 | + Mode ipV6AddressMode = Mode |
209 | - .valueOf(subnetNode.get("ipv6_address_mode").asText()); | 209 | + .valueOf(subnetNode.get("ipv6_address_mode").asText()); |
210 | - Mode ipV6RaMode = Mode | 210 | + Mode ipV6RaMode = Mode |
211 | - .valueOf(subnetNode.get("ipv6_ra_mode").asText()); | 211 | + .valueOf(subnetNode.get("ipv6_ra_mode").asText()); |
212 | - Subnet subnet = new DefaultSubnet(id, subnetName, networkId, | 212 | + Subnet subnet = new DefaultSubnet(id, subnetName, networkId, |
213 | - tenantId, ipVersion, cidr, | 213 | + tenantId, ipVersion, cidr, |
214 | - gatewayIp, dhcpEnabled, shared, | 214 | + gatewayIp, dhcpEnabled, shared, |
215 | - Sets.newHashSet(hostRoutesIt), ipV6AddressMode, | 215 | + Sets.newHashSet(hostRoutesIt), ipV6AddressMode, |
216 | - ipV6RaMode, Sets.newHashSet(allocationPoolsIt)); | 216 | + ipV6RaMode, Sets.newHashSet(allocationPoolsIt)); |
217 | - subMap.put(id, subnet); | 217 | + subMap.put(id, subnet); |
218 | - } | 218 | + } |
219 | - return Collections.unmodifiableCollection(subMap.values()); | 219 | + return Collections.unmodifiableCollection(subMap.values()); |
220 | - } | 220 | + } |
221 | - | 221 | + |
222 | - /** | 222 | + /** |
223 | - * Returns a collection of subnets from subnetNodes. | 223 | + * Returns a collection of subnets from subnetNodes. |
224 | - * | 224 | + * |
225 | - * @param subnetNodes the subnet json node | 225 | + * @param subnetNodes the subnet json node |
226 | - * @return subnets a collection of subnets | 226 | + * @return subnets a collection of subnets |
227 | - */ | 227 | + */ |
228 | - public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) { | 228 | + public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) { |
229 | - checkNotNull(subnetNodes, JSON_NOT_NULL); | 229 | + checkNotNull(subnetNodes, JSON_NOT_NULL); |
230 | - checkArgument(subnetNodes.get("enable_dhcp").isBoolean(), "enable_dhcp should be boolean"); | 230 | + checkArgument(subnetNodes.get("enable_dhcp").isBoolean(), "enable_dhcp should be boolean"); |
231 | - checkArgument(subnetNodes.get("shared").isBoolean(), "shared should be boolean"); | 231 | + checkArgument(subnetNodes.get("shared").isBoolean(), "shared should be boolean"); |
232 | - Map<SubnetId, Subnet> subMap = new HashMap<>(); | 232 | + Map<SubnetId, Subnet> subMap = new HashMap<>(); |
233 | - if (!subnetNodes.hasNonNull("id")) { | 233 | + if (!subnetNodes.hasNonNull("id")) { |
234 | - return null; | 234 | + return null; |
235 | - } | 235 | + } |
236 | - SubnetId id = SubnetId.subnetId(subnetNodes.get("id").asText()); | 236 | + SubnetId id = SubnetId.subnetId(subnetNodes.get("id").asText()); |
237 | - String subnetName = subnetNodes.get("name").asText(); | 237 | + String subnetName = subnetNodes.get("name").asText(); |
238 | - TenantId tenantId = TenantId | 238 | + TenantId tenantId = TenantId |
239 | - .tenantId(subnetNodes.get("tenant_id").asText()); | 239 | + .tenantId(subnetNodes.get("tenant_id").asText()); |
240 | - TenantNetworkId networkId = TenantNetworkId | 240 | + TenantNetworkId networkId = TenantNetworkId |
241 | - .networkId(subnetNodes.get("network_id").asText()); | 241 | + .networkId(subnetNodes.get("network_id").asText()); |
242 | - String version = subnetNodes.get("ip_version").asText(); | 242 | + String version = subnetNodes.get("ip_version").asText(); |
243 | - Version ipVersion; | 243 | + Version ipVersion; |
244 | - switch (version) { | 244 | + switch (version) { |
245 | - case "4": | 245 | + case "4": |
246 | - ipVersion = Version.INET; | 246 | + ipVersion = Version.INET; |
247 | - break; | 247 | + break; |
248 | - case "6": | 248 | + case "6": |
249 | - ipVersion = Version.INET; | 249 | + ipVersion = Version.INET; |
250 | - break; | 250 | + break; |
251 | - default: | 251 | + default: |
252 | - throw new IllegalArgumentException("ipVersion should be 4 or 6."); | 252 | + throw new IllegalArgumentException("ipVersion should be 4 or 6."); |
253 | - } | 253 | + } |
254 | - | 254 | + |
255 | - IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText()); | 255 | + IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText()); |
256 | - IpAddress gatewayIp = IpAddress | 256 | + IpAddress gatewayIp = IpAddress |
257 | - .valueOf(subnetNodes.get("gateway_ip").asText()); | 257 | + .valueOf(subnetNodes.get("gateway_ip").asText()); |
258 | - Boolean dhcpEnabled = subnetNodes.get("enable_dhcp").asBoolean(); | 258 | + Boolean dhcpEnabled = subnetNodes.get("enable_dhcp").asBoolean(); |
259 | - Boolean shared = subnetNodes.get("shared").asBoolean(); | 259 | + Boolean shared = subnetNodes.get("shared").asBoolean(); |
260 | - JsonNode hostRoutes = subnetNodes.get("host_routes"); | 260 | + JsonNode hostRoutes = subnetNodes.get("host_routes"); |
261 | - Iterable<HostRoute> hostRoutesIt = jsonNodeToHostRoutes(hostRoutes); | 261 | + Iterable<HostRoute> hostRoutesIt = jsonNodeToHostRoutes(hostRoutes); |
262 | - JsonNode allocationPools = subnetNodes.get("allocation_pools"); | 262 | + JsonNode allocationPools = subnetNodes.get("allocation_pools"); |
263 | - Iterable<AllocationPool> allocationPoolsIt = jsonNodeToAllocationPools(allocationPools); | 263 | + Iterable<AllocationPool> allocationPoolsIt = jsonNodeToAllocationPools(allocationPools); |
264 | - | 264 | + |
265 | - Mode ipV6AddressMode = getMode(subnetNodes.get("ipv6_address_mode") | 265 | + Mode ipV6AddressMode = getMode(subnetNodes.get("ipv6_address_mode") |
266 | - .asText()); | 266 | + .asText()); |
267 | - Mode ipV6RaMode = getMode(subnetNodes.get("ipv6_ra_mode").asText()); | 267 | + Mode ipV6RaMode = getMode(subnetNodes.get("ipv6_ra_mode").asText()); |
268 | - | 268 | + |
269 | - Subnet subnet = new DefaultSubnet(id, subnetName, networkId, tenantId, | 269 | + Subnet subnet = new DefaultSubnet(id, subnetName, networkId, tenantId, |
270 | - ipVersion, cidr, gatewayIp, | 270 | + ipVersion, cidr, gatewayIp, |
271 | - dhcpEnabled, shared, Sets.newHashSet(hostRoutesIt), | 271 | + dhcpEnabled, shared, Sets.newHashSet(hostRoutesIt), |
272 | - ipV6AddressMode, ipV6RaMode, | 272 | + ipV6AddressMode, ipV6RaMode, |
273 | - Sets.newHashSet(allocationPoolsIt)); | 273 | + Sets.newHashSet(allocationPoolsIt)); |
274 | - subMap.put(id, subnet); | 274 | + subMap.put(id, subnet); |
275 | - return Collections.unmodifiableCollection(subMap.values()); | 275 | + return Collections.unmodifiableCollection(subMap.values()); |
276 | - } | 276 | + } |
277 | - | 277 | + |
278 | - /** | 278 | + /** |
279 | - * Gets ipv6_address_mode or ipv6_ra_mode type. | 279 | + * Gets ipv6_address_mode or ipv6_ra_mode type. |
280 | - * | 280 | + * |
281 | - * @param mode the String value in JsonNode | 281 | + * @param mode the String value in JsonNode |
282 | - * @return ipV6Mode Mode of the ipV6Mode | 282 | + * @return ipV6Mode Mode of the ipV6Mode |
283 | - */ | 283 | + */ |
284 | - private Mode getMode(String mode) { | 284 | + private Mode getMode(String mode) { |
285 | - Mode ipV6Mode; | 285 | + Mode ipV6Mode; |
286 | - if (mode == null) { | 286 | + if (mode == null) { |
287 | - return null; | 287 | + return null; |
288 | - } | 288 | + } |
289 | - switch (mode) { | 289 | + switch (mode) { |
290 | - case "dhcpv6-stateful": | 290 | + case "dhcpv6-stateful": |
291 | - ipV6Mode = Mode.DHCPV6_STATEFUL; | 291 | + ipV6Mode = Mode.DHCPV6_STATEFUL; |
292 | - break; | 292 | + break; |
293 | - case "dhcpv6-stateless": | 293 | + case "dhcpv6-stateless": |
294 | - ipV6Mode = Mode.DHCPV6_STATELESS; | 294 | + ipV6Mode = Mode.DHCPV6_STATELESS; |
295 | - break; | 295 | + break; |
296 | - case "slaac": | 296 | + case "slaac": |
297 | - ipV6Mode = Mode.SLAAC; | 297 | + ipV6Mode = Mode.SLAAC; |
298 | - break; | 298 | + break; |
299 | - default: | 299 | + default: |
300 | - ipV6Mode = null; | 300 | + ipV6Mode = null; |
301 | - } | 301 | + } |
302 | - return ipV6Mode; | 302 | + return ipV6Mode; |
303 | - } | 303 | + } |
304 | - | 304 | + |
305 | - /** | 305 | + /** |
306 | - * Changes JsonNode alocPools to a collection of the alocPools. | 306 | + * Changes JsonNode alocPools to a collection of the alocPools. |
307 | - * | 307 | + * |
308 | - * @param allocationPools the allocationPools JsonNode | 308 | + * @param allocationPools the allocationPools JsonNode |
309 | - * @return a collection of allocationPools | 309 | + * @return a collection of allocationPools |
310 | - */ | 310 | + */ |
311 | - public Iterable<AllocationPool> jsonNodeToAllocationPools(JsonNode allocationPools) { | 311 | + public Iterable<AllocationPool> jsonNodeToAllocationPools(JsonNode allocationPools) { |
312 | - checkNotNull(allocationPools, JSON_NOT_NULL); | 312 | + checkNotNull(allocationPools, JSON_NOT_NULL); |
313 | - ConcurrentMap<Integer, AllocationPool> alocplMaps = Maps | 313 | + ConcurrentMap<Integer, AllocationPool> alocplMaps = Maps |
314 | - .newConcurrentMap(); | 314 | + .newConcurrentMap(); |
315 | - Integer i = 0; | 315 | + Integer i = 0; |
316 | - for (JsonNode node : allocationPools) { | 316 | + for (JsonNode node : allocationPools) { |
317 | - IpAddress startIp = IpAddress.valueOf(node.get("start").asText()); | 317 | + IpAddress startIp = IpAddress.valueOf(node.get("start").asText()); |
318 | - IpAddress endIp = IpAddress.valueOf(node.get("end").asText()); | 318 | + IpAddress endIp = IpAddress.valueOf(node.get("end").asText()); |
319 | - AllocationPool alocPls = new DefaultAllocationPool(startIp, endIp); | 319 | + AllocationPool alocPls = new DefaultAllocationPool(startIp, endIp); |
320 | - alocplMaps.putIfAbsent(i, alocPls); | 320 | + alocplMaps.putIfAbsent(i, alocPls); |
321 | - i++; | 321 | + i++; |
322 | - } | 322 | + } |
323 | - return Collections.unmodifiableCollection(alocplMaps.values()); | 323 | + return Collections.unmodifiableCollection(alocplMaps.values()); |
324 | - } | 324 | + } |
325 | - | 325 | + |
326 | - /** | 326 | + /** |
327 | - * Changes hostRoutes JsonNode to a collection of the hostRoutes. | 327 | + * Changes hostRoutes JsonNode to a collection of the hostRoutes. |
328 | - * | 328 | + * |
329 | - * @param hostRoutes the hostRoutes json node | 329 | + * @param hostRoutes the hostRoutes json node |
330 | - * @return a collection of hostRoutes | 330 | + * @return a collection of hostRoutes |
331 | - */ | 331 | + */ |
332 | - public Iterable<HostRoute> jsonNodeToHostRoutes(JsonNode hostRoutes) { | 332 | + public Iterable<HostRoute> jsonNodeToHostRoutes(JsonNode hostRoutes) { |
333 | - checkNotNull(hostRoutes, JSON_NOT_NULL); | 333 | + checkNotNull(hostRoutes, JSON_NOT_NULL); |
334 | - ConcurrentMap<Integer, HostRoute> hostRouteMaps = Maps | 334 | + ConcurrentMap<Integer, HostRoute> hostRouteMaps = Maps |
335 | - .newConcurrentMap(); | 335 | + .newConcurrentMap(); |
336 | - Integer i = 0; | 336 | + Integer i = 0; |
337 | - for (JsonNode node : hostRoutes) { | 337 | + for (JsonNode node : hostRoutes) { |
338 | - IpAddress nexthop = IpAddress.valueOf(node.get("nexthop").asText()); | 338 | + IpAddress nexthop = IpAddress.valueOf(node.get("nexthop").asText()); |
339 | - IpPrefix destination = IpPrefix.valueOf(node.get("destination") | 339 | + IpPrefix destination = IpPrefix.valueOf(node.get("destination") |
340 | - .asText()); | 340 | + .asText()); |
341 | - HostRoute hostRoute = new DefaultHostRoute(nexthop, destination); | 341 | + HostRoute hostRoute = new DefaultHostRoute(nexthop, destination); |
342 | - hostRouteMaps.putIfAbsent(i, hostRoute); | 342 | + hostRouteMaps.putIfAbsent(i, hostRoute); |
343 | - i++; | 343 | + i++; |
344 | - } | 344 | + } |
345 | - return Collections.unmodifiableCollection(hostRouteMaps.values()); | 345 | + return Collections.unmodifiableCollection(hostRouteMaps.values()); |
346 | - } | 346 | + } |
347 | - | 347 | + |
348 | - /** | 348 | + /** |
349 | - * Returns the specified item if that items is null; otherwise throws not | 349 | + * Returns the specified item if that items is null; otherwise throws not |
350 | - * found exception. | 350 | + * found exception. |
351 | - * | 351 | + * |
352 | - * @param item item to check | 352 | + * @param item item to check |
353 | - * @param <T> item type | 353 | + * @param <T> item type |
354 | - * @param message not found message | 354 | + * @param message not found message |
355 | - * @return item if not null | 355 | + * @return item if not null |
356 | - * @throws org.onlab.util.ItemNotFoundException if item is null | 356 | + * @throws org.onlab.util.ItemNotFoundException if item is null |
357 | - */ | 357 | + */ |
358 | - protected <T> T nullIsNotFound(T item, String message) { | 358 | + protected <T> T nullIsNotFound(T item, String message) { |
359 | - if (item == null) { | 359 | + if (item == null) { |
360 | - throw new ItemNotFoundException(message); | 360 | + throw new ItemNotFoundException(message); |
361 | - } | 361 | + } |
362 | - return item; | 362 | + return item; |
363 | - } | 363 | + } |
364 | - | 364 | + |
365 | -} | 365 | +} | ... | ... |
1 | -/* | 1 | +/* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | - * | 3 | + * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | - * you may not use this file except in compliance with 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 | 6 | + * You may obtain a copy of the License at |
7 | - * | 7 | + * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | - * | 9 | + * |
10 | - * Unless required by applicable law or agreed to in writing, software | 10 | + * Unless required by applicable law or agreed to in writing, software |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | - * See the License for the specific language governing permissions and | 13 | + * See the License for the specific language governing permissions and |
14 | - * limitations under the License. | 14 | + * limitations under the License. |
15 | - */ | 15 | + */ |
16 | -package org.onosproject.vtnweb.resources; | 16 | +package org.onosproject.vtnweb.resources; |
17 | - | 17 | + |
18 | -import static com.google.common.base.Preconditions.checkNotNull; | 18 | +import static com.google.common.base.Preconditions.checkNotNull; |
19 | -import static com.google.common.base.Preconditions.checkArgument; | 19 | +import static com.google.common.base.Preconditions.checkArgument; |
20 | -import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; | 20 | +import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
21 | -import static javax.ws.rs.core.Response.Status.OK; | 21 | +import static javax.ws.rs.core.Response.Status.OK; |
22 | - | 22 | + |
23 | -import java.io.InputStream; | 23 | +import java.io.InputStream; |
24 | -import java.util.Collections; | 24 | +import java.util.Collections; |
25 | -import java.util.HashSet; | 25 | +import java.util.HashSet; |
26 | -import java.util.Iterator; | 26 | +import java.util.Iterator; |
27 | -import java.util.Set; | 27 | +import java.util.Set; |
28 | -import java.util.concurrent.ConcurrentMap; | 28 | +import java.util.concurrent.ConcurrentMap; |
29 | - | 29 | + |
30 | -import javax.ws.rs.Consumes; | 30 | +import javax.ws.rs.Consumes; |
31 | -import javax.ws.rs.DELETE; | 31 | +import javax.ws.rs.DELETE; |
32 | -import javax.ws.rs.GET; | 32 | +import javax.ws.rs.GET; |
33 | -import javax.ws.rs.POST; | 33 | +import javax.ws.rs.POST; |
34 | -import javax.ws.rs.PUT; | 34 | +import javax.ws.rs.PUT; |
35 | -import javax.ws.rs.Path; | 35 | +import javax.ws.rs.Path; |
36 | -import javax.ws.rs.PathParam; | 36 | +import javax.ws.rs.PathParam; |
37 | -import javax.ws.rs.Produces; | 37 | +import javax.ws.rs.Produces; |
38 | -import javax.ws.rs.QueryParam; | 38 | +import javax.ws.rs.QueryParam; |
39 | -import javax.ws.rs.core.MediaType; | 39 | +import javax.ws.rs.core.MediaType; |
40 | -import javax.ws.rs.core.Response; | 40 | +import javax.ws.rs.core.Response; |
41 | - | 41 | + |
42 | -import org.onlab.util.ItemNotFoundException; | 42 | +import org.onlab.util.ItemNotFoundException; |
43 | -import org.onosproject.rest.AbstractWebResource; | 43 | +import org.onosproject.rest.AbstractWebResource; |
44 | -import org.onosproject.vtnrsc.DefaultTenantNetwork; | 44 | +import org.onosproject.vtnrsc.DefaultTenantNetwork; |
45 | -import org.onosproject.vtnrsc.PhysicalNetwork; | 45 | +import org.onosproject.vtnrsc.PhysicalNetwork; |
46 | -import org.onosproject.vtnrsc.SegmentationId; | 46 | +import org.onosproject.vtnrsc.SegmentationId; |
47 | -import org.onosproject.vtnrsc.TenantId; | 47 | +import org.onosproject.vtnrsc.TenantId; |
48 | -import org.onosproject.vtnrsc.TenantNetwork; | 48 | +import org.onosproject.vtnrsc.TenantNetwork; |
49 | -import org.onosproject.vtnrsc.TenantNetworkId; | 49 | +import org.onosproject.vtnrsc.TenantNetworkId; |
50 | -import org.onosproject.vtnrsc.TenantNetwork.State; | 50 | +import org.onosproject.vtnrsc.TenantNetwork.State; |
51 | -import org.onosproject.vtnrsc.TenantNetwork.Type; | 51 | +import org.onosproject.vtnrsc.TenantNetwork.Type; |
52 | -import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; | 52 | +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; |
53 | -import org.onosproject.vtnrsc.web.TenantNetworkCodec; | 53 | +import org.onosproject.vtnrsc.web.TenantNetworkCodec; |
54 | -import org.slf4j.Logger; | 54 | +import org.slf4j.Logger; |
55 | -import org.slf4j.LoggerFactory; | 55 | +import org.slf4j.LoggerFactory; |
56 | - | 56 | + |
57 | -import com.fasterxml.jackson.databind.JsonNode; | 57 | +import com.fasterxml.jackson.databind.JsonNode; |
58 | -import com.fasterxml.jackson.databind.ObjectMapper; | 58 | +import com.fasterxml.jackson.databind.ObjectMapper; |
59 | -import com.fasterxml.jackson.databind.node.ObjectNode; | 59 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
60 | -import com.google.common.collect.Maps; | 60 | +import com.google.common.collect.Maps; |
61 | - | 61 | + |
62 | -/** | 62 | +/** |
63 | - * REST resource for interacting with the inventory of networks. | 63 | + * REST resource for interacting with the inventory of networks. |
64 | - */ | 64 | + */ |
65 | -@Path("networks") | 65 | +@Path("networks") |
66 | -public class TenantNetworkWebResource extends AbstractWebResource { | 66 | +public class TenantNetworkWebResource extends AbstractWebResource { |
67 | - public static final String NETWORK_NOT_FOUND = "Network is not found"; | 67 | + public static final String NETWORK_NOT_FOUND = "Network is not found"; |
68 | - public static final String NETWORK_ID_EXIST = "Network id is existed"; | 68 | + public static final String NETWORK_ID_EXIST = "Network id is existed"; |
69 | - public static final String NETWORK_ID_NOT_EXIST = "Network id is not existed"; | 69 | + public static final String NETWORK_ID_NOT_EXIST = "Network id is not existed"; |
70 | - public static final String CREATE_NETWORK = "create network"; | 70 | + public static final String CREATE_NETWORK = "create network"; |
71 | - public static final String UPDATE_NETWORK = "update network"; | 71 | + public static final String UPDATE_NETWORK = "update network"; |
72 | - public static final String DELETE_NETWORK = "delete network"; | 72 | + public static final String DELETE_NETWORK = "delete network"; |
73 | - public static final String JSON_NOT_NULL = "JsonNode can not be null"; | 73 | + public static final String JSON_NOT_NULL = "JsonNode can not be null"; |
74 | - | 74 | + |
75 | - protected static final Logger log = LoggerFactory | 75 | + protected static final Logger log = LoggerFactory |
76 | - .getLogger(TenantNetworkWebResource.class); | 76 | + .getLogger(TenantNetworkWebResource.class); |
77 | - private final ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps | 77 | + private final ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps |
78 | - .newConcurrentMap(); | 78 | + .newConcurrentMap(); |
79 | - | 79 | + |
80 | - @GET | 80 | + @GET |
81 | - @Produces({ MediaType.APPLICATION_JSON }) | 81 | + @Produces({ MediaType.APPLICATION_JSON }) |
82 | - public Response getNetworks(@QueryParam("id") String queryId, | 82 | + public Response getNetworks(@QueryParam("id") String queryId, |
83 | - @QueryParam("name") String queryName, | 83 | + @QueryParam("name") String queryName, |
84 | - @QueryParam("admin_state_up") String queryadminStateUp, | 84 | + @QueryParam("admin_state_up") String queryadminStateUp, |
85 | - @QueryParam("status") String querystate, | 85 | + @QueryParam("status") String querystate, |
86 | - @QueryParam("shared") String queryshared, | 86 | + @QueryParam("shared") String queryshared, |
87 | - @QueryParam("tenant_id") String querytenantId, | 87 | + @QueryParam("tenant_id") String querytenantId, |
88 | - @QueryParam("router:external") String routerExternal, | 88 | + @QueryParam("router:external") String routerExternal, |
89 | - @QueryParam("provider:network_type") String type, | 89 | + @QueryParam("provider:network_type") String type, |
90 | - @QueryParam("provider:physical_network") String physicalNetwork, | 90 | + @QueryParam("provider:physical_network") String physicalNetwork, |
91 | - @QueryParam("provider:segmentation_id") String segmentationId) { | 91 | + @QueryParam("provider:segmentation_id") String segmentationId) { |
92 | - Iterable<TenantNetwork> networks = get(TenantNetworkService.class) | 92 | + Iterable<TenantNetwork> networks = get(TenantNetworkService.class) |
93 | - .getNetworks(); | 93 | + .getNetworks(); |
94 | - Iterator<TenantNetwork> networkors = networks.iterator(); | 94 | + Iterator<TenantNetwork> networkors = networks.iterator(); |
95 | - while (networkors.hasNext()) { | 95 | + while (networkors.hasNext()) { |
96 | - TenantNetwork network = networkors.next(); | 96 | + TenantNetwork network = networkors.next(); |
97 | - if ((queryId == null || queryId.equals(network.id().toString())) | 97 | + if ((queryId == null || queryId.equals(network.id().toString())) |
98 | - && (queryName == null || queryName.equals(network.name())) | 98 | + && (queryName == null || queryName.equals(network.name())) |
99 | - && (queryadminStateUp == null || queryadminStateUp | 99 | + && (queryadminStateUp == null || queryadminStateUp |
100 | - .equals(network.adminStateUp())) | 100 | + .equals(network.adminStateUp())) |
101 | - && (querystate == null || querystate.equals(network.state() | 101 | + && (querystate == null || querystate.equals(network.state() |
102 | - .toString())) | 102 | + .toString())) |
103 | - && (queryshared == null || queryshared.equals(network | 103 | + && (queryshared == null || queryshared.equals(network |
104 | - .shared())) | 104 | + .shared())) |
105 | - && (querytenantId == null || querytenantId.equals(network | 105 | + && (querytenantId == null || querytenantId.equals(network |
106 | - .tenantId().toString())) | 106 | + .tenantId().toString())) |
107 | - && (routerExternal == null || routerExternal.equals(network | 107 | + && (routerExternal == null || routerExternal.equals(network |
108 | - .routerExternal())) | 108 | + .routerExternal())) |
109 | - && (type == null || type.equals(network.type())) | 109 | + && (type == null || type.equals(network.type())) |
110 | - && (physicalNetwork == null || physicalNetwork | 110 | + && (physicalNetwork == null || physicalNetwork |
111 | - .equals(network.physicalNetwork())) | 111 | + .equals(network.physicalNetwork())) |
112 | - && (segmentationId == null || segmentationId.equals(network | 112 | + && (segmentationId == null || segmentationId.equals(network |
113 | - .segmentationId()))) { | 113 | + .segmentationId()))) { |
114 | - networksMap.putIfAbsent(network.id(), network); | 114 | + networksMap.putIfAbsent(network.id(), network); |
115 | - } | 115 | + } |
116 | - } | 116 | + } |
117 | - networks = Collections.unmodifiableCollection(networksMap.values()); | 117 | + networks = Collections.unmodifiableCollection(networksMap.values()); |
118 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 118 | + ObjectNode result = new ObjectMapper().createObjectNode(); |
119 | - result.set("networks", new TenantNetworkCodec().encode(networks, this)); | 119 | + result.set("networks", new TenantNetworkCodec().encode(networks, this)); |
120 | - | 120 | + |
121 | - return ok(result.toString()).build(); | 121 | + return ok(result.toString()).build(); |
122 | - } | 122 | + } |
123 | - | 123 | + |
124 | - private State isState(String state) { | 124 | + private State isState(String state) { |
125 | - if (state.equals("ACTIVE")) { | 125 | + if (state.equals("ACTIVE")) { |
126 | - return TenantNetwork.State.ACTIVE; | 126 | + return TenantNetwork.State.ACTIVE; |
127 | - } else if (state.equals("BUILD")) { | 127 | + } else if (state.equals("BUILD")) { |
128 | - return TenantNetwork.State.BUILD; | 128 | + return TenantNetwork.State.BUILD; |
129 | - } else if (state.equals("DOWN")) { | 129 | + } else if (state.equals("DOWN")) { |
130 | - return TenantNetwork.State.DOWN; | 130 | + return TenantNetwork.State.DOWN; |
131 | - } else if (state.equals("ERROR")) { | 131 | + } else if (state.equals("ERROR")) { |
132 | - return TenantNetwork.State.ERROR; | 132 | + return TenantNetwork.State.ERROR; |
133 | - } else { | 133 | + } else { |
134 | - return null; | 134 | + return null; |
135 | - } | 135 | + } |
136 | - } | 136 | + } |
137 | - | 137 | + |
138 | - private Type isType(String type) { | 138 | + private Type isType(String type) { |
139 | - if (type.equals("LOCAL")) { | 139 | + if (type.equals("LOCAL")) { |
140 | - return TenantNetwork.Type.LOCAL; | 140 | + return TenantNetwork.Type.LOCAL; |
141 | - } else { | 141 | + } else { |
142 | - return null; | 142 | + return null; |
143 | - } | 143 | + } |
144 | - } | 144 | + } |
145 | - | 145 | + |
146 | - @GET | 146 | + @GET |
147 | - @Path("{id}") | 147 | + @Path("{id}") |
148 | - @Produces({ MediaType.APPLICATION_JSON }) | 148 | + @Produces({ MediaType.APPLICATION_JSON }) |
149 | - public Response getNetwork(@PathParam("id") String id) { | 149 | + public Response getNetwork(@PathParam("id") String id) { |
150 | - | 150 | + |
151 | - if (!get(TenantNetworkService.class).exists(TenantNetworkId | 151 | + if (!get(TenantNetworkService.class).exists(TenantNetworkId |
152 | - .networkId(id))) { | 152 | + .networkId(id))) { |
153 | - return ok("The tenantNetwork does not exists").build(); | 153 | + return ok("The tenantNetwork does not exists").build(); |
154 | - } | 154 | + } |
155 | - TenantNetwork network = nullIsNotFound(get(TenantNetworkService.class) | 155 | + TenantNetwork network = nullIsNotFound(get(TenantNetworkService.class) |
156 | - .getNetwork(TenantNetworkId.networkId(id)), NETWORK_NOT_FOUND); | 156 | + .getNetwork(TenantNetworkId.networkId(id)), NETWORK_NOT_FOUND); |
157 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 157 | + ObjectNode result = new ObjectMapper().createObjectNode(); |
158 | - result.set("network", new TenantNetworkCodec().encode(network, this)); | 158 | + result.set("network", new TenantNetworkCodec().encode(network, this)); |
159 | - | 159 | + |
160 | - return ok(result.toString()).build(); | 160 | + return ok(result.toString()).build(); |
161 | - | 161 | + |
162 | - } | 162 | + } |
163 | - | 163 | + |
164 | - @POST | 164 | + @POST |
165 | - @Produces(MediaType.APPLICATION_JSON) | 165 | + @Produces(MediaType.APPLICATION_JSON) |
166 | - @Consumes(MediaType.APPLICATION_JSON) | 166 | + @Consumes(MediaType.APPLICATION_JSON) |
167 | - public Response createNetworks(InputStream input) { | 167 | + public Response createNetworks(InputStream input) { |
168 | - try { | 168 | + try { |
169 | - ObjectMapper mapper = new ObjectMapper(); | 169 | + ObjectMapper mapper = new ObjectMapper(); |
170 | - JsonNode cfg = mapper.readTree(input); | 170 | + JsonNode cfg = mapper.readTree(input); |
171 | - JsonNode nodes = null; | 171 | + JsonNode nodes = null; |
172 | - Iterable<TenantNetwork> networks = null; | 172 | + Iterable<TenantNetwork> networks = null; |
173 | - if (cfg.get("network") != null) { | 173 | + if (cfg.get("network") != null) { |
174 | - nodes = cfg.get("network"); | 174 | + nodes = cfg.get("network"); |
175 | - if (nodes.isArray()) { | 175 | + if (nodes.isArray()) { |
176 | - networks = changeJson2objs(nodes); | 176 | + networks = changeJson2objs(nodes); |
177 | - } else { | 177 | + } else { |
178 | - networks = changeJson2obj(CREATE_NETWORK, null, nodes); | 178 | + networks = changeJson2obj(CREATE_NETWORK, null, nodes); |
179 | - } | 179 | + } |
180 | - } else if (cfg.get("networks") != null) { | 180 | + } else if (cfg.get("networks") != null) { |
181 | - nodes = cfg.get("networks"); | 181 | + nodes = cfg.get("networks"); |
182 | - networks = changeJson2objs(nodes); | 182 | + networks = changeJson2objs(nodes); |
183 | - } | 183 | + } |
184 | - Boolean issuccess = nullIsNotFound((get(TenantNetworkService.class) | 184 | + Boolean issuccess = nullIsNotFound((get(TenantNetworkService.class) |
185 | - .createNetworks(networks)), | 185 | + .createNetworks(networks)), |
186 | - NETWORK_NOT_FOUND); | 186 | + NETWORK_NOT_FOUND); |
187 | - | 187 | + |
188 | - if (!issuccess) { | 188 | + if (!issuccess) { |
189 | - return Response.status(INTERNAL_SERVER_ERROR) | 189 | + return Response.status(INTERNAL_SERVER_ERROR) |
190 | - .entity(NETWORK_ID_EXIST).build(); | 190 | + .entity(NETWORK_ID_EXIST).build(); |
191 | - } | 191 | + } |
192 | - return Response.status(OK).entity(issuccess.toString()).build(); | 192 | + return Response.status(OK).entity(issuccess.toString()).build(); |
193 | - } catch (Exception e) { | 193 | + } catch (Exception e) { |
194 | - log.error("Creates tenantNetwork exception {}.", e.toString()); | 194 | + log.error("Creates tenantNetwork exception {}.", e.toString()); |
195 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 195 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
196 | - .build(); | 196 | + .build(); |
197 | - } | 197 | + } |
198 | - } | 198 | + } |
199 | - | 199 | + |
200 | - @PUT | 200 | + @PUT |
201 | - @Path("{id}") | 201 | + @Path("{id}") |
202 | - @Produces(MediaType.APPLICATION_JSON) | 202 | + @Produces(MediaType.APPLICATION_JSON) |
203 | - @Consumes(MediaType.APPLICATION_JSON) | 203 | + @Consumes(MediaType.APPLICATION_JSON) |
204 | - public Response updateNetworks(@PathParam("id") String id, InputStream input) { | 204 | + public Response updateNetworks(@PathParam("id") String id, InputStream input) { |
205 | - try { | 205 | + try { |
206 | - ObjectMapper mapper = new ObjectMapper(); | 206 | + ObjectMapper mapper = new ObjectMapper(); |
207 | - JsonNode cfg = mapper.readTree(input); | 207 | + JsonNode cfg = mapper.readTree(input); |
208 | - JsonNode nodes = null; | 208 | + JsonNode nodes = null; |
209 | - Iterable<TenantNetwork> networks = null; | 209 | + Iterable<TenantNetwork> networks = null; |
210 | - if (cfg.get("network") != null) { | 210 | + if (cfg.get("network") != null) { |
211 | - nodes = cfg.get("network"); | 211 | + nodes = cfg.get("network"); |
212 | - if (nodes.isArray()) { | 212 | + if (nodes.isArray()) { |
213 | - networks = changeJson2objs(nodes); | 213 | + networks = changeJson2objs(nodes); |
214 | - } else { | 214 | + } else { |
215 | - networks = changeJson2obj(UPDATE_NETWORK, | 215 | + networks = changeJson2obj(UPDATE_NETWORK, |
216 | - TenantNetworkId.networkId(id), | 216 | + TenantNetworkId.networkId(id), |
217 | - nodes); | 217 | + nodes); |
218 | - } | 218 | + } |
219 | - } else if (cfg.get("networks") != null) { | 219 | + } else if (cfg.get("networks") != null) { |
220 | - nodes = cfg.get("networks"); | 220 | + nodes = cfg.get("networks"); |
221 | - networks = changeJson2objs(nodes); | 221 | + networks = changeJson2objs(nodes); |
222 | - } | 222 | + } |
223 | - Boolean issuccess = nullIsNotFound((get(TenantNetworkService.class) | 223 | + Boolean issuccess = nullIsNotFound((get(TenantNetworkService.class) |
224 | - .updateNetworks(networks)), | 224 | + .updateNetworks(networks)), |
225 | - NETWORK_NOT_FOUND); | 225 | + NETWORK_NOT_FOUND); |
226 | - if (!issuccess) { | 226 | + if (!issuccess) { |
227 | - return Response.status(INTERNAL_SERVER_ERROR) | 227 | + return Response.status(INTERNAL_SERVER_ERROR) |
228 | - .entity(NETWORK_ID_NOT_EXIST).build(); | 228 | + .entity(NETWORK_ID_NOT_EXIST).build(); |
229 | - } | 229 | + } |
230 | - return Response.status(OK).entity(issuccess.toString()).build(); | 230 | + return Response.status(OK).entity(issuccess.toString()).build(); |
231 | - } catch (Exception e) { | 231 | + } catch (Exception e) { |
232 | - log.error("Updates tenantNetwork failed because of exception {}.", | 232 | + log.error("Updates tenantNetwork failed because of exception {}.", |
233 | - e.toString()); | 233 | + e.toString()); |
234 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 234 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
235 | - .build(); | 235 | + .build(); |
236 | - } | 236 | + } |
237 | - } | 237 | + } |
238 | - | 238 | + |
239 | - @DELETE | 239 | + @DELETE |
240 | - @Path("{id}") | 240 | + @Path("{id}") |
241 | - public Response deleteNetworks(@PathParam("id") String id) { | 241 | + public Response deleteNetworks(@PathParam("id") String id) { |
242 | - log.debug("Deletes network by identifier {}.", id); | 242 | + log.debug("Deletes network by identifier {}.", id); |
243 | - Set<TenantNetworkId> networkSet = new HashSet<>(); | 243 | + Set<TenantNetworkId> networkSet = new HashSet<>(); |
244 | - networkSet.add(TenantNetworkId.networkId(id)); | 244 | + networkSet.add(TenantNetworkId.networkId(id)); |
245 | - Boolean issuccess = nullIsNotFound(get(TenantNetworkService.class) | 245 | + Boolean issuccess = nullIsNotFound(get(TenantNetworkService.class) |
246 | - .removeNetworks(networkSet), NETWORK_NOT_FOUND); | 246 | + .removeNetworks(networkSet), NETWORK_NOT_FOUND); |
247 | - if (!issuccess) { | 247 | + if (!issuccess) { |
248 | - log.debug("Network identifier {} is not existed", id); | 248 | + log.debug("Network identifier {} is not existed", id); |
249 | - return Response.status(INTERNAL_SERVER_ERROR) | 249 | + return Response.status(INTERNAL_SERVER_ERROR) |
250 | - .entity(NETWORK_ID_NOT_EXIST).build(); | 250 | + .entity(NETWORK_ID_NOT_EXIST).build(); |
251 | - } | 251 | + } |
252 | - return Response.status(OK).entity(issuccess.toString()).build(); | 252 | + return Response.status(OK).entity(issuccess.toString()).build(); |
253 | - } | 253 | + } |
254 | - | 254 | + |
255 | - /** | 255 | + /** |
256 | - * Returns a collection of tenantNetworks. | 256 | + * Returns a collection of tenantNetworks. |
257 | - * | 257 | + * |
258 | - * @param flag the flag | 258 | + * @param flag the flag |
259 | - * @param networkId network identifier | 259 | + * @param networkId network identifier |
260 | - * @param node the network json node | 260 | + * @param node the network json node |
261 | - * @return a collection of tenantNetworks | 261 | + * @return a collection of tenantNetworks |
262 | - */ | 262 | + */ |
263 | - public Iterable<TenantNetwork> changeJson2obj(String flag, | 263 | + public Iterable<TenantNetwork> changeJson2obj(String flag, |
264 | - TenantNetworkId networkId, | 264 | + TenantNetworkId networkId, |
265 | - JsonNode node) { | 265 | + JsonNode node) { |
266 | - checkNotNull(node, JSON_NOT_NULL); | 266 | + checkNotNull(node, JSON_NOT_NULL); |
267 | - TenantNetwork network = null; | 267 | + TenantNetwork network = null; |
268 | - ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps | 268 | + ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps |
269 | - .newConcurrentMap(); | 269 | + .newConcurrentMap(); |
270 | - if (node != null) { | 270 | + if (node != null) { |
271 | - checkArgument(node.get("admin_state_up").isBoolean(), "admin_state_up should be boolean"); | 271 | + checkArgument(node.get("admin_state_up").isBoolean(), "admin_state_up should be boolean"); |
272 | - checkArgument(node.get("shared").isBoolean(), "shared should be boolean"); | 272 | + checkArgument(node.get("shared").isBoolean(), "shared should be boolean"); |
273 | - checkArgument(node.get("router:external").isBoolean(), "router:external should be boolean"); | 273 | + checkArgument(node.get("router:external").isBoolean(), "router:external should be boolean"); |
274 | - String name = node.get("name").asText(); | 274 | + String name = node.get("name").asText(); |
275 | - boolean adminStateUp = node.get("admin_state_up").asBoolean(); | 275 | + boolean adminStateUp = node.get("admin_state_up").asBoolean(); |
276 | - String state = node.get("status").asText(); | 276 | + String state = node.get("status").asText(); |
277 | - boolean shared = node.get("shared").asBoolean(); | 277 | + boolean shared = node.get("shared").asBoolean(); |
278 | - String tenantId = node.get("tenant_id").asText(); | 278 | + String tenantId = node.get("tenant_id").asText(); |
279 | - boolean routerExternal = node.get("router:external").asBoolean(); | 279 | + boolean routerExternal = node.get("router:external").asBoolean(); |
280 | - String type = node.get("provider:network_type").asText(); | 280 | + String type = node.get("provider:network_type").asText(); |
281 | - String physicalNetwork = node.get("provider:physical_network") | 281 | + String physicalNetwork = node.get("provider:physical_network") |
282 | - .asText(); | 282 | + .asText(); |
283 | - String segmentationId = node.get("provider:segmentation_id") | 283 | + String segmentationId = node.get("provider:segmentation_id") |
284 | - .asText(); | 284 | + .asText(); |
285 | - TenantNetworkId id = null; | 285 | + TenantNetworkId id = null; |
286 | - if (flag == CREATE_NETWORK) { | 286 | + if (flag == CREATE_NETWORK) { |
287 | - id = TenantNetworkId.networkId(node.get("id").asText()); | 287 | + id = TenantNetworkId.networkId(node.get("id").asText()); |
288 | - } else if (flag == UPDATE_NETWORK) { | 288 | + } else if (flag == UPDATE_NETWORK) { |
289 | - id = networkId; | 289 | + id = networkId; |
290 | - } | 290 | + } |
291 | - network = new DefaultTenantNetwork( | 291 | + network = new DefaultTenantNetwork( |
292 | - id, | 292 | + id, |
293 | - name, | 293 | + name, |
294 | - adminStateUp, | 294 | + adminStateUp, |
295 | - isState(state), | 295 | + isState(state), |
296 | - shared, | 296 | + shared, |
297 | - TenantId.tenantId(tenantId), | 297 | + TenantId.tenantId(tenantId), |
298 | - routerExternal, | 298 | + routerExternal, |
299 | - isType(type), | 299 | + isType(type), |
300 | - PhysicalNetwork | 300 | + PhysicalNetwork |
301 | - .physicalNetwork(physicalNetwork), | 301 | + .physicalNetwork(physicalNetwork), |
302 | - SegmentationId | 302 | + SegmentationId |
303 | - .segmentationId(segmentationId)); | 303 | + .segmentationId(segmentationId)); |
304 | - networksMap.putIfAbsent(id, network); | 304 | + networksMap.putIfAbsent(id, network); |
305 | - } | 305 | + } |
306 | - return Collections.unmodifiableCollection(networksMap.values()); | 306 | + return Collections.unmodifiableCollection(networksMap.values()); |
307 | - } | 307 | + } |
308 | - | 308 | + |
309 | - /** | 309 | + /** |
310 | - * Returns a collection of tenantNetworks. | 310 | + * Returns a collection of tenantNetworks. |
311 | - * | 311 | + * |
312 | - * @param nodes the network jsonnodes | 312 | + * @param nodes the network jsonnodes |
313 | - * @return a collection of tenantNetworks | 313 | + * @return a collection of tenantNetworks |
314 | - */ | 314 | + */ |
315 | - public Iterable<TenantNetwork> changeJson2objs(JsonNode nodes) { | 315 | + public Iterable<TenantNetwork> changeJson2objs(JsonNode nodes) { |
316 | - checkNotNull(nodes, JSON_NOT_NULL); | 316 | + checkNotNull(nodes, JSON_NOT_NULL); |
317 | - TenantNetwork network = null; | 317 | + TenantNetwork network = null; |
318 | - ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps | 318 | + ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps |
319 | - .newConcurrentMap(); | 319 | + .newConcurrentMap(); |
320 | - if (nodes != null) { | 320 | + if (nodes != null) { |
321 | - for (JsonNode node : nodes) { | 321 | + for (JsonNode node : nodes) { |
322 | - String id = node.get("id").asText(); | 322 | + String id = node.get("id").asText(); |
323 | - String name = node.get("name").asText(); | 323 | + String name = node.get("name").asText(); |
324 | - boolean adminStateUp = node.get("admin_state_up").asBoolean(); | 324 | + boolean adminStateUp = node.get("admin_state_up").asBoolean(); |
325 | - String state = node.get("status").asText(); | 325 | + String state = node.get("status").asText(); |
326 | - boolean shared = node.get("shared").asBoolean(); | 326 | + boolean shared = node.get("shared").asBoolean(); |
327 | - String tenantId = node.get("tenant_id").asText(); | 327 | + String tenantId = node.get("tenant_id").asText(); |
328 | - boolean routerExternal = node.get("router:external") | 328 | + boolean routerExternal = node.get("router:external") |
329 | - .asBoolean(); | 329 | + .asBoolean(); |
330 | - String type = node.get("provider:network_type").asText(); | 330 | + String type = node.get("provider:network_type").asText(); |
331 | - String physicalNetwork = node.get("provider:physical_network") | 331 | + String physicalNetwork = node.get("provider:physical_network") |
332 | - .asText(); | 332 | + .asText(); |
333 | - String segmentationId = node.get("provider:segmentation_id") | 333 | + String segmentationId = node.get("provider:segmentation_id") |
334 | - .asText(); | 334 | + .asText(); |
335 | - network = new DefaultTenantNetwork( | 335 | + network = new DefaultTenantNetwork( |
336 | - TenantNetworkId | 336 | + TenantNetworkId |
337 | - .networkId(id), | 337 | + .networkId(id), |
338 | - name, | 338 | + name, |
339 | - adminStateUp, | 339 | + adminStateUp, |
340 | - isState(state), | 340 | + isState(state), |
341 | - shared, | 341 | + shared, |
342 | - TenantId.tenantId(tenantId), | 342 | + TenantId.tenantId(tenantId), |
343 | - routerExternal, | 343 | + routerExternal, |
344 | - isType(type), | 344 | + isType(type), |
345 | - PhysicalNetwork | 345 | + PhysicalNetwork |
346 | - .physicalNetwork(physicalNetwork), | 346 | + .physicalNetwork(physicalNetwork), |
347 | - SegmentationId | 347 | + SegmentationId |
348 | - .segmentationId(segmentationId)); | 348 | + .segmentationId(segmentationId)); |
349 | - networksMap.putIfAbsent(TenantNetworkId.networkId(id), network); | 349 | + networksMap.putIfAbsent(TenantNetworkId.networkId(id), network); |
350 | - } | 350 | + } |
351 | - } | 351 | + } |
352 | - return Collections.unmodifiableCollection(networksMap.values()); | 352 | + return Collections.unmodifiableCollection(networksMap.values()); |
353 | - } | 353 | + } |
354 | - | 354 | + |
355 | - /** | 355 | + /** |
356 | - * Returns the specified item if that items is null; otherwise throws not | 356 | + * Returns the specified item if that items is null; otherwise throws not |
357 | - * found exception. | 357 | + * found exception. |
358 | - * | 358 | + * |
359 | - * @param item item to check | 359 | + * @param item item to check |
360 | - * @param <T> item type | 360 | + * @param <T> item type |
361 | - * @param message not found message | 361 | + * @param message not found message |
362 | - * @return item if not null | 362 | + * @return item if not null |
363 | - * @throws org.onlab.util.ItemNotFoundException if item is null | 363 | + * @throws org.onlab.util.ItemNotFoundException if item is null |
364 | - */ | 364 | + */ |
365 | - protected <T> T nullIsNotFound(T item, String message) { | 365 | + protected <T> T nullIsNotFound(T item, String message) { |
366 | - if (item == null) { | 366 | + if (item == null) { |
367 | - throw new ItemNotFoundException(message); | 367 | + throw new ItemNotFoundException(message); |
368 | - } | 368 | + } |
369 | - return item; | 369 | + return item; |
370 | - } | 370 | + } |
371 | -} | 371 | +} | ... | ... |
1 | -/* | 1 | +/* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | - * | 3 | + * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | - * you may not use this file except in compliance with 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 | 6 | + * You may obtain a copy of the License at |
7 | - * | 7 | + * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | - * | 9 | + * |
10 | - * Unless required by applicable law or agreed to in writing, software | 10 | + * Unless required by applicable law or agreed to in writing, software |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | - * See the License for the specific language governing permissions and | 13 | + * See the License for the specific language governing permissions and |
14 | - * limitations under the License. | 14 | + * limitations under the License. |
15 | - */ | 15 | + */ |
16 | -package org.onosproject.vtnweb.resources; | 16 | +package org.onosproject.vtnweb.resources; |
17 | - | 17 | + |
18 | -import static com.google.common.base.Preconditions.checkArgument; | 18 | +import static com.google.common.base.Preconditions.checkArgument; |
19 | -import static com.google.common.base.Preconditions.checkNotNull; | 19 | +import static com.google.common.base.Preconditions.checkNotNull; |
20 | -import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; | 20 | +import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
21 | -import static javax.ws.rs.core.Response.Status.OK; | 21 | +import static javax.ws.rs.core.Response.Status.OK; |
22 | - | 22 | + |
23 | -import java.io.InputStream; | 23 | +import java.io.InputStream; |
24 | -import java.util.Collection; | 24 | +import java.util.Collection; |
25 | -import java.util.Collections; | 25 | +import java.util.Collections; |
26 | -import java.util.HashMap; | 26 | +import java.util.HashMap; |
27 | -import java.util.HashSet; | 27 | +import java.util.HashSet; |
28 | -import java.util.Map; | 28 | +import java.util.Map; |
29 | -import java.util.Set; | 29 | +import java.util.Set; |
30 | -import java.util.concurrent.ConcurrentMap; | 30 | +import java.util.concurrent.ConcurrentMap; |
31 | - | 31 | + |
32 | -import javax.ws.rs.Consumes; | 32 | +import javax.ws.rs.Consumes; |
33 | -import javax.ws.rs.DELETE; | 33 | +import javax.ws.rs.DELETE; |
34 | -import javax.ws.rs.GET; | 34 | +import javax.ws.rs.GET; |
35 | -import javax.ws.rs.POST; | 35 | +import javax.ws.rs.POST; |
36 | -import javax.ws.rs.PUT; | 36 | +import javax.ws.rs.PUT; |
37 | -import javax.ws.rs.Path; | 37 | +import javax.ws.rs.Path; |
38 | -import javax.ws.rs.PathParam; | 38 | +import javax.ws.rs.PathParam; |
39 | -import javax.ws.rs.Produces; | 39 | +import javax.ws.rs.Produces; |
40 | -import javax.ws.rs.core.MediaType; | 40 | +import javax.ws.rs.core.MediaType; |
41 | -import javax.ws.rs.core.Response; | 41 | +import javax.ws.rs.core.Response; |
42 | - | 42 | + |
43 | -import org.onlab.packet.IpAddress; | 43 | +import org.onlab.packet.IpAddress; |
44 | -import org.onlab.packet.MacAddress; | 44 | +import org.onlab.packet.MacAddress; |
45 | -import org.onlab.util.ItemNotFoundException; | 45 | +import org.onlab.util.ItemNotFoundException; |
46 | -import org.onosproject.net.DeviceId; | 46 | +import org.onosproject.net.DeviceId; |
47 | -import org.onosproject.rest.AbstractWebResource; | 47 | +import org.onosproject.rest.AbstractWebResource; |
48 | -import org.onosproject.vtnrsc.AllowedAddressPair; | 48 | +import org.onosproject.vtnrsc.AllowedAddressPair; |
49 | -import org.onosproject.vtnrsc.BindingHostId; | 49 | +import org.onosproject.vtnrsc.BindingHostId; |
50 | -import org.onosproject.vtnrsc.DefaultVirtualPort; | 50 | +import org.onosproject.vtnrsc.DefaultVirtualPort; |
51 | -import org.onosproject.vtnrsc.FixedIp; | 51 | +import org.onosproject.vtnrsc.FixedIp; |
52 | -import org.onosproject.vtnrsc.SecurityGroup; | 52 | +import org.onosproject.vtnrsc.SecurityGroup; |
53 | -import org.onosproject.vtnrsc.SubnetId; | 53 | +import org.onosproject.vtnrsc.SubnetId; |
54 | -import org.onosproject.vtnrsc.TenantId; | 54 | +import org.onosproject.vtnrsc.TenantId; |
55 | -import org.onosproject.vtnrsc.TenantNetworkId; | 55 | +import org.onosproject.vtnrsc.TenantNetworkId; |
56 | -import org.onosproject.vtnrsc.VirtualPort; | 56 | +import org.onosproject.vtnrsc.VirtualPort; |
57 | -import org.onosproject.vtnrsc.VirtualPort.State; | 57 | +import org.onosproject.vtnrsc.VirtualPort.State; |
58 | -import org.onosproject.vtnrsc.VirtualPortId; | 58 | +import org.onosproject.vtnrsc.VirtualPortId; |
59 | -import org.onosproject.vtnrsc.virtualport.VirtualPortService; | 59 | +import org.onosproject.vtnrsc.virtualport.VirtualPortService; |
60 | -import org.onosproject.vtnrsc.web.VirtualPortCodec; | 60 | +import org.onosproject.vtnrsc.web.VirtualPortCodec; |
61 | -import org.slf4j.Logger; | 61 | +import org.slf4j.Logger; |
62 | -import org.slf4j.LoggerFactory; | 62 | +import org.slf4j.LoggerFactory; |
63 | - | 63 | + |
64 | -import com.fasterxml.jackson.databind.JsonNode; | 64 | +import com.fasterxml.jackson.databind.JsonNode; |
65 | -import com.fasterxml.jackson.databind.ObjectMapper; | 65 | +import com.fasterxml.jackson.databind.ObjectMapper; |
66 | -import com.fasterxml.jackson.databind.node.ObjectNode; | 66 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
67 | -import com.google.common.collect.Maps; | 67 | +import com.google.common.collect.Maps; |
68 | -import com.google.common.collect.Sets; | 68 | +import com.google.common.collect.Sets; |
69 | - | 69 | + |
70 | -/** | 70 | +/** |
71 | - * REST resource for interacting with the inventory of infrastructure | 71 | + * REST resource for interacting with the inventory of infrastructure |
72 | - * virtualPort. | 72 | + * virtualPort. |
73 | - */ | 73 | + */ |
74 | -@Path("ports") | 74 | +@Path("ports") |
75 | -public class VirtualPortWebResource extends AbstractWebResource { | 75 | +public class VirtualPortWebResource extends AbstractWebResource { |
76 | - public static final String VPORT_NOT_FOUND = "VirtualPort is not found"; | 76 | + public static final String VPORT_NOT_FOUND = "VirtualPort is not found"; |
77 | - public static final String VPORT_ID_EXIST = "VirtualPort id is exist"; | 77 | + public static final String VPORT_ID_EXIST = "VirtualPort id is exist"; |
78 | - public static final String VPORT_ID_NOT_EXIST = "VirtualPort id is not exist"; | 78 | + public static final String VPORT_ID_NOT_EXIST = "VirtualPort id is not exist"; |
79 | - public static final String JSON_NOT_NULL = "JsonNode can not be null"; | 79 | + public static final String JSON_NOT_NULL = "JsonNode can not be null"; |
80 | - protected static final Logger log = LoggerFactory | 80 | + protected static final Logger log = LoggerFactory |
81 | - .getLogger(VirtualPortService.class); | 81 | + .getLogger(VirtualPortService.class); |
82 | - | 82 | + |
83 | - @GET | 83 | + @GET |
84 | - @Produces({ MediaType.APPLICATION_JSON }) | 84 | + @Produces({ MediaType.APPLICATION_JSON }) |
85 | - public Response getPorts() { | 85 | + public Response getPorts() { |
86 | - Iterable<VirtualPort> virtualPorts = get(VirtualPortService.class) | 86 | + Iterable<VirtualPort> virtualPorts = get(VirtualPortService.class) |
87 | - .getPorts(); | 87 | + .getPorts(); |
88 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 88 | + ObjectNode result = new ObjectMapper().createObjectNode(); |
89 | - result.set("ports", new VirtualPortCodec().encode(virtualPorts, this)); | 89 | + result.set("ports", new VirtualPortCodec().encode(virtualPorts, this)); |
90 | - return ok(result.toString()).build(); | 90 | + return ok(result.toString()).build(); |
91 | - } | 91 | + } |
92 | - | 92 | + |
93 | - @GET | 93 | + @GET |
94 | - @Path("{id}") | 94 | + @Path("{id}") |
95 | - @Produces({ MediaType.APPLICATION_JSON }) | 95 | + @Produces({ MediaType.APPLICATION_JSON }) |
96 | - public Response getportsById(@PathParam("id") String id) { | 96 | + public Response getportsById(@PathParam("id") String id) { |
97 | - | 97 | + |
98 | - if (!get(VirtualPortService.class).exists(VirtualPortId.portId(id))) { | 98 | + if (!get(VirtualPortService.class).exists(VirtualPortId.portId(id))) { |
99 | - return ok("The virtualPort does not exists").build(); | 99 | + return ok("The virtualPort does not exists").build(); |
100 | - } | 100 | + } |
101 | - VirtualPort virtualPort = nullIsNotFound(get(VirtualPortService.class) | 101 | + VirtualPort virtualPort = nullIsNotFound(get(VirtualPortService.class) |
102 | - .getPort(VirtualPortId.portId(id)), VPORT_NOT_FOUND); | 102 | + .getPort(VirtualPortId.portId(id)), VPORT_NOT_FOUND); |
103 | - ObjectNode result = new ObjectMapper().createObjectNode(); | 103 | + ObjectNode result = new ObjectMapper().createObjectNode(); |
104 | - result.set("port", new VirtualPortCodec().encode(virtualPort, this)); | 104 | + result.set("port", new VirtualPortCodec().encode(virtualPort, this)); |
105 | - return ok(result.toString()).build(); | 105 | + return ok(result.toString()).build(); |
106 | - } | 106 | + } |
107 | - | 107 | + |
108 | - @POST | 108 | + @POST |
109 | - @Consumes(MediaType.APPLICATION_JSON) | 109 | + @Consumes(MediaType.APPLICATION_JSON) |
110 | - @Produces(MediaType.APPLICATION_JSON) | 110 | + @Produces(MediaType.APPLICATION_JSON) |
111 | - public Response createPorts(InputStream input) { | 111 | + public Response createPorts(InputStream input) { |
112 | - try { | 112 | + try { |
113 | - ObjectMapper mapper = new ObjectMapper(); | 113 | + ObjectMapper mapper = new ObjectMapper(); |
114 | - JsonNode cfg = mapper.readTree(input); | 114 | + JsonNode cfg = mapper.readTree(input); |
115 | - Iterable<VirtualPort> vPorts = createOrUpdateByInputStream(cfg); | 115 | + Iterable<VirtualPort> vPorts = createOrUpdateByInputStream(cfg); |
116 | - Boolean issuccess = nullIsNotFound(get(VirtualPortService.class) | 116 | + Boolean issuccess = nullIsNotFound(get(VirtualPortService.class) |
117 | - .createPorts(vPorts), VPORT_NOT_FOUND); | 117 | + .createPorts(vPorts), VPORT_NOT_FOUND); |
118 | - if (!issuccess) { | 118 | + if (!issuccess) { |
119 | - return Response.status(INTERNAL_SERVER_ERROR) | 119 | + return Response.status(INTERNAL_SERVER_ERROR) |
120 | - .entity(VPORT_ID_NOT_EXIST).build(); | 120 | + .entity(VPORT_ID_NOT_EXIST).build(); |
121 | - } | 121 | + } |
122 | - return Response.status(OK).entity(issuccess.toString()).build(); | 122 | + return Response.status(OK).entity(issuccess.toString()).build(); |
123 | - } catch (Exception e) { | 123 | + } catch (Exception e) { |
124 | - log.error("Creates VirtualPort failed because of exception {}", | 124 | + log.error("Creates VirtualPort failed because of exception {}", |
125 | - e.toString()); | 125 | + e.toString()); |
126 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 126 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
127 | - .build(); | 127 | + .build(); |
128 | - } | 128 | + } |
129 | - } | 129 | + } |
130 | - | 130 | + |
131 | - @Path("{portUUID}") | 131 | + @Path("{portUUID}") |
132 | - @DELETE | 132 | + @DELETE |
133 | - public Response deletePorts(@PathParam("portUUID") String id) { | 133 | + public Response deletePorts(@PathParam("portUUID") String id) { |
134 | - Set<VirtualPortId> vPortIds = new HashSet<>(); | 134 | + Set<VirtualPortId> vPortIds = new HashSet<>(); |
135 | - try { | 135 | + try { |
136 | - if (id != null) { | 136 | + if (id != null) { |
137 | - vPortIds.add(VirtualPortId.portId(id)); | 137 | + vPortIds.add(VirtualPortId.portId(id)); |
138 | - } | 138 | + } |
139 | - Boolean issuccess = nullIsNotFound(get(VirtualPortService.class) | 139 | + Boolean issuccess = nullIsNotFound(get(VirtualPortService.class) |
140 | - .removePorts(vPortIds), VPORT_NOT_FOUND); | 140 | + .removePorts(vPortIds), VPORT_NOT_FOUND); |
141 | - if (!issuccess) { | 141 | + if (!issuccess) { |
142 | - return Response.status(INTERNAL_SERVER_ERROR) | 142 | + return Response.status(INTERNAL_SERVER_ERROR) |
143 | - .entity(VPORT_ID_NOT_EXIST).build(); | 143 | + .entity(VPORT_ID_NOT_EXIST).build(); |
144 | - } | 144 | + } |
145 | - return Response.status(OK).entity(issuccess.toString()).build(); | 145 | + return Response.status(OK).entity(issuccess.toString()).build(); |
146 | - } catch (Exception e) { | 146 | + } catch (Exception e) { |
147 | - log.error("Deletes VirtualPort failed because of exception {}", | 147 | + log.error("Deletes VirtualPort failed because of exception {}", |
148 | - e.toString()); | 148 | + e.toString()); |
149 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 149 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
150 | - .build(); | 150 | + .build(); |
151 | - } | 151 | + } |
152 | - } | 152 | + } |
153 | - | 153 | + |
154 | - @PUT | 154 | + @PUT |
155 | - @Path("{id}") | 155 | + @Path("{id}") |
156 | - @Consumes(MediaType.APPLICATION_JSON) | 156 | + @Consumes(MediaType.APPLICATION_JSON) |
157 | - @Produces(MediaType.APPLICATION_JSON) | 157 | + @Produces(MediaType.APPLICATION_JSON) |
158 | - public Response updatePorts(@PathParam("id") String id, InputStream input) { | 158 | + public Response updatePorts(@PathParam("id") String id, InputStream input) { |
159 | - try { | 159 | + try { |
160 | - ObjectMapper mapper = new ObjectMapper(); | 160 | + ObjectMapper mapper = new ObjectMapper(); |
161 | - JsonNode cfg = mapper.readTree(input); | 161 | + JsonNode cfg = mapper.readTree(input); |
162 | - Iterable<VirtualPort> vPorts = createOrUpdateByInputStream(cfg); | 162 | + Iterable<VirtualPort> vPorts = createOrUpdateByInputStream(cfg); |
163 | - Boolean issuccess = nullIsNotFound(get(VirtualPortService.class) | 163 | + Boolean issuccess = nullIsNotFound(get(VirtualPortService.class) |
164 | - .updatePorts(vPorts), VPORT_NOT_FOUND); | 164 | + .updatePorts(vPorts), VPORT_NOT_FOUND); |
165 | - if (!issuccess) { | 165 | + if (!issuccess) { |
166 | - return Response.status(INTERNAL_SERVER_ERROR) | 166 | + return Response.status(INTERNAL_SERVER_ERROR) |
167 | - .entity(VPORT_ID_NOT_EXIST).build(); | 167 | + .entity(VPORT_ID_NOT_EXIST).build(); |
168 | - } | 168 | + } |
169 | - return Response.status(OK).entity(issuccess.toString()).build(); | 169 | + return Response.status(OK).entity(issuccess.toString()).build(); |
170 | - } catch (Exception e) { | 170 | + } catch (Exception e) { |
171 | - log.error("Updates failed because of exception {}", e.toString()); | 171 | + log.error("Updates failed because of exception {}", e.toString()); |
172 | - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) | 172 | + return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
173 | - .build(); | 173 | + .build(); |
174 | - } | 174 | + } |
175 | - } | 175 | + } |
176 | - | 176 | + |
177 | - /** | 177 | + /** |
178 | - * Returns a Object of the currently known infrastructure virtualPort. | 178 | + * Returns a Object of the currently known infrastructure virtualPort. |
179 | - * | 179 | + * |
180 | - * @param vPortNode the virtualPort json node | 180 | + * @param vPortNode the virtualPort json node |
181 | - * @return a collection of virtualPorts | 181 | + * @return a collection of virtualPorts |
182 | - */ | 182 | + */ |
183 | - public Iterable<VirtualPort> createOrUpdateByInputStream(JsonNode vPortNode) { | 183 | + public Iterable<VirtualPort> createOrUpdateByInputStream(JsonNode vPortNode) { |
184 | - checkNotNull(vPortNode, JSON_NOT_NULL); | 184 | + checkNotNull(vPortNode, JSON_NOT_NULL); |
185 | - JsonNode vPortNodes = vPortNode.get("ports"); | 185 | + JsonNode vPortNodes = vPortNode.get("ports"); |
186 | - if (vPortNodes == null) { | 186 | + if (vPortNodes == null) { |
187 | - vPortNodes = vPortNode.get("port"); | 187 | + vPortNodes = vPortNode.get("port"); |
188 | - } | 188 | + } |
189 | - if (vPortNodes.isArray()) { | 189 | + if (vPortNodes.isArray()) { |
190 | - return changeJsonToPorts(vPortNodes); | 190 | + return changeJsonToPorts(vPortNodes); |
191 | - } else { | 191 | + } else { |
192 | - return changeJsonToPort(vPortNodes); | 192 | + return changeJsonToPort(vPortNodes); |
193 | - } | 193 | + } |
194 | - } | 194 | + } |
195 | - | 195 | + |
196 | - /** | 196 | + /** |
197 | - * Returns the iterable collection of virtualports from subnetNodes. | 197 | + * Returns the iterable collection of virtualports from subnetNodes. |
198 | - * | 198 | + * |
199 | - * @param vPortNodes the virtualPort json node | 199 | + * @param vPortNodes the virtualPort json node |
200 | - * @return virtualPorts a collection of virtualPorts | 200 | + * @return virtualPorts a collection of virtualPorts |
201 | - */ | 201 | + */ |
202 | - public Iterable<VirtualPort> changeJsonToPorts(JsonNode vPortNodes) { | 202 | + public Iterable<VirtualPort> changeJsonToPorts(JsonNode vPortNodes) { |
203 | - checkNotNull(vPortNodes, JSON_NOT_NULL); | 203 | + checkNotNull(vPortNodes, JSON_NOT_NULL); |
204 | - Map<VirtualPortId, VirtualPort> portMap = new HashMap<>(); | 204 | + Map<VirtualPortId, VirtualPort> portMap = new HashMap<>(); |
205 | - Map<String, String> strMap = new HashMap<>(); | 205 | + Map<String, String> strMap = new HashMap<>(); |
206 | - for (JsonNode vPortnode : vPortNodes) { | 206 | + for (JsonNode vPortnode : vPortNodes) { |
207 | - VirtualPortId id = VirtualPortId.portId(vPortnode.get("id") | 207 | + VirtualPortId id = VirtualPortId.portId(vPortnode.get("id") |
208 | - .asText()); | 208 | + .asText()); |
209 | - String name = vPortnode.get("name").asText(); | 209 | + String name = vPortnode.get("name").asText(); |
210 | - TenantId tenantId = TenantId.tenantId(vPortnode.get("tenant_id") | 210 | + TenantId tenantId = TenantId.tenantId(vPortnode.get("tenant_id") |
211 | - .asText()); | 211 | + .asText()); |
212 | - TenantNetworkId networkId = TenantNetworkId.networkId(vPortnode | 212 | + TenantNetworkId networkId = TenantNetworkId.networkId(vPortnode |
213 | - .get("network_id").asText()); | 213 | + .get("network_id").asText()); |
214 | - checkArgument(vPortnode.get("admin_state_up").isBoolean(), "admin_state_up should be boolean"); | 214 | + checkArgument(vPortnode.get("admin_state_up").isBoolean(), "admin_state_up should be boolean"); |
215 | - Boolean adminStateUp = vPortnode.get("admin_state_up").asBoolean(); | 215 | + Boolean adminStateUp = vPortnode.get("admin_state_up").asBoolean(); |
216 | - String state = vPortnode.get("status").asText(); | 216 | + String state = vPortnode.get("status").asText(); |
217 | - MacAddress macAddress = MacAddress.valueOf(vPortnode | 217 | + MacAddress macAddress = MacAddress.valueOf(vPortnode |
218 | - .get("mac_address").asText()); | 218 | + .get("mac_address").asText()); |
219 | - DeviceId deviceId = DeviceId.deviceId(vPortnode.get("device_id") | 219 | + DeviceId deviceId = DeviceId.deviceId(vPortnode.get("device_id") |
220 | - .asText()); | 220 | + .asText()); |
221 | - String deviceOwner = vPortnode.get("device_owner").asText(); | 221 | + String deviceOwner = vPortnode.get("device_owner").asText(); |
222 | - JsonNode fixedIpNodes = vPortNodes.get("fixed_ips"); | 222 | + JsonNode fixedIpNodes = vPortNodes.get("fixed_ips"); |
223 | - Set<FixedIp> fixedIps = new HashSet<>(); | 223 | + Set<FixedIp> fixedIps = new HashSet<>(); |
224 | - for (JsonNode fixedIpNode : fixedIpNodes) { | 224 | + for (JsonNode fixedIpNode : fixedIpNodes) { |
225 | - FixedIp fixedIp = jsonNodeToFixedIps(fixedIpNode); | 225 | + FixedIp fixedIp = jsonNodeToFixedIps(fixedIpNode); |
226 | - fixedIps.add(fixedIp); | 226 | + fixedIps.add(fixedIp); |
227 | - } | 227 | + } |
228 | - | 228 | + |
229 | - BindingHostId bindingHostId = BindingHostId | 229 | + BindingHostId bindingHostId = BindingHostId |
230 | - .bindingHostId(vPortnode.get("binding:host_id").asText()); | 230 | + .bindingHostId(vPortnode.get("binding:host_id").asText()); |
231 | - String bindingVnicType = vPortnode.get("binding:vnic_type") | 231 | + String bindingVnicType = vPortnode.get("binding:vnic_type") |
232 | - .asText(); | 232 | + .asText(); |
233 | - String bindingVifType = vPortnode.get("binding:vif_type").asText(); | 233 | + String bindingVifType = vPortnode.get("binding:vif_type").asText(); |
234 | - String bindingVifDetails = vPortnode.get("binding:vif_details") | 234 | + String bindingVifDetails = vPortnode.get("binding:vif_details") |
235 | - .asText(); | 235 | + .asText(); |
236 | - JsonNode allowedAddressPairJsonNode = vPortnode | 236 | + JsonNode allowedAddressPairJsonNode = vPortnode |
237 | - .get("allowed_address_pairs"); | 237 | + .get("allowed_address_pairs"); |
238 | - Collection<AllowedAddressPair> allowedAddressPairs = | 238 | + Collection<AllowedAddressPair> allowedAddressPairs = |
239 | - jsonNodeToAllowedAddressPair(allowedAddressPairJsonNode); | 239 | + jsonNodeToAllowedAddressPair(allowedAddressPairJsonNode); |
240 | - JsonNode securityGroupNode = vPortnode.get("security_groups"); | 240 | + JsonNode securityGroupNode = vPortnode.get("security_groups"); |
241 | - Collection<SecurityGroup> securityGroups = jsonNodeToSecurityGroup(securityGroupNode); | 241 | + Collection<SecurityGroup> securityGroups = jsonNodeToSecurityGroup(securityGroupNode); |
242 | - strMap.put("name", name); | 242 | + strMap.put("name", name); |
243 | - strMap.put("deviceOwner", deviceOwner); | 243 | + strMap.put("deviceOwner", deviceOwner); |
244 | - strMap.put("bindingVnicType", bindingVnicType); | 244 | + strMap.put("bindingVnicType", bindingVnicType); |
245 | - strMap.put("bindingVifType", bindingVifType); | 245 | + strMap.put("bindingVifType", bindingVifType); |
246 | - strMap.put("bindingVifDetails", bindingVifDetails); | 246 | + strMap.put("bindingVifDetails", bindingVifDetails); |
247 | - VirtualPort vPort = new DefaultVirtualPort(id, networkId, | 247 | + VirtualPort vPort = new DefaultVirtualPort(id, networkId, |
248 | - adminStateUp, strMap, | 248 | + adminStateUp, strMap, |
249 | - isState(state), | 249 | + isState(state), |
250 | - macAddress, tenantId, | 250 | + macAddress, tenantId, |
251 | - deviceId, fixedIps, | 251 | + deviceId, fixedIps, |
252 | - bindingHostId, | 252 | + bindingHostId, |
253 | - Sets.newHashSet(allowedAddressPairs), | 253 | + Sets.newHashSet(allowedAddressPairs), |
254 | - Sets.newHashSet(securityGroups)); | 254 | + Sets.newHashSet(securityGroups)); |
255 | - portMap.put(id, vPort); | 255 | + portMap.put(id, vPort); |
256 | - } | 256 | + } |
257 | - return Collections.unmodifiableCollection(portMap.values()); | 257 | + return Collections.unmodifiableCollection(portMap.values()); |
258 | - } | 258 | + } |
259 | - | 259 | + |
260 | - /** | 260 | + /** |
261 | - * Returns a collection of virtualPorts from subnetNodes. | 261 | + * Returns a collection of virtualPorts from subnetNodes. |
262 | - * | 262 | + * |
263 | - * @param vPortNodes the virtualPort json node | 263 | + * @param vPortNodes the virtualPort json node |
264 | - * @return virtualPorts a collection of virtualPorts | 264 | + * @return virtualPorts a collection of virtualPorts |
265 | - */ | 265 | + */ |
266 | - public Iterable<VirtualPort> changeJsonToPort(JsonNode vPortNodes) { | 266 | + public Iterable<VirtualPort> changeJsonToPort(JsonNode vPortNodes) { |
267 | - checkNotNull(vPortNodes, JSON_NOT_NULL); | 267 | + checkNotNull(vPortNodes, JSON_NOT_NULL); |
268 | - Map<VirtualPortId, VirtualPort> vportMap = new HashMap<>(); | 268 | + Map<VirtualPortId, VirtualPort> vportMap = new HashMap<>(); |
269 | - Map<String, String> strMap = new HashMap<>(); | 269 | + Map<String, String> strMap = new HashMap<>(); |
270 | - VirtualPortId id = VirtualPortId.portId(vPortNodes.get("id").asText()); | 270 | + VirtualPortId id = VirtualPortId.portId(vPortNodes.get("id").asText()); |
271 | - String name = vPortNodes.get("name").asText(); | 271 | + String name = vPortNodes.get("name").asText(); |
272 | - TenantId tenantId = TenantId.tenantId(vPortNodes.get("tenant_id") | 272 | + TenantId tenantId = TenantId.tenantId(vPortNodes.get("tenant_id") |
273 | - .asText()); | 273 | + .asText()); |
274 | - TenantNetworkId networkId = TenantNetworkId.networkId(vPortNodes | 274 | + TenantNetworkId networkId = TenantNetworkId.networkId(vPortNodes |
275 | - .get("network_id").asText()); | 275 | + .get("network_id").asText()); |
276 | - Boolean adminStateUp = vPortNodes.get("admin_state_up").asBoolean(); | 276 | + Boolean adminStateUp = vPortNodes.get("admin_state_up").asBoolean(); |
277 | - String state = vPortNodes.get("status").asText(); | 277 | + String state = vPortNodes.get("status").asText(); |
278 | - MacAddress macAddress = MacAddress.valueOf(vPortNodes | 278 | + MacAddress macAddress = MacAddress.valueOf(vPortNodes |
279 | - .get("mac_address").asText()); | 279 | + .get("mac_address").asText()); |
280 | - DeviceId deviceId = DeviceId.deviceId(vPortNodes.get("device_id") | 280 | + DeviceId deviceId = DeviceId.deviceId(vPortNodes.get("device_id") |
281 | - .asText()); | 281 | + .asText()); |
282 | - String deviceOwner = vPortNodes.get("device_owner").asText(); | 282 | + String deviceOwner = vPortNodes.get("device_owner").asText(); |
283 | - JsonNode fixedIpNodes = vPortNodes.get("fixed_ips"); | 283 | + JsonNode fixedIpNodes = vPortNodes.get("fixed_ips"); |
284 | - Set<FixedIp> fixedIps = new HashSet<>(); | 284 | + Set<FixedIp> fixedIps = new HashSet<>(); |
285 | - for (JsonNode fixedIpNode : fixedIpNodes) { | 285 | + for (JsonNode fixedIpNode : fixedIpNodes) { |
286 | - FixedIp fixedIp = jsonNodeToFixedIps(fixedIpNode); | 286 | + FixedIp fixedIp = jsonNodeToFixedIps(fixedIpNode); |
287 | - fixedIps.add(fixedIp); | 287 | + fixedIps.add(fixedIp); |
288 | - } | 288 | + } |
289 | - | 289 | + |
290 | - BindingHostId bindingHostId = BindingHostId | 290 | + BindingHostId bindingHostId = BindingHostId |
291 | - .bindingHostId(vPortNodes.get("binding:host_id").asText()); | 291 | + .bindingHostId(vPortNodes.get("binding:host_id").asText()); |
292 | - String bindingVnicType = vPortNodes.get("binding:vnic_type").asText(); | 292 | + String bindingVnicType = vPortNodes.get("binding:vnic_type").asText(); |
293 | - String bindingVifType = vPortNodes.get("binding:vif_type").asText(); | 293 | + String bindingVifType = vPortNodes.get("binding:vif_type").asText(); |
294 | - String bindingVifDetails = vPortNodes.get("binding:vif_details") | 294 | + String bindingVifDetails = vPortNodes.get("binding:vif_details") |
295 | - .asText(); | 295 | + .asText(); |
296 | - JsonNode allowedAddressPairJsonNode = vPortNodes | 296 | + JsonNode allowedAddressPairJsonNode = vPortNodes |
297 | - .get("allowed_address_pairs"); | 297 | + .get("allowed_address_pairs"); |
298 | - Collection<AllowedAddressPair> allowedAddressPairs = | 298 | + Collection<AllowedAddressPair> allowedAddressPairs = |
299 | - jsonNodeToAllowedAddressPair(allowedAddressPairJsonNode); | 299 | + jsonNodeToAllowedAddressPair(allowedAddressPairJsonNode); |
300 | - JsonNode securityGroupNode = vPortNodes.get("security_groups"); | 300 | + JsonNode securityGroupNode = vPortNodes.get("security_groups"); |
301 | - Collection<SecurityGroup> securityGroups = jsonNodeToSecurityGroup(securityGroupNode); | 301 | + Collection<SecurityGroup> securityGroups = jsonNodeToSecurityGroup(securityGroupNode); |
302 | - strMap.put("name", name); | 302 | + strMap.put("name", name); |
303 | - strMap.put("deviceOwner", deviceOwner); | 303 | + strMap.put("deviceOwner", deviceOwner); |
304 | - strMap.put("bindingVnicType", bindingVnicType); | 304 | + strMap.put("bindingVnicType", bindingVnicType); |
305 | - strMap.put("bindingVifType", bindingVifType); | 305 | + strMap.put("bindingVifType", bindingVifType); |
306 | - strMap.put("bindingVifDetails", bindingVifDetails); | 306 | + strMap.put("bindingVifDetails", bindingVifDetails); |
307 | - VirtualPort vPort = new DefaultVirtualPort(id, networkId, adminStateUp, | 307 | + VirtualPort vPort = new DefaultVirtualPort(id, networkId, adminStateUp, |
308 | - strMap, isState(state), | 308 | + strMap, isState(state), |
309 | - macAddress, tenantId, | 309 | + macAddress, tenantId, |
310 | - deviceId, fixedIps, | 310 | + deviceId, fixedIps, |
311 | - bindingHostId, | 311 | + bindingHostId, |
312 | - Sets.newHashSet(allowedAddressPairs), | 312 | + Sets.newHashSet(allowedAddressPairs), |
313 | - Sets.newHashSet(securityGroups)); | 313 | + Sets.newHashSet(securityGroups)); |
314 | - vportMap.put(id, vPort); | 314 | + vportMap.put(id, vPort); |
315 | - | 315 | + |
316 | - return Collections.unmodifiableCollection(vportMap.values()); | 316 | + return Collections.unmodifiableCollection(vportMap.values()); |
317 | - } | 317 | + } |
318 | - | 318 | + |
319 | - /** | 319 | + /** |
320 | - * Returns a Object of the currently known infrastructure virtualPort. | 320 | + * Returns a Object of the currently known infrastructure virtualPort. |
321 | - * | 321 | + * |
322 | - * @param allowedAddressPairs the allowedAddressPairs json node | 322 | + * @param allowedAddressPairs the allowedAddressPairs json node |
323 | - * @return a collection of allowedAddressPair | 323 | + * @return a collection of allowedAddressPair |
324 | - */ | 324 | + */ |
325 | - public Collection<AllowedAddressPair> jsonNodeToAllowedAddressPair(JsonNode allowedAddressPairs) { | 325 | + public Collection<AllowedAddressPair> jsonNodeToAllowedAddressPair(JsonNode allowedAddressPairs) { |
326 | - checkNotNull(allowedAddressPairs, JSON_NOT_NULL); | 326 | + checkNotNull(allowedAddressPairs, JSON_NOT_NULL); |
327 | - ConcurrentMap<Integer, AllowedAddressPair> allowMaps = Maps | 327 | + ConcurrentMap<Integer, AllowedAddressPair> allowMaps = Maps |
328 | - .newConcurrentMap(); | 328 | + .newConcurrentMap(); |
329 | - int i = 0; | 329 | + int i = 0; |
330 | - for (JsonNode node : allowedAddressPairs) { | 330 | + for (JsonNode node : allowedAddressPairs) { |
331 | - IpAddress ip = IpAddress.valueOf(node.get("ip_address").asText()); | 331 | + IpAddress ip = IpAddress.valueOf(node.get("ip_address").asText()); |
332 | - MacAddress mac = MacAddress.valueOf(node.get("mac_address") | 332 | + MacAddress mac = MacAddress.valueOf(node.get("mac_address") |
333 | - .asText()); | 333 | + .asText()); |
334 | - AllowedAddressPair allows = AllowedAddressPair | 334 | + AllowedAddressPair allows = AllowedAddressPair |
335 | - .allowedAddressPair(ip, mac); | 335 | + .allowedAddressPair(ip, mac); |
336 | - allowMaps.put(i, allows); | 336 | + allowMaps.put(i, allows); |
337 | - i++; | 337 | + i++; |
338 | - } | 338 | + } |
339 | - log.debug("The jsonNode of allowedAddressPairallow is {}" | 339 | + log.debug("The jsonNode of allowedAddressPairallow is {}" |
340 | - + allowedAddressPairs.toString()); | 340 | + + allowedAddressPairs.toString()); |
341 | - return Collections.unmodifiableCollection(allowMaps.values()); | 341 | + return Collections.unmodifiableCollection(allowMaps.values()); |
342 | - } | 342 | + } |
343 | - | 343 | + |
344 | - /** | 344 | + /** |
345 | - * Returns a collection of virtualPorts. | 345 | + * Returns a collection of virtualPorts. |
346 | - * | 346 | + * |
347 | - * @param securityGroups the virtualPort jsonnode | 347 | + * @param securityGroups the virtualPort jsonnode |
348 | - * @return a collection of securityGroups | 348 | + * @return a collection of securityGroups |
349 | - */ | 349 | + */ |
350 | - public Collection<SecurityGroup> jsonNodeToSecurityGroup(JsonNode securityGroups) { | 350 | + public Collection<SecurityGroup> jsonNodeToSecurityGroup(JsonNode securityGroups) { |
351 | - checkNotNull(securityGroups, JSON_NOT_NULL); | 351 | + checkNotNull(securityGroups, JSON_NOT_NULL); |
352 | - ConcurrentMap<Integer, SecurityGroup> securMaps = Maps | 352 | + ConcurrentMap<Integer, SecurityGroup> securMaps = Maps |
353 | - .newConcurrentMap(); | 353 | + .newConcurrentMap(); |
354 | - int i = 0; | 354 | + int i = 0; |
355 | - for (JsonNode node : securityGroups) { | 355 | + for (JsonNode node : securityGroups) { |
356 | - SecurityGroup securityGroup = SecurityGroup | 356 | + SecurityGroup securityGroup = SecurityGroup |
357 | - .securityGroup(node.asText()); | 357 | + .securityGroup(node.asText()); |
358 | - securMaps.put(i, securityGroup); | 358 | + securMaps.put(i, securityGroup); |
359 | - i++; | 359 | + i++; |
360 | - } | 360 | + } |
361 | - return Collections.unmodifiableCollection(securMaps.values()); | 361 | + return Collections.unmodifiableCollection(securMaps.values()); |
362 | - } | 362 | + } |
363 | - | 363 | + |
364 | - /** | 364 | + /** |
365 | - * Returns a collection of fixedIps. | 365 | + * Returns a collection of fixedIps. |
366 | - * | 366 | + * |
367 | - * @param fixedIpNode the fixedIp jsonnode | 367 | + * @param fixedIpNode the fixedIp jsonnode |
368 | - * @return a collection of SecurityGroup | 368 | + * @return a collection of SecurityGroup |
369 | - */ | 369 | + */ |
370 | - public FixedIp jsonNodeToFixedIps(JsonNode fixedIpNode) { | 370 | + public FixedIp jsonNodeToFixedIps(JsonNode fixedIpNode) { |
371 | - SubnetId subnetId = SubnetId.subnetId(fixedIpNode.get("subnet_id") | 371 | + SubnetId subnetId = SubnetId.subnetId(fixedIpNode.get("subnet_id") |
372 | - .asText()); | 372 | + .asText()); |
373 | - IpAddress ipAddress = IpAddress.valueOf(fixedIpNode.get("ip_address") | 373 | + IpAddress ipAddress = IpAddress.valueOf(fixedIpNode.get("ip_address") |
374 | - .asText()); | 374 | + .asText()); |
375 | - FixedIp fixedIps = FixedIp.fixedIp(subnetId, ipAddress); | 375 | + FixedIp fixedIps = FixedIp.fixedIp(subnetId, ipAddress); |
376 | - return fixedIps; | 376 | + return fixedIps; |
377 | - } | 377 | + } |
378 | - | 378 | + |
379 | - /** | 379 | + /** |
380 | - * Returns VirtualPort State. | 380 | + * Returns VirtualPort State. |
381 | - * | 381 | + * |
382 | - * @param state the virtualport state | 382 | + * @param state the virtualport state |
383 | - * @return the virtualPort state | 383 | + * @return the virtualPort state |
384 | - */ | 384 | + */ |
385 | - private State isState(String state) { | 385 | + private State isState(String state) { |
386 | - if (state.equals("ACTIVE")) { | 386 | + if (state.equals("ACTIVE")) { |
387 | - return VirtualPort.State.ACTIVE; | 387 | + return VirtualPort.State.ACTIVE; |
388 | - } else { | 388 | + } else { |
389 | - return VirtualPort.State.DOWN; | 389 | + return VirtualPort.State.DOWN; |
390 | - } | 390 | + } |
391 | - | 391 | + |
392 | - } | 392 | + } |
393 | - | 393 | + |
394 | - /** | 394 | + /** |
395 | - * Returns the specified item if that items is null; otherwise throws not | 395 | + * Returns the specified item if that items is null; otherwise throws not |
396 | - * found exception. | 396 | + * found exception. |
397 | - * | 397 | + * |
398 | - * @param item item to check | 398 | + * @param item item to check |
399 | - * @param <T> item type | 399 | + * @param <T> item type |
400 | - * @param message not found message | 400 | + * @param message not found message |
401 | - * @return item if not null | 401 | + * @return item if not null |
402 | - * @throws org.onlab.util.ItemNotFoundException if item is null | 402 | + * @throws org.onlab.util.ItemNotFoundException if item is null |
403 | - */ | 403 | + */ |
404 | - protected <T> T nullIsNotFound(T item, String message) { | 404 | + protected <T> T nullIsNotFound(T item, String message) { |
405 | - if (item == null) { | 405 | + if (item == null) { |
406 | - throw new ItemNotFoundException(message); | 406 | + throw new ItemNotFoundException(message); |
407 | - } | 407 | + } |
408 | - return item; | 408 | + return item; |
409 | - } | 409 | + } |
410 | -} | 410 | +} | ... | ... |
1 | -/* | 1 | +/* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | - * | 3 | + * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | - * you may not use this file except in compliance with 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 | 6 | + * You may obtain a copy of the License at |
7 | - * | 7 | + * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | - * | 9 | + * |
10 | - * Unless required by applicable law or agreed to in writing, software | 10 | + * Unless required by applicable law or agreed to in writing, software |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | - * See the License for the specific language governing permissions and | 13 | + * See the License for the specific language governing permissions and |
14 | - * limitations under the License. | 14 | + * limitations under the License. |
15 | - */ | 15 | + */ |
16 | -package org.onosproject.store.host.impl; | 16 | +package org.onosproject.store.host.impl; |
17 | - | 17 | + |
18 | -import static com.google.common.base.Preconditions.checkNotNull; | 18 | +import static com.google.common.base.Preconditions.checkNotNull; |
19 | -import static org.onosproject.net.DefaultAnnotations.merge; | 19 | +import static org.onosproject.net.DefaultAnnotations.merge; |
20 | -import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; | 20 | +import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; |
21 | -import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; | 21 | +import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; |
22 | -import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED; | 22 | +import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED; |
23 | -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; | 23 | +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; |
24 | -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; | 24 | +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; |
25 | -import static org.slf4j.LoggerFactory.getLogger; | 25 | +import static org.slf4j.LoggerFactory.getLogger; |
26 | - | 26 | + |
27 | -import java.util.Collection; | 27 | +import java.util.Collection; |
28 | -import java.util.Collections; | 28 | +import java.util.Collections; |
29 | -import java.util.Objects; | 29 | +import java.util.Objects; |
30 | -import java.util.Set; | 30 | +import java.util.Set; |
31 | -import java.util.function.Predicate; | 31 | +import java.util.function.Predicate; |
32 | -import java.util.stream.Collectors; | 32 | +import java.util.stream.Collectors; |
33 | - | 33 | + |
34 | -import org.apache.felix.scr.annotations.Activate; | 34 | +import org.apache.felix.scr.annotations.Activate; |
35 | -import org.apache.felix.scr.annotations.Component; | 35 | +import org.apache.felix.scr.annotations.Component; |
36 | -import org.apache.felix.scr.annotations.Deactivate; | 36 | +import org.apache.felix.scr.annotations.Deactivate; |
37 | -import org.apache.felix.scr.annotations.Reference; | 37 | +import org.apache.felix.scr.annotations.Reference; |
38 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | 38 | +import org.apache.felix.scr.annotations.ReferenceCardinality; |
39 | -import org.apache.felix.scr.annotations.Service; | 39 | +import org.apache.felix.scr.annotations.Service; |
40 | -import org.onlab.packet.IpAddress; | 40 | +import org.onlab.packet.IpAddress; |
41 | -import org.onlab.packet.MacAddress; | 41 | +import org.onlab.packet.MacAddress; |
42 | -import org.onlab.packet.VlanId; | 42 | +import org.onlab.packet.VlanId; |
43 | -import org.onlab.util.KryoNamespace; | 43 | +import org.onlab.util.KryoNamespace; |
44 | -import org.onosproject.net.Annotations; | 44 | +import org.onosproject.net.Annotations; |
45 | -import org.onosproject.net.ConnectPoint; | 45 | +import org.onosproject.net.ConnectPoint; |
46 | -import org.onosproject.net.DefaultAnnotations; | 46 | +import org.onosproject.net.DefaultAnnotations; |
47 | -import org.onosproject.net.DefaultHost; | 47 | +import org.onosproject.net.DefaultHost; |
48 | -import org.onosproject.net.DeviceId; | 48 | +import org.onosproject.net.DeviceId; |
49 | -import org.onosproject.net.Host; | 49 | +import org.onosproject.net.Host; |
50 | -import org.onosproject.net.HostId; | 50 | +import org.onosproject.net.HostId; |
51 | -import org.onosproject.net.host.HostDescription; | 51 | +import org.onosproject.net.host.HostDescription; |
52 | -import org.onosproject.net.host.HostEvent; | 52 | +import org.onosproject.net.host.HostEvent; |
53 | -import org.onosproject.net.host.HostStore; | 53 | +import org.onosproject.net.host.HostStore; |
54 | -import org.onosproject.net.host.HostStoreDelegate; | 54 | +import org.onosproject.net.host.HostStoreDelegate; |
55 | -import org.onosproject.net.host.PortAddresses; | 55 | +import org.onosproject.net.host.PortAddresses; |
56 | -import org.onosproject.net.host.HostEvent.Type; | 56 | +import org.onosproject.net.host.HostEvent.Type; |
57 | -import org.onosproject.net.provider.ProviderId; | 57 | +import org.onosproject.net.provider.ProviderId; |
58 | -import org.onosproject.store.AbstractStore; | 58 | +import org.onosproject.store.AbstractStore; |
59 | -import org.onosproject.store.serializers.KryoNamespaces; | 59 | +import org.onosproject.store.serializers.KryoNamespaces; |
60 | -import org.onosproject.store.service.EventuallyConsistentMap; | 60 | +import org.onosproject.store.service.EventuallyConsistentMap; |
61 | -import org.onosproject.store.service.EventuallyConsistentMapEvent; | 61 | +import org.onosproject.store.service.EventuallyConsistentMapEvent; |
62 | -import org.onosproject.store.service.EventuallyConsistentMapListener; | 62 | +import org.onosproject.store.service.EventuallyConsistentMapListener; |
63 | -import org.onosproject.store.service.LogicalClockService; | 63 | +import org.onosproject.store.service.LogicalClockService; |
64 | -import org.onosproject.store.service.StorageService; | 64 | +import org.onosproject.store.service.StorageService; |
65 | -import org.slf4j.Logger; | 65 | +import org.slf4j.Logger; |
66 | - | 66 | + |
67 | -import com.google.common.collect.HashMultimap; | 67 | +import com.google.common.collect.HashMultimap; |
68 | -import com.google.common.collect.ImmutableMultimap; | 68 | +import com.google.common.collect.ImmutableMultimap; |
69 | -import com.google.common.collect.ImmutableSet; | 69 | +import com.google.common.collect.ImmutableSet; |
70 | -import com.google.common.collect.Multimaps; | 70 | +import com.google.common.collect.Multimaps; |
71 | -import com.google.common.collect.SetMultimap; | 71 | +import com.google.common.collect.SetMultimap; |
72 | -import com.google.common.collect.Sets; | 72 | +import com.google.common.collect.Sets; |
73 | - | 73 | + |
74 | -/** | 74 | +/** |
75 | - * Manages the inventory of hosts using a {@code EventuallyConsistentMap}. | 75 | + * Manages the inventory of hosts using a {@code EventuallyConsistentMap}. |
76 | - */ | 76 | + */ |
77 | -@Component(immediate = true) | 77 | +@Component(immediate = true) |
78 | -@Service | 78 | +@Service |
79 | -public class ECHostStore | 79 | +public class ECHostStore |
80 | - extends AbstractStore<HostEvent, HostStoreDelegate> | 80 | + extends AbstractStore<HostEvent, HostStoreDelegate> |
81 | - implements HostStore { | 81 | + implements HostStore { |
82 | - | 82 | + |
83 | - private final Logger log = getLogger(getClass()); | 83 | + private final Logger log = getLogger(getClass()); |
84 | - | 84 | + |
85 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 85 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
86 | - protected StorageService storageService; | 86 | + protected StorageService storageService; |
87 | - | 87 | + |
88 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 88 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
89 | - protected LogicalClockService clockService; | 89 | + protected LogicalClockService clockService; |
90 | - | 90 | + |
91 | - // Hosts tracked by their location | 91 | + // Hosts tracked by their location |
92 | - private final SetMultimap<ConnectPoint, Host> locations = | 92 | + private final SetMultimap<ConnectPoint, Host> locations = |
93 | - Multimaps.synchronizedSetMultimap( | 93 | + Multimaps.synchronizedSetMultimap( |
94 | - HashMultimap.<ConnectPoint, Host>create()); | 94 | + HashMultimap.<ConnectPoint, Host>create()); |
95 | - | 95 | + |
96 | - private final SetMultimap<ConnectPoint, PortAddresses> portAddresses = | 96 | + private final SetMultimap<ConnectPoint, PortAddresses> portAddresses = |
97 | - Multimaps.synchronizedSetMultimap( | 97 | + Multimaps.synchronizedSetMultimap( |
98 | - HashMultimap.<ConnectPoint, PortAddresses>create()); | 98 | + HashMultimap.<ConnectPoint, PortAddresses>create()); |
99 | - | 99 | + |
100 | - private EventuallyConsistentMap<HostId, DefaultHost> hosts; | 100 | + private EventuallyConsistentMap<HostId, DefaultHost> hosts; |
101 | - | 101 | + |
102 | - private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker = | 102 | + private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker = |
103 | - new HostLocationTracker(); | 103 | + new HostLocationTracker(); |
104 | - | 104 | + |
105 | - @Activate | 105 | + @Activate |
106 | - public void activate() { | 106 | + public void activate() { |
107 | - KryoNamespace.Builder hostSerializer = KryoNamespace.newBuilder() | 107 | + KryoNamespace.Builder hostSerializer = KryoNamespace.newBuilder() |
108 | - .register(KryoNamespaces.API); | 108 | + .register(KryoNamespaces.API); |
109 | - | 109 | + |
110 | - hosts = storageService.<HostId, DefaultHost>eventuallyConsistentMapBuilder() | 110 | + hosts = storageService.<HostId, DefaultHost>eventuallyConsistentMapBuilder() |
111 | - .withName("onos-hosts") | 111 | + .withName("onos-hosts") |
112 | - .withSerializer(hostSerializer) | 112 | + .withSerializer(hostSerializer) |
113 | - .withTimestampProvider((k, v) -> clockService.getTimestamp()) | 113 | + .withTimestampProvider((k, v) -> clockService.getTimestamp()) |
114 | - .build(); | 114 | + .build(); |
115 | - | 115 | + |
116 | - hosts.addListener(hostLocationTracker); | 116 | + hosts.addListener(hostLocationTracker); |
117 | - | 117 | + |
118 | - log.info("Started"); | 118 | + log.info("Started"); |
119 | - } | 119 | + } |
120 | - | 120 | + |
121 | - @Deactivate | 121 | + @Deactivate |
122 | - public void deactivate() { | 122 | + public void deactivate() { |
123 | - hosts.removeListener(hostLocationTracker); | 123 | + hosts.removeListener(hostLocationTracker); |
124 | - hosts.destroy(); | 124 | + hosts.destroy(); |
125 | - locations.clear(); | 125 | + locations.clear(); |
126 | - portAddresses.clear(); | 126 | + portAddresses.clear(); |
127 | - | 127 | + |
128 | - log.info("Stopped"); | 128 | + log.info("Stopped"); |
129 | - } | 129 | + } |
130 | - | 130 | + |
131 | - @Override | 131 | + @Override |
132 | - public HostEvent createOrUpdateHost(ProviderId providerId, | 132 | + public HostEvent createOrUpdateHost(ProviderId providerId, |
133 | - HostId hostId, | 133 | + HostId hostId, |
134 | - HostDescription hostDescription) { | 134 | + HostDescription hostDescription) { |
135 | - DefaultHost currentHost = hosts.get(hostId); | 135 | + DefaultHost currentHost = hosts.get(hostId); |
136 | - if (currentHost == null) { | 136 | + if (currentHost == null) { |
137 | - DefaultHost newhost = new DefaultHost( | 137 | + DefaultHost newhost = new DefaultHost( |
138 | - providerId, | 138 | + providerId, |
139 | - hostId, | 139 | + hostId, |
140 | - hostDescription.hwAddress(), | 140 | + hostDescription.hwAddress(), |
141 | - hostDescription.vlan(), | 141 | + hostDescription.vlan(), |
142 | - hostDescription.location(), | 142 | + hostDescription.location(), |
143 | - ImmutableSet.copyOf(hostDescription.ipAddress()), | 143 | + ImmutableSet.copyOf(hostDescription.ipAddress()), |
144 | - hostDescription.annotations()); | 144 | + hostDescription.annotations()); |
145 | - hosts.put(hostId, newhost); | 145 | + hosts.put(hostId, newhost); |
146 | - return new HostEvent(HOST_ADDED, newhost); | 146 | + return new HostEvent(HOST_ADDED, newhost); |
147 | - } | 147 | + } |
148 | - return updateHost(providerId, hostId, hostDescription, currentHost); | 148 | + return updateHost(providerId, hostId, hostDescription, currentHost); |
149 | - } | 149 | + } |
150 | - | 150 | + |
151 | - @Override | 151 | + @Override |
152 | - public HostEvent removeHost(HostId hostId) { | 152 | + public HostEvent removeHost(HostId hostId) { |
153 | - Host host = hosts.remove(hostId); | 153 | + Host host = hosts.remove(hostId); |
154 | - return host != null ? new HostEvent(HOST_REMOVED, host) : null; | 154 | + return host != null ? new HostEvent(HOST_REMOVED, host) : null; |
155 | - } | 155 | + } |
156 | - | 156 | + |
157 | - @Override | 157 | + @Override |
158 | - public int getHostCount() { | 158 | + public int getHostCount() { |
159 | - return hosts.size(); | 159 | + return hosts.size(); |
160 | - } | 160 | + } |
161 | - | 161 | + |
162 | - @Override | 162 | + @Override |
163 | - public Iterable<Host> getHosts() { | 163 | + public Iterable<Host> getHosts() { |
164 | - return ImmutableSet.copyOf(hosts.values()); | 164 | + return ImmutableSet.copyOf(hosts.values()); |
165 | - } | 165 | + } |
166 | - | 166 | + |
167 | - @Override | 167 | + @Override |
168 | - public Host getHost(HostId hostId) { | 168 | + public Host getHost(HostId hostId) { |
169 | - return hosts.get(hostId); | 169 | + return hosts.get(hostId); |
170 | - } | 170 | + } |
171 | - | 171 | + |
172 | - @Override | 172 | + @Override |
173 | - public Set<Host> getHosts(VlanId vlanId) { | 173 | + public Set<Host> getHosts(VlanId vlanId) { |
174 | - return filter(hosts.values(), host -> Objects.equals(host.vlan(), vlanId)); | 174 | + return filter(hosts.values(), host -> Objects.equals(host.vlan(), vlanId)); |
175 | - } | 175 | + } |
176 | - | 176 | + |
177 | - @Override | 177 | + @Override |
178 | - public Set<Host> getHosts(MacAddress mac) { | 178 | + public Set<Host> getHosts(MacAddress mac) { |
179 | - return filter(hosts.values(), host -> Objects.equals(host.mac(), mac)); | 179 | + return filter(hosts.values(), host -> Objects.equals(host.mac(), mac)); |
180 | - } | 180 | + } |
181 | - | 181 | + |
182 | - @Override | 182 | + @Override |
183 | - public Set<Host> getHosts(IpAddress ip) { | 183 | + public Set<Host> getHosts(IpAddress ip) { |
184 | - return filter(hosts.values(), host -> host.ipAddresses().contains(ip)); | 184 | + return filter(hosts.values(), host -> host.ipAddresses().contains(ip)); |
185 | - } | 185 | + } |
186 | - | 186 | + |
187 | - @Override | 187 | + @Override |
188 | - public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { | 188 | + public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
189 | - return ImmutableSet.copyOf(locations.get(connectPoint)); | 189 | + return ImmutableSet.copyOf(locations.get(connectPoint)); |
190 | - } | 190 | + } |
191 | - | 191 | + |
192 | - @Override | 192 | + @Override |
193 | - public Set<Host> getConnectedHosts(DeviceId deviceId) { | 193 | + public Set<Host> getConnectedHosts(DeviceId deviceId) { |
194 | - return ImmutableMultimap.copyOf(locations) | 194 | + return ImmutableMultimap.copyOf(locations) |
195 | - .entries() | 195 | + .entries() |
196 | - .stream() | 196 | + .stream() |
197 | - .filter(entry -> entry.getKey().deviceId().equals(deviceId)) | 197 | + .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
198 | - .map(entry -> entry.getValue()) | 198 | + .map(entry -> entry.getValue()) |
199 | - .collect(Collectors.toSet()); | 199 | + .collect(Collectors.toSet()); |
200 | - } | 200 | + } |
201 | - | 201 | + |
202 | - @Override | 202 | + @Override |
203 | - public void updateAddressBindings(PortAddresses addresses) { | 203 | + public void updateAddressBindings(PortAddresses addresses) { |
204 | - portAddresses.put(addresses.connectPoint(), addresses); | 204 | + portAddresses.put(addresses.connectPoint(), addresses); |
205 | - } | 205 | + } |
206 | - | 206 | + |
207 | - @Override | 207 | + @Override |
208 | - public void removeAddressBindings(PortAddresses addresses) { | 208 | + public void removeAddressBindings(PortAddresses addresses) { |
209 | - portAddresses.remove(addresses.connectPoint(), addresses); | 209 | + portAddresses.remove(addresses.connectPoint(), addresses); |
210 | - } | 210 | + } |
211 | - | 211 | + |
212 | - @Override | 212 | + @Override |
213 | - public void clearAddressBindings(ConnectPoint connectPoint) { | 213 | + public void clearAddressBindings(ConnectPoint connectPoint) { |
214 | - portAddresses.removeAll(connectPoint); | 214 | + portAddresses.removeAll(connectPoint); |
215 | - } | 215 | + } |
216 | - | 216 | + |
217 | - @Override | 217 | + @Override |
218 | - public Set<PortAddresses> getAddressBindings() { | 218 | + public Set<PortAddresses> getAddressBindings() { |
219 | - return ImmutableSet.copyOf(portAddresses.values()); | 219 | + return ImmutableSet.copyOf(portAddresses.values()); |
220 | - } | 220 | + } |
221 | - | 221 | + |
222 | - @Override | 222 | + @Override |
223 | - public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) { | 223 | + public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) { |
224 | - synchronized (portAddresses) { | 224 | + synchronized (portAddresses) { |
225 | - Set<PortAddresses> addresses = portAddresses.get(connectPoint); | 225 | + Set<PortAddresses> addresses = portAddresses.get(connectPoint); |
226 | - return addresses == null ? Collections.emptySet() : ImmutableSet.copyOf(addresses); | 226 | + return addresses == null ? Collections.emptySet() : ImmutableSet.copyOf(addresses); |
227 | - } | 227 | + } |
228 | - } | 228 | + } |
229 | - | 229 | + |
230 | - private Set<Host> filter(Collection<DefaultHost> collection, Predicate<DefaultHost> predicate) { | 230 | + private Set<Host> filter(Collection<DefaultHost> collection, Predicate<DefaultHost> predicate) { |
231 | - return collection.stream().filter(predicate).collect(Collectors.toSet()); | 231 | + return collection.stream().filter(predicate).collect(Collectors.toSet()); |
232 | - } | 232 | + } |
233 | - | 233 | + |
234 | - // checks for type of update to host, sends appropriate event | 234 | + // checks for type of update to host, sends appropriate event |
235 | - private HostEvent updateHost(ProviderId providerId, | 235 | + private HostEvent updateHost(ProviderId providerId, |
236 | - HostId hostId, | 236 | + HostId hostId, |
237 | - HostDescription descr, | 237 | + HostDescription descr, |
238 | - DefaultHost currentHost) { | 238 | + DefaultHost currentHost) { |
239 | - | 239 | + |
240 | - final boolean hostMoved = !currentHost.location().equals(descr.location()); | 240 | + final boolean hostMoved = !currentHost.location().equals(descr.location()); |
241 | - if (hostMoved || | 241 | + if (hostMoved || |
242 | - !currentHost.ipAddresses().containsAll(descr.ipAddress()) || | 242 | + !currentHost.ipAddresses().containsAll(descr.ipAddress()) || |
243 | - !descr.annotations().keys().isEmpty()) { | 243 | + !descr.annotations().keys().isEmpty()) { |
244 | - | 244 | + |
245 | - Set<IpAddress> addresses = Sets.newHashSet(currentHost.ipAddresses()); | 245 | + Set<IpAddress> addresses = Sets.newHashSet(currentHost.ipAddresses()); |
246 | - addresses.addAll(descr.ipAddress()); | 246 | + addresses.addAll(descr.ipAddress()); |
247 | - Annotations annotations = merge((DefaultAnnotations) currentHost.annotations(), | 247 | + Annotations annotations = merge((DefaultAnnotations) currentHost.annotations(), |
248 | - descr.annotations()); | 248 | + descr.annotations()); |
249 | - | 249 | + |
250 | - DefaultHost updatedHost = new DefaultHost(providerId, currentHost.id(), | 250 | + DefaultHost updatedHost = new DefaultHost(providerId, currentHost.id(), |
251 | - currentHost.mac(), currentHost.vlan(), | 251 | + currentHost.mac(), currentHost.vlan(), |
252 | - descr.location(), | 252 | + descr.location(), |
253 | - addresses, | 253 | + addresses, |
254 | - annotations); | 254 | + annotations); |
255 | - | 255 | + |
256 | - // TODO: We need a way to detect conflicting changes and abort update. | 256 | + // TODO: We need a way to detect conflicting changes and abort update. |
257 | - hosts.put(hostId, updatedHost); | 257 | + hosts.put(hostId, updatedHost); |
258 | - locations.remove(currentHost.location(), currentHost); | 258 | + locations.remove(currentHost.location(), currentHost); |
259 | - locations.put(updatedHost.location(), updatedHost); | 259 | + locations.put(updatedHost.location(), updatedHost); |
260 | - | 260 | + |
261 | - HostEvent.Type eventType = hostMoved ? Type.HOST_MOVED : Type.HOST_UPDATED; | 261 | + HostEvent.Type eventType = hostMoved ? Type.HOST_MOVED : Type.HOST_UPDATED; |
262 | - return new HostEvent(eventType, updatedHost); | 262 | + return new HostEvent(eventType, updatedHost); |
263 | - } | 263 | + } |
264 | - return null; | 264 | + return null; |
265 | - } | 265 | + } |
266 | - | 266 | + |
267 | - private class HostLocationTracker implements EventuallyConsistentMapListener<HostId, DefaultHost> { | 267 | + private class HostLocationTracker implements EventuallyConsistentMapListener<HostId, DefaultHost> { |
268 | - @Override | 268 | + @Override |
269 | - public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) { | 269 | + public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) { |
270 | - DefaultHost host = checkNotNull(event.value()); | 270 | + DefaultHost host = checkNotNull(event.value()); |
271 | - if (event.type() == PUT) { | 271 | + if (event.type() == PUT) { |
272 | - boolean isNew = locations.put(host.location(), host); | 272 | + boolean isNew = locations.put(host.location(), host); |
273 | - notifyDelegate(new HostEvent(isNew ? HOST_ADDED : HOST_UPDATED, host)); | 273 | + notifyDelegate(new HostEvent(isNew ? HOST_ADDED : HOST_UPDATED, host)); |
274 | - } else if (event.type() == REMOVE) { | 274 | + } else if (event.type() == REMOVE) { |
275 | - if (locations.remove(host.location(), host)) { | 275 | + if (locations.remove(host.location(), host)) { |
276 | - notifyDelegate(new HostEvent(HOST_REMOVED, host)); | 276 | + notifyDelegate(new HostEvent(HOST_REMOVED, host)); |
277 | - } | 277 | + } |
278 | - | 278 | + |
279 | - } | 279 | + } |
280 | - } | 280 | + } |
281 | - } | 281 | + } |
282 | -} | 282 | +} | ... | ... |
1 | -/* | 1 | +/* |
2 | - * Copyright 2015 Open Networking Laboratory | 2 | + * Copyright 2015 Open Networking Laboratory |
3 | - * | 3 | + * |
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | - * you may not use this file except in compliance with 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 | 6 | + * You may obtain a copy of the License at |
7 | - * | 7 | + * |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | - * | 9 | + * |
10 | - * Unless required by applicable law or agreed to in writing, software | 10 | + * Unless required by applicable law or agreed to in writing, software |
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | - * See the License for the specific language governing permissions and | 13 | + * See the License for the specific language governing permissions and |
14 | - * limitations under the License. | 14 | + * limitations under the License. |
15 | - */ | 15 | + */ |
16 | -package org.onosproject.ovsdb.provider.host; | 16 | +package org.onosproject.ovsdb.provider.host; |
17 | - | 17 | + |
18 | -import static com.google.common.base.Preconditions.checkNotNull; | 18 | +import static com.google.common.base.Preconditions.checkNotNull; |
19 | -import static org.onlab.util.Tools.toHex; | 19 | +import static org.onlab.util.Tools.toHex; |
20 | -import static org.slf4j.LoggerFactory.getLogger; | 20 | +import static org.slf4j.LoggerFactory.getLogger; |
21 | - | 21 | + |
22 | -import java.net.URI; | 22 | +import java.net.URI; |
23 | -import java.net.URISyntaxException; | 23 | +import java.net.URISyntaxException; |
24 | - | 24 | + |
25 | -import org.apache.felix.scr.annotations.Activate; | 25 | +import org.apache.felix.scr.annotations.Activate; |
26 | -import org.apache.felix.scr.annotations.Component; | 26 | +import org.apache.felix.scr.annotations.Component; |
27 | -import org.apache.felix.scr.annotations.Deactivate; | 27 | +import org.apache.felix.scr.annotations.Deactivate; |
28 | -import org.apache.felix.scr.annotations.Reference; | 28 | +import org.apache.felix.scr.annotations.Reference; |
29 | -import org.apache.felix.scr.annotations.ReferenceCardinality; | 29 | +import org.apache.felix.scr.annotations.ReferenceCardinality; |
30 | -import org.apache.felix.scr.annotations.Service; | 30 | +import org.apache.felix.scr.annotations.Service; |
31 | -import org.onlab.packet.VlanId; | 31 | +import org.onlab.packet.VlanId; |
32 | -import org.onosproject.core.CoreService; | 32 | +import org.onosproject.core.CoreService; |
33 | -import org.onosproject.net.DefaultAnnotations; | 33 | +import org.onosproject.net.DefaultAnnotations; |
34 | -import org.onosproject.net.DeviceId; | 34 | +import org.onosproject.net.DeviceId; |
35 | -import org.onosproject.net.Host; | 35 | +import org.onosproject.net.Host; |
36 | -import org.onosproject.net.HostId; | 36 | +import org.onosproject.net.HostId; |
37 | -import org.onosproject.net.HostLocation; | 37 | +import org.onosproject.net.HostLocation; |
38 | -import org.onosproject.net.PortNumber; | 38 | +import org.onosproject.net.PortNumber; |
39 | -import org.onosproject.net.SparseAnnotations; | 39 | +import org.onosproject.net.SparseAnnotations; |
40 | -import org.onosproject.net.host.DefaultHostDescription; | 40 | +import org.onosproject.net.host.DefaultHostDescription; |
41 | -import org.onosproject.net.host.HostDescription; | 41 | +import org.onosproject.net.host.HostDescription; |
42 | -import org.onosproject.net.host.HostProvider; | 42 | +import org.onosproject.net.host.HostProvider; |
43 | -import org.onosproject.net.host.HostProviderRegistry; | 43 | +import org.onosproject.net.host.HostProviderRegistry; |
44 | -import org.onosproject.net.host.HostProviderService; | 44 | +import org.onosproject.net.host.HostProviderService; |
45 | -import org.onosproject.net.host.HostService; | 45 | +import org.onosproject.net.host.HostService; |
46 | -import org.onosproject.net.provider.AbstractProvider; | 46 | +import org.onosproject.net.provider.AbstractProvider; |
47 | -import org.onosproject.net.provider.ProviderId; | 47 | +import org.onosproject.net.provider.ProviderId; |
48 | -import org.onosproject.ovsdb.controller.EventSubject; | 48 | +import org.onosproject.ovsdb.controller.EventSubject; |
49 | -import org.onosproject.ovsdb.controller.OvsdbController; | 49 | +import org.onosproject.ovsdb.controller.OvsdbController; |
50 | -import org.onosproject.ovsdb.controller.OvsdbEvent; | 50 | +import org.onosproject.ovsdb.controller.OvsdbEvent; |
51 | -import org.onosproject.ovsdb.controller.OvsdbEventListener; | 51 | +import org.onosproject.ovsdb.controller.OvsdbEventListener; |
52 | -import org.onosproject.ovsdb.controller.OvsdbEventSubject; | 52 | +import org.onosproject.ovsdb.controller.OvsdbEventSubject; |
53 | -import org.slf4j.Logger; | 53 | +import org.slf4j.Logger; |
54 | - | 54 | + |
55 | -/** | 55 | +/** |
56 | - * Provider which uses an ovsdb controller to detect host. | 56 | + * Provider which uses an ovsdb controller to detect host. |
57 | - */ | 57 | + */ |
58 | -@Component(immediate = true) | 58 | +@Component(immediate = true) |
59 | -@Service | 59 | +@Service |
60 | -public class OvsdbHostProvider extends AbstractProvider implements HostProvider { | 60 | +public class OvsdbHostProvider extends AbstractProvider implements HostProvider { |
61 | - private final Logger log = getLogger(getClass()); | 61 | + private final Logger log = getLogger(getClass()); |
62 | - | 62 | + |
63 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 63 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
64 | - protected HostProviderRegistry providerRegistry; | 64 | + protected HostProviderRegistry providerRegistry; |
65 | - | 65 | + |
66 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 66 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
67 | - protected HostService hostService; | 67 | + protected HostService hostService; |
68 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 68 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
69 | - protected CoreService coreService; | 69 | + protected CoreService coreService; |
70 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 70 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
71 | - protected OvsdbController controller; | 71 | + protected OvsdbController controller; |
72 | - | 72 | + |
73 | - private HostProviderService providerService; | 73 | + private HostProviderService providerService; |
74 | - private OvsdbEventListener innerEventListener = new InnerOvsdbEventListener(); | 74 | + private OvsdbEventListener innerEventListener = new InnerOvsdbEventListener(); |
75 | - | 75 | + |
76 | - @Activate | 76 | + @Activate |
77 | - public void activate() { | 77 | + public void activate() { |
78 | - providerService = providerRegistry.register(this); | 78 | + providerService = providerRegistry.register(this); |
79 | - controller.addOvsdbEventListener(innerEventListener); | 79 | + controller.addOvsdbEventListener(innerEventListener); |
80 | - log.info("Started"); | 80 | + log.info("Started"); |
81 | - } | 81 | + } |
82 | - | 82 | + |
83 | - @Deactivate | 83 | + @Deactivate |
84 | - public void deactivate() { | 84 | + public void deactivate() { |
85 | - providerRegistry.unregister(this); | 85 | + providerRegistry.unregister(this); |
86 | - providerService = null; | 86 | + providerService = null; |
87 | - log.info("Stopped"); | 87 | + log.info("Stopped"); |
88 | - } | 88 | + } |
89 | - | 89 | + |
90 | - public OvsdbHostProvider() { | 90 | + public OvsdbHostProvider() { |
91 | - super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.host")); | 91 | + super(new ProviderId("ovsdb", "org.onosproject.ovsdb.provider.host")); |
92 | - } | 92 | + } |
93 | - | 93 | + |
94 | - @Override | 94 | + @Override |
95 | - public void triggerProbe(Host host) { | 95 | + public void triggerProbe(Host host) { |
96 | - log.info("Triggering probe on host {}", host); | 96 | + log.info("Triggering probe on host {}", host); |
97 | - } | 97 | + } |
98 | - | 98 | + |
99 | - private class InnerOvsdbEventListener implements OvsdbEventListener { | 99 | + private class InnerOvsdbEventListener implements OvsdbEventListener { |
100 | - | 100 | + |
101 | - @Override | 101 | + @Override |
102 | - public void handle(OvsdbEvent<EventSubject> event) { | 102 | + public void handle(OvsdbEvent<EventSubject> event) { |
103 | - OvsdbEventSubject subject = null; | 103 | + OvsdbEventSubject subject = null; |
104 | - if (event.subject() instanceof OvsdbEventSubject) { | 104 | + if (event.subject() instanceof OvsdbEventSubject) { |
105 | - subject = (OvsdbEventSubject) event.subject(); | 105 | + subject = (OvsdbEventSubject) event.subject(); |
106 | - } | 106 | + } |
107 | - checkNotNull(subject, "EventSubject is not null"); | 107 | + checkNotNull(subject, "EventSubject is not null"); |
108 | - // If ifaceid is null,it indicates this is not a vm port. | 108 | + // If ifaceid is null,it indicates this is not a vm port. |
109 | - if (subject.ifaceid() == null) { | 109 | + if (subject.ifaceid() == null) { |
110 | - return; | 110 | + return; |
111 | - } | 111 | + } |
112 | - switch (event.type()) { | 112 | + switch (event.type()) { |
113 | - case PORT_ADDED: | 113 | + case PORT_ADDED: |
114 | - HostId hostId = HostId.hostId(subject.hwAddress(), null); | 114 | + HostId hostId = HostId.hostId(subject.hwAddress(), null); |
115 | - DeviceId deviceId = DeviceId.deviceId(uri(subject.dpid().value())); | 115 | + DeviceId deviceId = DeviceId.deviceId(uri(subject.dpid().value())); |
116 | - PortNumber portNumber = PortNumber.portNumber(subject | 116 | + PortNumber portNumber = PortNumber.portNumber(subject |
117 | - .portNumber().value(), subject.portName().value()); | 117 | + .portNumber().value(), subject.portName().value()); |
118 | - HostLocation loaction = new HostLocation(deviceId, portNumber, | 118 | + HostLocation loaction = new HostLocation(deviceId, portNumber, |
119 | - 0L); | 119 | + 0L); |
120 | - SparseAnnotations annotations = DefaultAnnotations.builder() | 120 | + SparseAnnotations annotations = DefaultAnnotations.builder() |
121 | - .set("ifaceid", subject.ifaceid().value()).build(); | 121 | + .set("ifaceid", subject.ifaceid().value()).build(); |
122 | - HostDescription hostDescription = new DefaultHostDescription( | 122 | + HostDescription hostDescription = new DefaultHostDescription( |
123 | - subject.hwAddress(), | 123 | + subject.hwAddress(), |
124 | - VlanId.vlanId(), | 124 | + VlanId.vlanId(), |
125 | - loaction, | 125 | + loaction, |
126 | - annotations); | 126 | + annotations); |
127 | - providerService.hostDetected(hostId, hostDescription); | 127 | + providerService.hostDetected(hostId, hostDescription); |
128 | - break; | 128 | + break; |
129 | - case PORT_REMOVED: | 129 | + case PORT_REMOVED: |
130 | - HostId host = HostId.hostId(subject.hwAddress(), null); | 130 | + HostId host = HostId.hostId(subject.hwAddress(), null); |
131 | - providerService.hostVanished(host); | 131 | + providerService.hostVanished(host); |
132 | - break; | 132 | + break; |
133 | - default: | 133 | + default: |
134 | - break; | 134 | + break; |
135 | - } | 135 | + } |
136 | - | 136 | + |
137 | - } | 137 | + } |
138 | - | 138 | + |
139 | - } | 139 | + } |
140 | - | 140 | + |
141 | - public URI uri(String value) { | 141 | + public URI uri(String value) { |
142 | - try { | 142 | + try { |
143 | - return new URI("of", toHex(Long.valueOf(value)), null); | 143 | + return new URI("of", toHex(Long.valueOf(value)), null); |
144 | - } catch (URISyntaxException e) { | 144 | + } catch (URISyntaxException e) { |
145 | - return null; | 145 | + return null; |
146 | - } | 146 | + } |
147 | - } | 147 | + } |
148 | -} | 148 | +} | ... | ... |
-
Please register or login to post a comment