blob: 277246ddb4eb7f4ccafddcf8debbc82e11b34625 [file] [log] [blame]
Gamze Abaka1e5ccf52018-07-02 11:59:03 +00001/*
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.opencord.sadis.impl;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import org.onosproject.codec.CodecContext;
20import org.onosproject.codec.JsonCodec;
21import org.opencord.sadis.BandwidthProfileInformation;
22
23public class BandwidthProfileCodec extends JsonCodec<BandwidthProfileInformation> {
24 @Override
25 public ObjectNode encode(BandwidthProfileInformation entry, CodecContext context) {
Gamze Abakad46003f2021-03-03 10:37:07 +000026
27 ObjectNode node = context.mapper().createObjectNode()
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000028 .put("id", entry.id())
29 .put("cir", (entry.committedInformationRate()))
30 .put("cbs", (entry.committedBurstSize() == null) ? "" : entry.committedBurstSize().toString())
Gamze Abakad46003f2021-03-03 10:37:07 +000031 .put("air", entry.assuredInformationRate())
32 .put("gir", entry.guaranteedInformationRate());
33
34 if (entry.peakInformationRate() == 0 && entry.peakBurstSize() == null) {
35 node.put("eir", entry.exceededInformationRate());
36 node.put("ebs", (entry.exceededBurstSize() == null) ? "" : entry.exceededBurstSize().toString());
37 } else {
38 node.put("pir", entry.peakInformationRate());
39 node.put("pbs", (entry.peakBurstSize() == null) ? "" : entry.peakBurstSize().toString());
40 }
41
42 return node;
Gamze Abaka1e5ccf52018-07-02 11:59:03 +000043 }
44
45}