blob: 260c873d278f0c5c1d49cf47e049cb77b8ee9043 [file] [log] [blame]
jiangrui330b0c92015-11-28 14:09:50 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui330b0c92015-11-28 14:09:50 +08003 *
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 */
16package org.onosproject.vtnweb.web;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22import org.onosproject.vtnrsc.RouterGateway;
23
24import com.fasterxml.jackson.databind.node.ObjectNode;
25
26/**
27 * Subnet Router Gateway Info codec.
28 */
29public class RouterGatewayInfoCodec extends JsonCodec<RouterGateway> {
30 @Override
31 public ObjectNode encode(RouterGateway routerGateway, CodecContext context) {
32 checkNotNull(routerGateway, "routerGateway cannot be null");
33 ObjectNode result = context.mapper().createObjectNode()
34 .put("network_id", routerGateway.networkId().toString());
35 result.set("external_fixed_ips", new FixedIpCodec()
36 .encode(routerGateway.externalFixedIps(), context));
37 return result;
38 }
39}