Open Kilda Java Documentation
EndpointReport.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.testing.service.traffexam.model;
17 
18 import lombok.Getter;
19 import org.apache.logging.log4j.util.Strings;
20 
21 @Getter
22 public class EndpointReport {
23  private Long packets = 0L;
24  private Long bytes = 0L;
25 
26  private Long lostPackets = 0L;
27  private Float lostPercent = 0f;
28 
29  private Double seconds = 0d;
30  private Double bitsPerSecond = 0d;
31 
32  private final String error;
33 
34  public EndpointReport(String error) {
35  this.error = error;
36  }
37 
38  public EndpointReport(ReportResponse report) {
39  if (Strings.isEmpty(report.getError())) {
40  this.error = report.getReport().error;
41  } else {
42  this.error = report.getError();
43  }
44 
45  IPerfReportEndBranch finalResults = report.getReport().end;
46  if (finalResults.sumReceived != null) {
47  unpackTcpReport(finalResults.sumReceived);
48  } else if (finalResults.sumSent != null) {
49  unpackTcpReport(finalResults.sumSent);
50  } else if (finalResults.sum != null) {
51  unpackUdpReport(finalResults);
52  }
53  }
54 
55  private void unpackTcpReport(IPerfReportTcpSumSection finalResults) {
56  bytes = finalResults.getBytes();
57  seconds = finalResults.getEnd() - finalResults.getStart();
58  bitsPerSecond = finalResults.getBitsPerSecond();
59  }
60 
61  private void unpackUdpReport(IPerfReportEndBranch finalResults) {
62  try {
63  IPerfReportSumBranch summary = finalResults.sum;
64  packets = summary.packets;
65  bytes = summary.bytes;
66  lostPackets = summary.lostPackets;
67  lostPercent = summary.lostPercent;
68  seconds = summary.seconds;
69  bitsPerSecond = summary.bitsPerSecond;
70  } catch (NullPointerException e) {
71  // skip initialisation it there is no summary data
72  }
73  }
74 }