Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.vtnweb.resources; |
| 17 | |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 21 | import com.google.common.collect.Maps; |
| 22 | import org.onlab.util.ItemNotFoundException; |
| 23 | import org.onosproject.rest.AbstractWebResource; |
| 24 | import org.onosproject.vtnrsc.DefaultTenantNetwork; |
| 25 | import org.onosproject.vtnrsc.PhysicalNetwork; |
| 26 | import org.onosproject.vtnrsc.SegmentationId; |
| 27 | import org.onosproject.vtnrsc.TenantId; |
| 28 | import org.onosproject.vtnrsc.TenantNetwork; |
| 29 | import org.onosproject.vtnrsc.TenantNetwork.State; |
| 30 | import org.onosproject.vtnrsc.TenantNetwork.Type; |
| 31 | import org.onosproject.vtnrsc.TenantNetworkId; |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 32 | import org.onosproject.vtnrsc.service.VtnRscService; |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 33 | import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; |
| 34 | import org.onosproject.vtnweb.web.TenantNetworkCodec; |
| 35 | import org.slf4j.Logger; |
| 36 | import org.slf4j.LoggerFactory; |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 37 | |
| 38 | import javax.ws.rs.Consumes; |
| 39 | import javax.ws.rs.DELETE; |
| 40 | import javax.ws.rs.GET; |
| 41 | import javax.ws.rs.POST; |
| 42 | import javax.ws.rs.PUT; |
| 43 | import javax.ws.rs.Path; |
| 44 | import javax.ws.rs.PathParam; |
| 45 | import javax.ws.rs.Produces; |
| 46 | import javax.ws.rs.QueryParam; |
| 47 | import javax.ws.rs.core.MediaType; |
| 48 | import javax.ws.rs.core.Response; |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 49 | import java.io.InputStream; |
| 50 | import java.util.Collections; |
| 51 | import java.util.HashSet; |
| 52 | import java.util.Iterator; |
| 53 | import java.util.Set; |
| 54 | import java.util.concurrent.ConcurrentMap; |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 55 | |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 56 | import static com.google.common.base.Preconditions.checkArgument; |
| 57 | import static com.google.common.base.Preconditions.checkNotNull; |
| 58 | import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
| 59 | import static javax.ws.rs.core.Response.Status.NOT_FOUND; |
| 60 | import static javax.ws.rs.core.Response.Status.OK; |
Ray Milkey | 86ee5e8 | 2018-04-02 15:33:07 -0700 | [diff] [blame] | 61 | import static org.onlab.util.Tools.readTreeFromStream; |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * REST resource for interacting with the inventory of networks. |
| 65 | */ |
| 66 | @Path("networks") |
| 67 | public class TenantNetworkWebResource extends AbstractWebResource { |
| 68 | public static final String NETWORK_NOT_FOUND = "Network is not found"; |
| 69 | public static final String NETWORK_ID_EXIST = "Network id is existed"; |
| 70 | public static final String NETWORK_ID_NOT_EXIST = "Network id is not existed"; |
| 71 | public static final String CREATE_NETWORK = "create network"; |
| 72 | public static final String UPDATE_NETWORK = "update network"; |
| 73 | public static final String DELETE_NETWORK = "delete network"; |
| 74 | public static final String JSON_NOT_NULL = "JsonNode can not be null"; |
| 75 | |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 76 | private static final Logger log = LoggerFactory |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 77 | .getLogger(TenantNetworkWebResource.class); |
| 78 | private final ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps |
| 79 | .newConcurrentMap(); |
| 80 | |
| 81 | @GET |
Wu wenbin | d0b119f | 2016-05-11 18:03:41 +0800 | [diff] [blame] | 82 | @Produces(MediaType.APPLICATION_JSON) |
| 83 | @Consumes(MediaType.APPLICATION_JSON) |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 84 | public Response getNetworks(@QueryParam("id") String queryId, |
| 85 | @QueryParam("name") String queryName, |
| 86 | @QueryParam("admin_state_up") String queryadminStateUp, |
| 87 | @QueryParam("status") String querystate, |
| 88 | @QueryParam("shared") String queryshared, |
| 89 | @QueryParam("tenant_id") String querytenantId, |
| 90 | @QueryParam("router:external") String routerExternal, |
| 91 | @QueryParam("provider:network_type") String type, |
| 92 | @QueryParam("provider:physical_network") String physicalNetwork, |
| 93 | @QueryParam("provider:segmentation_id") String segmentationId) { |
| 94 | Iterable<TenantNetwork> networks = get(TenantNetworkService.class) |
| 95 | .getNetworks(); |
| 96 | Iterator<TenantNetwork> networkors = networks.iterator(); |
| 97 | while (networkors.hasNext()) { |
| 98 | TenantNetwork network = networkors.next(); |
| 99 | if ((queryId == null || queryId.equals(network.id().toString())) |
| 100 | && (queryName == null || queryName.equals(network.name())) |
| 101 | && (queryadminStateUp == null || queryadminStateUp |
Satish K | 3203557 | 2015-11-22 14:49:14 +0530 | [diff] [blame] | 102 | .equals(Boolean.toString(network.adminStateUp()))) |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 103 | && (querystate == null || querystate.equals(network.state() |
| 104 | .toString())) |
Satish K | 3203557 | 2015-11-22 14:49:14 +0530 | [diff] [blame] | 105 | && (queryshared == null || queryshared.equals(Boolean.toString(network |
| 106 | .shared()))) |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 107 | && (querytenantId == null || querytenantId.equals(network |
| 108 | .tenantId().toString())) |
Satish K | 3203557 | 2015-11-22 14:49:14 +0530 | [diff] [blame] | 109 | && (routerExternal == null || routerExternal.equals(Boolean.toString(network |
| 110 | .routerExternal()))) |
| 111 | && (type == null || type.equals(network.type().toString())) |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 112 | && (physicalNetwork == null || physicalNetwork |
Satish K | 3203557 | 2015-11-22 14:49:14 +0530 | [diff] [blame] | 113 | .equals(network.physicalNetwork().toString())) |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 114 | && (segmentationId == null || segmentationId.equals(network |
Satish K | 3203557 | 2015-11-22 14:49:14 +0530 | [diff] [blame] | 115 | .segmentationId().toString()))) { |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 116 | networksMap.putIfAbsent(network.id(), network); |
| 117 | } |
| 118 | } |
| 119 | networks = Collections.unmodifiableCollection(networksMap.values()); |
| 120 | ObjectNode result = new ObjectMapper().createObjectNode(); |
| 121 | result.set("networks", new TenantNetworkCodec().encode(networks, this)); |
| 122 | |
| 123 | return ok(result.toString()).build(); |
| 124 | } |
| 125 | |
| 126 | private State isState(String state) { |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 127 | if ("ACTIVE".equals(state)) { |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 128 | return TenantNetwork.State.ACTIVE; |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 129 | } else if ("BUILD".equals(state)) { |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 130 | return TenantNetwork.State.BUILD; |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 131 | } else if ("DOWN".equals(state)) { |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 132 | return TenantNetwork.State.DOWN; |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 133 | } else if ("ERROR".equals(state)) { |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 134 | return TenantNetwork.State.ERROR; |
| 135 | } else { |
| 136 | return null; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | private Type isType(String type) { |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 141 | if ("LOCAL".equals(type)) { |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 142 | return TenantNetwork.Type.LOCAL; |
| 143 | } else { |
| 144 | return null; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | @GET |
| 149 | @Path("{id}") |
Wu wenbin | d0b119f | 2016-05-11 18:03:41 +0800 | [diff] [blame] | 150 | @Produces(MediaType.APPLICATION_JSON) |
| 151 | @Consumes(MediaType.APPLICATION_JSON) |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 152 | public Response getNetwork(@PathParam("id") String id) { |
| 153 | |
| 154 | if (!get(TenantNetworkService.class).exists(TenantNetworkId |
| 155 | .networkId(id))) { |
lishuai | 0f47f34 | 2015-09-16 11:38:48 +0800 | [diff] [blame] | 156 | return Response.status(NOT_FOUND) |
| 157 | .entity(NETWORK_NOT_FOUND).build(); |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 158 | } |
| 159 | TenantNetwork network = nullIsNotFound(get(TenantNetworkService.class) |
| 160 | .getNetwork(TenantNetworkId.networkId(id)), NETWORK_NOT_FOUND); |
| 161 | ObjectNode result = new ObjectMapper().createObjectNode(); |
| 162 | result.set("network", new TenantNetworkCodec().encode(network, this)); |
| 163 | |
| 164 | return ok(result.toString()).build(); |
| 165 | |
| 166 | } |
| 167 | |
| 168 | @POST |
| 169 | @Produces(MediaType.APPLICATION_JSON) |
| 170 | @Consumes(MediaType.APPLICATION_JSON) |
| 171 | public Response createNetworks(InputStream input) { |
| 172 | try { |
| 173 | ObjectMapper mapper = new ObjectMapper(); |
Ray Milkey | 86ee5e8 | 2018-04-02 15:33:07 -0700 | [diff] [blame] | 174 | JsonNode cfg = readTreeFromStream(mapper, input); |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 175 | JsonNode nodes = null; |
| 176 | Iterable<TenantNetwork> networks = null; |
| 177 | if (cfg.get("network") != null) { |
| 178 | nodes = cfg.get("network"); |
| 179 | if (nodes.isArray()) { |
| 180 | networks = changeJson2objs(nodes); |
| 181 | } else { |
| 182 | networks = changeJson2obj(CREATE_NETWORK, null, nodes); |
| 183 | } |
| 184 | } else if (cfg.get("networks") != null) { |
| 185 | nodes = cfg.get("networks"); |
| 186 | networks = changeJson2objs(nodes); |
| 187 | } |
| 188 | Boolean issuccess = nullIsNotFound((get(TenantNetworkService.class) |
| 189 | .createNetworks(networks)), |
| 190 | NETWORK_NOT_FOUND); |
| 191 | |
| 192 | if (!issuccess) { |
| 193 | return Response.status(INTERNAL_SERVER_ERROR) |
| 194 | .entity(NETWORK_ID_EXIST).build(); |
| 195 | } |
| 196 | return Response.status(OK).entity(issuccess.toString()).build(); |
| 197 | } catch (Exception e) { |
| 198 | log.error("Creates tenantNetwork exception {}.", e.toString()); |
| 199 | return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
| 200 | .build(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | @PUT |
| 205 | @Path("{id}") |
| 206 | @Produces(MediaType.APPLICATION_JSON) |
| 207 | @Consumes(MediaType.APPLICATION_JSON) |
| 208 | public Response updateNetworks(@PathParam("id") String id, InputStream input) { |
| 209 | try { |
| 210 | ObjectMapper mapper = new ObjectMapper(); |
Ray Milkey | 86ee5e8 | 2018-04-02 15:33:07 -0700 | [diff] [blame] | 211 | JsonNode cfg = readTreeFromStream(mapper, input); |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 212 | JsonNode nodes = null; |
| 213 | Iterable<TenantNetwork> networks = null; |
| 214 | if (cfg.get("network") != null) { |
| 215 | nodes = cfg.get("network"); |
| 216 | if (nodes.isArray()) { |
| 217 | networks = changeJson2objs(nodes); |
| 218 | } else { |
| 219 | networks = changeJson2obj(UPDATE_NETWORK, |
| 220 | TenantNetworkId.networkId(id), |
| 221 | nodes); |
| 222 | } |
| 223 | } else if (cfg.get("networks") != null) { |
| 224 | nodes = cfg.get("networks"); |
| 225 | networks = changeJson2objs(nodes); |
| 226 | } |
| 227 | Boolean issuccess = nullIsNotFound((get(TenantNetworkService.class) |
| 228 | .updateNetworks(networks)), |
| 229 | NETWORK_NOT_FOUND); |
| 230 | if (!issuccess) { |
| 231 | return Response.status(INTERNAL_SERVER_ERROR) |
| 232 | .entity(NETWORK_ID_NOT_EXIST).build(); |
| 233 | } |
| 234 | return Response.status(OK).entity(issuccess.toString()).build(); |
| 235 | } catch (Exception e) { |
| 236 | log.error("Updates tenantNetwork failed because of exception {}.", |
| 237 | e.toString()); |
| 238 | return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()) |
| 239 | .build(); |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | @DELETE |
| 244 | @Path("{id}") |
Wu wenbin | b0bd613 | 2016-05-10 19:20:23 +0800 | [diff] [blame] | 245 | @Consumes(MediaType.APPLICATION_JSON) |
| 246 | @Produces(MediaType.APPLICATION_JSON) |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 247 | public Response deleteNetworks(@PathParam("id") String id) { |
| 248 | log.debug("Deletes network by identifier {}.", id); |
| 249 | Set<TenantNetworkId> networkSet = new HashSet<>(); |
| 250 | networkSet.add(TenantNetworkId.networkId(id)); |
| 251 | Boolean issuccess = nullIsNotFound(get(TenantNetworkService.class) |
| 252 | .removeNetworks(networkSet), NETWORK_NOT_FOUND); |
| 253 | if (!issuccess) { |
| 254 | log.debug("Network identifier {} is not existed", id); |
| 255 | return Response.status(INTERNAL_SERVER_ERROR) |
| 256 | .entity(NETWORK_ID_NOT_EXIST).build(); |
| 257 | } |
Jian Li | c2a542b | 2016-05-10 11:48:19 -0700 | [diff] [blame] | 258 | return ok(issuccess.toString()).build(); |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Returns a collection of tenantNetworks. |
| 263 | * |
| 264 | * @param flag the flag |
| 265 | * @param networkId network identifier |
| 266 | * @param node the network json node |
| 267 | * @return a collection of tenantNetworks |
| 268 | */ |
| 269 | public Iterable<TenantNetwork> changeJson2obj(String flag, |
| 270 | TenantNetworkId networkId, |
| 271 | JsonNode node) { |
| 272 | checkNotNull(node, JSON_NOT_NULL); |
| 273 | TenantNetwork network = null; |
| 274 | ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps |
| 275 | .newConcurrentMap(); |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 276 | checkArgument(node.get("admin_state_up").isBoolean(), "admin_state_up should be boolean"); |
| 277 | checkArgument(node.get("shared").isBoolean(), "shared should be boolean"); |
| 278 | checkArgument(node.get("router:external").isBoolean(), "router:external should be boolean"); |
| 279 | String name = node.get("name").asText(); |
| 280 | boolean adminStateUp = node.get("admin_state_up").asBoolean(); |
| 281 | String state = node.get("status").asText(); |
| 282 | boolean shared = node.get("shared").asBoolean(); |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 283 | String tenantIdStr = node.get("tenant_id").asText(); |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 284 | boolean routerExternal = node.get("router:external").asBoolean(); |
| 285 | String type = node.get("provider:network_type").asText(); |
| 286 | String physicalNetwork = node.get("provider:physical_network").asText(); |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 287 | String segmentationIdStr = node.get("provider:segmentation_id").asText(); |
| 288 | SegmentationId segmentationId = SegmentationId.segmentationId(segmentationIdStr); |
| 289 | TenantId tenantId = TenantId.tenantId(tenantIdStr); |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 290 | if (segmentationIdStr == null || "null".equals(segmentationIdStr)) { |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 291 | segmentationId = get(VtnRscService.class).getL3vni(tenantId); |
| 292 | } |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 293 | TenantNetworkId id = null; |
| 294 | if (flag.equals(CREATE_NETWORK)) { |
| 295 | id = TenantNetworkId.networkId(node.get("id").asText()); |
| 296 | } else if (flag.equals(UPDATE_NETWORK)) { |
| 297 | id = networkId; |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 298 | } |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 299 | network = new DefaultTenantNetwork( |
| 300 | id, |
| 301 | name, |
| 302 | adminStateUp, |
| 303 | isState(state), |
| 304 | shared, |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 305 | tenantId, |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 306 | routerExternal, |
| 307 | isType(type), |
| 308 | PhysicalNetwork |
| 309 | .physicalNetwork(physicalNetwork), |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 310 | segmentationId); |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 311 | networksMap.putIfAbsent(id, network); |
| 312 | |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 313 | return Collections.unmodifiableCollection(networksMap.values()); |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Returns a collection of tenantNetworks. |
| 318 | * |
| 319 | * @param nodes the network jsonnodes |
| 320 | * @return a collection of tenantNetworks |
| 321 | */ |
| 322 | public Iterable<TenantNetwork> changeJson2objs(JsonNode nodes) { |
| 323 | checkNotNull(nodes, JSON_NOT_NULL); |
| 324 | TenantNetwork network = null; |
| 325 | ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps |
| 326 | .newConcurrentMap(); |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 327 | for (JsonNode node : nodes) { |
| 328 | String id = node.get("id").asText(); |
| 329 | String name = node.get("name").asText(); |
| 330 | boolean adminStateUp = node.get("admin_state_up").asBoolean(); |
| 331 | String state = node.get("status").asText(); |
| 332 | boolean shared = node.get("shared").asBoolean(); |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 333 | String tenantIdStr = node.get("tenant_id").asText(); |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 334 | boolean routerExternal = node.get("router:external") |
| 335 | .asBoolean(); |
| 336 | String type = node.get("provider:network_type").asText(); |
| 337 | String physicalNetwork = node.get("provider:physical_network").asText(); |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 338 | String segmentationIdStr = node.get("provider:segmentation_id").asText(); |
| 339 | SegmentationId segmentationId = SegmentationId.segmentationId(segmentationIdStr); |
| 340 | TenantId tenantId = TenantId.tenantId(tenantIdStr); |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 341 | if (segmentationIdStr == null || "null".equals(segmentationIdStr)) { |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 342 | segmentationId = get(VtnRscService.class).getL3vni(tenantId); |
| 343 | } |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 344 | network = new DefaultTenantNetwork( |
| 345 | TenantNetworkId.networkId(id), |
| 346 | name, |
| 347 | adminStateUp, |
| 348 | isState(state), |
| 349 | shared, |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 350 | tenantId, |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 351 | routerExternal, |
| 352 | isType(type), |
| 353 | PhysicalNetwork.physicalNetwork(physicalNetwork), |
lishuai | 38eeac4 | 2016-05-19 15:34:30 +0800 | [diff] [blame] | 354 | segmentationId); |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 355 | networksMap.putIfAbsent(TenantNetworkId.networkId(id), network); |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 356 | } |
Satish K | ab54ffa | 2015-11-27 14:19:42 +0530 | [diff] [blame] | 357 | |
Madan Jampani | 38a8821 | 2015-09-15 11:21:27 -0700 | [diff] [blame] | 358 | return Collections.unmodifiableCollection(networksMap.values()); |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Returns the specified item if that items is null; otherwise throws not |
| 363 | * found exception. |
| 364 | * |
| 365 | * @param item item to check |
| 366 | * @param <T> item type |
| 367 | * @param message not found message |
| 368 | * @return item if not null |
| 369 | * @throws org.onlab.util.ItemNotFoundException if item is null |
| 370 | */ |
| 371 | protected <T> T nullIsNotFound(T item, String message) { |
| 372 | if (item == null) { |
| 373 | throw new ItemNotFoundException(message); |
| 374 | } |
| 375 | return item; |
| 376 | } |
| 377 | } |