blob: f04890fb05b715d6fd51e905ecb0e8ebb65c72b7 [file] [log] [blame]
Jian Li45083522017-03-20 18:46:07 +09001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jian Li45083522017-03-20 18:46:07 +09003 *
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 */
Jian Li2e818b02017-04-12 19:28:30 +090016package org.onosproject.mapping.codec;
Jian Li45083522017-03-20 18:46:07 +090017
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
21import org.onosproject.mapping.addresses.MappingAddress;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
25/**
26 * Mapping address codec.
27 */
28public final class MappingAddressCodec extends JsonCodec<MappingAddress> {
29
Ray Milkey9c9cde42018-01-12 14:22:06 -080030 private static final Logger log =
Jian Li45083522017-03-20 18:46:07 +090031 LoggerFactory.getLogger(MappingAddressCodec.class);
32
Ray Milkey9c9cde42018-01-12 14:22:06 -080033 static final String TYPE = "type";
34 static final String IPV4 = "ipv4";
35 static final String IPV6 = "ipv6";
36 static final String MAC = "mac";
37 static final String DN = "dn";
38 static final String AS = "as";
Jian Li45083522017-03-20 18:46:07 +090039
40 @Override
41 public ObjectNode encode(MappingAddress address, CodecContext context) {
42 EncodeMappingAddressCodecHelper encoder =
43 new EncodeMappingAddressCodecHelper(address, context);
44 return encoder.encode();
45 }
46
47 @Override
48 public MappingAddress decode(ObjectNode json, CodecContext context) {
Jian Lif92a2ea2017-04-05 16:06:06 +090049 if (json == null || !json.isObject()) {
50 return null;
51 }
52
Jian Li45083522017-03-20 18:46:07 +090053 DecodeMappingAddressCodecHelper decoder =
54 new DecodeMappingAddressCodecHelper(json);
55 return decoder.decode();
56 }
57}