VLAN changes per AP request to create LAN and WAN Vlan Interfaces whenever a VLAN is provisioned

This commit is contained in:
Mike Hansen
2020-10-29 17:42:12 -04:00
parent 4df03431ed
commit 15e26fd829
2 changed files with 4596 additions and 4553 deletions

View File

@@ -1268,7 +1268,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
protocolStatus.setDetails(protocolStatusData);
protocolStatus = statusServiceInterface.update(protocolStatus);
LOG.info("Updated IpV4Addr for AP {} to {} from Wifi_Inet_State change for if_name {}", apId,
((EquipmentProtocolStatusData) protocolStatus.getDetails()).getReportedIpV4Addr(), inetState.ifName);
((EquipmentProtocolStatusData) protocolStatus.getDetails()).getReportedIpV4Addr(),
inetState.ifName);
LOG.debug("ProtocolStatus for AP {} updated to {}", apId, protocolStatus);
} catch (UnknownHostException e) {
@@ -1279,46 +1280,61 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra
}
if (inetState.getVlanId() > 1) {
if (!lanStatusData.getVlanStatusDataMap().containsKey(inetState.getVlanId())) {
lanStatusData.getVlanStatusDataMap().put(inetState.getVlanId(), new VLANStatusData());
}
if (inetState.getIfType().equals("vlan") && inetState.parentIfName != null
&& inetState.parentIfName.equals(defaultWanInterfaceName)) {
try {
lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId())
.setGateway(InetAddress.getByName(inetState.getGateway()));
String primaryDns = inetState.getDns().get("primary");
VLANStatusData vlanStatusData = new VLANStatusData();
if (inetState.gateway != null)
vlanStatusData.setGateway(InetAddress.getByName(inetState.getGateway()));
if (inetState.dns != null) {
String primaryDns = inetState.dns.get("primary");
if (primaryDns != null) {
lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId())
vlanStatusData
.setDnsServer1(InetAddress.getByName(primaryDns));
}
lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId())
.setSubnetMask(InetAddress.getByName(inetState.getNetmask()));
String secondaryDns = inetState.dns.get("secondary");
if (secondaryDns != null) {
vlanStatusData
.setDnsServer2(InetAddress.getByName(secondaryDns));
}
}
String dhcpOption = inetState.getDhcpd().get("dhcp_option");
if (inetState.netmask != null) {
vlanStatusData
.setSubnetMask(InetAddress.getByName(inetState.netmask));
}
if (inetState.dhcpd != null) {
String dhcpOption = inetState.dhcpd.get("dhcp_option");
if (dhcpOption != null) {
String dhcpServer = dhcpOption.split(",")[1];
if (dhcpServer != null) {
lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId())
vlanStatusData
.setDhcpServer(InetAddress.getByName(dhcpServer));
}
}
}
String inetAddr = inetState.getInetAddr();
if (inetAddr != null) {
lanStatusData.getVlanStatusDataMap().get(inetState.getVlanId())
vlanStatusData
.setIpBase(InetAddress.getByName(inetAddr));
}
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
lanStatusData.getVlanStatusDataMap().put(inetState.vlanId, vlanStatusData);
lanStatus.setDetails(lanStatusData);
lanStatus = statusServiceInterface.update(lanStatus);
LOG.info("LANINFO updated for VLAN {}", lanStatus);
} catch (UnknownHostException e) {
LOG.error("Unknown Host while configuring LANINFO", e);
}
}
}

View File

