blob: 1bacec2aa06e96b82605b16617ca1d02ea42f546 [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
18import org.onlab.packet.Ethernet;
19import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
21import 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 * Ethernet codec.
30 */
31public class EthernetCodec extends JsonCodec<Ethernet> {
32
33 protected static final Logger log = LoggerFactory.getLogger(CriterionCodec.class);
34
35 @Override
36 public ObjectNode encode(Ethernet ethernet, CodecContext context) {
37 checkNotNull(ethernet, "Ethernet cannot be null");
38
39 return context.mapper().createObjectNode()
40 .put("destinationMacAddress", ethernet.getDestinationMAC().toString())
41 .put("sourceMacAddress", ethernet.getSourceMAC().toString())
42 .put("priorityCode", ethernet.getPriorityCode())
43 .put("vlanId", ethernet.getVlanID())
44 .put("etherType", ethernet.getEtherType())
45 .put("pad", ethernet.isPad());
46 }
47
48}