2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onosproject.openstackswitching.web;
18 import com.fasterxml.jackson.databind.JsonNode;
19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 import org.onosproject.codec.CodecContext;
21 import org.onosproject.codec.JsonCodec;
22 import org.onosproject.openstackswitching.OpenstackNetwork;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Implementation of the OpenstackNetwork Codec.
30 public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> {
32 protected static final Logger log = LoggerFactory
33 .getLogger(OpenstackNetworkCodec.class);
35 private static final String NETWORK = "network";
36 private static final String NAME = "name";
37 private static final String TENANT_ID = "tenant_id";
38 private static final String SEGMENTATION_ID = "provider:segmentation_id";
39 private static final String NETWORK_TYPE = "provider:network_type";
40 private static final String ID = "id";
43 public OpenstackNetwork decode(ObjectNode json, CodecContext context) {
45 JsonNode networkInfo = json.get(NETWORK);
47 String name = networkInfo.path(NAME).asText();
48 String tenantId = networkInfo.path(TENANT_ID).asText();
49 String id = networkInfo.path(ID).asText();
51 OpenstackNetwork.Builder onb = OpenstackNetwork.builder();
56 if (!networkInfo.path(NETWORK_TYPE).isMissingNode()) {
57 onb.name(networkInfo.path(NETWORK_TYPE).asText());
58 onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText());