blob: d5d5a16ad78460974780c10763a8a1ff329e603d [file] [log] [blame]
Ray Milkeyb9a8a182015-01-20 14:15:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkeyb9a8a182015-01-20 14:15:35 -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.codec.impl;
17
18import org.onosproject.codec.CodecContext;
19import org.onosproject.codec.JsonCodec;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080020import org.onosproject.net.intent.Constraint;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080021
Ray Milkeyb9a8a182015-01-20 14:15:35 -080022import com.fasterxml.jackson.databind.node.ObjectNode;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Constraint JSON codec.
28 */
Ray Milkey540b2ce2015-02-04 17:50:20 -080029public final class ConstraintCodec extends JsonCodec<Constraint> {
Ray Milkeyb9a8a182015-01-20 14:15:35 -080030
Ray Milkeyb82c42b2015-06-30 09:42:20 -070031 protected static final String MISSING_MEMBER_MESSAGE =
32 " member is required in Constraint";
Ray Milkey9c9cde42018-01-12 14:22:06 -080033 static final String TYPE = "type";
34 static final String TYPES = "types";
35 static final String INCLUSIVE = "inclusive";
36 static final String KEY = "key";
37 static final String THRESHOLD = "threshold";
38 static final String BANDWIDTH = "bandwidth";
David Glantz05c6f432020-03-19 14:56:12 -050039 static final String METERED = "metered";
Ray Milkey9c9cde42018-01-12 14:22:06 -080040 static final String LAMBDA = "lambda";
41 static final String LATENCY_MILLIS = "latencyMillis";
42 static final String OBSTACLES = "obstacles";
43 static final String WAYPOINTS = "waypoints";
David Glantz05c6f432020-03-19 14:56:12 -050044 static final String TIERS = "tiers";
45 static final String COST_TYPE = "costType";
Ray Milkeyb9a8a182015-01-20 14:15:35 -080046
47 @Override
48 public ObjectNode encode(Constraint constraint, CodecContext context) {
49 checkNotNull(constraint, "Constraint cannot be null");
50
Ray Milkey6d7968e2015-07-06 14:30:02 -070051 final EncodeConstraintCodecHelper encodeCodec =
52 new EncodeConstraintCodecHelper(constraint, context);
Ray Milkeyb9a8a182015-01-20 14:15:35 -080053
Ray Milkeyb82c42b2015-06-30 09:42:20 -070054 return encodeCodec.encode();
55 }
56
57 @Override
58 public Constraint decode(ObjectNode json, CodecContext context) {
59 checkNotNull(json, "JSON cannot be null");
60
Ray Milkey6d7968e2015-07-06 14:30:02 -070061 final DecodeConstraintCodecHelper decodeCodec =
62 new DecodeConstraintCodecHelper(json);
Ray Milkeyb82c42b2015-06-30 09:42:20 -070063
64 return decodeCodec.decode();
Ray Milkeyb9a8a182015-01-20 14:15:35 -080065 }
66}