mirror of
https://github.com/Telecominfraproject/wlan-cloud-rrm.git
synced 2025-10-29 17:52:24 +00:00
Move AVAILABLE_CHANNELS_BAND to UCentralUtils before adding 6G support (#100)
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
package com.facebook.openwifi.cloudsdk;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -58,9 +60,30 @@ public class UCentralUtils {
|
||||
UCentralUtils.UPPER_CHANNEL_LIMIT.put(UCentralConstants.BAND_5G, 165);
|
||||
}
|
||||
|
||||
/** List of available channels per band for use. */
|
||||
public static final Map<String, List<Integer>> AVAILABLE_CHANNELS_BAND = Collections
|
||||
.unmodifiableMap(buildBandToChannelsMap());
|
||||
|
||||
// This class should not be instantiated.
|
||||
private UCentralUtils() {}
|
||||
|
||||
private static Map<String, List<Integer>> buildBandToChannelsMap() {
|
||||
Map<String, List<Integer>> bandToChannelsMap = new HashMap<>();
|
||||
bandToChannelsMap.put(
|
||||
UCentralConstants.BAND_5G,
|
||||
Collections.unmodifiableList(
|
||||
Arrays.asList(36, 40, 44, 48, 149, 153, 157, 161, 165)
|
||||
)
|
||||
);
|
||||
bandToChannelsMap.put(
|
||||
UCentralConstants.BAND_2G,
|
||||
Collections.unmodifiableList(
|
||||
Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
|
||||
)
|
||||
);
|
||||
return bandToChannelsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a JSON wifi scan result into a list of WifiScanEntry objects.
|
||||
*
|
||||
|
||||
@@ -39,24 +39,6 @@ public abstract class ChannelOptimizer {
|
||||
/** Minimum supported channel width (MHz), inclusive. */
|
||||
public static final int MIN_CHANNEL_WIDTH = 20;
|
||||
|
||||
/** List of available channels per band for use. */
|
||||
public static final Map<String, List<Integer>> AVAILABLE_CHANNELS_BAND =
|
||||
new HashMap<>();
|
||||
static {
|
||||
AVAILABLE_CHANNELS_BAND.put(
|
||||
UCentralConstants.BAND_5G,
|
||||
Collections.unmodifiableList(
|
||||
Arrays.asList(36, 40, 44, 48, 149, 153, 157, 161, 165)
|
||||
)
|
||||
);
|
||||
AVAILABLE_CHANNELS_BAND.put(
|
||||
UCentralConstants.BAND_2G,
|
||||
Collections.unmodifiableList(
|
||||
Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** Map of channel width (MHz) to available (primary) channels */
|
||||
protected static final Map<Integer, List<Integer>> AVAILABLE_CHANNELS_WIDTH =
|
||||
new HashMap<>();
|
||||
@@ -197,7 +179,7 @@ public abstract class ChannelOptimizer {
|
||||
String vhtOper
|
||||
) {
|
||||
if (
|
||||
AVAILABLE_CHANNELS_BAND.get(UCentralConstants.BAND_2G)
|
||||
UCentralUtils.AVAILABLE_CHANNELS_BAND.get(UCentralConstants.BAND_2G)
|
||||
.contains(channel)
|
||||
) {
|
||||
// 2.4G, it only supports 20 MHz
|
||||
|
||||
@@ -96,7 +96,7 @@ public class LeastUsedChannelOptimizer extends ChannelOptimizer {
|
||||
UCentralUtils.LOWER_CHANNEL_LIMIT.get(UCentralConstants.BAND_2G);
|
||||
Map<Integer, Integer> occupiedOverlapChannels = new TreeMap<>();
|
||||
for (
|
||||
int overlapChannel : AVAILABLE_CHANNELS_BAND
|
||||
int overlapChannel : UCentralUtils.AVAILABLE_CHANNELS_BAND
|
||||
.get(UCentralConstants.BAND_2G)
|
||||
) {
|
||||
int occupancy = 0;
|
||||
@@ -338,7 +338,7 @@ public class LeastUsedChannelOptimizer extends ChannelOptimizer {
|
||||
UCentralUtils.getDeviceAvailableChannels(
|
||||
model.latestDeviceStatusRadios,
|
||||
model.latestDeviceCapabilities,
|
||||
AVAILABLE_CHANNELS_BAND
|
||||
UCentralUtils.AVAILABLE_CHANNELS_BAND
|
||||
);
|
||||
|
||||
Map<String, State> latestState =
|
||||
@@ -372,7 +372,8 @@ public class LeastUsedChannelOptimizer extends ChannelOptimizer {
|
||||
availableChannelsList == null ||
|
||||
availableChannelsList.isEmpty()
|
||||
) {
|
||||
availableChannelsList = AVAILABLE_CHANNELS_BAND.get(band);
|
||||
availableChannelsList =
|
||||
UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band);
|
||||
}
|
||||
|
||||
// Get current channel of the device
|
||||
|
||||
@@ -126,7 +126,7 @@ public class RandomChannelInitializer extends ChannelOptimizer {
|
||||
UCentralUtils.getDeviceAvailableChannels(
|
||||
model.latestDeviceStatusRadios,
|
||||
model.latestDeviceCapabilities,
|
||||
AVAILABLE_CHANNELS_BAND
|
||||
UCentralUtils.AVAILABLE_CHANNELS_BAND
|
||||
);
|
||||
|
||||
Map<String, State> latestState =
|
||||
@@ -152,7 +152,7 @@ public class RandomChannelInitializer extends ChannelOptimizer {
|
||||
// to get the valid result for single channel assignment
|
||||
// If the intersection is empty, then turn back to the default channels list
|
||||
List<Integer> availableChannelsList = new ArrayList<>(
|
||||
AVAILABLE_CHANNELS_BAND.get(band)
|
||||
UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band)
|
||||
);
|
||||
for (String serialNumber : entry.getValue()) {
|
||||
List<Integer> deviceChannelsList = deviceAvailableChannels
|
||||
@@ -161,14 +161,16 @@ public class RandomChannelInitializer extends ChannelOptimizer {
|
||||
if (
|
||||
deviceChannelsList == null || deviceChannelsList.isEmpty()
|
||||
) {
|
||||
deviceChannelsList = AVAILABLE_CHANNELS_BAND.get(band);
|
||||
deviceChannelsList =
|
||||
UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band);
|
||||
}
|
||||
availableChannelsList.retainAll(deviceChannelsList);
|
||||
}
|
||||
if (
|
||||
availableChannelsList == null || availableChannelsList.isEmpty()
|
||||
) {
|
||||
availableChannelsList = AVAILABLE_CHANNELS_BAND.get(band);
|
||||
availableChannelsList =
|
||||
UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band);
|
||||
logger.debug(
|
||||
"The intersection of the device channels lists is empty!!! " +
|
||||
"Fall back to the default channels list"
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import com.facebook.openwifi.cloudsdk.UCentralConstants;
|
||||
import com.facebook.openwifi.cloudsdk.UCentralUtils;
|
||||
import com.facebook.openwifi.rrm.DeviceConfig;
|
||||
import com.facebook.openwifi.rrm.DeviceDataManager;
|
||||
import com.facebook.openwifi.rrm.modules.Modeler.DataModel;
|
||||
@@ -74,7 +75,7 @@ public class LeastUsedChannelOptimizerTest {
|
||||
|
||||
// B -> Assign to only free channel (165)
|
||||
LinkedList<Integer> channelsB = new LinkedList<>();
|
||||
channelsB.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
int bExpectedChannel = channelsB.removeLast();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceB,
|
||||
@@ -94,8 +95,8 @@ public class LeastUsedChannelOptimizerTest {
|
||||
|
||||
// C -> No free channels, assign to least occupied (36)
|
||||
LinkedList<Integer> channelsC = new LinkedList<>();
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
int cExpectedChannel = channelsC.removeFirst();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceC,
|
||||
@@ -166,7 +167,7 @@ public class LeastUsedChannelOptimizerTest {
|
||||
|
||||
// B -> No free channels, assign to least occupied (11)
|
||||
LinkedList<Integer> channelsB = new LinkedList<>();
|
||||
channelsB.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
int bExpectedChannel = channelsB.removeLast();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceB,
|
||||
@@ -261,7 +262,7 @@ public class LeastUsedChannelOptimizerTest {
|
||||
expected.put(deviceA, radioMapA);
|
||||
|
||||
LinkedList<Integer> channelsB = new LinkedList<>();
|
||||
channelsB.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.removeLast();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceB,
|
||||
@@ -280,8 +281,8 @@ public class LeastUsedChannelOptimizerTest {
|
||||
expected.put(deviceB, radioMapB);
|
||||
|
||||
LinkedList<Integer> channelsC = new LinkedList<>();
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.removeFirst();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceC,
|
||||
@@ -361,7 +362,7 @@ public class LeastUsedChannelOptimizerTest {
|
||||
// B -> Assign to only free channel and
|
||||
// the free channel is in allowedChannels (165)
|
||||
LinkedList<Integer> channelsB = new LinkedList<>();
|
||||
channelsB.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.removeLast();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceB,
|
||||
@@ -381,8 +382,8 @@ public class LeastUsedChannelOptimizerTest {
|
||||
|
||||
// C -> No free channels, assign to least occupied in allowedChannels (48)
|
||||
LinkedList<Integer> channelsC = new LinkedList<>();
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.removeFirst();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceC,
|
||||
@@ -477,8 +478,8 @@ public class LeastUsedChannelOptimizerTest {
|
||||
|
||||
// C -> No free channels, assign to least occupied (36)
|
||||
LinkedList<Integer> channelsC = new LinkedList<>();
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
int cExpectedChannel = channelsC.removeFirst();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceC,
|
||||
@@ -598,8 +599,8 @@ public class LeastUsedChannelOptimizerTest {
|
||||
|
||||
// C -> No free channels, assign to least occupied (36)
|
||||
LinkedList<Integer> channelsC = new LinkedList<>();
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
int cExpectedChannel = channelsC.removeFirst();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceC,
|
||||
@@ -752,7 +753,7 @@ public class LeastUsedChannelOptimizerTest {
|
||||
// C -> No free channels, assign to least occupied (36)
|
||||
LinkedList<Integer> channelsC1 = new LinkedList<>(); // bandwidth-agnostic
|
||||
LinkedList<Integer> channelsC2 = new LinkedList<>(); // bandwidth-aware
|
||||
channelsC1.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC1.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC2.addAll(Arrays.asList(36, 157, 165));
|
||||
int cExpectedChannel = channelsC1.removeFirst();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import com.facebook.openwifi.cloudsdk.UCentralConstants;
|
||||
import com.facebook.openwifi.cloudsdk.UCentralUtils;
|
||||
import com.facebook.openwifi.rrm.DeviceDataManager;
|
||||
import com.facebook.openwifi.rrm.modules.Modeler.DataModel;
|
||||
import com.facebook.openwifi.rrm.optimizers.TestUtils;
|
||||
@@ -78,7 +79,7 @@ public class UnmanagedApAwareChannelOptimizerTest {
|
||||
|
||||
// B -> Assign to only free channel (165)
|
||||
LinkedList<Integer> channelsB = new LinkedList<>();
|
||||
channelsB.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
int bExpectedChannel = channelsB.removeLast();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceB,
|
||||
@@ -99,7 +100,7 @@ public class UnmanagedApAwareChannelOptimizerTest {
|
||||
// C -> No free channels, assign to the channel with the least weight (48)
|
||||
// since A is on 48, the weight of channel 48 is lower than the other channels
|
||||
LinkedList<Integer> channelsC = new LinkedList<>();
|
||||
channelsC.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsC.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
LinkedList<String> bssidsC = new LinkedList<>(
|
||||
Arrays.asList(
|
||||
"dd:dd:dd:dd:dd:dd",
|
||||
@@ -184,7 +185,7 @@ public class UnmanagedApAwareChannelOptimizerTest {
|
||||
|
||||
// B -> No free channels, assign to least occupied (11)
|
||||
LinkedList<Integer> channelsB = new LinkedList<>();
|
||||
channelsB.addAll(ChannelOptimizer.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
channelsB.addAll(UCentralUtils.AVAILABLE_CHANNELS_BAND.get(band));
|
||||
int bExpectedChannel = channelsB.removeLast();
|
||||
dataModel.latestDeviceStatusRadios.put(
|
||||
deviceB,
|
||||
|
||||
Reference in New Issue
Block a user