blob: 07c44646cd59cbf2943f53433ad8412f04920fb9 [file] [log] [blame]
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -08003 *
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;
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -080019import org.onosproject.net.device.PortStatistics;
20
21import com.fasterxml.jackson.databind.node.ObjectNode;
22
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Port statistics entry JSON codec.
27 */
Laszlo Papp7390b5c2018-01-12 19:27:47 +000028public final class PortStatisticsCodec extends AnnotatedCodec<PortStatistics> {
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -080029
30 @Override
31 public ObjectNode encode(PortStatistics entry, CodecContext context) {
32 checkNotNull(entry, "Port Statistics cannot be null");
33
34 final ObjectNode result = context.mapper().createObjectNode()
Ray Milkey5ec42082019-02-13 09:56:07 -080035 .put("port", entry.portNumber().toLong())
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -080036 .put("packetsReceived", entry.packetsReceived())
37 .put("packetsSent", entry.packetsSent())
38 .put("bytesReceived", entry.bytesReceived())
39 .put("bytesSent", entry.bytesSent())
40 .put("packetsRxDropped", entry.packetsRxDropped())
41 .put("packetsTxDropped", entry.packetsTxDropped())
42 .put("packetsRxErrors", entry.packetsRxErrors())
43 .put("packetsTxErrors", entry.packetsTxErrors())
44 .put("durationSec", entry.durationSec());
45
Laszlo Papp7390b5c2018-01-12 19:27:47 +000046 return annotate(result, entry, context);
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -080047 }
48
49}
50