Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.opencord.sadis.impl; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import org.onosproject.codec.CodecContext; |
| 20 | import org.onosproject.codec.JsonCodec; |
| 21 | import org.opencord.sadis.BandwidthProfileInformation; |
| 22 | |
| 23 | public class BandwidthProfileCodec extends JsonCodec<BandwidthProfileInformation> { |
| 24 | @Override |
| 25 | public ObjectNode encode(BandwidthProfileInformation entry, CodecContext context) { |
Gamze Abaka | d46003f | 2021-03-03 10:37:07 +0000 | [diff] [blame^] | 26 | |
| 27 | ObjectNode node = context.mapper().createObjectNode() |
Gamze Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 28 | .put("id", entry.id()) |
| 29 | .put("cir", (entry.committedInformationRate())) |
| 30 | .put("cbs", (entry.committedBurstSize() == null) ? "" : entry.committedBurstSize().toString()) |
Gamze Abaka | d46003f | 2021-03-03 10:37:07 +0000 | [diff] [blame^] | 31 | .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 Abaka | 1e5ccf5 | 2018-07-02 11:59:03 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | } |