Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 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.codec.impl; |
| 17 | |
| 18 | import org.onosproject.codec.CodecContext; |
| 19 | import org.onosproject.codec.JsonCodec; |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 20 | import org.onosproject.net.intent.Constraint; |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 21 | |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 22 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
| 25 | |
| 26 | /** |
| 27 | * Constraint JSON codec. |
| 28 | */ |
Ray Milkey | 540b2ce | 2015-02-04 17:50:20 -0800 | [diff] [blame] | 29 | public final class ConstraintCodec extends JsonCodec<Constraint> { |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 30 | |
Ray Milkey | b82c42b | 2015-06-30 09:42:20 -0700 | [diff] [blame] | 31 | protected static final String MISSING_MEMBER_MESSAGE = |
| 32 | " member is required in Constraint"; |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 33 | 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 Glantz | 05c6f43 | 2020-03-19 14:56:12 -0500 | [diff] [blame] | 39 | static final String METERED = "metered"; |
Ray Milkey | 9c9cde4 | 2018-01-12 14:22:06 -0800 | [diff] [blame] | 40 | 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 Glantz | 05c6f43 | 2020-03-19 14:56:12 -0500 | [diff] [blame] | 44 | static final String TIERS = "tiers"; |
| 45 | static final String COST_TYPE = "costType"; |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 46 | |
| 47 | @Override |
| 48 | public ObjectNode encode(Constraint constraint, CodecContext context) { |
| 49 | checkNotNull(constraint, "Constraint cannot be null"); |
| 50 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 51 | final EncodeConstraintCodecHelper encodeCodec = |
| 52 | new EncodeConstraintCodecHelper(constraint, context); |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 53 | |
Ray Milkey | b82c42b | 2015-06-30 09:42:20 -0700 | [diff] [blame] | 54 | return encodeCodec.encode(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public Constraint decode(ObjectNode json, CodecContext context) { |
| 59 | checkNotNull(json, "JSON cannot be null"); |
| 60 | |
Ray Milkey | 6d7968e | 2015-07-06 14:30:02 -0700 | [diff] [blame] | 61 | final DecodeConstraintCodecHelper decodeCodec = |
| 62 | new DecodeConstraintCodecHelper(json); |
Ray Milkey | b82c42b | 2015-06-30 09:42:20 -0700 | [diff] [blame] | 63 | |
| 64 | return decodeCodec.decode(); |
Ray Milkey | b9a8a18 | 2015-01-20 14:15:35 -0800 | [diff] [blame] | 65 | } |
| 66 | } |