mirror of
https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
synced 2025-11-01 11:07:49 +00:00
Update Wifi_Inet_Config for vlan handling
This commit is contained in:
@@ -1373,6 +1373,9 @@ public class OvsdbDao {
|
||||
columns.add("mtu");
|
||||
columns.add("netmask");
|
||||
columns.add("vlan_id");
|
||||
columns.add("gateway");
|
||||
columns.add("dns");
|
||||
columns.add("dhcpd");
|
||||
|
||||
try {
|
||||
LOG.debug("Retrieving WifiInetConfig:");
|
||||
@@ -1422,6 +1425,9 @@ public class OvsdbDao {
|
||||
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
|
||||
wifiInetConfigInfo.vlanId = row.getIntegerColumn("vlan_id").intValue();
|
||||
}
|
||||
wifiInetConfigInfo.dns = row.getMapColumn("dns");
|
||||
wifiInetConfigInfo.dhcpd = row.getMapColumn("dhcpd");
|
||||
wifiInetConfigInfo.gateway = getSingleValueFromSet(row, "gateway");
|
||||
ret.put(wifiInetConfigInfo.ifName, wifiInetConfigInfo);
|
||||
}
|
||||
|
||||
@@ -3110,57 +3116,13 @@ public class OvsdbDao {
|
||||
private void createInetConfigForVlan(OvsdbClient ovsdbClient, String parentIfName, boolean isNAT, String vlanIfName,
|
||||
int vlanId, String gateway, String inet, String ipAssignScheme, Map<String, String> dns, boolean isUpdate) {
|
||||
try {
|
||||
|
||||
Map<String, WifiInetConfigInfo> wifiInetConfigsMap = getProvisionedWifiInetConfigs(ovsdbClient);
|
||||
WifiInetConfigInfo parentWifiInetConfig = wifiInetConfigsMap.get(parentIfName);
|
||||
|
||||
List<Operation> operations = new ArrayList<>();
|
||||
Map<String, Value> tableColumns = new HashMap<>();
|
||||
Map<String, String> parentDhcpd = null;
|
||||
String parentNetmask = null;
|
||||
|
||||
// if (ipAssignScheme == null) {
|
||||
|
||||
List<String> parentTableColumns = new ArrayList<>();
|
||||
parentTableColumns.add("gateway");
|
||||
parentTableColumns.add("if_name");
|
||||
parentTableColumns.add("if_type");
|
||||
parentTableColumns.add("inet_addr");
|
||||
parentTableColumns.add("netmask");
|
||||
parentTableColumns.add("dhcpd");
|
||||
parentTableColumns.add("dns");
|
||||
parentTableColumns.add("ip_assign_scheme");
|
||||
|
||||
List<Condition> parentTableConditions = new ArrayList<>();
|
||||
parentTableConditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(parentIfName)));
|
||||
operations.add(new Select(wifiInetStateDbTable, parentTableConditions, parentTableColumns));
|
||||
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
|
||||
|
||||
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
|
||||
|
||||
String parentInetAddr = null;
|
||||
String parentGateway = null;
|
||||
Map<String, String> parentDns = null;
|
||||
|
||||
String parentIpAssignScheme = null;
|
||||
for (Row row : ((SelectResult) result[0]).getRows()) {
|
||||
parentGateway = getSingleValueFromSet(row, "gateway");
|
||||
if ((row.getColumns().get("inet_addr") != null) && row.getColumns().get("inet_addr").getClass()
|
||||
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
|
||||
parentInetAddr = row.getStringColumn("inet_addr");
|
||||
}
|
||||
if ((row.getColumns().get("netmask") != null) && row.getColumns().get("netmask").getClass()
|
||||
.equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) {
|
||||
parentNetmask = row.getStringColumn("netmask");
|
||||
}
|
||||
parentDns = row.getMapColumn("dns");
|
||||
parentDhcpd = row.getMapColumn("dhcpd");
|
||||
parentIpAssignScheme = getSingleValueFromSet(row, "ip_assign_scheme");
|
||||
|
||||
}
|
||||
|
||||
inet = parentInetAddr;
|
||||
gateway = parentGateway;
|
||||
dns = parentDns;
|
||||
ipAssignScheme = parentIpAssignScheme;
|
||||
|
||||
// }
|
||||
tableColumns.put("if_type", new Atom<>("vlan"));
|
||||
tableColumns.put("vlan_id", new Atom<>(vlanId));
|
||||
tableColumns.put("if_name", new Atom<>(vlanIfName));
|
||||
@@ -3170,26 +3132,31 @@ public class OvsdbDao {
|
||||
tableColumns.put("network", new Atom<>(true));
|
||||
tableColumns.put("mtu", new Atom<>(1500));
|
||||
tableColumns.put("dhcp_sniff", new Atom<>(true));
|
||||
tableColumns.put("ip_assign_scheme",new Atom<>(ipAssignScheme));
|
||||
if (ipAssignScheme.equals("static")) {
|
||||
|
||||
tableColumns.put("dns", com.vmware.ovsdb.protocol.operation.notation.Map.of(dns));
|
||||
tableColumns.put("dhcpd", com.vmware.ovsdb.protocol.operation.notation.Map.of(parentDhcpd));
|
||||
if (gateway != null) {
|
||||
tableColumns.put("gateway", new Atom<>(gateway));
|
||||
}
|
||||
if (parentNetmask != null) {
|
||||
tableColumns.put("netmask", new Atom<>(parentNetmask));
|
||||
}
|
||||
if (inet != null) {
|
||||
String[] inetAddrOctets = inet.split("\\.");
|
||||
if (inetAddrOctets.length == 4) {
|
||||
// change the subnet octet to be the vlan
|
||||
tableColumns.put("inet_addr", new Atom<>(
|
||||
inetAddrOctets[0] + "." + inetAddrOctets[1] + "." + vlanId + "." + inetAddrOctets[3]));
|
||||
if (parentWifiInetConfig != null) {
|
||||
tableColumns.put("ip_assign_scheme", new Atom<>(parentWifiInetConfig.ipAssignScheme));
|
||||
if (parentWifiInetConfig.ipAssignScheme.equals("static")) {
|
||||
tableColumns.put("dns",
|
||||
com.vmware.ovsdb.protocol.operation.notation.Map.of(parentWifiInetConfig.dns));
|
||||
tableColumns.put("dhcpd",
|
||||
com.vmware.ovsdb.protocol.operation.notation.Map.of(parentWifiInetConfig.dhcpd));
|
||||
if (parentWifiInetConfig.gateway != null) {
|
||||
tableColumns.put("gateway", new Atom<>(parentWifiInetConfig.gateway));
|
||||
}
|
||||
if (parentWifiInetConfig.netmask != null) {
|
||||
tableColumns.put("netmask", new Atom<>(parentWifiInetConfig.netmask));
|
||||
}
|
||||
if (parentWifiInetConfig.inetAddr != null) {
|
||||
String[] inetAddrOctets = parentWifiInetConfig.inetAddr.split("\\.");
|
||||
if (inetAddrOctets.length == 4) {
|
||||
// change the subnet octet to be the vlan
|
||||
tableColumns.put("inet_addr", new Atom<>(inetAddrOctets[0] + "." + inetAddrOctets[1] + "."
|
||||
+ vlanId + "." + inetAddrOctets[3]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
tableColumns.put("ip_assign_scheme", new Atom<>(ipAssignScheme));
|
||||
}
|
||||
|
||||
Row row = new Row(tableColumns);
|
||||
@@ -3203,8 +3170,8 @@ tableColumns.put("ip_assign_scheme",new Atom<>(ipAssignScheme));
|
||||
operations.add(new Insert(wifiInetConfigDbTable, row));
|
||||
}
|
||||
|
||||
fResult = ovsdbClient.transact(ovsdbName, operations);
|
||||
result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
|
||||
CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations);
|
||||
OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS);
|
||||
|
||||
LOG.debug("Provisioned Vlan {}", vlanId);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.telecominfraproject.wlan.opensync.ovsdb.dao.models;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.vmware.ovsdb.protocol.operation.notation.Uuid;
|
||||
|
||||
public class WifiInetConfigInfo implements Cloneable{
|
||||
@@ -17,22 +19,126 @@ public class WifiInetConfigInfo implements Cloneable{
|
||||
public String inetAddr;
|
||||
public int mtu;
|
||||
public String netmask;
|
||||
public String gateway;
|
||||
public Map<String,String> dns;
|
||||
public Map<String,String> dhcpd;
|
||||
|
||||
|
||||
@Override
|
||||
public WifiInetConfigInfo clone() {
|
||||
try {
|
||||
WifiInetConfigInfo ret = (WifiInetConfigInfo)super.clone();
|
||||
if (dns != null) ret.dns = this.dns;
|
||||
if (dhcpd != null) ret.dhcpd = this.dhcpd;
|
||||
return ret;
|
||||
}catch(CloneNotSupportedException e) {
|
||||
throw new IllegalStateException("Cannot clone ", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"WifiInetConfigInfo [nat=%s, broadcast=%s, enabled=%s, ifName=%s, ifType=%s, ipAssignScheme=%s, network=%s, uuid=%s, inetAddr=%s, mtu=%s, netmask=%s, vlanId=%s]",
|
||||
nat, broadcast, enabled, ifName, ifType, ipAssignScheme, network, uuid,inetAddr, mtu, netmask, vlanId);
|
||||
}
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((broadcast == null) ? 0 : broadcast.hashCode());
|
||||
result = prime * result + ((dhcpd == null) ? 0 : dhcpd.hashCode());
|
||||
result = prime * result + ((dns == null) ? 0 : dns.hashCode());
|
||||
result = prime * result + (enabled ? 1231 : 1237);
|
||||
result = prime * result + ((gateway == null) ? 0 : gateway.hashCode());
|
||||
result = prime * result + ((ifName == null) ? 0 : ifName.hashCode());
|
||||
result = prime * result + ((ifType == null) ? 0 : ifType.hashCode());
|
||||
result = prime * result + ((inetAddr == null) ? 0 : inetAddr.hashCode());
|
||||
result = prime * result + ((ipAssignScheme == null) ? 0 : ipAssignScheme.hashCode());
|
||||
result = prime * result + mtu;
|
||||
result = prime * result + (nat ? 1231 : 1237);
|
||||
result = prime * result + ((netmask == null) ? 0 : netmask.hashCode());
|
||||
result = prime * result + (network ? 1231 : 1237);
|
||||
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
|
||||
result = prime * result + vlanId;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
WifiInetConfigInfo other = (WifiInetConfigInfo) obj;
|
||||
if (broadcast == null) {
|
||||
if (other.broadcast != null)
|
||||
return false;
|
||||
} else if (!broadcast.equals(other.broadcast))
|
||||
return false;
|
||||
if (dhcpd == null) {
|
||||
if (other.dhcpd != null)
|
||||
return false;
|
||||
} else if (!dhcpd.equals(other.dhcpd))
|
||||
return false;
|
||||
if (dns == null) {
|
||||
if (other.dns != null)
|
||||
return false;
|
||||
} else if (!dns.equals(other.dns))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
return false;
|
||||
if (gateway == null) {
|
||||
if (other.gateway != null)
|
||||
return false;
|
||||
} else if (!gateway.equals(other.gateway))
|
||||
return false;
|
||||
if (ifName == null) {
|
||||
if (other.ifName != null)
|
||||
return false;
|
||||
} else if (!ifName.equals(other.ifName))
|
||||
return false;
|
||||
if (ifType == null) {
|
||||
if (other.ifType != null)
|
||||
return false;
|
||||
} else if (!ifType.equals(other.ifType))
|
||||
return false;
|
||||
if (inetAddr == null) {
|
||||
if (other.inetAddr != null)
|
||||
return false;
|
||||
} else if (!inetAddr.equals(other.inetAddr))
|
||||
return false;
|
||||
if (ipAssignScheme == null) {
|
||||
if (other.ipAssignScheme != null)
|
||||
return false;
|
||||
} else if (!ipAssignScheme.equals(other.ipAssignScheme))
|
||||
return false;
|
||||
if (mtu != other.mtu)
|
||||
return false;
|
||||
if (nat != other.nat)
|
||||
return false;
|
||||
if (netmask == null) {
|
||||
if (other.netmask != null)
|
||||
return false;
|
||||
} else if (!netmask.equals(other.netmask))
|
||||
return false;
|
||||
if (network != other.network)
|
||||
return false;
|
||||
if (uuid == null) {
|
||||
if (other.uuid != null)
|
||||
return false;
|
||||
} else if (!uuid.equals(other.uuid))
|
||||
return false;
|
||||
if (vlanId != other.vlanId)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WifiInetConfigInfo [nat=" + nat + ", enabled=" + enabled + ", ifName=" + ifName + ", ifType=" + ifType
|
||||
+ ", ipAssignScheme=" + ipAssignScheme + ", network=" + network + ", uuid=" + uuid + ", vlanId="
|
||||
+ vlanId + ", broadcast=" + broadcast + ", inetAddr=" + inetAddr + ", mtu=" + mtu + ", netmask="
|
||||
+ netmask + ", gateway=" + gateway + ", dns=" + dns + ", dhcpd=" + dhcpd + "]";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user