+ private synchronized void mapUniPortBandwidthLimits(String uniId, String portId, Long maxKbps, Long maxBurstKb,
+ String profileName) {
+ Log.info("Record rate limits for Uni {} port {} maxKbps {} maxBurstKb {}", uniId, portId, maxKbps, maxBurstKb);
+ uniPortBandwidthLimits.putIfAbsent(uniId, new ConcurrentHashMap<>());
+ ConcurrentHashMap<String, BandwidthLimits> uniMap = uniPortBandwidthLimits.get(uniId);
+ uniMap.put(portId, new BandwidthLimits(maxKbps, maxBurstKb, profileName));
+ }
+
+ public void updateUni(Identifier45 uniId, Identifier45 bwProfile) {
+ String bwProfileSafe = replaceNull(bwProfile);
+ Log.info("Update rate limits for Uni {}", uniId.getValue());
+ ConcurrentHashMap<String, BandwidthLimits> uniMap = uniPortBandwidthLimits.get(uniId.getValue());
+ if (uniMap == null) {
+ Log.error("Trying to update limits for non-exsting uni {}", uniId.getValue());
+ return;
+ }
+ for (String portName : uniMap.keySet()) {
+ if (uniMap.get(portName).getProfileName().equals(bwProfileSafe)) {
+ continue;
+ }
+ if (bwProfile != null) {
+ mapUniPortBandwidthLimits(uniId.getValue(), portName, new Identifier45(bwProfileSafe));
+ } else {
+ unMapUniPortBandwidthLimits(uniId.getValue(), portName);
+ }
+ }
+ }
+
+ private void updateProfile(Identifier45 bwProfile) {
+ Log.info("Update rate limits for profile {}", bwProfile);
+ List<String> unisWithProfile = uniBandwidthLimits.entrySet().stream()
+ .filter(m -> m.getValue().profileName.equals(bwProfile.getValue())).map(m -> m.getKey())
+ .collect(Collectors.toList());
+
+ for (String uniId : unisWithProfile) {
+ ConcurrentHashMap<String, BandwidthLimits> uniMap = uniPortBandwidthLimits.get(uniId);
+ uniMap.forEach((k, v) -> {
+ mapUniPortBandwidthLimits(uniId, k, bwProfile);
+ });
+ }
+
+ for (String uniId : unisWithProfile) {
+ setUniBandwidthLimits(uniId);
+ }
+ }
+
+ public void deleteProfile(Identifier45 bwProfile) {
+ Log.info("Delete rate limits for profile {}", bwProfile);
+ List<String> unisWithProfile = uniBandwidthLimits.entrySet().stream()
+ .filter(m -> m.getValue().profileName.equals(bwProfile.getValue())).map(m -> m.getKey())
+ .collect(Collectors.toList());
+
+ for (String uniId : unisWithProfile) {
+ ConcurrentHashMap<String, BandwidthLimits> uniMap = uniPortBandwidthLimits.get(uniId);
+ uniMap.forEach((k, v) -> {
+ unMapUniPortBandwidthLimits(uniId, k, bwProfile.getValue());
+ });
+ }
+
+ for (String uniId : unisWithProfile) {
+ setUniBandwidthLimits(uniId);
+ }
+ }
+
+ public synchronized void unMapUniPortBandwidthLimits(String uniId, String portId) {
+ unMapUniPortBandwidthLimits(uniId, portId, noProfile);
+ }
+
+ public synchronized void unMapUniPortBandwidthLimits(String uniId, String portId, String profileTosave) {
+ Log.info("Delete rate limits for Uni {} port {}", uniId, portId);