CNlucius | 5b2fff1 | 2015-08-20 14:13:46 +0800 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright 2015 Open Networking Laboratory
|
| 3 | *
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 | * you may not use this file except in compliance with the License.
|
| 6 | * You may obtain a copy of the License at
|
| 7 | *
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 9 | *
|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 | * See the License for the specific language governing permissions and
|
| 14 | * limitations under the License.
|
| 15 | */
|
| 16 | package org.onosproject.vtnrsc.web;
|
| 17 |
|
| 18 | import static com.google.common.base.Preconditions.checkNotNull;
|
| 19 |
|
| 20 | import org.onosproject.codec.CodecContext;
|
| 21 | import org.onosproject.codec.JsonCodec;
|
| 22 | import org.onosproject.vtnrsc.TenantNetwork;
|
| 23 |
|
| 24 | import com.fasterxml.jackson.databind.node.ObjectNode;
|
| 25 |
|
| 26 | /**
|
| 27 | * TenantNetwork JSON codec.
|
| 28 | */
|
| 29 | public final class TenantNetworkCodec extends JsonCodec<TenantNetwork> {
|
| 30 |
|
| 31 | @Override
|
| 32 | public ObjectNode encode(TenantNetwork network, CodecContext context) {
|
| 33 | checkNotNull(network, "Network cannot be null");
|
| 34 | ObjectNode result = context.mapper().createObjectNode()
|
| 35 | .put("id", network.id().toString())
|
Sho SHIMIZU | c0b211a | 2015-09-11 11:22:07 -0700 | [diff] [blame^] | 36 | .put("name", network.name())
|
CNlucius | 5b2fff1 | 2015-08-20 14:13:46 +0800 | [diff] [blame] | 37 | .put("admin_state_up", network.adminStateUp())
|
| 38 | .put("status", "" + network.state())
|
| 39 | .put("shared", network.shared())
|
| 40 | .put("tenant_id", network.tenantId().toString())
|
| 41 | .put("router:external", network.routerExternal())
|
| 42 | .put("provider:network_type", "" + network.type())
|
| 43 | .put("provider:physical_network", network.physicalNetwork().toString())
|
| 44 | .put("provider:segmentation_id", network.segmentationId().toString());
|
| 45 | return result;
|
| 46 | }
|
| 47 | }
|