@@ -604,8 +604,9 @@ public class OvsdbDao {
/**
* @param ovsdbClient
* @return value of reporting_interval column for the stats_type=device from the
* Wifi_Stats_Config table. If value is not provisioned then return -1.
* @return value of reporting_interval column for the stats_type=device from
* the Wifi_Stats_Config table. If value is not provisioned then
* return -1.
*/
public long getDeviceStatsReportingInterval(OvsdbClient ovsdbClient) {
long ret = -1;
@@ -649,9 +650,10 @@ public class OvsdbDao {
/**
* @param ovsdbClient
* @param value of reporting_interval column for the stats_type=device
* from the Wifi_Stats_Config table. If value is not
* provisioned then return -1.
* @param value
* of reporting_interval column for the stats_type=device from
* the Wifi_Stats_Config table. If value is not provisioned then
* return -1.
*/
public void updateDeviceStatsReportingInterval(OvsdbClient ovsdbClient, long newValue) {
try {
@@ -2630,20 +2632,8 @@ public class OvsdbDao {
}
if (vlanId > 1) {
// vlan config, check to see if we already have the vlan in
// question
Map<String, WifiInetConfigInfo> wifiInetConfigInfoMap = getProvisionedWifiInetConfigs(ovsdbClient);
String vlanIfName = bridgeInterfaceName + "_" + vlanId;
if (!wifiInetConfigInfoMap.containsKey(vlanIfName)) {
// we need to make a VLAN, before we do anything else
createInetConfigForVlan(ovsdbClient, bridgeInterfaceName, vlanIfName, vlanId, false);
} else {
createInetConfigForVlan(ovsdbClient, bridgeInterfaceName, vlanIfName, vlanId, true);
}
createVlanNetworkInterfaces(ovsdbClient, vlanId);
updateColumns.put("vlan_id", new Atom<>(vlanId));
}
updateColumns.put("mode", new Atom<>("ap"));
@@ -2714,7 +2704,8 @@ public class OvsdbDao {
customOptions.put("client_ul_limit", String.valueOf(clientUlLimit * 1000));
customOptions.put("rts_threshold", String.valueOf(rtsCtsThreshold));
// TODO: the frag_threshold is not supported on the AP
// customOptions.put("frag_threshold", String.valueOf(fragThresholdBytes));
// customOptions.put("frag_threshold",
// String.valueOf(fragThresholdBytes));
customOptions.put("dtim_period", String.valueOf(dtimPeriod));
if (enable80211k) {
@@ -2756,9 +2747,11 @@ public class OvsdbDao {
Map<String, WifiInetConfigInfo> inetConfigs = getProvisionedWifiInetConfigs(ovsdbClient);
if (inetConfigs.containsKey(vifInterfaceName)) {
configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", true, (networkForwardMode == NetworkForwardMode.NAT));
configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", true,
(networkForwardMode == NetworkForwardMode.NAT));
} else {
configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", false, (networkForwardMode == NetworkForwardMode.NAT));
configureInetInterface(ovsdbClient, vifInterfaceName, enabled, "vif", false,
(networkForwardMode == NetworkForwardMode.NAT));
}
LOG.info("Provisioned SSID {} on interface {} / {}", ssid, vifInterfaceName, radioFreqBand);
@@ -3150,43 +3143,73 @@ public class OvsdbDao {
}
private void createInetConfigForVlan(OvsdbClient ovsdbClient, String parentIfName, String vlanIfName, int vlanId,
boolean isUpdate) {
private void createVlanNetworkInterfaces(OvsdbClient ovsdbClient, int vlanId) {
try {
List<Operation> operations = new ArrayList<>();
Map<String, Value> tableColumns = new HashMap<>();
Map<String, WifiInetConfigInfo> inetConfigMap = getProvisionedWifiInetConfigs(ovsdbClient);
WifiInetConfigInfo parentLanInterface = inetConfigMap.get(defaultLanInterfaceName);
if (parentLanInterface == null)
throw new RuntimeException(
"Cannot get lan interface " + defaultLanInterfaceName + " for vlan " + vlanId);
tableColumns.put("if_type", new Atom<>("vlan"));
tableColumns.put("vlan_id", new Atom<>(vlanId));
tableColumns.put("if_name", new Atom<>(vlanIfName));
tableColumns.put("parent_ifname", new Atom<>(parentIfName));
tableColumns.put("if_name", new Atom<>(parentLanInterface.ifName + "_" + Integer.toString(vlanId)));
tableColumns.put("parent_ifname", new Atom<>(parentLanInterface.ifName));
tableColumns.put("enabled", new Atom<>(true));
tableColumns.put("network", new Atom<>(true));
tableColumns.put("dhcp_sniff", new Atom<>(true));
WifiInetConfigInfo parent = getProvisionedWifiInetConfigs(ovsdbClient).get(parentIfName);
if (parent == null)
throw new RuntimeException("Cannot get parent interface " + parentIfName + " for vlan " + vlanId);
tableColumns.put("ip_assign_scheme", new Atom<>(parent.ipAssignScheme));
tableColumns.put("NAT", new Atom<>(parent.nat));
tableColumns.put("ip_assign_scheme", new Atom<>(parentLanInterface.ipAssignScheme));
tableColumns.put("NAT", new Atom<>(parentLanInterface.nat));
tableColumns.put("mtu", new Atom<>(1500));
if (parent.ipAssignScheme.equals("static")) {
String[] inetAddress = parent.inetAddr.split("\\.");
String[] inetAddress = parentLanInterface.inetAddr.split("\\.");
String vlanAddress = inetAddress[0] + "." + inetAddress[1] + "." + vlanId + "." + inetAddress[3];
tableColumns.put("inet_addr", new Atom<>(vlanAddress));
tableColumns.put("netmask", new Atom<>(parent.netmask));
}
tableColumns.put("netmask", new Atom<>(parentLanInterface.netmask));
tableColumns.put("dhcpd", com.vmware.ovsdb.protocol.operation.notation.Map.of(parentLanInterface.dhcpd));
Row row = new Row(tableColumns);
operations.clear();
if (isUpdate) {
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(vlanIfName)));
operations.add(new Update(wifiInetConfigDbTable, conditions, row));
if (inetConfigMap.containsKey(parentLanInterface.ifName + "_" + Integer.toString(vlanId))) {
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("vlan_id", Function.EQUALS, new Atom<>(vlanId)));
conditions.add(new Condition("parent_ifname", Function.EQUALS, new Atom<>(parentLanInterface.ifName)));
operations.add(new Update(wifiInetConfigDbTable, conditions, row));
} else {
operations.add(new Insert(wifiInetConfigDbTable, row));
}
WifiInetConfigInfo parentWanInterface = inetConfigMap.get(defaultWanInterfaceName);
if (parentWanInterface == null)
throw new RuntimeException(
"Cannot get wan interface " + defaultWanInterfaceName + " for vlan " + vlanId);
tableColumns = new HashMap<>();
tableColumns.put("if_type", new Atom<>("vlan"));
tableColumns.put("vlan_id", new Atom<>(vlanId));
tableColumns.put("if_name", new Atom<>(parentWanInterface.ifName + "_" + Integer.toString(vlanId)));
tableColumns.put("parent_ifname", new Atom<>(parentWanInterface.ifName));
tableColumns.put("enabled", new Atom<>(true));
tableColumns.put("network", new Atom<>(true));
tableColumns.put("dhcp_sniff", new Atom<>(true));
tableColumns.put("ip_assign_scheme", new Atom<>(parentWanInterface.ipAssignScheme));
tableColumns.put("NAT", new Atom<>(parentWanInterface.nat));
tableColumns.put("mtu", new Atom<>(1500));
row = new Row(tableColumns);
if (inetConfigMap.containsKey(parentWanInterface.ifName + "_" + Integer.toString(vlanId))) {
List<Condition> conditions = new ArrayList<>();
conditions.add(new Condition("vlan_id", Function.EQUALS, new Atom<>(vlanId)));
conditions.add(new Condition("parent_ifname", Function.EQUALS, new Atom<>(parentWanInterface.ifName)));
} else {
operations.add(new Insert(wifiInetConfigDbTable, row));
}
@@ -3194,12 +3217,16 @@ public class OvsdbDao {
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
LOG.debug("Provisioned Vlan {}", vlanId);
for (OperationResult res : result) {
LOG.debug("Op Result {}", res);
}
inetConfigMap = getProvisionedWifiInetConfigs(ovsdbClient);
LOG.debug("Provisioned vlan on wan {} and lan {}",
inetConfigMap.get(parentWanInterface.ifName + "_" + Integer.toString(vlanId)),
inetConfigMap.get(parentLanInterface.ifName + "_" + Integer.toString(vlanId)));
} catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) {
LOG.error("Error in provisioning Vlan", e);
throw new RuntimeException(e);