blob: cb051e4f84873267b29ec9c5d7724f714db00162 [file] [log] [blame]
Andreas Pantelopoulosfdcfe532018-04-02 10:59:23 -07001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16package org.onosproject.driver.extensions.codec;
17
18import org.onosproject.driver.extensions.OfdpaMatchActsetOutput;
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import org.onosproject.codec.CodecContext;
21import org.onosproject.codec.JsonCodec;
22import org.onosproject.net.PortNumber;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25import static org.onlab.util.Tools.nullIsIllegal;
26
27/**
28 * JSON Codec for Ofdpa match actset output class.
29 */
30public class OfdpaMatchActsetOutputCodec extends JsonCodec<OfdpaMatchActsetOutput> {
31
32 private static final String ACTSET_OUTPUT = "actsetOutput";
33 private static final String MISSING_MEMBER_MESSAGE = " member is required in OfdpaMatchActsetOutput";
34 private static final String MISSING_ACTSET_OUTPUT_MESSAGE = "Actset Output cannot be null";
35
36 @Override
37 public ObjectNode encode(OfdpaMatchActsetOutput actsetOutput, CodecContext context) {
38 checkNotNull(actsetOutput, MISSING_ACTSET_OUTPUT_MESSAGE);
39 return context.mapper().createObjectNode()
40 .put(ACTSET_OUTPUT, actsetOutput.port().toLong());
41 }
42
43 @Override
44 public OfdpaMatchActsetOutput decode(ObjectNode json, CodecContext context) {
45 if (json == null || !json.isObject()) {
46 return null;
47 }
48
49 // parse ofdpa match actset output
50 long portNumber = nullIsIllegal(json.get(ACTSET_OUTPUT),
51 ACTSET_OUTPUT + MISSING_MEMBER_MESSAGE).asLong();
52 return new OfdpaMatchActsetOutput(PortNumber.portNumber(portNumber));
53 }
54}