Daniele Moro | 5e66f98 | 2021-06-11 16:41:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021-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 | |
| 17 | package org.onosproject.net.behaviour.upf; |
| 18 | |
| 19 | |
| 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 21 | |
| 22 | /** |
| 23 | * A structure for compactly passing PDR counter values for a given counter ID. |
| 24 | * Contains four counts: Ingress Packets, Ingress Bytes, Egress Packets, Egress Bytes |
| 25 | */ |
| 26 | public final class PdrStats { |
| 27 | private final int cellId; |
| 28 | private final long ingressPkts; |
| 29 | private final long ingressBytes; |
| 30 | private final long egressPkts; |
| 31 | private final long egressBytes; |
| 32 | |
| 33 | private PdrStats(int cellId, long ingressPkts, long ingressBytes, |
| 34 | long egressPkts, long egressBytes) { |
| 35 | this.cellId = cellId; |
| 36 | this.ingressPkts = ingressPkts; |
| 37 | this.ingressBytes = ingressBytes; |
| 38 | this.egressPkts = egressPkts; |
| 39 | this.egressBytes = egressBytes; |
| 40 | } |
| 41 | |
| 42 | public static Builder builder() { |
| 43 | return new Builder(); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public String toString() { |
| 48 | return String.format("PDR-Stats:{ CellID: %d, Ingress:(%dpkts,%dbytes), Egress:(%dpkts,%dbytes) }", |
| 49 | cellId, ingressPkts, ingressBytes, egressPkts, egressBytes); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the cell ID (index) of the dataplane PDR counter that produced this set of stats. |
| 54 | * |
| 55 | * @return counter cell ID |
| 56 | */ |
| 57 | public int getCellId() { |
| 58 | return cellId; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get the number of packets that hit this counter in the dataplane ingress pipeline. |
| 63 | * |
| 64 | * @return ingress packet count |
| 65 | */ |
| 66 | public long getIngressPkts() { |
| 67 | return ingressPkts; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get the number of packets that hit this counter in the dataplane egress pipeline. |
| 72 | * |
| 73 | * @return egress packet count |
| 74 | */ |
| 75 | public long getEgressPkts() { |
| 76 | return egressPkts; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Get the number of packet bytes that hit this counter in the dataplane ingress pipeline. |
| 81 | * |
| 82 | * @return ingress byte count |
| 83 | */ |
| 84 | public long getIngressBytes() { |
| 85 | return ingressBytes; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Get the number of packet bytes that hit this counter in the dataplane egress pipeline. |
| 90 | * |
| 91 | * @return egress byte count |
| 92 | */ |
| 93 | public long getEgressBytes() { |
| 94 | return egressBytes; |
| 95 | } |
| 96 | |
| 97 | public static class Builder { |
| 98 | private Integer cellId; |
| 99 | private long ingressPkts; |
| 100 | private long ingressBytes; |
| 101 | private long egressPkts; |
| 102 | private long egressBytes; |
| 103 | |
| 104 | public Builder() { |
| 105 | this.ingressPkts = 0; |
| 106 | this.ingressBytes = 0; |
| 107 | this.egressPkts = 0; |
| 108 | this.egressBytes = 0; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Set the Cell ID (index) of the datalane PDR counter that produced this set of stats. |
| 113 | * |
| 114 | * @param cellId the counter cell ID |
| 115 | * @return This builder |
| 116 | */ |
| 117 | public Builder withCellId(int cellId) { |
| 118 | this.cellId = cellId; |
| 119 | return this; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Set the number of packets and bytes that hit the PDR counter in the dataplane ingress pipeline. |
| 124 | * |
| 125 | * @param ingressPkts ingress packet count |
| 126 | * @param ingressBytes egress packet count |
| 127 | * @return This builder |
| 128 | */ |
| 129 | public Builder setIngress(long ingressPkts, long ingressBytes) { |
| 130 | this.ingressPkts = ingressPkts; |
| 131 | this.ingressBytes = ingressBytes; |
| 132 | return this; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Set the number of packets and bytes that hit the PDR counter in the dataplane egress pipeline. |
| 137 | * |
| 138 | * @param egressPkts egress packet count |
| 139 | * @param egressBytes egress byte count |
| 140 | * @return This builder |
| 141 | */ |
| 142 | public Builder setEgress(long egressPkts, long egressBytes) { |
| 143 | this.egressPkts = egressPkts; |
| 144 | this.egressBytes = egressBytes; |
| 145 | return this; |
| 146 | } |
| 147 | |
| 148 | public PdrStats build() { |
| 149 | checkNotNull(cellId, "CellID must be provided"); |
| 150 | return new PdrStats(cellId, ingressPkts, ingressBytes, egressPkts, egressBytes); |
| 151 | } |
| 152 | } |
| 153 | } |