mirror of
https://github.com/Telecominfraproject/wlan-cloud-rrm.git
synced 2025-10-30 18:17:58 +00:00
Refactor IE parsing (#90)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
package com.facebook.openwifirrm.ucentral;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.Country;
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.LocalPowerConstraint;
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.QbssLoad;
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.TxPwrInfo;
|
||||
|
||||
/** Wrapper class containing information elements */
|
||||
public final class InformationElements {
|
||||
|
||||
public Country country;
|
||||
public QbssLoad qbssLoad;
|
||||
public LocalPowerConstraint localPowerConstraint;
|
||||
public TxPwrInfo txPwrInfo;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(country, localPowerConstraint, qbssLoad, txPwrInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
InformationElements other = (InformationElements) obj;
|
||||
return Objects.equals(country, other.country) && Objects.equals(
|
||||
localPowerConstraint,
|
||||
other.localPowerConstraint
|
||||
) && Objects.equals(qbssLoad, other.qbssLoad) &&
|
||||
Objects.equals(txPwrInfo, other.txPwrInfo);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,8 +111,9 @@ public class UCentralUtils {
|
||||
logger.debug("Wifiscan entry does not contain 'ies' field.");
|
||||
return;
|
||||
}
|
||||
JsonArray ies = iesJsonElement.getAsJsonArray();
|
||||
for (JsonElement ie : ies) {
|
||||
JsonArray iesJsonArray = iesJsonElement.getAsJsonArray();
|
||||
InformationElements ieContainer = new InformationElements();
|
||||
for (JsonElement ie : iesJsonArray) {
|
||||
JsonElement typeElement = ie.getAsJsonObject().get("type");
|
||||
if (typeElement == null) {
|
||||
continue;
|
||||
@@ -122,23 +123,25 @@ public class UCentralUtils {
|
||||
try {
|
||||
switch (typeElement.getAsInt()) {
|
||||
case Country.TYPE:
|
||||
entry.country = Country.parse(contents);
|
||||
ieContainer.country = Country.parse(contents);
|
||||
break;
|
||||
case QbssLoad.TYPE:
|
||||
entry.qbssLoad = QbssLoad.parse(contents);
|
||||
ieContainer.qbssLoad = QbssLoad.parse(contents);
|
||||
break;
|
||||
case LocalPowerConstraint.TYPE:
|
||||
entry.localPowerConstraint =
|
||||
ieContainer.localPowerConstraint =
|
||||
LocalPowerConstraint.parse(contents);
|
||||
break;
|
||||
case TxPwrInfo.TYPE:
|
||||
entry.txPwrInfo = TxPwrInfo.parse(contents);
|
||||
ieContainer.txPwrInfo = TxPwrInfo.parse(contents);
|
||||
break;
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
} catch (Exception e) {
|
||||
logger.debug("Skipping invalid IE.", e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
entry.ieContainer = ieContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,10 +10,6 @@ package com.facebook.openwifirrm.ucentral;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.Country;
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.LocalPowerConstraint;
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.QbssLoad;
|
||||
import com.facebook.openwifirrm.ucentral.informationelement.TxPwrInfo;
|
||||
import com.facebook.openwifirrm.ucentral.models.WifiScanEntryResult;
|
||||
|
||||
/**
|
||||
@@ -26,10 +22,8 @@ public class WifiScanEntry extends WifiScanEntryResult {
|
||||
* time reference.
|
||||
*/
|
||||
public long unixTimeMs;
|
||||
public Country country;
|
||||
public QbssLoad qbssLoad;
|
||||
public LocalPowerConstraint localPowerConstraint;
|
||||
public TxPwrInfo txPwrInfo;
|
||||
/** Stores Information Elements (IEs) from the wifiscan entry. */
|
||||
public InformationElements ieContainer;
|
||||
|
||||
/** Default Constructor. */
|
||||
public WifiScanEntry() {}
|
||||
@@ -38,23 +32,14 @@ public class WifiScanEntry extends WifiScanEntryResult {
|
||||
public WifiScanEntry(WifiScanEntry o) {
|
||||
super(o);
|
||||
this.unixTimeMs = o.unixTimeMs;
|
||||
this.country = o.country;
|
||||
this.qbssLoad = o.qbssLoad;
|
||||
this.localPowerConstraint = o.localPowerConstraint;
|
||||
this.txPwrInfo = o.txPwrInfo;
|
||||
this.ieContainer = o.ieContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = super.hashCode();
|
||||
result = prime * result + Objects.hash(
|
||||
country,
|
||||
localPowerConstraint,
|
||||
qbssLoad,
|
||||
txPwrInfo,
|
||||
unixTimeMs
|
||||
);
|
||||
result = prime * result + Objects.hash(ieContainer, unixTimeMs);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -70,11 +55,7 @@ public class WifiScanEntry extends WifiScanEntryResult {
|
||||
return false;
|
||||
}
|
||||
WifiScanEntry other = (WifiScanEntry) obj;
|
||||
return Objects.equals(country, other.country) && Objects.equals(
|
||||
localPowerConstraint,
|
||||
other.localPowerConstraint
|
||||
) && Objects.equals(qbssLoad, other.qbssLoad) && Objects
|
||||
.equals(txPwrInfo, other.txPwrInfo) &&
|
||||
return Objects.equals(ieContainer, other.ieContainer) &&
|
||||
unixTimeMs == other.unixTimeMs;
|
||||
}
|
||||
|
||||
@@ -87,5 +68,4 @@ public class WifiScanEntry extends WifiScanEntryResult {
|
||||
unixTimeMs
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +30,7 @@ public class Country {
|
||||
/** Defined in 802.11 */
|
||||
public static final int TYPE = 7;
|
||||
|
||||
/** Constraints for a subset of channels in the AP's country */
|
||||
public static class CountryInfo {
|
||||
/**
|
||||
* The lowest channel number in the CountryInfo.
|
||||
@@ -124,15 +125,9 @@ public class Country {
|
||||
JsonElement constraintsObject = contents.get("constraints");
|
||||
if (constraintsObject != null) {
|
||||
for (JsonElement jsonElement : constraintsObject.getAsJsonArray()) {
|
||||
try {
|
||||
constraints
|
||||
.add(CountryInfo.parse(jsonElement.getAsJsonObject()));
|
||||
} catch (NullPointerException e) {
|
||||
logger.debug(
|
||||
"Skipping invalid constraint encountered in Country IE.",
|
||||
e
|
||||
);
|
||||
}
|
||||
CountryInfo countryInfo =
|
||||
CountryInfo.parse(jsonElement.getAsJsonObject());
|
||||
constraints.add(countryInfo);
|
||||
}
|
||||
}
|
||||
return new Country(constraints);
|
||||
|
||||
@@ -10,6 +10,7 @@ package com.facebook.openwifirrm.ucentral.informationelement;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
/**
|
||||
@@ -61,9 +62,14 @@ public class QbssLoad {
|
||||
this.availableAdmissionCapacity = availableAdmissionCapacity;
|
||||
}
|
||||
|
||||
/** Parse QbssLoad IE from appropriate Json object. */
|
||||
/** Parse QbssLoad IE from appropriate Json object; return null if invalid. */
|
||||
public static QbssLoad parse(JsonObject contents) {
|
||||
contents = contents.get("802.11e CCA Version").getAsJsonObject();
|
||||
// unclear why there is this additional nested layer
|
||||
JsonElement ccaContentJsonElement = contents.get("802.11e CCA Version");
|
||||
if (ccaContentJsonElement == null) {
|
||||
return null;
|
||||
}
|
||||
contents = ccaContentJsonElement.getAsJsonObject();
|
||||
final int stationCount = contents.get("Station Count").getAsInt();
|
||||
final int channelUtilization =
|
||||
contents.get("Channel Utilization").getAsInt();
|
||||
|
||||
Reference in New Issue
Block a user