blob: e8b3c4c664fbf32ee8f741c2f4e404729eebca0b [file] [log] [blame]
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -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.onosproject.codec.CodecContext;
19import org.onosproject.codec.JsonCodec;
20import org.onosproject.net.device.PortStatistics;
21
22import com.fasterxml.jackson.databind.node.ObjectNode;
23
24import static com.google.common.base.Preconditions.checkNotNull;
25
26/**
27 * Port statistics entry JSON codec.
28 */
29public final class PortStatisticsCodec extends JsonCodec<PortStatistics> {
30
31 @Override
32 public ObjectNode encode(PortStatistics entry, CodecContext context) {
33 checkNotNull(entry, "Port Statistics cannot be null");
34
35 final ObjectNode result = context.mapper().createObjectNode()
36 .put("port", entry.port())
37 .put("packetsReceived", entry.packetsReceived())
38 .put("packetsSent", entry.packetsSent())
39 .put("bytesReceived", entry.bytesReceived())
40 .put("bytesSent", entry.bytesSent())
41 .put("packetsRxDropped", entry.packetsRxDropped())
42 .put("packetsTxDropped", entry.packetsTxDropped())
43 .put("packetsRxErrors", entry.packetsRxErrors())
44 .put("packetsTxErrors", entry.packetsTxErrors())
45 .put("durationSec", entry.durationSec());
46
47 return result;
48 }
49
50}
51