blob: 6f680c81d6851ee323444c722a5451c7156f721b [file] [log] [blame]
Ray Milkeyc95bb9d2015-01-06 10:28:24 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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.codec.impl;
17
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080018import org.onosproject.codec.CodecContext;
19import org.onosproject.codec.JsonCodec;
20import org.onosproject.net.flow.instructions.Instruction;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080021import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24import com.fasterxml.jackson.databind.node.ObjectNode;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Instruction codec.
30 */
Ray Milkey540b2ce2015-02-04 17:50:20 -080031public final class InstructionCodec extends JsonCodec<Instruction> {
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080032
33 protected static final Logger log = LoggerFactory.getLogger(InstructionCodec.class);
34
Ray Milkeyd43fe452015-05-29 09:35:12 -070035 protected static final String TYPE = "type";
36 protected static final String SUBTYPE = "subtype";
37 protected static final String PORT = "port";
38 protected static final String MAC = "mac";
39 protected static final String VLAN_ID = "vlanId";
40 protected static final String VLAN_PCP = "vlanPcp";
41 protected static final String MPLS_LABEL = "label";
42 protected static final String IP = "ip";
43 protected static final String FLOW_LABEL = "flowLabel";
44 protected static final String LAMBDA = "lambda";
45 protected static final String GRID_TYPE = "gridType";
46 protected static final String CHANNEL_SPACING = "channelSpacing";
47 protected static final String SPACING_MULTIPLIER = "spacingMultiplier";
48 protected static final String SLOT_GRANULARITY = "slotGranularity";
49 protected static final String ETHERNET_TYPE = "ethernetType";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080050
Ray Milkeyd43fe452015-05-29 09:35:12 -070051 protected static final String MISSING_MEMBER_MESSAGE =
52 " member is required in Instruction";
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080053
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080054
55 @Override
56 public ObjectNode encode(Instruction instruction, CodecContext context) {
57 checkNotNull(instruction, "Instruction cannot be null");
58
Ray Milkey6d7968e2015-07-06 14:30:02 -070059 return new EncodeInstructionCodecHelper(instruction, context).encode();
Ray Milkeyd43fe452015-05-29 09:35:12 -070060 }
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080061
Ray Milkeyd43fe452015-05-29 09:35:12 -070062 @Override
63 public Instruction decode(ObjectNode json, CodecContext context) {
64 if (json == null || !json.isObject()) {
65 return null;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080066 }
Ray Milkeyd43fe452015-05-29 09:35:12 -070067
Ray Milkey6d7968e2015-07-06 14:30:02 -070068 return new DecodeInstructionCodecHelper(json).decode();
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080069 }
70}