Skip to content

Commit

Permalink
Add port utilization report (#484)
Browse files Browse the repository at this point in the history
* add a port utilization report

* rollback app.properties
  • Loading branch information
haniotak authored May 21, 2024
1 parent 186a125 commit 8b1d63c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# OSCARS Release Notes
### 1.2.8
> May 2024
- Add port utilization report API

### 1.2.8
> May 2024
- Add edge port search
Expand Down
2 changes: 1 addition & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<groupId>net.es.oscars</groupId>
<artifactId>backend</artifactId>
<name>backend</name>
<version>1.2.8</version>
<version>1.2.9</version>

<description>OSCARS backend</description>
<properties>
Expand Down
16 changes: 16 additions & 0 deletions backend/src/main/java/net/es/oscars/topo/beans/v2/Bandwidth.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package net.es.oscars.topo.beans.v2;

import com.fasterxml.jackson.annotation.JsonGetter;
import lombok.*;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Data
@Builder
@AllArgsConstructor
Expand All @@ -17,6 +21,18 @@ public class Bandwidth {
@NonNull
private Integer physical;

@JsonGetter
private Double utilization() {

if (physical == 0) {
return 0.0;
}
BigDecimal bd = BigDecimal.valueOf(1.0 - (available.doubleValue() / physical.doubleValue()));
bd = bd.setScale(3, RoundingMode.HALF_UP);
return bd.doubleValue();

}

public enum Unit {
MBPS, GBPS
}
Expand Down
29 changes: 25 additions & 4 deletions backend/src/main/java/net/es/oscars/topo/beans/v2/EdgePort.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,37 @@ public String getUrn() {
@NonNull
private Bandwidth bandwidth;

@JsonProperty("vlan-availability")
private VlanAvailability vlanAvailability;
@NonNull
private Availability availability;

@JsonProperty("vlan-usage")
private Map<Integer, Set<String>> vlanUsage;
@NonNull
private Usage usage;

@JsonProperty("esdb-equipment-interface-id")
private Integer esdbEquipmentInterfaceId;

private ArrayList<String> description;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class Usage {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<Integer, Set<String>> vlan;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Integer> bandwidth;
}
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class Availability {
@JsonProperty("vlan")
private VlanAvailability vlan;

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
import net.es.oscars.topo.enums.Layer;
import net.es.oscars.topo.pop.ConsistencyException;
import net.es.oscars.topo.svc.TopologyStore;
import net.es.oscars.web.beans.Interval;
import net.es.oscars.web.beans.v2.PortSearchRequest;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;

@RestController
Expand Down Expand Up @@ -144,6 +147,36 @@ public List<EdgePort> edgePortSearch(@RequestBody PortSearchRequest psr)
return results;
}


@RequestMapping(value = "/api/reports/utilization", method = RequestMethod.GET)
@ResponseBody
@Transactional
public List<EdgePort> utilizationReport()
throws ConsistencyException, StartupException {
startup.startupCheck();
List<EdgePort> results = new ArrayList<>();

Topology topology = topologyStore.getTopology();
if (topology.getVersion() == null) {
throw new ConsistencyException("null current topology");
}
Interval interval = Interval.builder()
.beginning(Instant.now())
.ending(Instant.now().plus(24, ChronoUnit.HOURS))
.build();
Map<String, PortBwVlan> available = resvService.available(interval, null);
Map<String, Map<Integer, Set<String>>> vlanUsageMap = resvService.vlanUsage(interval, null);


for (Device d : topology.getDevices().values()) {
for (net.es.oscars.topo.beans.Port p : d.getPorts()) {
results.add(fromOldPort(p, available, vlanUsageMap));
}
}
return results;
}


private EdgePort fromOldPort(net.es.oscars.topo.beans.Port p,
Map<String, PortBwVlan> available,
Map<String, Map<Integer, Set<String>>> vlanUsageMap) throws ConsistencyException {
Expand Down Expand Up @@ -187,10 +220,10 @@ private EdgePort fromOldPort(net.es.oscars.topo.beans.Port p,
.device(parts[0])
.name(parts[1])
.bandwidth(bw)
.vlanAvailability(vlanAvailability)
.availability(EdgePort.Availability.builder().vlan(vlanAvailability).build())
.description(p.getTags())
.esdbEquipmentInterfaceId(p.getEsdbEquipmentInterfaceId())
.vlanUsage(vlanUsage)
.usage(EdgePort.Usage.builder().vlan(vlanUsage).build())
.build();
}

Expand Down

0 comments on commit 8b1d63c

Please sign in to comment.