mirror of
				https://github.com/Telecominfraproject/wlan-cloud-opensync-controller.git
				synced 2025-10-31 02:27:49 +00:00 
			
		
		
		
	Compare commits
	
		
			20 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | dcfefa2adb | ||
|   | 3647fd6bec | ||
|   | 738b2f013e | ||
|   | 55096881f6 | ||
|   | ca40563375 | ||
|   | 0fb70603b4 | ||
|   | c5127e4d8e | ||
|   | dfd7e13399 | ||
|   | b48f340d11 | ||
|   | a520690976 | ||
|   | ec617cb47f | ||
|   | 6b7dcd4878 | ||
|   | 4d919cf21e | ||
|   | 2bf00e82a7 | ||
|   | 9f9e469b17 | ||
|   | 6a75356441 | ||
|   | 40277e3799 | ||
|   | 7e0da1505e | ||
|   | b3a15d06a2 | ||
|   | 66daa8bc60 | 
| @@ -9,7 +9,6 @@ import java.text.DateFormat; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.time.Instant; | ||||
| import java.time.temporal.ChronoField; | ||||
| import java.time.temporal.TemporalField; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.EnumMap; | ||||
| @@ -25,6 +24,7 @@ import java.util.function.Predicate; | ||||
| import java.util.regex.Matcher; | ||||
| import java.util.regex.Pattern; | ||||
| import java.util.stream.Collectors; | ||||
| import java.util.Arrays; | ||||
|  | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| @@ -48,6 +48,7 @@ import com.telecominfraproject.wlan.client.session.models.ClientSession; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails; | ||||
| import com.telecominfraproject.wlan.core.model.entity.CountryCode; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.EquipmentType; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.LedStatus; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.MacAddress; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.RadioType; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.WiFiSessionUtility; | ||||
| @@ -112,7 +113,6 @@ import com.telecominfraproject.wlan.status.equipment.models.EquipmentProtocolSta | ||||
| import com.telecominfraproject.wlan.status.equipment.models.EquipmentUpgradeState; | ||||
| import com.telecominfraproject.wlan.status.equipment.models.EquipmentUpgradeState.FailureReason; | ||||
| import com.telecominfraproject.wlan.status.equipment.models.EquipmentUpgradeStatusData; | ||||
| import com.telecominfraproject.wlan.status.equipment.models.LedStatus; | ||||
| import com.telecominfraproject.wlan.status.equipment.models.VLANStatusData; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs; | ||||
| @@ -120,6 +120,8 @@ import com.telecominfraproject.wlan.status.equipment.report.models.ClientConnect | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.EquipmentScanDetails; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.OperatingSystemPerformance; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.RadioUtilizationReport; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.WiredEthernetPortStatusData; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.WiredPortStatus; | ||||
| import com.telecominfraproject.wlan.status.models.Status; | ||||
| import com.telecominfraproject.wlan.status.models.StatusCode; | ||||
| import com.telecominfraproject.wlan.status.models.StatusDataType; | ||||
| @@ -135,6 +137,10 @@ import sts.OpensyncStats.Report; | ||||
| public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegrationInterface { | ||||
|  | ||||
|     protected static final String standard_linux_date_format = "EEE MMM dd HH:mm:ss zzz yyyy"; | ||||
|     private static final String VLAN_TRUNK_IF_TYPE = "vlan_trunk"; | ||||
|     private static final String ALLOWED_VLANS = "allowed_vlans"; | ||||
|     private static final String NATIVE_VLAN_ID = "pvid"; | ||||
|     private static final String SPACE_SEPERATOR = " "; | ||||
|  | ||||
|     private static final Logger LOG = LoggerFactory.getLogger(OpensyncExternalIntegrationCloud.class); | ||||
|  | ||||
| @@ -186,6 +192,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|     public String defaultWanInterfaceType; | ||||
|     @Value("${tip.wlan.ovsdb.wifi-iface.default_wan_name:wan}") | ||||
|     public String defaultWanInterfaceName; | ||||
|     @Value("${tip.wlan.ovsdb.wifi-iface.default_wan6_name:wan6}") | ||||
|     public String defaultWan6InterfaceName; | ||||
|  | ||||
|     @Value("${tip.wlan.ovsdb.syncUpRadioConfigsForProvisionedEquipment:true}") | ||||
|     private boolean syncUpRadioConfigsForProvisionedEquipment; | ||||
| @@ -1010,6 +1018,10 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|             ret.setRfProfile(profileContainer.getChildOfTypeOrNull(equipmentConfig.getProfileId(), ProfileType.rf)); | ||||
|  | ||||
|             ret.setSsidProfile(profileContainer.getChildrenOfType(equipmentConfig.getProfileId(), ProfileType.ssid)); | ||||
|              | ||||
| 			ret.setWiredEthernetPortProfile( | ||||
| 					profileContainer.getChildOfTypeOrNullByEquipmentModel(equipmentConfig.getProfileId(), | ||||
| 							ProfileType.wired_ethernet_port, equipmentConfig.getDetails().getEquipmentModel())); | ||||
|  | ||||
|             ret.setMetricsProfiles(profileContainer.getChildrenOfType(equipmentConfig.getProfileId(), ProfileType.service_metrics_collection_config)); | ||||
|  | ||||
| @@ -1140,7 +1152,8 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             LOG.debug("Values from Vif State Mac (BSSID) {} SSID {} AssociatedClients {} Channel {}", bssid, ssid, vifState.getAssociatedClients()); | ||||
|             LOG.debug("Values from Vif State Mac (BSSID) {} SSID {} AssociatedClients {} Channel {}", bssid, ssid, | ||||
|                     vifState.getAssociatedClients(), channel); | ||||
|  | ||||
|             RadioType radioType = null; | ||||
|             Map<RadioType, RfElementConfiguration> rfElementMap = rfConfig.getRfConfigMap(); | ||||
| @@ -1392,7 +1405,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|             apElementConfiguration.getRadioMap().get(radioState.getFreqBand()).setAllowedChannelsPowerLevels(channelPowerLevels); | ||||
|         } | ||||
|  | ||||
|         LOG.debug("Updated AllowedChannels from Wifi_Radio_State table change for AP {}", apId); | ||||
|         LOG.debug("Updated AllowedChannels from Wifi_Radio_State table change for AP {} configStateMismatch {}", apId, configStateMismatch); | ||||
|         return configStateMismatch; | ||||
|     } | ||||
|  | ||||
| @@ -1449,7 +1462,7 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|     public void wifiInetStateDbTableUpdate(List<OpensyncAPInetState> inetStateTables, String apId) { | ||||
|  | ||||
|         LOG.debug("Received Wifi_Inet_State table update for AP {}", apId); | ||||
|  | ||||
|          | ||||
|         OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); | ||||
|  | ||||
|         if (ovsdbSession == null) { | ||||
| @@ -1492,26 +1505,48 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|         } | ||||
|  | ||||
|         EquipmentProtocolStatusData protocolStatusData = (EquipmentProtocolStatusData) protocolStatus.getDetails(); | ||||
|          | ||||
|         Status ethernetPortStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.WIRED_ETHERNET_PORT); | ||||
|         if (ethernetPortStatus == null) { | ||||
|         	ethernetPortStatus = new Status(); | ||||
|         	ethernetPortStatus.setCustomerId(customerId); | ||||
|         	ethernetPortStatus.setEquipmentId(equipmentId); | ||||
|         	ethernetPortStatus.setStatusDataType(StatusDataType.WIRED_ETHERNET_PORT); | ||||
|         	ethernetPortStatus.setDetails(new WiredEthernetPortStatusData()); | ||||
|         	ethernetPortStatus = statusServiceInterface.update(ethernetPortStatus); | ||||
|         } | ||||
|          | ||||
|         WiredEthernetPortStatusData ethernetPortStatusData = (WiredEthernetPortStatusData) ethernetPortStatus.getDetails();	 | ||||
|         Map<String, List<WiredPortStatus>> portStatus = ethernetPortStatusData.getInterfacePortStatusMap(); | ||||
|  | ||||
|         for (OpensyncAPInetState inetState : inetStateTables) { | ||||
| 		for (OpensyncAPInetState inetState : inetStateTables) { | ||||
| 			if (inetState.ifName != null) { | ||||
| 				parseRawDataToWiredPortStatus(customerId, equipmentId, portStatus, inetState); | ||||
| 				ethernetPortStatusData.setInterfacePortStatusMap(portStatus); | ||||
| 				ethernetPortStatus.setDetails(ethernetPortStatusData); | ||||
| 				ethernetPortStatus = statusServiceInterface.update(ethernetPortStatus); | ||||
| 				LOG.debug("EthernetPortStatus for AP {} updated to {}", apId, ethernetPortStatus); | ||||
| 			} | ||||
|  | ||||
|             if (inetState.ifName != null && inetState.ifName.equals(defaultWanInterfaceName)) { | ||||
| 			if (inetState.ifName != null && inetState.ifName.equals(defaultWanInterfaceName)) { | ||||
|  | ||||
|                 if (inetState.inetAddr != null) { | ||||
|                     try { | ||||
|                         protocolStatusData.setReportedIpV4Addr(Inet4Address.getByName(inetState.inetAddr)); | ||||
|                         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); | ||||
|                         LOG.debug("ProtocolStatus for AP {} updated to {}", apId, protocolStatus); | ||||
| 				if (inetState.inetAddr != null) { | ||||
| 					try { | ||||
| 						protocolStatusData.setReportedIpV4Addr(Inet4Address.getByName(inetState.inetAddr)); | ||||
| 						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); | ||||
| 						LOG.debug("ProtocolStatus for AP {} updated to {}", apId, protocolStatus); | ||||
|  | ||||
|                     } catch (UnknownHostException e) { | ||||
|                         LOG.error("Could not set IpV4Addr {} on AP {} due to UnknownHostException ", inetState.inetAddr, apId, e); | ||||
|                     } | ||||
|                 } | ||||
| 					} catch (UnknownHostException e) { | ||||
| 						LOG.error("Could not set IpV4Addr {} on AP {} due to UnknownHostException ", inetState.inetAddr, | ||||
| 								apId, e); | ||||
| 					} | ||||
| 				} | ||||
|  | ||||
|             } | ||||
| 			} | ||||
|  | ||||
|             if (inetState.getIfType().equals("vlan") && inetState.parentIfName != null && inetState.parentIfName.equals(defaultWanInterfaceName)) { | ||||
|  | ||||
| @@ -1565,13 +1600,122 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void wifiInetStateDbTableDelete(List<OpensyncAPInetState> inetStateTables, String apId) { | ||||
| 	protected void parseRawDataToWiredPortStatus(int customerId, long equipmentId, | ||||
| 			Map<String, List<WiredPortStatus>> portStatus, OpensyncAPInetState inetState) { | ||||
|         LOG.debug("Entering parseRawDataToWiredPortStatus for Customer {}, Equipment {} with inetState {}", | ||||
|                 customerId, equipmentId, inetState); | ||||
|         List<WiredPortStatus> ports = new ArrayList<>(); | ||||
|         inetState.ethPorts.forEach((key, ethPort) -> { | ||||
|             try { | ||||
|                 // Raw data from AP example: ethPorts={eth1=up wan 1000Mbps full} | ||||
|                 String[] ethPortsValues = ethPort.split(SPACE_SEPERATOR); | ||||
|                 List<Integer> allowedVlans = getAllowedVlans(inetState.getVlanTrunk()); | ||||
|  | ||||
|         LOG.debug("Received Wifi_Inet_State table delete for AP {}", apId); | ||||
|                 if (ethPortsValues.length == 4 && inetState.getIfType() != null) { | ||||
|                     int speed = Integer.parseInt(ethPortsValues[2].replaceAll("[^0-9]", "")); | ||||
|                     boolean isTrunkEnabled = VLAN_TRUNK_IF_TYPE.equalsIgnoreCase(inetState.getIfType()); | ||||
|  | ||||
|                     int vlanId = inetState.getVlanId(); | ||||
|                     if (isTrunkEnabled) { | ||||
|                         vlanId = getNativeVlanIdForTrunk(inetState.getVlanTrunk()); | ||||
|                     } | ||||
|  | ||||
|                     WiredPortStatus wps = new WiredPortStatus(key, ethPortsValues[1], inetState.getIfName(), | ||||
|                             inetState.getIfType(), speed, ethPortsValues[3], ethPortsValues[0], vlanId, | ||||
|                             isTrunkEnabled, allowedVlans); | ||||
|                      | ||||
|                     ports.add(wps); | ||||
|                 } else { | ||||
|                     LOG.error("EthPorts doesn't have enough raw data for CustomerId {} or EquipmentId {}", customerId, | ||||
|                             equipmentId); | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
|                 LOG.error("CustomerId {} or EquipmentId {} has error when parsing raw data to WiredPortStatus: {}", | ||||
|                         customerId, equipmentId, e); | ||||
|             } | ||||
|         }); | ||||
|         addToPortStatus(portStatus, inetState.getIfName(), ports); | ||||
|     } | ||||
|  | ||||
|     // Raw data from AP example: ["allowed_vlans": " 100  200  300 "] | ||||
|     // convert to List of Integer | ||||
| 	private List<Integer> getAllowedVlans(Map<String, String> vlanTrunk) { | ||||
| 		List<Integer> allowedVlans = new ArrayList<>(); | ||||
| 		try { | ||||
| 			if (!vlanTrunk.isEmpty() && vlanTrunk.get(ALLOWED_VLANS) != null | ||||
| 					&& !Objects.equals(vlanTrunk.get(ALLOWED_VLANS), "")) { | ||||
| 				List<String> allowedVlansStringList = Arrays.asList(vlanTrunk.get(ALLOWED_VLANS).trim().split("\\s+")); | ||||
| 				for (String allowedVlan : allowedVlansStringList) { | ||||
| 					allowedVlans.add(Integer.parseInt(allowedVlan)); | ||||
| 				} | ||||
| 			} | ||||
| 		} catch (Exception ex) { | ||||
| 			LOG.error("Unable to parse the allowed vlans from the vlanTrunk. Returning empty AllowedVlanList", ex); | ||||
| 		} | ||||
| 		LOG.debug("Returning allowed Vlans {}", allowedVlans); | ||||
| 		return allowedVlans; | ||||
| 	} | ||||
|  | ||||
|     private int getNativeVlanIdForTrunk(Map<String, String> vlanTrunk) { | ||||
|         int nativeVlanId = 0; | ||||
|         if (!vlanTrunk.isEmpty() && vlanTrunk.get(NATIVE_VLAN_ID) != null && | ||||
|                 !Objects.equals(vlanTrunk.get(NATIVE_VLAN_ID), "")) { | ||||
|             nativeVlanId = Integer.parseInt(vlanTrunk.get(NATIVE_VLAN_ID)); | ||||
|         } | ||||
|         return nativeVlanId; | ||||
|     } | ||||
|  | ||||
| 	private void addToPortStatus(Map<String, List<WiredPortStatus>> portStatus, String ifName, | ||||
| 			List<WiredPortStatus> ports) { | ||||
| 		portStatus.put(ifName, ports); | ||||
| 		LOG.debug("Returning addToPortStatus with portStatus {}", portStatus); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void wifiInetStateDbTableDelete(List<OpensyncAPInetState> inetStateTables, String apId) { | ||||
|  | ||||
| 		LOG.debug("Received Wifi_Inet_State table delete for AP {}", apId); | ||||
|  | ||||
| 		OvsdbSession ovsdbSession = ovsdbSessionMapInterface.getSession(apId); | ||||
|  | ||||
| 		if (ovsdbSession == null) { | ||||
| 			LOG.debug("wifiInetStateDbTableDelete::Cannot get Session for AP {}", apId); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		long equipmentId = ovsdbSession.getEquipmentId(); | ||||
| 		Equipment ce = equipmentServiceInterface.getOrNull(equipmentId); | ||||
| 		if (ce == null) { | ||||
| 			LOG.debug("wifiInetStateDbTableDelete Cannot get customer Equipment for {}", apId); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		int customerId = ce.getCustomerId(); | ||||
| 		if ((customerId < 0) || (equipmentId < 0)) { | ||||
| 			LOG.debug("wifiInetStateDbTableUpdate::Cannot get valid CustomerId {} or EquipmentId {} for AP {}", | ||||
| 					customerId, equipmentId, apId); | ||||
| 			return; | ||||
| 		} | ||||
|  | ||||
| 		Status ethernetPortStatus = statusServiceInterface.getOrNull(customerId, equipmentId, | ||||
| 				StatusDataType.WIRED_ETHERNET_PORT); | ||||
| 		if (ethernetPortStatus != null) { | ||||
| 			WiredEthernetPortStatusData ethernetPortStatusData = (WiredEthernetPortStatusData) ethernetPortStatus | ||||
| 					.getDetails(); | ||||
| 			Map<String, List<WiredPortStatus>> portStatus = ethernetPortStatusData.getInterfacePortStatusMap(); | ||||
|  | ||||
| 			for (OpensyncAPInetState inetState : inetStateTables) { | ||||
|  | ||||
| 				portStatus.remove(inetState.getIfName()); | ||||
| 				ethernetPortStatusData.setInterfacePortStatusMap(portStatus); | ||||
| 				ethernetPortStatus.setDetails(ethernetPortStatusData); | ||||
| 				ethernetPortStatus = statusServiceInterface.update(ethernetPortStatus); | ||||
| 				LOG.debug("Deleted ifName {} from the AP {}. EthernetPortStatus after deletion{}", | ||||
| 						inetState.getIfName(), apId, ethernetPortStatus); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|     @Override | ||||
|     public void wifiAssociatedClientsDbTableUpdate(List<OpensyncWifiAssociatedClients> wifiAssociatedClients, String apId) { | ||||
|  | ||||
| @@ -2438,18 +2582,20 @@ public class OpensyncExternalIntegrationCloud implements OpensyncExternalIntegra | ||||
|  | ||||
|         Status eqAdminStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.EQUIPMENT_ADMIN); | ||||
|  | ||||
|         LedStatus ledStatus = null; | ||||
|         for (Map<String, String> nsa : nodeStateAttributes) { | ||||
|             if (nsa.get("module").equals("led")) { | ||||
|                 if (nsa.get("key").equals("led_blink") && nsa.get("value").equals("on")) { | ||||
|                     ledStatus = LedStatus.led_blink; | ||||
|                 } else if (nsa.get("key").equals("led_off") && nsa.get("value").equals("off")) { | ||||
|                     ledStatus = LedStatus.led_off; | ||||
|                 } else { | ||||
|                     ledStatus = LedStatus.UNKNOWN; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 		LedStatus ledStatus = null; | ||||
| 		for (Map<String, String> nsa : nodeStateAttributes) { | ||||
| 			if (nsa.get("module").equals("led")) { | ||||
| 				if (nsa.get("key").equals("led_state") && nsa.get("value").equals("on")) { | ||||
| 					ledStatus = LedStatus.led_on; | ||||
| 				} else if (nsa.get("key").equals("led_state") && nsa.get("value").equals("off")) { | ||||
| 					ledStatus = LedStatus.led_off; | ||||
| 				} else if (nsa.get("key").equals("led_blink")) { | ||||
| 					ledStatus = LedStatus.led_blink; | ||||
| 				} else { | ||||
| 					ledStatus = LedStatus.UNKNOWN; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
|         if (ledStatus != null) { | ||||
|             if (eqAdminStatus != null) { | ||||
|   | ||||
| @@ -25,7 +25,6 @@ import org.springframework.security.web.bind.annotation.AuthenticationPrincipal; | ||||
| import org.springframework.web.bind.annotation.RequestBody; | ||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||
| import org.springframework.web.bind.annotation.RequestMethod; | ||||
| import org.springframework.web.bind.annotation.RequestParam; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
|  | ||||
| import com.telecominfraproject.wlan.core.client.PingClient; | ||||
| @@ -51,7 +50,6 @@ import com.telecominfraproject.wlan.equipmentgateway.models.CEGWRebootRequest; | ||||
| import com.telecominfraproject.wlan.equipmentgateway.models.CEGWRouteCheck; | ||||
| import com.telecominfraproject.wlan.equipmentgateway.models.CEGWStartDebugEngine; | ||||
| import com.telecominfraproject.wlan.equipmentgateway.models.CEGWStopDebugEngine; | ||||
| import com.telecominfraproject.wlan.equipmentgateway.models.CEGatewayCommand; | ||||
| import com.telecominfraproject.wlan.equipmentgateway.models.EquipmentCommand; | ||||
| import com.telecominfraproject.wlan.equipmentgateway.models.EquipmentCommandResponse; | ||||
| import com.telecominfraproject.wlan.equipmentgateway.models.GatewayDefaults; | ||||
|   | ||||
| @@ -0,0 +1,365 @@ | ||||
| package com.telecominfraproject.wlan.opensync.external.integration.utils; | ||||
|  | ||||
| import java.net.Inet4Address; | ||||
| import java.net.Inet6Address; | ||||
| import java.net.InetAddress; | ||||
| import java.net.UnknownHostException; | ||||
| import java.util.List; | ||||
| import java.util.concurrent.TimeUnit; | ||||
|  | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.scheduling.annotation.Async; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import com.google.common.base.Objects; | ||||
| import com.google.protobuf.ByteString; | ||||
| import com.telecominfraproject.wlan.client.ClientServiceInterface; | ||||
| import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails; | ||||
| import com.telecominfraproject.wlan.client.session.models.AssociationState; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientDhcpDetails; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientSession; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails; | ||||
| import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.MacAddress; | ||||
| import com.telecominfraproject.wlan.opensync.util.OvsdbToWlanCloudTypeMappingUtility; | ||||
| import com.telecominfraproject.wlan.servicemetric.models.ServiceMetric; | ||||
|  | ||||
| import sts.OpensyncStats.AssocType; | ||||
| import sts.OpensyncStats.DeviceType; | ||||
| import sts.OpensyncStats.EventReport; | ||||
| import sts.OpensyncStats.FrameType; | ||||
| import sts.OpensyncStats.Report; | ||||
| import sts.OpensyncStats.EventReport.ClientAssocEvent; | ||||
| import sts.OpensyncStats.EventReport.ClientAuthEvent; | ||||
| import sts.OpensyncStats.EventReport.ClientDisconnectEvent; | ||||
| import sts.OpensyncStats.EventReport.ClientIpEvent; | ||||
|  | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| /*** | ||||
|  * MqttStatsPublisher will use this class to publish Stats and Events asynchronously. | ||||
|  * We use async to decrease the processing time for the gateway. | ||||
|  *  | ||||
|  * Note: @Async only applies on public method and cannot have self-invocation (i.e. cannot | ||||
|  * calling the async method from within the same class) | ||||
|  */ | ||||
| @Service | ||||
| public class AsyncPublishService { | ||||
| 	 | ||||
| 	private static final Logger LOG = LoggerFactory.getLogger(MqttStatsPublisher.class); | ||||
| 	 | ||||
|     @Autowired | ||||
|     private CloudEventDispatcherInterface cloudEventDispatcherInterface; | ||||
|      | ||||
|     @Autowired | ||||
|     private RealtimeEventPublisher realtimeEventPublisher; | ||||
|      | ||||
|     @Autowired | ||||
|     private ClientServiceInterface clientServiceInterface; | ||||
|      | ||||
|      | ||||
|     @Async | ||||
|     public void asyncPublishStats(String apId, List<ServiceMetric> metricRecordList) { | ||||
|         try { | ||||
|             long publishStart = System.nanoTime(); | ||||
|             cloudEventDispatcherInterface.publishMetrics(metricRecordList); | ||||
|             long publishStop = System.nanoTime(); | ||||
|             if (LOG.isDebugEnabled()) | ||||
|                 LOG.debug("Elapsed publishing time for metrics records from AP {} is {} milliseconds", apId, | ||||
|                         TimeUnit.MILLISECONDS.convert(publishStop - publishStart, TimeUnit.NANOSECONDS)); | ||||
|         } catch (Exception e) { | ||||
|             LOG.error("Exception when trying to publishServiceMetrics.", e); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Async | ||||
|     public void asyncPublishEvents(Report report, int customerId, long equipmentId, String apId, long locationId) { | ||||
|         try { | ||||
|             long mqttEventsStart = System.nanoTime(); | ||||
|             publishEvents(report, customerId, equipmentId, apId, locationId); | ||||
|             long mqttEventsStop = System.nanoTime(); | ||||
|             if (LOG.isDebugEnabled()) | ||||
|                 LOG.debug("Elapsed publishing time for mqtt events from AP {} is {} milliseconds", apId, | ||||
|                         TimeUnit.MILLISECONDS.convert(mqttEventsStop - mqttEventsStart, TimeUnit.NANOSECONDS)); | ||||
|         } catch (Exception e) { | ||||
|             LOG.error("Exception when trying to publishEvents.", e); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     void publishEvents(Report report, int customerId, long equipmentId, String apId, long locationId) { | ||||
|  | ||||
|         realtimeEventPublisher.publishSipCallEvents(customerId, equipmentId, locationId, report.getVideoVoiceReportList()); | ||||
|  | ||||
|         for (EventReport eventReport : report.getEventReportList()) { | ||||
|  | ||||
|             for (sts.OpensyncStats.EventReport.ClientSession apEventClientSession : eventReport.getClientSessionList()) { | ||||
|  | ||||
|                 LOG.debug("Processing EventReport::ClientSession for AP {}", apId); | ||||
|                 // for the following MQTT events, the client/client session is first updated, then the real time event | ||||
|                 // is published. | ||||
|                 if (apEventClientSession.hasClientAuthEvent()) { | ||||
|                     processClientAuthEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|                 if (apEventClientSession.hasClientAssocEvent()) { | ||||
|                     processClientAssocEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|                 if (apEventClientSession.hasClientIpEvent()) { | ||||
|                     processClientIpEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|                 if (apEventClientSession.hasClientDisconnectEvent()) { | ||||
|                     processClientDisconnectEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|             } | ||||
|             realtimeEventPublisher.publishChannelHopEvents(customerId, equipmentId, locationId, eventReport); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|      | ||||
|     private void processClientAuthEvent(int customerId, long equipmentId, long locationId, sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientAuthEvent apClientEvent = apEventClientSession.getClientAuthEvent(); | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|  | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorEquipmentId() == null) { | ||||
|             clientSession.getDetails().setPriorEquipmentId(clientSession.getEquipmentId()); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         clientSession.getDetails().setSsid(apClientEvent.getSsid()); | ||||
|         if (apClientEvent.hasAuthStatus()) { | ||||
|             clientSession.getDetails().setAssociationStatus(apClientEvent.getAuthStatus()); | ||||
|         } | ||||
|         clientSession.getDetails().setAuthTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession.getDetails().setAssociationState(AssociationState._802_11_Authenticated); | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|  | ||||
|         realtimeEventPublisher.publishClientAuthSystemEvent(customerId, equipmentId, locationId, apEventClientSession.getClientAuthEvent()); | ||||
|  | ||||
|     } | ||||
|      | ||||
|     private void processClientAssocEvent(int customerId, long equipmentId, long locationId, | ||||
|             sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientAssocEvent apClientEvent = apEventClientSession.getClientAssocEvent(); | ||||
|  | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|  | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorEquipmentId() == null) { | ||||
|             clientSession.getDetails().setPriorEquipmentId(clientSession.getEquipmentId()); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         clientSession.getDetails().setSsid(apClientEvent.getSsid()); | ||||
|         if (apClientEvent.hasStatus()) { | ||||
|             clientSession.getDetails().setAssociationStatus(apClientEvent.getStatus()); | ||||
|         } | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         if (apClientEvent.hasUsing11K()) { | ||||
|             clientSession.getDetails().setIs11KUsed(apClientEvent.getUsing11K()); | ||||
|         } | ||||
|         if (apClientEvent.hasUsing11R()) { | ||||
|             clientSession.getDetails().setIs11RUsed(apClientEvent.getUsing11R()); | ||||
|         } | ||||
|         if (apClientEvent.hasUsing11V()) { | ||||
|             clientSession.getDetails().setIs11VUsed(apClientEvent.getUsing11V()); | ||||
|         } | ||||
|         if (apClientEvent.hasAssocType()) { | ||||
|             clientSession.getDetails().setIsReassociation(apClientEvent.getAssocType().equals(AssocType.REASSOC)); | ||||
|         } | ||||
|         if (apClientEvent.hasRssi()) { | ||||
|             clientSession.getDetails().setAssocRssi(apClientEvent.getRssi()); | ||||
|         } | ||||
|         if (apClientEvent.hasInternalSc()) { | ||||
|             clientSession.getDetails().setAssocInternalSC(apClientEvent.getInternalSc()); | ||||
|         } | ||||
|         clientSession.getDetails().setAssocTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession.getDetails().setAssociationState(AssociationState._802_11_Associated); | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|         realtimeEventPublisher.publishClientAssocEvent(customerId, equipmentId, locationId, apEventClientSession.getClientAssocEvent()); | ||||
|  | ||||
|     } | ||||
|      | ||||
|     private void processClientIpEvent(int customerId, long equipmentId, long locationId, sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientIpEvent apClientEvent = apEventClientSession.getClientIpEvent(); | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|         client = clientServiceInterface.update(client); | ||||
|  | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorEquipmentId() == null) { | ||||
|             clientSession.getDetails().setPriorEquipmentId(clientSession.getEquipmentId()); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         if (apClientEvent.hasIpAddr()) { | ||||
|             ByteString ipAddress = apClientEvent.getIpAddr(); | ||||
|             if (ipAddress != null) { | ||||
|                 try { | ||||
|                     InetAddress inetAddress = InetAddress.getByAddress(ipAddress.toByteArray()); | ||||
|                     if (inetAddress instanceof Inet4Address) { | ||||
|                         clientSession.getDetails().setIpAddress(inetAddress); | ||||
|                     } else if (inetAddress instanceof Inet6Address) { | ||||
|                         clientSession.getDetails().setIpAddress(inetAddress); | ||||
|                     } else { | ||||
|                         LOG.error("Invalid IP Address {}", ipAddress); | ||||
|                     } | ||||
|                     clientSession.getDetails().setIpTimestamp(apClientEvent.getTimestampMs()); | ||||
|  | ||||
|                 } catch (UnknownHostException ex) { | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|         realtimeEventPublisher.publishClientIpEvent(customerId, equipmentId, locationId, apEventClientSession.getClientIpEvent()); | ||||
|     } | ||||
|      | ||||
|     private void processClientDisconnectEvent(int customerId, long equipmentId, long locationId, | ||||
|             sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientDisconnectEvent apClientEvent = apEventClientSession.getClientDisconnectEvent(); | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|  | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         clientSession.getDetails().setSsid(apClientEvent.getSsid()); | ||||
|         if (apClientEvent.hasDevType()) { | ||||
|             if (apClientEvent.getDevType().equals(DeviceType.DEV_AP)) { | ||||
|                 clientSession.getDetails().setDisconnectByApTimestamp(apClientEvent.getTimestampMs()); | ||||
|                 if (apClientEvent.hasInternalRc()) { | ||||
|                     clientSession.getDetails().setDisconnectByApInternalReasonCode(apClientEvent.getInternalRc()); | ||||
|                 } | ||||
|                 if (apClientEvent.hasReason()) { | ||||
|                     clientSession.getDetails().setDisconnectByApReasonCode(apClientEvent.getReason()); | ||||
|                 } | ||||
|             } else { | ||||
|                 clientSession.getDetails().setDisconnectByClientTimestamp(apClientEvent.getTimestampMs()); | ||||
|                 if (apClientEvent.hasInternalRc()) { | ||||
|                     clientSession.getDetails().setDisconnectByClientInternalReasonCode(apClientEvent.getInternalRc()); | ||||
|                 } | ||||
|                 if (apClientEvent.hasReason()) { | ||||
|                     clientSession.getDetails().setDisconnectByClientReasonCode(apClientEvent.getReason()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if (apClientEvent.hasFrType()) { | ||||
|             if (apClientEvent.getFrType().equals(FrameType.FT_DEAUTH)) { | ||||
|             } | ||||
|             if (apClientEvent.getFrType().equals(FrameType.FT_DISASSOC)) { | ||||
|             } | ||||
|         } | ||||
|         if (apClientEvent.hasRssi()) { | ||||
|             clientSession.getDetails().setAssocRssi(apClientEvent.getRssi()); | ||||
|         } | ||||
|         if (apClientEvent.hasLrcvUpTsInUs()) { | ||||
|             clientSession.getDetails().setLastRxTimestamp(apClientEvent.getLrcvUpTsInUs()); | ||||
|         } | ||||
|         if (apClientEvent.hasLsentUpTsInUs()) { | ||||
|             clientSession.getDetails().setLastTxTimestamp(apClientEvent.getLsentUpTsInUs()); | ||||
|         } | ||||
|         clientSession.getDetails().setAssociationState(AssociationState.Disconnected); | ||||
|         clientSession.getDetails().setAssocTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|         realtimeEventPublisher.publishClientDisconnectEvent(customerId, equipmentId, locationId, apEventClientSession.getClientDisconnectEvent()); | ||||
|  | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,8 +1,7 @@ | ||||
|  | ||||
|  | ||||
| package com.telecominfraproject.wlan.opensync.external.integration.utils; | ||||
|  | ||||
| import java.net.Inet4Address; | ||||
| import java.net.Inet6Address; | ||||
| import java.net.InetAddress; | ||||
| import java.net.UnknownHostException; | ||||
| import java.util.ArrayList; | ||||
| @@ -22,20 +21,12 @@ import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| import com.google.common.base.Objects; | ||||
| import com.google.protobuf.ByteString; | ||||
| import com.telecominfraproject.wlan.alarm.AlarmServiceInterface; | ||||
| import com.telecominfraproject.wlan.alarm.models.Alarm; | ||||
| import com.telecominfraproject.wlan.alarm.models.AlarmCode; | ||||
| import com.telecominfraproject.wlan.alarm.models.AlarmDetails; | ||||
| import com.telecominfraproject.wlan.alarm.models.AlarmScopeType; | ||||
| import com.telecominfraproject.wlan.alarm.models.OriginatorType; | ||||
| import com.telecominfraproject.wlan.client.ClientServiceInterface; | ||||
| import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails; | ||||
| import com.telecominfraproject.wlan.client.session.models.AssociationState; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientDhcpDetails; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientSession; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails; | ||||
| import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.ChannelBandwidth; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.DetectedAuthMode; | ||||
| @@ -85,19 +76,11 @@ import com.telecominfraproject.wlan.status.models.StatusDataType; | ||||
| import com.telecominfraproject.wlan.status.network.models.NetworkAdminStatusData; | ||||
| import com.telecominfraproject.wlan.systemevent.models.SystemEvent; | ||||
|  | ||||
| import sts.OpensyncStats.AssocType; | ||||
| import sts.OpensyncStats.Client; | ||||
| import sts.OpensyncStats.ClientReport; | ||||
| import sts.OpensyncStats.DNSProbeMetric; | ||||
| import sts.OpensyncStats.Device; | ||||
| import sts.OpensyncStats.Device.RadioTemp; | ||||
| import sts.OpensyncStats.DeviceType; | ||||
| import sts.OpensyncStats.EventReport; | ||||
| import sts.OpensyncStats.EventReport.ClientAssocEvent; | ||||
| import sts.OpensyncStats.EventReport.ClientAuthEvent; | ||||
| import sts.OpensyncStats.EventReport.ClientDisconnectEvent; | ||||
| import sts.OpensyncStats.EventReport.ClientIpEvent; | ||||
| import sts.OpensyncStats.FrameType; | ||||
| import sts.OpensyncStats.Neighbor; | ||||
| import sts.OpensyncStats.Neighbor.NeighborBss; | ||||
| import sts.OpensyncStats.NetworkProbe; | ||||
| @@ -124,13 +107,11 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|     @Autowired | ||||
|     private StatusServiceInterface statusServiceInterface; | ||||
|     @Autowired | ||||
|     private ClientServiceInterface clientServiceInterface; | ||||
|     @Autowired | ||||
|     private CloudEventDispatcherInterface cloudEventDispatcherInterface; | ||||
|     @Autowired | ||||
|     private RealtimeEventPublisher realtimeEventPublisher; | ||||
|     @Autowired | ||||
|     private AlarmServiceInterface alarmServiceInterface; | ||||
|     @Autowired | ||||
|     private AsyncPublishService asyncPublishService; | ||||
|  | ||||
|     @Value("${tip.wlan.mqttStatsPublisher.temperatureThresholdInC:80}") | ||||
|     private int temperatureThresholdInC; | ||||
| @@ -148,7 +129,6 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|     public int statsTimeDriftThresholdSec; | ||||
|  | ||||
|     @Override | ||||
|      | ||||
|     public void processMqttMessage(String topic, Report report) { | ||||
|         // Numerous try/catch blocks to address situations where logs are not being reported due to corrupt or invalid | ||||
|         // data in mqtt stats causing a crash | ||||
| @@ -256,28 +236,12 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|  | ||||
|             }); | ||||
|  | ||||
|             try { | ||||
|                 long publishStart = System.nanoTime(); | ||||
|                 cloudEventDispatcherInterface.publishMetrics(metricRecordList); | ||||
|                 long publishStop = System.nanoTime(); | ||||
|                 if (LOG.isDebugEnabled()) | ||||
|                     LOG.debug("Elapsed publishing time for metrics records from AP {} is {} milliseconds", apId, | ||||
|                             TimeUnit.MILLISECONDS.convert(publishStop - publishStart, TimeUnit.NANOSECONDS)); | ||||
|             } catch (Exception e) { | ||||
|                 LOG.error("Exception when trying to publishServiceMetrics.", e); | ||||
|             } | ||||
|             // Make it asynchronous to decrease processing time | ||||
|             asyncPublishService.asyncPublishStats(apId, metricRecordList); | ||||
|         } | ||||
|  | ||||
|         try { | ||||
|             long mqttEventsStart = System.nanoTime(); | ||||
|             publishEvents(report, customerId, equipmentId, apId, locationId); | ||||
|             long mqttEventsStop = System.nanoTime(); | ||||
|             if (LOG.isDebugEnabled()) | ||||
|                 LOG.debug("Elapsed publishing time for mqtt events from AP {} is {} milliseconds", apId, | ||||
|                         TimeUnit.MILLISECONDS.convert(mqttEventsStop - mqttEventsStart, TimeUnit.NANOSECONDS)); | ||||
|         } catch (Exception e) { | ||||
|             LOG.error("Exception when trying to publishEvents.", e); | ||||
|         } | ||||
|         // Make it asynchronous to decrease processing time | ||||
|         asyncPublishService.asyncPublishEvents(report, customerId, equipmentId, apId, locationId); | ||||
|  | ||||
|         try { | ||||
|             long endTime = System.nanoTime(); | ||||
| @@ -302,288 +266,13 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|  | ||||
|         LOG.info("processMqttMessage for {} complete", topic); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     @Override | ||||
|     public void publishSystemEventFromTableStateMonitor(SystemEvent event) { | ||||
|         LOG.info("Publishing SystemEvent received by TableStateMonitor {}", event); | ||||
|         cloudEventDispatcherInterface.publishEvent(event); | ||||
|     } | ||||
|  | ||||
|     void publishEvents(Report report, int customerId, long equipmentId, String apId, long locationId) { | ||||
|  | ||||
|         realtimeEventPublisher.publishSipCallEvents(customerId, equipmentId, locationId, report.getVideoVoiceReportList()); | ||||
|  | ||||
|         for (EventReport eventReport : report.getEventReportList()) { | ||||
|  | ||||
|             for (sts.OpensyncStats.EventReport.ClientSession apEventClientSession : eventReport.getClientSessionList()) { | ||||
|  | ||||
|                 LOG.debug("Processing EventReport::ClientSession for AP {}", apId); | ||||
|                 // for the following MQTT events, the client/client session is first updated, then the real time event | ||||
|                 // is published. | ||||
|                 if (apEventClientSession.hasClientAuthEvent()) { | ||||
|                     processClientAuthEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|                 if (apEventClientSession.hasClientAssocEvent()) { | ||||
|                     processClientAssocEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|                 if (apEventClientSession.hasClientIpEvent()) { | ||||
|                     processClientIpEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|                 if (apEventClientSession.hasClientDisconnectEvent()) { | ||||
|                     processClientDisconnectEvent(customerId, equipmentId, locationId, apEventClientSession); | ||||
|                 } | ||||
|             } | ||||
|             realtimeEventPublisher.publishChannelHopEvents(customerId, equipmentId, locationId, eventReport); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     protected void processClientDisconnectEvent(int customerId, long equipmentId, long locationId, | ||||
|             sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientDisconnectEvent apClientEvent = apEventClientSession.getClientDisconnectEvent(); | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|  | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         clientSession.getDetails().setSsid(apClientEvent.getSsid()); | ||||
|         if (apClientEvent.hasDevType()) { | ||||
|             if (apClientEvent.getDevType().equals(DeviceType.DEV_AP)) { | ||||
|                 clientSession.getDetails().setDisconnectByApTimestamp(apClientEvent.getTimestampMs()); | ||||
|                 if (apClientEvent.hasInternalRc()) { | ||||
|                     clientSession.getDetails().setDisconnectByApInternalReasonCode(apClientEvent.getInternalRc()); | ||||
|                 } | ||||
|                 if (apClientEvent.hasReason()) { | ||||
|                     clientSession.getDetails().setDisconnectByApReasonCode(apClientEvent.getReason()); | ||||
|                 } | ||||
|             } else { | ||||
|                 clientSession.getDetails().setDisconnectByClientTimestamp(apClientEvent.getTimestampMs()); | ||||
|                 if (apClientEvent.hasInternalRc()) { | ||||
|                     clientSession.getDetails().setDisconnectByClientInternalReasonCode(apClientEvent.getInternalRc()); | ||||
|                 } | ||||
|                 if (apClientEvent.hasReason()) { | ||||
|                     clientSession.getDetails().setDisconnectByClientReasonCode(apClientEvent.getReason()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         if (apClientEvent.hasFrType()) { | ||||
|             if (apClientEvent.getFrType().equals(FrameType.FT_DEAUTH)) { | ||||
|             } | ||||
|             if (apClientEvent.getFrType().equals(FrameType.FT_DISASSOC)) { | ||||
|             } | ||||
|         } | ||||
|         if (apClientEvent.hasRssi()) { | ||||
|             clientSession.getDetails().setAssocRssi(apClientEvent.getRssi()); | ||||
|         } | ||||
|         if (apClientEvent.hasLrcvUpTsInUs()) { | ||||
|             clientSession.getDetails().setLastRxTimestamp(apClientEvent.getLrcvUpTsInUs()); | ||||
|         } | ||||
|         if (apClientEvent.hasLsentUpTsInUs()) { | ||||
|             clientSession.getDetails().setLastTxTimestamp(apClientEvent.getLsentUpTsInUs()); | ||||
|         } | ||||
|         clientSession.getDetails().setAssociationState(AssociationState.Disconnected); | ||||
|         clientSession.getDetails().setAssocTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|         realtimeEventPublisher.publishClientDisconnectEvent(customerId, equipmentId, locationId, apEventClientSession.getClientDisconnectEvent()); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     protected void processClientAuthEvent(int customerId, long equipmentId, long locationId, sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientAuthEvent apClientEvent = apEventClientSession.getClientAuthEvent(); | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|  | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorEquipmentId() == null) { | ||||
|             clientSession.getDetails().setPriorEquipmentId(clientSession.getEquipmentId()); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         clientSession.getDetails().setSsid(apClientEvent.getSsid()); | ||||
|         if (apClientEvent.hasAuthStatus()) { | ||||
|             clientSession.getDetails().setAssociationStatus(apClientEvent.getAuthStatus()); | ||||
|         } | ||||
|         clientSession.getDetails().setAuthTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession.getDetails().setAssociationState(AssociationState._802_11_Authenticated); | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|  | ||||
|         realtimeEventPublisher.publishClientAuthSystemEvent(customerId, equipmentId, locationId, apEventClientSession.getClientAuthEvent()); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     protected void processClientAssocEvent(int customerId, long equipmentId, long locationId, | ||||
|             sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientAssocEvent apClientEvent = apEventClientSession.getClientAssocEvent(); | ||||
|  | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|  | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|  | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorEquipmentId() == null) { | ||||
|             clientSession.getDetails().setPriorEquipmentId(clientSession.getEquipmentId()); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         clientSession.getDetails().setSsid(apClientEvent.getSsid()); | ||||
|         if (apClientEvent.hasStatus()) { | ||||
|             clientSession.getDetails().setAssociationStatus(apClientEvent.getStatus()); | ||||
|         } | ||||
|         clientSession.getDetails().setRadioType(OvsdbToWlanCloudTypeMappingUtility.getRadioTypeFromOpensyncStatsRadioBandType(apClientEvent.getBand())); | ||||
|         if (apClientEvent.hasUsing11K()) { | ||||
|             clientSession.getDetails().setIs11KUsed(apClientEvent.getUsing11K()); | ||||
|         } | ||||
|         if (apClientEvent.hasUsing11R()) { | ||||
|             clientSession.getDetails().setIs11RUsed(apClientEvent.getUsing11R()); | ||||
|         } | ||||
|         if (apClientEvent.hasUsing11V()) { | ||||
|             clientSession.getDetails().setIs11VUsed(apClientEvent.getUsing11V()); | ||||
|         } | ||||
|         if (apClientEvent.hasAssocType()) { | ||||
|             clientSession.getDetails().setIsReassociation(apClientEvent.getAssocType().equals(AssocType.REASSOC)); | ||||
|         } | ||||
|         if (apClientEvent.hasRssi()) { | ||||
|             clientSession.getDetails().setAssocRssi(apClientEvent.getRssi()); | ||||
|         } | ||||
|         if (apClientEvent.hasInternalSc()) { | ||||
|             clientSession.getDetails().setAssocInternalSC(apClientEvent.getInternalSc()); | ||||
|         } | ||||
|         clientSession.getDetails().setAssocTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession.getDetails().setAssociationState(AssociationState._802_11_Associated); | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|         realtimeEventPublisher.publishClientAssocEvent(customerId, equipmentId, locationId, apEventClientSession.getClientAssocEvent()); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     protected void processClientIpEvent(int customerId, long equipmentId, long locationId, sts.OpensyncStats.EventReport.ClientSession apEventClientSession) { | ||||
|         ClientIpEvent apClientEvent = apEventClientSession.getClientIpEvent(); | ||||
|         com.telecominfraproject.wlan.client.models.Client client = clientServiceInterface.getOrNull(customerId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (client == null) { | ||||
|             client = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|             client.setCustomerId(customerId); | ||||
|             client.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             client.setDetails(new ClientInfoDetails()); | ||||
|             client = clientServiceInterface.create(client); | ||||
|         } | ||||
|         client = clientServiceInterface.update(client); | ||||
|  | ||||
|         ClientSession clientSession = clientServiceInterface.getSessionOrNull(customerId, equipmentId, MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|         if (clientSession == null) { | ||||
|             clientSession = new ClientSession(); | ||||
|             clientSession.setCustomerId(customerId); | ||||
|             clientSession.setEquipmentId(equipmentId); | ||||
|             clientSession.setMacAddress(MacAddress.valueOf(apClientEvent.getStaMac())); | ||||
|             clientSession.setLocationId(locationId); | ||||
|             clientSession.setDetails(new ClientSessionDetails()); | ||||
|             clientSession.getDetails().setDhcpDetails(new ClientDhcpDetails(Long.toUnsignedString(apEventClientSession.getSessionId()))); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorEquipmentId() == null) { | ||||
|             clientSession.getDetails().setPriorEquipmentId(clientSession.getEquipmentId()); | ||||
|         } | ||||
|         if (clientSession.getDetails().getPriorSessionId() == null) { | ||||
|             if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) | ||||
|                 clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         if (!Objects.equal(clientSession.getDetails().getSessionId(), Long.toUnsignedString(apEventClientSession.getSessionId()))) { | ||||
|             clientSession.getDetails().setPriorSessionId(clientSession.getDetails().getSessionId()); | ||||
|         } | ||||
|         clientSession.getDetails().setSessionId(Long.toUnsignedString(apEventClientSession.getSessionId())); | ||||
|         if (apClientEvent.hasIpAddr()) { | ||||
|             ByteString ipAddress = apClientEvent.getIpAddr(); | ||||
|             if (ipAddress != null) { | ||||
|                 try { | ||||
|                     InetAddress inetAddress = InetAddress.getByAddress(ipAddress.toByteArray()); | ||||
|                     if (inetAddress instanceof Inet4Address) { | ||||
|                         clientSession.getDetails().setIpAddress(inetAddress); | ||||
|                     } else if (inetAddress instanceof Inet6Address) { | ||||
|                         clientSession.getDetails().setIpAddress(inetAddress); | ||||
|                     } else { | ||||
|                         LOG.error("Invalid IP Address {}", ipAddress); | ||||
|                     } | ||||
|                     clientSession.getDetails().setIpTimestamp(apClientEvent.getTimestampMs()); | ||||
|  | ||||
|                 } catch (UnknownHostException ex) { | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         clientSession.getDetails().setLastEventTimestamp(apClientEvent.getTimestampMs()); | ||||
|         clientSession = clientServiceInterface.updateSession(clientSession); | ||||
|         realtimeEventPublisher.publishClientIpEvent(customerId, equipmentId, locationId, apEventClientSession.getClientIpEvent()); | ||||
|     } | ||||
|  | ||||
|     void populateApNodeMetrics(List<ServiceMetric> metricRecordList, Report report, int customerId, long equipmentId, long locationId) { | ||||
|         LOG.info("populateApNodeMetrics for Customer {} Equipment {}", customerId, equipmentId); | ||||
|         ApNodeMetrics apNodeMetrics = new ApNodeMetrics(); | ||||
| @@ -596,6 +285,8 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|         for (Device deviceReport : report.getDeviceList()) { | ||||
|  | ||||
|             int avgRadioTemp = 0; | ||||
|             // The 3 fixed alarm codes | ||||
|             List<Alarm> alarms = alarmServiceInterface.get(customerId, Set.of(equipmentId), Set.of(AlarmCode.CPUTemperature, AlarmCode.CPUUtilization, AlarmCode.MemoryUtilization)); | ||||
|  | ||||
|             ApPerformance apPerformance = new ApPerformance(); | ||||
|             apNodeMetrics.setApPerformance(apPerformance); | ||||
| @@ -614,10 +305,10 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|                     apPerformance.setCpuTemperature(avgRadioTemp); | ||||
|                 } | ||||
|                 if (avgRadioTemp > temperatureThresholdInC) { | ||||
|                     raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUTemperature, deviceReport.getTimestampMs()); | ||||
|                     raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUTemperature, deviceReport.getTimestampMs(), alarms); | ||||
|                 } else { | ||||
|                     // Clear any existing temperature alarms for this ap | ||||
|                     clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUTemperature); | ||||
|                     clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUTemperature, alarms); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| @@ -625,10 +316,10 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|                 Integer cpuUtilization = deviceReport.getCpuUtil().getCpuUtil(); | ||||
|                 apPerformance.setCpuUtilized(new int[] {cpuUtilization}); | ||||
|                 if (cpuUtilization > cpuUtilThresholdPct) { | ||||
|                     raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUUtilization, deviceReport.getTimestampMs()); | ||||
|                     raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUUtilization, deviceReport.getTimestampMs(), alarms); | ||||
|                 } else { | ||||
|                     // Clear any existing cpuUtilization alarms | ||||
|                     clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUUtilization); | ||||
|                     clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.CPUUtilization, alarms); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
| @@ -640,10 +331,10 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|                 double usedMemory = deviceReport.getMemUtil().getMemUsed(); | ||||
|                 double totalMemory = deviceReport.getMemUtil().getMemTotal(); | ||||
|                 if (usedMemory / totalMemory * 100 > memoryUtilThresholdPct) { | ||||
|                     raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.MemoryUtilization, deviceReport.getTimestampMs()); | ||||
|                     raiseDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.MemoryUtilization, deviceReport.getTimestampMs(), alarms); | ||||
|                 } else { | ||||
|                     // Clear any existing cpuUtilization alarms | ||||
|                     clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.MemoryUtilization); | ||||
|                     clearDeviceThresholdAlarm(customerId, equipmentId, AlarmCode.MemoryUtilization, alarms); | ||||
|                 } | ||||
|  | ||||
|             } | ||||
| @@ -898,16 +589,23 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|     } | ||||
|  | ||||
|      | ||||
|     void clearDeviceThresholdAlarm(int customerId, long equipmentId, AlarmCode alarmCode) { | ||||
|         alarmServiceInterface.get(customerId, Set.of(equipmentId), Set.of(alarmCode)).stream().forEach(a -> { | ||||
|             Alarm alarm = alarmServiceInterface.delete(customerId, equipmentId, a.getAlarmCode(), a.getCreatedTimestamp()); | ||||
|             LOG.debug("Cleared device threshold alarm {}", alarm); | ||||
|         }); | ||||
|     void clearDeviceThresholdAlarm(int customerId, long equipmentId, AlarmCode alarmCode, List<Alarm> alarms) { | ||||
|     	for (Alarm alarm: alarms) { | ||||
|     		if (alarm.getAlarmCode() == alarmCode) { | ||||
|     			Alarm removedAlarm = alarmServiceInterface.delete(customerId, equipmentId, alarm.getAlarmCode(), alarm.getCreatedTimestamp()); | ||||
|     			LOG.debug("Cleared device threshold alarm {}", removedAlarm); | ||||
|     			return; | ||||
|     		} | ||||
|     	} | ||||
|     } | ||||
|  | ||||
|      | ||||
|     void raiseDeviceThresholdAlarm(int customerId, long equipmentId, AlarmCode alarmCode, long timestampMs) { | ||||
|         // Raise an alarm for temperature | ||||
|     void raiseDeviceThresholdAlarm(int customerId, long equipmentId, AlarmCode alarmCode, long timestampMs, List<Alarm> alarms) { | ||||
|     	for (Alarm alarm: alarms) { | ||||
|     		if (alarm.getAlarmCode() == alarmCode) { | ||||
|     			return; | ||||
|     		} | ||||
|     	} | ||||
|         Alarm alarm = new Alarm(); | ||||
|         alarm.setCustomerId(customerId); | ||||
|         alarm.setEquipmentId(equipmentId); | ||||
| @@ -921,11 +619,8 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|         alarmDetails.setMessage(alarmCode.getDescription()); | ||||
|         alarmDetails.setAffectedEquipmentIds(Collections.singletonList(equipmentId)); | ||||
|         alarm.setDetails(alarmDetails); | ||||
|         List<Alarm> alarms = alarmServiceInterface.get(customerId, Set.of(equipmentId), Set.of(alarmCode)); | ||||
|         if (alarms.isEmpty()) { | ||||
|             alarm.setCreatedTimestamp(timestampMs); | ||||
|             alarm = alarmServiceInterface.create(alarm); | ||||
|         } | ||||
|         alarm.setCreatedTimestamp(timestampMs); | ||||
|         alarm = alarmServiceInterface.create(alarm); | ||||
|     } | ||||
|  | ||||
|     private void checkIfOutOfBound(String checkedType, int checkedValue, Survey survey, int totalDurationMs, int busyTx, int busyRx, int busy, int busySelf) { | ||||
| @@ -1006,14 +701,12 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|  | ||||
|     void updateDeviceStatusRadioUtilizationReport(int customerId, long equipmentId, RadioUtilizationReport radioUtilizationReport) { | ||||
|         LOG.info("Processing updateDeviceStatusRadioUtilizationReport for equipmentId {} with RadioUtilizationReport {}", equipmentId, radioUtilizationReport); | ||||
|         Status radioUtilizationStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.RADIO_UTILIZATION); | ||||
|         if (radioUtilizationStatus == null) { | ||||
|             LOG.debug("Create new radioUtilizationStatus"); | ||||
|             radioUtilizationStatus = new Status(); | ||||
|             radioUtilizationStatus.setCustomerId(customerId); | ||||
|             radioUtilizationStatus.setEquipmentId(equipmentId); | ||||
|             radioUtilizationStatus.setStatusDataType(StatusDataType.RADIO_UTILIZATION); | ||||
|         } | ||||
|         // remove statusServiceInterface.getOrNull() for better performance (i.e. no createdTimestamp) | ||||
|         LOG.debug("Create new radioUtilizationStatus"); | ||||
|         Status radioUtilizationStatus = new Status(); | ||||
|         radioUtilizationStatus.setCustomerId(customerId); | ||||
|         radioUtilizationStatus.setEquipmentId(equipmentId); | ||||
|         radioUtilizationStatus.setStatusDataType(StatusDataType.RADIO_UTILIZATION); | ||||
|         radioUtilizationStatus.setDetails(radioUtilizationReport); | ||||
|         statusServiceInterface.update(radioUtilizationStatus); | ||||
|     } | ||||
| @@ -1163,12 +856,7 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|                     if (cl.getStats().hasTxRate()) { | ||||
|                         cMetrics.setAverageTxRate(cl.getStats().getTxRate() / 1000); | ||||
|                     } | ||||
|  | ||||
|                     if (cl.getStats().hasTxRate() && cl.getStats().hasRxRate()) { | ||||
|                         cMetrics.setRates(new int[] {Double.valueOf(cl.getStats().getTxRate() / 1000).intValue(), | ||||
|                                 Double.valueOf(cl.getStats().getRxRate() / 1000).intValue()}); | ||||
|                     } | ||||
|  | ||||
|                      | ||||
|                     if (cl.getStats().hasTxErrors()) { | ||||
|                         cMetrics.setNumTxDropped((int) cl.getStats().getTxErrors()); | ||||
|                     } | ||||
| @@ -1181,7 +869,8 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|                         cMetrics.setNumTxDataRetries((int) cl.getStats().getTxRetries()); | ||||
|                     } | ||||
|  | ||||
|                     LOG.debug("ApClientMetrics Report {}", cMetrics); | ||||
|                     // Commented to increase performance as it repetitive | ||||
|                     // LOG.debug("ApClientMetrics Report {}", cMetrics); | ||||
|  | ||||
|                 } | ||||
|  | ||||
| @@ -1253,6 +942,9 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|  | ||||
|     void populateApSsidMetrics(List<ServiceMetric> metricRecordList, Report report, int customerId, long equipmentId, String apId, long locationId) { | ||||
|         LOG.debug("populateApSsidMetrics start"); | ||||
|          | ||||
|         Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.ACTIVE_BSSIDS); | ||||
|         LOG.debug("populateApSsidMetrics get BSSID from activeBssids {}", activeBssidsStatus); | ||||
|  | ||||
|         if (report.getClientsCount() == 0) { | ||||
|             LOG.info("populateApSsidMetrics no client data present, cannot build {}", ServiceMetricDataType.ApSsid); | ||||
| @@ -1295,7 +987,7 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|                 stats.setSourceTimestampMs(clientReport.getTimestampMs()); | ||||
|  | ||||
|                 // Get the BSSID (MAC address) for this SSID | ||||
|                 String bssid = getBssidForClientSsid(customerId, equipmentId, apId, e.getKey(), radioType); | ||||
|                 String bssid = getBssidForClientSsid(apId, e.getKey(), radioType, activeBssidsStatus); | ||||
|                 if (bssid != null) | ||||
|                     stats.setBssid(MacAddress.valueOf(bssid)); | ||||
|                 else | ||||
| @@ -1342,26 +1034,20 @@ public class MqttStatsPublisher implements StatsPublisherInterface { | ||||
|         LOG.debug("populateApSsidMetrics finished"); | ||||
|     } | ||||
|  | ||||
|     String getBssidForClientSsid(int customerId, long equipmentId, String apId, String ssid, RadioType radioType) { | ||||
|     String getBssidForClientSsid(String apId, String ssid, RadioType radioType, Status activeBssidsStatus) { | ||||
|         try { | ||||
|             Status activeBssidsStatus = statusServiceInterface.getOrNull(customerId, equipmentId, StatusDataType.ACTIVE_BSSIDS); | ||||
|             LOG.debug("populateApSsidMetrics get BSSID from activeBssids {}", activeBssidsStatus); | ||||
|             if (activeBssidsStatus != null) { | ||||
|                 if (activeBssidsStatus.getDetails() != null) { | ||||
|                     ActiveBSSIDs activeBssids = (ActiveBSSIDs) activeBssidsStatus.getDetails(); | ||||
|                     if (activeBssids.getActiveBSSIDs() != null) { | ||||
|                         for (ActiveBSSID activeBssid : activeBssids.getActiveBSSIDs()) { | ||||
|                             if (activeBssid.getRadioType() != null && activeBssid.getRadioType().equals(radioType)) { | ||||
|                                 if (activeBssid.getSsid() != null && activeBssid.getSsid().equals(ssid)) { | ||||
|                                     if (activeBssid.getBssid() != null) { | ||||
|                                         return activeBssid.getBssid(); | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 			ActiveBSSIDs activeBssids = (ActiveBSSIDs) activeBssidsStatus.getDetails(); | ||||
| 			if (activeBssids.getActiveBSSIDs() != null) { | ||||
| 				for (ActiveBSSID activeBssid : activeBssids.getActiveBSSIDs()) { | ||||
| 					if (activeBssid.getRadioType() != null && activeBssid.getRadioType().equals(radioType)) { | ||||
| 						if (activeBssid.getSsid() != null && activeBssid.getSsid().equals(ssid)) { | ||||
| 							if (activeBssid.getBssid() != null) { | ||||
| 								return activeBssid.getBssid(); | ||||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
|         } catch (Exception e) { | ||||
|             LOG.error("Could not get active BSSIDs for apId {} radioType {}", apId, radioType, e); | ||||
|         } | ||||
|   | ||||
| @@ -50,7 +50,6 @@ import com.telecominfraproject.wlan.core.model.entity.CountryCode; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.EquipmentType; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.MacAddress; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.RadioType; | ||||
| import com.telecominfraproject.wlan.core.model.pagination.PaginationContext; | ||||
| import com.telecominfraproject.wlan.core.model.pagination.PaginationResponse; | ||||
| import com.telecominfraproject.wlan.customer.models.Customer; | ||||
| import com.telecominfraproject.wlan.customer.models.CustomerDetails; | ||||
| @@ -68,6 +67,7 @@ import com.telecominfraproject.wlan.location.models.LocationType; | ||||
| import com.telecominfraproject.wlan.location.service.LocationServiceInterface; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.controller.OpensyncCloudGatewayController; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPInetState; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPRadioState; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPVIFState; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.utils.MqttStatsPublisher; | ||||
| @@ -85,6 +85,7 @@ import com.telecominfraproject.wlan.status.equipment.models.EquipmentUpgradeStat | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.ClientConnectionDetails; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.WiredPortStatus; | ||||
| import com.telecominfraproject.wlan.status.models.Status; | ||||
| import com.telecominfraproject.wlan.status.models.StatusDataType; | ||||
| import com.vmware.ovsdb.protocol.operation.notation.Uuid; | ||||
| @@ -93,7 +94,6 @@ import sts.OpensyncStats.AssocType; | ||||
| import sts.OpensyncStats.Client; | ||||
| import sts.OpensyncStats.ClientReport; | ||||
| import sts.OpensyncStats.EventReport; | ||||
| import sts.OpensyncStats.EventReport.ClientAssocEvent; | ||||
| import sts.OpensyncStats.RadioBandType; | ||||
| import sts.OpensyncStats.Report; | ||||
|  | ||||
| @@ -702,6 +702,26 @@ public class OpensyncExternalIntegrationCloudTest { | ||||
|         Mockito.verify(statusServiceInterface, Mockito.never()).update(bssidStatus); | ||||
|  | ||||
|     } | ||||
|      | ||||
|     @Test | ||||
|     public void testParseRawDataToWiredPortStatus() { | ||||
|     	 Map<String, List<WiredPortStatus>> portStatus = new HashMap<>(); | ||||
|     	OpensyncAPInetState inetState = new OpensyncAPInetState(); | ||||
|     	inetState.setIfType("bridge"); | ||||
|     	@SuppressWarnings("serial") | ||||
| 		Map<String, String> ethPorts = new HashMap<String, String>(){{ | ||||
|     	     put("eth0", "up lan 1000Mbps full"); | ||||
|     	     put("eth1", "up wan 1000Mbps full"); | ||||
|     	     put("eth2", "incorrect value"); | ||||
|     	}}; | ||||
|     	inetState.setIfName("lan"); | ||||
|     	inetState.setEthPorts(ethPorts); | ||||
|     	opensyncExternalIntegrationCloud.parseRawDataToWiredPortStatus(2, 1, portStatus, inetState); | ||||
|     	assertEquals(1, portStatus.size()); | ||||
|     	assertEquals(true, portStatus.containsKey("lan")); | ||||
|     	assertEquals(2, portStatus.get("lan").size()); | ||||
|     	assertEquals("lan", portStatus.get("lan").get(0).getCurrentIfName()); | ||||
|     } | ||||
|  | ||||
|     @Ignore | ||||
|     public void testWifiInetStateDbTableUpdate() { | ||||
|   | ||||
| @@ -1,391 +0,0 @@ | ||||
| package com.telecominfraproject.wlan.opensync.external.integration.utils; | ||||
|  | ||||
| import static org.junit.Assert.assertNotNull; | ||||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||||
|  | ||||
| import java.net.InetAddress; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| import org.junit.After; | ||||
| import org.junit.Before; | ||||
| import org.junit.Ignore; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.mockito.Answers; | ||||
| import org.mockito.ArgumentMatchers; | ||||
| import org.mockito.Mockito; | ||||
| import org.mockito.MockitoSession; | ||||
| import org.mockito.quality.Strictness; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||||
| import org.springframework.boot.test.mock.mockito.MockBean; | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.context.annotation.Import; | ||||
| import org.springframework.test.context.ActiveProfiles; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
|  | ||||
| import com.google.common.collect.ImmutableList; | ||||
| import com.google.protobuf.ByteString; | ||||
| import com.telecominfraproject.wlan.alarm.AlarmServiceInterface; | ||||
| import com.telecominfraproject.wlan.client.ClientServiceInterface; | ||||
| import com.telecominfraproject.wlan.client.info.models.ClientInfoDetails; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientSession; | ||||
| import com.telecominfraproject.wlan.client.session.models.ClientSessionDetails; | ||||
| import com.telecominfraproject.wlan.cloudeventdispatcher.CloudEventDispatcherInterface; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.MacAddress; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.RadioType; | ||||
| import com.telecominfraproject.wlan.customer.service.CustomerServiceInterface; | ||||
| import com.telecominfraproject.wlan.equipment.EquipmentServiceInterface; | ||||
| import com.telecominfraproject.wlan.equipment.models.ApElementConfiguration; | ||||
| import com.telecominfraproject.wlan.equipment.models.Equipment; | ||||
| import com.telecominfraproject.wlan.firmware.FirmwareServiceInterface; | ||||
| import com.telecominfraproject.wlan.location.service.LocationServiceInterface; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.OpensyncExternalIntegrationCloud; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.OvsdbSession; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.OvsdbSessionMapInterface; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.controller.OpensyncCloudGatewayController; | ||||
| import com.telecominfraproject.wlan.profile.ProfileServiceInterface; | ||||
| import com.telecominfraproject.wlan.routing.RoutingServiceInterface; | ||||
| import com.telecominfraproject.wlan.servicemetric.apnode.models.ApNodeMetrics; | ||||
| import com.telecominfraproject.wlan.servicemetric.apnode.models.StateUpDownError; | ||||
| import com.telecominfraproject.wlan.status.StatusServiceInterface; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSID; | ||||
| import com.telecominfraproject.wlan.status.equipment.report.models.ActiveBSSIDs; | ||||
| import com.telecominfraproject.wlan.status.models.Status; | ||||
| import com.telecominfraproject.wlan.status.models.StatusDataType; | ||||
|  | ||||
| import sts.OpensyncStats.AssocType; | ||||
| import sts.OpensyncStats.ChannelSwitchReason; | ||||
| import sts.OpensyncStats.Client; | ||||
| import sts.OpensyncStats.ClientReport; | ||||
| import sts.OpensyncStats.DNSProbeMetric; | ||||
| import sts.OpensyncStats.EventReport; | ||||
| import sts.OpensyncStats.EventReport.ChannelSwitchEvent; | ||||
| import sts.OpensyncStats.EventReport.ClientAssocEvent; | ||||
| import sts.OpensyncStats.NetworkProbe; | ||||
| import sts.OpensyncStats.RADIUSMetrics; | ||||
| import sts.OpensyncStats.RadioBandType; | ||||
| import sts.OpensyncStats.Report; | ||||
| import sts.OpensyncStats.StateUpDown; | ||||
| import sts.OpensyncStats.VLANMetrics; | ||||
|  | ||||
| @RunWith(SpringRunner.class) | ||||
| @ActiveProfiles(profiles = { "integration_test", }) | ||||
| @SpringBootTest(webEnvironment = WebEnvironment.NONE, classes = MqttStatsPublisherTest.class) | ||||
| @Import(value = { AlarmServiceInterface.class, OpensyncExternalIntegrationCloud.class, | ||||
|         MqttStatsPublisherTest.Config.class, | ||||
|  | ||||
| }) | ||||
| public class MqttStatsPublisherTest { | ||||
|  | ||||
|     @MockBean | ||||
|     AlarmServiceInterface alarmServiceInterface; | ||||
|     @MockBean | ||||
|     CustomerServiceInterface customerServiceInterface; | ||||
|     @MockBean | ||||
|     LocationServiceInterface locationServiceInterface; | ||||
|     @MockBean(answer = Answers.RETURNS_MOCKS) | ||||
|     OvsdbSessionMapInterface ovsdbSessionMapInterface; | ||||
|     @MockBean | ||||
|     CloudEventDispatcherInterface equipmentMetricsCollectorInterface; | ||||
|     @MockBean | ||||
|     EquipmentServiceInterface equipmentServiceInterface; | ||||
|     @MockBean | ||||
|     RoutingServiceInterface routingServiceInterface; | ||||
|     @MockBean | ||||
|     ProfileServiceInterface profileServiceInterface; | ||||
|     @MockBean | ||||
|     StatusServiceInterface statusServiceInterface; | ||||
|     @MockBean | ||||
|     ClientServiceInterface clientServiceInterface; | ||||
|     @MockBean | ||||
|     FirmwareServiceInterface firmwareServiceInterface; | ||||
|     @MockBean(answer = Answers.RETURNS_MOCKS) | ||||
|     OpensyncCloudGatewayController gatewayController; | ||||
|     @MockBean | ||||
|     RealtimeEventPublisher realtimeEventPublisher; | ||||
|     @Autowired | ||||
|     MqttStatsPublisher opensyncExternalIntegrationMqttProcessor; | ||||
|  | ||||
|     MockitoSession mockito; | ||||
|  | ||||
|     @Configuration | ||||
|     static class Config { | ||||
|  | ||||
|         @Bean | ||||
|         public StatsPublisherInterface mqttStatsPublisher() { | ||||
|             return new MqttStatsPublisher(); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Before | ||||
|     public void setUp() throws Exception { | ||||
|  | ||||
|         mockito = Mockito.mockitoSession().initMocks(this).strictness(Strictness.LENIENT).startMocking(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @After | ||||
|     public void tearDown() throws Exception { | ||||
|         mockito.finishMocking(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testExtractApIdFromTopic() { | ||||
|  | ||||
|         String topic = "/ap/Test_Client_21P10C68818122/opensync"; | ||||
|  | ||||
|         assertEquals("Test_Client_21P10C68818122", MqttStatsPublisher.extractApIdFromTopic(topic)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testExtractCustomerIdFromTopic() { | ||||
|         String topic = "/ap/Test_Client_21P10C68818122/opensync"; | ||||
|         OvsdbSession session = Mockito.mock(OvsdbSession.class); | ||||
|         Equipment ce = Mockito.mock(Equipment.class); | ||||
|         Mockito.when(ce.getCustomerId()).thenReturn(2); | ||||
|  | ||||
|         Mockito.when( | ||||
|                 equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.eq("Test_Client_21P10C68818122"))) | ||||
|                 .thenReturn(ce); | ||||
|         Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); | ||||
|  | ||||
|         assertEquals(2, opensyncExternalIntegrationMqttProcessor.extractCustomerIdFromTopic(topic)); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testExtractEquipmentIdFromTopic() { | ||||
|  | ||||
|         String topic = "/ap/Test_Client_21P10C68818122/opensync"; | ||||
|         OvsdbSession session = Mockito.mock(OvsdbSession.class); | ||||
|         Mockito.when(session.getEquipmentId()).thenReturn(1L); | ||||
|  | ||||
|         Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); | ||||
|  | ||||
|         assertEquals(1L, opensyncExternalIntegrationMqttProcessor.extractEquipmentIdFromTopic(topic)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testProcessMqttMessageStringReport() { | ||||
|         Equipment equipment = new Equipment(); | ||||
|  | ||||
|         equipment.setDetails(ApElementConfiguration.createWithDefaults()); | ||||
|         equipment.setId(1L); equipment.setCustomerId(2); | ||||
|  | ||||
|         Mockito.when( | ||||
|                 equipmentServiceInterface.getByInventoryIdOrNull(ArgumentMatchers.eq("Test_Client_21P10C68818122"))) | ||||
|                 .thenReturn(equipment); | ||||
|  | ||||
|         equipment.setProfileId(0L); | ||||
|  | ||||
|         Mockito.when(equipmentServiceInterface.getOrNull(1L)).thenReturn(equipment); | ||||
|         Mockito.when(equipmentServiceInterface.get(1L)).thenReturn(equipment); | ||||
|  | ||||
|         Report report = Report.newBuilder().setNodeID("21P10C68818122") | ||||
|                 .addAllClients(getOpensyncStatsClientReportsList()) | ||||
|                 .addAllEventReport(getOpensyncStatsEventReportsList()).build(); | ||||
|  | ||||
|         String topic = "/ap/Test_Client_21P10C68818122/opensync"; | ||||
|  | ||||
|         OvsdbSession session = Mockito.mock(OvsdbSession.class); | ||||
|         Mockito.when(session.getEquipmentId()).thenReturn(1L); | ||||
|  | ||||
|         Mockito.when(ovsdbSessionMapInterface.getSession("Test_Client_21P10C68818122")).thenReturn(session); | ||||
|  | ||||
|         Status bssidStatus = new Status(); | ||||
|         bssidStatus.setStatusDataType(StatusDataType.ACTIVE_BSSIDS); | ||||
|         bssidStatus.setCustomerId(2); | ||||
|  | ||||
|         ActiveBSSIDs activeBssidsDetails = new ActiveBSSIDs(); | ||||
|         activeBssidsDetails.setActiveBSSIDs(getActiveBssidList()); | ||||
|         bssidStatus.setDetails(activeBssidsDetails); | ||||
|  | ||||
|         Mockito.when(statusServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), | ||||
|                 ArgumentMatchers.eq(StatusDataType.ACTIVE_BSSIDS))).thenReturn(bssidStatus); | ||||
|  | ||||
|         Mockito.when(statusServiceInterface.update(ArgumentMatchers.any(Status.class))).thenReturn(bssidStatus); | ||||
|         com.telecominfraproject.wlan.client.models.Client clientInstance = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|         clientInstance.setMacAddress(MacAddress.valueOf("7C:AB:60:E6:EA:4D")); | ||||
|         clientInstance.setDetails(new ClientInfoDetails()); | ||||
|         com.telecominfraproject.wlan.client.models.Client clientInstance2 = new com.telecominfraproject.wlan.client.models.Client(); | ||||
|         clientInstance2.setMacAddress(MacAddress.valueOf("C0:9A:D0:76:A9:69")); | ||||
|         clientInstance2.setDetails(new ClientInfoDetails()); | ||||
|         Mockito.when( | ||||
|                 clientServiceInterface.getOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.any(MacAddress.class))) | ||||
|                 .thenReturn(clientInstance).thenReturn(clientInstance2); | ||||
|         Mockito.when(clientServiceInterface | ||||
|                 .update(ArgumentMatchers.any(com.telecominfraproject.wlan.client.models.Client.class))) | ||||
|                 .thenReturn(clientInstance).thenReturn(clientInstance2); | ||||
|  | ||||
|         ClientSession clientSession = new ClientSession(); | ||||
|         clientSession.setMacAddress(MacAddress.valueOf("7C:AB:60:E6:EA:4D")); | ||||
|         clientSession.setDetails(new ClientSessionDetails()); | ||||
|         ClientSession clientSession2 = new ClientSession(); | ||||
|         clientSession2.setMacAddress(MacAddress.valueOf("C0:9A:D0:76:A9:69")); | ||||
|         clientSession2.setDetails(new ClientSessionDetails()); | ||||
|         Mockito.when(clientServiceInterface.getSessionOrNull(ArgumentMatchers.anyInt(), ArgumentMatchers.anyLong(), | ||||
|                 ArgumentMatchers.any(MacAddress.class))).thenReturn(clientSession).thenReturn(clientSession2); | ||||
|  | ||||
|         Mockito.when(clientServiceInterface.updateSession(ArgumentMatchers.any(ClientSession.class))) | ||||
|                 .thenReturn(clientSession).thenReturn(clientSession2); | ||||
|  | ||||
|         opensyncExternalIntegrationMqttProcessor.processMqttMessage(topic, report); | ||||
|  | ||||
|         // Mockito.verify(clientServiceInterface, | ||||
|         // Mockito.times(4)).getOrNull(Mockito.anyInt(), | ||||
|         // Mockito.any(MacAddress.class)); | ||||
|         // Mockito.verify(clientServiceInterface, | ||||
|         // Mockito.times(4)).getSessionOrNull(Mockito.anyInt(), | ||||
|         // Mockito.anyLong(), | ||||
|         // Mockito.any(MacAddress.class)); | ||||
|         // Mockito.verify(statusServiceInterface, | ||||
|         // Mockito.times(3)).getOrNull(Mockito.anyInt(), Mockito.anyLong(), | ||||
|         // Mockito.eq(StatusDataType.ACTIVE_BSSIDS)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     @Ignore | ||||
|     public void testProcessMqttMessageStringFlowReport() { | ||||
|         // TODO: implement me when support flow reports | ||||
|     } | ||||
|  | ||||
|     @Ignore | ||||
|     public void testProcessMqttMessageStringWCStatsReport() { | ||||
|         // TODO: implement me when wcs stats reports supported | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testpopulateNetworkProbeMetrics() throws Exception { | ||||
|  | ||||
|         InetAddress ip = InetAddress.getLocalHost(); | ||||
|  | ||||
|         DNSProbeMetric dnsProbeMetric = DNSProbeMetric.getDefaultInstance().toBuilder().setLatency(10) | ||||
|                 .setState(StateUpDown.SUD_up).setServerIP(ip.getHostName()).build(); | ||||
|         RADIUSMetrics radiusProbeMetric = RADIUSMetrics.getDefaultInstance().toBuilder().setLatency(10) | ||||
|                 .setRadiusState(StateUpDown.SUD_up).setServerIP(ip.getHostName()).build(); | ||||
|         VLANMetrics vlanMetrics = VLANMetrics.getDefaultInstance().toBuilder().setLatency(10) | ||||
|                 .setDhcpState(StateUpDown.SUD_up).setVlanIF("vlan-1").build(); | ||||
|         NetworkProbe networkProbe = NetworkProbe.getDefaultInstance().toBuilder().setVlanProbe(vlanMetrics) | ||||
|                 .setDnsProbe(dnsProbeMetric).addRadiusProbe(radiusProbeMetric).build(); | ||||
|  | ||||
|         Report report = Report.getDefaultInstance().toBuilder().setNodeID("21P10C68818122") | ||||
|                 .addNetworkProbe(networkProbe).build(); | ||||
|  | ||||
|         ApNodeMetrics apNodeMetrics = new ApNodeMetrics(); | ||||
|  | ||||
|         opensyncExternalIntegrationMqttProcessor.populateNetworkProbeMetrics(report, apNodeMetrics); | ||||
|  | ||||
|         assertNotNull(apNodeMetrics.getNetworkProbeMetrics()); | ||||
|  | ||||
|         assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDnsLatencyMs() == 10); | ||||
|         assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDhcpLatencyMs() == 10); | ||||
|         assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getRadiusState().equals(StateUpDownError.enabled)); | ||||
|         assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDhcpState().equals(StateUpDownError.enabled)); | ||||
|         assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getDnsState().equals(StateUpDownError.enabled)); | ||||
|         assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getRadiusLatencyInMs() == 10); | ||||
|         assert (apNodeMetrics.getNetworkProbeMetrics().get(0).getVlanIF().equals("vlan-1")); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     // Helper methods | ||||
|     private List<ActiveBSSID> getActiveBssidList() { | ||||
|         ActiveBSSID activeBssid = new ActiveBSSID(); | ||||
|         activeBssid.setBssid("24:f5:a2:ef:2e:54"); | ||||
|         activeBssid.setSsid("ssid-1"); | ||||
|         activeBssid.setNumDevicesConnected(1); | ||||
|         activeBssid.setRadioType(RadioType.is2dot4GHz); | ||||
|         ActiveBSSID activeBssid2 = new ActiveBSSID(); | ||||
|         activeBssid2.setBssid("24:f5:a2:ef:2e:55"); | ||||
|         activeBssid2.setSsid("ssid-2"); | ||||
|         activeBssid2.setNumDevicesConnected(1); | ||||
|         activeBssid2.setRadioType(RadioType.is5GHzL); | ||||
|         ActiveBSSID activeBssid3 = new ActiveBSSID(); | ||||
|         activeBssid3.setBssid("24:f5:a2:ef:2e:56"); | ||||
|         activeBssid3.setSsid("ssid-3"); | ||||
|         activeBssid3.setNumDevicesConnected(1); | ||||
|         activeBssid3.setRadioType(RadioType.is5GHzU); | ||||
|  | ||||
|         List<ActiveBSSID> bssidList = new ArrayList<>(); | ||||
|         bssidList.add(activeBssid); | ||||
|         bssidList.add(activeBssid2); | ||||
|         bssidList.add(activeBssid3); | ||||
|         return bssidList; | ||||
|     } | ||||
|     private List<EventReport> getOpensyncStatsEventReportsList() { | ||||
|  | ||||
|         sts.OpensyncStats.EventReport.ClientAssocEvent.Builder clientAssocBuilder = EventReport.ClientAssocEvent | ||||
|                 .getDefaultInstance().toBuilder(); | ||||
|         clientAssocBuilder.setAssocType(AssocType.ASSOC); | ||||
|         clientAssocBuilder.setBand(RadioBandType.BAND5GU); | ||||
|         clientAssocBuilder.setRssi(-65); | ||||
|         clientAssocBuilder.setStaMac("C0:9A:D0:76:A9:69"); | ||||
|         clientAssocBuilder.setStaMacBytes(ByteString.copyFrom("C0:9A:D0:76:A9:69".getBytes())); | ||||
|         clientAssocBuilder.setSessionId(1000L); | ||||
|         clientAssocBuilder.setInternalSc(1); | ||||
|         clientAssocBuilder.setSsid("ssid-3"); | ||||
|         clientAssocBuilder.setStatus(1); | ||||
|         clientAssocBuilder.setTimestampMs(System.currentTimeMillis()); | ||||
|  | ||||
|         List<EventReport> eventReportList = new ArrayList<>(); | ||||
|  | ||||
|         EventReport.Builder eventReportBuilder = EventReport.getDefaultInstance().toBuilder(); | ||||
|  | ||||
|         sts.OpensyncStats.EventReport.ClientSession.Builder clientSessionBuilder = sts.OpensyncStats.EventReport.ClientSession | ||||
|                 .getDefaultInstance().toBuilder(); | ||||
|  | ||||
|         clientSessionBuilder.setSessionId(1000L); | ||||
|  | ||||
|         clientSessionBuilder.setClientAssocEvent(clientAssocBuilder.build()); | ||||
|         List<sts.OpensyncStats.EventReport.ClientSession> clientSessionList = new ArrayList<>(); | ||||
|         clientSessionList.add(clientSessionBuilder.build()); | ||||
|  | ||||
|         sts.OpensyncStats.EventReport.ChannelSwitchEvent.Builder channelSwitchEventBuilder = sts.OpensyncStats.EventReport.ChannelSwitchEvent | ||||
|                 .getDefaultInstance().toBuilder(); | ||||
|         channelSwitchEventBuilder.setBand(RadioBandType.BAND5GL).setChannel(40) | ||||
|                 .setReason(ChannelSwitchReason.high_interference).setTimestampMs(System.currentTimeMillis()); | ||||
|  | ||||
|         List<ChannelSwitchEvent> channelSwitchEventList = new ArrayList<>(); | ||||
|         channelSwitchEventList.add(channelSwitchEventBuilder.build()); | ||||
|  | ||||
|         eventReportBuilder.addAllClientSession(clientSessionList); | ||||
|         eventReportBuilder.addAllChannelSwitch(channelSwitchEventList); | ||||
|  | ||||
|         eventReportList.add(eventReportBuilder.build()); | ||||
|  | ||||
|         return eventReportList; | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private List<ClientReport> getOpensyncStatsClientReportsList() { | ||||
|         int rssi = Long.valueOf(4294967239L).intValue(); | ||||
|  | ||||
|         Client.Stats clientStats = Client.Stats.getDefaultInstance().toBuilder().setRssi(rssi).setRxBytes(225554786) | ||||
|                 .setRxRate(24000.0).setTxBytes(1208133026).setTxRate(433300.0).setRssi(758722570).setRxFrames(10000) | ||||
|                 .setTxFrames(10000).setTxRate(24000.0).build(); | ||||
|         Client client2g = Client.getDefaultInstance().toBuilder().setMacAddress("7C:AB:60:E6:EA:4D").setSsid("ssid-1") | ||||
|                 .setConnected(true).setDurationMs(59977).setStats(clientStats).build(); | ||||
|         Client client5gu = Client.getDefaultInstance().toBuilder().setMacAddress("C0:9A:D0:76:A9:69").setSsid("ssid-3") | ||||
|                 .setConnected(true).setDurationMs(298127).setStats(clientStats).build(); | ||||
|  | ||||
|         ClientReport clientReport2g = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND2G) | ||||
|                 .setChannel(6).addAllClientList(ImmutableList.of(client2g)).build(); | ||||
|         ClientReport clientReport5gl = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND5GL) | ||||
|                 .setChannel(36).addAllClientList(new ArrayList<Client>()).build(); | ||||
|         ClientReport clientReport5gu = ClientReport.getDefaultInstance().toBuilder().setBand(RadioBandType.BAND5GU) | ||||
|                 .setChannel(157).addAllClientList(ImmutableList.of(client5gu)).build(); | ||||
|  | ||||
|         List<ClientReport> clients = new ArrayList<>(); | ||||
|         clients.add(clientReport2g); | ||||
|         clients.add(clientReport5gl); | ||||
|         clients.add(clientReport5gu); | ||||
|         return clients; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -4,6 +4,7 @@ import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Set; | ||||
|  | ||||
| import com.telecominfraproject.wlan.core.model.equipment.LedStatus; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.MacAddress; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.RadioType; | ||||
| import com.telecominfraproject.wlan.equipment.models.CellSizeAttributes; | ||||
|   | ||||
| @@ -38,6 +38,7 @@ public class OpensyncAPConfig extends OpensyncAPBase { | ||||
|     private List<Profile> ssidProfile; | ||||
|     private List<Profile> metricsProfile; | ||||
|     private List<Profile> radiusProfiles; | ||||
|     private Profile wiredEthernetPortProfile; | ||||
|     private Location equipmentLocation; | ||||
|     private EquipmentRoutingRecord equipmentRouting; | ||||
|     private EquipmentGatewayRecord equipmentGateway; | ||||
| @@ -136,7 +137,8 @@ public class OpensyncAPConfig extends OpensyncAPBase { | ||||
|                 && Objects.equals(hotspotConfig, other.hotspotConfig) | ||||
|                 && Objects.equals(metricsProfile, other.metricsProfile) | ||||
|                 && Objects.equals(radiusProfiles, other.radiusProfiles) && Objects.equals(rfProfile, other.rfProfile) | ||||
|                 && Objects.equals(ssidProfile, other.ssidProfile); | ||||
|                 && Objects.equals(ssidProfile, other.ssidProfile) | ||||
|                 && Objects.equals(wiredEthernetPortProfile, other.wiredEthernetPortProfile); | ||||
|     } | ||||
|  | ||||
|     public Profile getApProfile() { | ||||
| @@ -195,11 +197,15 @@ public class OpensyncAPConfig extends OpensyncAPBase { | ||||
|         return ssidProfile; | ||||
|     } | ||||
|  | ||||
| 	public Profile getWiredEthernetPortProfile() { | ||||
| 		return wiredEthernetPortProfile; | ||||
| 	} | ||||
| 	 | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         return Objects.hash(apProfile, blockedClients, bonjourGatewayProfiles, captiveProfiles, customerEquipment, | ||||
|                 equipmentGateway, equipmentLocation, equipmentRouting, hotspotConfig, metricsProfile, radiusProfiles, | ||||
|                 rfProfile, ssidProfile); | ||||
|                 rfProfile, ssidProfile, wiredEthernetPortProfile); | ||||
|     } | ||||
|  | ||||
|     public void setApProfile(Profile apProfile) { | ||||
| @@ -325,4 +331,8 @@ public class OpensyncAPConfig extends OpensyncAPBase { | ||||
|         this.ssidProfile = ssidProfile; | ||||
|     } | ||||
|  | ||||
| 	public void setWiredEthernetPortProfile(Profile wiredEthernetPortProfile) { | ||||
| 		this.wiredEthernetPortProfile = wiredEthernetPortProfile; | ||||
| 	} | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -22,8 +22,10 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|     public String ifType; | ||||
|     public String softwdsMacAddr; | ||||
|     public boolean enabled; | ||||
|     public Map<String, String> ethPorts; | ||||
|     public boolean sofwdsWrap; | ||||
|     public int vlanId; | ||||
|     public Map<String, String> vlanTrunk; | ||||
|     public String netmask; | ||||
|     public boolean nat; | ||||
|     public String greRemoteInetAddr; | ||||
| @@ -43,17 +45,21 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|     public Uuid _uuid; | ||||
|     public Uuid version; | ||||
|     public String greLocalInetAddr; | ||||
|  | ||||
|     // the following attribute is in inetC but not in inetS | ||||
|     public String greRemoteMacAddr; | ||||
|  | ||||
|     public OpensyncAPInetState() { | ||||
|         dns = new HashMap<>(); | ||||
|         dhcpc = new HashMap<>(); | ||||
|         ethPorts = new HashMap<>(); | ||||
|         vlanTrunk = new HashMap<>(); | ||||
|     } | ||||
|  | ||||
|     public OpensyncAPInetState(Row row) { | ||||
|         dns = new HashMap<>(); | ||||
|         dhcpc = new HashMap<>(); | ||||
|         ethPorts = new HashMap<>(); | ||||
|         vlanTrunk = new HashMap<>(); | ||||
|  | ||||
|         Map<String, Value> map = row.getColumns(); | ||||
|  | ||||
| @@ -83,6 +89,12 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|         if (map.containsKey("dns")) { | ||||
|             this.setDns(row.getMapColumn("dns")); | ||||
|         } | ||||
|         if (map.containsKey("eth_ports")) { | ||||
|         	this.setEthPorts(row.getMapColumn("eth_ports")); | ||||
|         } | ||||
|         if (map.containsKey("vlan_trunk")) { | ||||
|         	this.setVlanTrunk(row.getMapColumn("vlan_trunk")); | ||||
|         } | ||||
|         if (map.get("inet_addr") != null | ||||
|                 && map.get("inet_addr").getClass().equals(com.vmware.ovsdb.protocol.operation.notation.Atom.class)) { | ||||
|             this.setInetAddr(row.getStringColumn("inet_addr")); | ||||
| @@ -157,6 +169,12 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|         if (!Objects.equals(dhcpd, other.dhcpd)) { | ||||
|             return false; | ||||
|         } | ||||
|         if (!Objects.equals(ethPorts, other.ethPorts)) { | ||||
|         	return false; | ||||
|         } | ||||
|         if (!Objects.equals(vlanTrunk, other.vlanTrunk)) { | ||||
|         	return false; | ||||
|         } | ||||
|         if (!Objects.equals(dns, other.dns)) { | ||||
|             return false; | ||||
|         } | ||||
| @@ -251,6 +269,14 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|     public Map<String, String> getDns() { | ||||
|         return dns; | ||||
|     } | ||||
|      | ||||
|     public Map<String, String> getEthPorts() { | ||||
|     	return ethPorts; | ||||
|     } | ||||
|      | ||||
|     public Map<String, String> getVlanTrunk() { | ||||
|     	return vlanTrunk; | ||||
|     } | ||||
|  | ||||
|     public String getGateway() { | ||||
|         return gateway; | ||||
| @@ -330,9 +356,9 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|  | ||||
|     @Override | ||||
|     public int hashCode() { | ||||
|         return Objects.hash(_uuid, broadcast, dhcpc, dhcpd, dns, enabled, gateway, greIfName, greLocalInetAddr, greRemoteInetAddr, | ||||
|         return Objects.hash(_uuid, broadcast, dhcpc, dhcpd, dns, ethPorts, enabled, gateway, greIfName, greLocalInetAddr, greRemoteInetAddr, | ||||
|                 hwAddr, ifName, ifType, ifUuid, inetAddr, inetConfig, ipAssignScheme, mtw, nat, netmask, network, | ||||
|                 parentIfName, greRemoteMacAddr, softwdsMacAddr, sofwdsWrap, unpnpMode, version, vlanId); | ||||
|                 parentIfName, greRemoteMacAddr, softwdsMacAddr, sofwdsWrap, unpnpMode, version, vlanId, vlanTrunk); | ||||
|     } | ||||
|  | ||||
|     public boolean isEnabled() { | ||||
| @@ -370,6 +396,14 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|     public void setDns(Map<String, String> dns) { | ||||
|         this.dns = dns; | ||||
|     } | ||||
|      | ||||
|     public void setEthPorts(Map<String, String> ethPorts) { | ||||
|     	this.ethPorts = ethPorts; | ||||
|     } | ||||
|      | ||||
|     public void setVlanTrunk(Map<String, String> vlanTrunk) { | ||||
|     	this.vlanTrunk = vlanTrunk; | ||||
|     } | ||||
|  | ||||
|     public void setEnabled(boolean enabled) { | ||||
|         this.enabled = enabled; | ||||
| @@ -466,9 +500,9 @@ public class OpensyncAPInetState extends OpensyncAPBase { | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "OpensyncAPInetState [ifName=" + ifName + ", dhcpd=" + dhcpd + ", unpnpMode=" + unpnpMode + ", ifType=" | ||||
|         return "OpensyncAPInetState [ifName=" + ifName + ", dhcpd=" + dhcpd + ", ethPorts=" + ethPorts + ", unpnpMode=" + unpnpMode + ", ifType=" | ||||
|                 + ifType + ", softwdsMacAddr=" + softwdsMacAddr + ", enabled=" + enabled + ", sofwdsWrap=" + sofwdsWrap | ||||
|                 + ", vlanId=" + vlanId + ", netmask=" + netmask + ", nat=" + nat + ", greRemoteInetAddr=" | ||||
|                 + ", vlanId=" + vlanId + ", vlanTrunk=" + vlanTrunk + ", netmask=" + netmask + ", nat=" + nat + ", greRemoteInetAddr=" | ||||
|                 + greRemoteInetAddr + ", ifUuid=" + ifUuid + ", inetAddr=" + inetAddr + ", hwAddr=" + hwAddr + ", mtw=" | ||||
|                 + mtw + ", network=" + network + ", dns=" + dns + ", parentIfName=" + parentIfName + ", greIfName=" | ||||
|                 + greIfName + ", broadcast=" + broadcast + ", dhcpc=" + dhcpc + ", gateway=" + gateway | ||||
|   | ||||
| @@ -73,4 +73,3 @@ | ||||
| 	</dependencies> | ||||
|  | ||||
| </project> | ||||
|  | ||||
|   | ||||
| @@ -195,7 +195,7 @@ public class OpensyncMqttClient implements ApplicationListener<ContextClosedEven | ||||
|                                 stopwatchTimerMessageProcess.stop(); | ||||
|                             } | ||||
|                         } | ||||
|                     } catch (Exception e) { | ||||
|                     } catch (Throwable e) { | ||||
|                         LOG.error("Exception in MQTT receiver", e); | ||||
|                     } finally { | ||||
|                         try { | ||||
|   | ||||
| @@ -6,7 +6,6 @@ import com.netflix.servo.DefaultMonitorRegistry; | ||||
| import com.netflix.servo.monitor.BasicCounter; | ||||
| import com.netflix.servo.monitor.Counter; | ||||
| import com.netflix.servo.monitor.MonitorConfig; | ||||
| import com.netflix.servo.monitor.Monitors; | ||||
| import com.netflix.servo.tag.TagList; | ||||
| import com.telecominfraproject.wlan.cloudmetrics.CloudMetricsTags; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.MacAddress; | ||||
| @@ -19,7 +18,6 @@ import com.telecominfraproject.wlan.opensync.external.integration.OvsdbSession; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.OvsdbSessionMapInterface; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.*; | ||||
| import com.telecominfraproject.wlan.opensync.ovsdb.dao.OvsdbDao; | ||||
| import com.telecominfraproject.wlan.opensync.ovsdb.dao.OvsdbMonitor; | ||||
| import com.telecominfraproject.wlan.opensync.ovsdb.metrics.OvsdbClientWithMetrics; | ||||
| import com.telecominfraproject.wlan.opensync.ovsdb.metrics.OvsdbMetrics; | ||||
| import com.telecominfraproject.wlan.opensync.util.OvsdbStringConstants; | ||||
| @@ -30,6 +28,7 @@ import com.vmware.ovsdb.protocol.methods.*; | ||||
| import com.vmware.ovsdb.protocol.operation.notation.Row; | ||||
| import com.vmware.ovsdb.protocol.operation.notation.Value; | ||||
| import com.vmware.ovsdb.service.OvsdbClient; | ||||
| import com.vmware.ovsdb.service.OvsdbConnectionInfo; | ||||
| import com.vmware.ovsdb.service.OvsdbPassiveConnectionListener; | ||||
| import io.netty.handler.ssl.SslContext; | ||||
| import org.slf4j.Logger; | ||||
| @@ -39,6 +38,7 @@ import org.springframework.context.annotation.Profile; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| import javax.annotation.PostConstruct; | ||||
| import java.security.cert.Certificate; | ||||
| import java.security.cert.X509Certificate; | ||||
| import java.util.*; | ||||
| import java.util.concurrent.CompletableFuture; | ||||
| @@ -114,18 +114,25 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { | ||||
|  | ||||
|             @Override | ||||
|             public void connected(OvsdbClient ovsdbClient) { | ||||
|  | ||||
|             	 | ||||
|                 connectionsAttempted.increment(); | ||||
|  | ||||
|                  | ||||
|                 if (!(ovsdbClient instanceof OvsdbClientWithMetrics)) { | ||||
|                     ovsdbClient = new OvsdbClientWithMetrics(ovsdbClient, ovsdbMetrics); | ||||
|                 } | ||||
|  | ||||
|                 String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress(); | ||||
|                 int localPort = ovsdbClient.getConnectionInfo().getLocalPort(); | ||||
|                  | ||||
|                 String subjectDn; | ||||
|                 try { | ||||
|                     subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate()).getSubjectDN().getName(); | ||||
|                 	OvsdbConnectionInfo connectionInfo = ovsdbClient.getConnectionInfo(); | ||||
|                 	String remoteHost = connectionInfo.getRemoteAddress().getHostAddress(); | ||||
|                     Certificate remoteCertificate = connectionInfo.getRemoteCertificate(); | ||||
|                     if (remoteCertificate == null) { | ||||
|                     	LOG.debug("Connect attempt no certificate from {} on remote port {}", remoteHost, connectionInfo.getRemotePort()); | ||||
|                     	return; | ||||
|                     } | ||||
|                      | ||||
|                     int localPort = connectionInfo.getLocalPort(); | ||||
| 					subjectDn = ((X509Certificate) remoteCertificate).getSubjectDN().getName(); | ||||
|  | ||||
|                     String clientCn = SslUtil.extractCN(subjectDn); | ||||
|                     LOG.info("ovsdbClient connecting from {} on port {} clientCn {}", remoteHost, localPort, clientCn); | ||||
| @@ -186,7 +193,9 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { | ||||
|                     localPort = ovsdbClient.getConnectionInfo().getLocalPort(); | ||||
|                     String subjectDn = null; | ||||
|                     try { | ||||
|                         subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate()).getSubjectDN().getName(); | ||||
|                     	Certificate remoteCertificate = ovsdbClient.getConnectionInfo().getRemoteCertificate(); | ||||
|                     	if (remoteCertificate != null) | ||||
|                     		subjectDn = ((X509Certificate) remoteCertificate).getSubjectDN().getName(); | ||||
|                     } catch (Exception e) { | ||||
|                         // do nothing | ||||
|                     } | ||||
| @@ -197,7 +206,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { | ||||
|                             extIntegrationInterface.apDisconnected(key); | ||||
|                             ovsdbSessionMapInterface.removeSession(key); | ||||
|                         } catch (Exception e) { | ||||
|                             LOG.debug("Unable to process ap disconnect. {}", e.getMessage()); | ||||
|                             LOG.debug("Unable to process ap disconnect. {}", e); | ||||
|                         } | ||||
|                     } | ||||
|                     LOG.info("ovsdbClient disconnected from {} on port {} clientCn {} AP {} ", remoteHost, localPort, clientCn, key); | ||||
| @@ -247,6 +256,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { | ||||
|             ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig); | ||||
|             ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); | ||||
|             ovsdbDao.createVlanNetworkInterfaces(ovsdbClient, opensyncAPConfig); | ||||
|             ovsdbDao.configureWiredPort(ovsdbClient, opensyncAPConfig); | ||||
|             ovsdbDao.configureRadsecRadiusAndRealm(ovsdbClient, opensyncAPConfig); | ||||
|             ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig); | ||||
|             if (opensyncAPConfig.getHotspotConfig() != null) { | ||||
| @@ -329,6 +339,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { | ||||
|         ovsdbDao.configureWifiRrm(ovsdbClient, opensyncAPConfig); | ||||
|         ovsdbDao.configureGreTunnels(ovsdbClient, opensyncAPConfig); | ||||
|         ovsdbDao.createVlanNetworkInterfaces(ovsdbClient, opensyncAPConfig); | ||||
|         ovsdbDao.configureWiredPort(ovsdbClient, opensyncAPConfig); | ||||
|         ovsdbDao.configureRadsecRadiusAndRealm(ovsdbClient, opensyncAPConfig); | ||||
|         ovsdbDao.configureSsids(ovsdbClient, opensyncAPConfig); | ||||
|         if (opensyncAPConfig.getHotspotConfig() != null) { | ||||
| @@ -634,7 +645,7 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { | ||||
|                         List<OpensyncAPInetState> inetStateDelete = new ArrayList<>(); | ||||
|  | ||||
|                         for (TableUpdate tableUpdate : tableUpdates.getTableUpdates().values()) { | ||||
|  | ||||
|                         	 | ||||
|                             for (RowUpdate rowUpdate : tableUpdate.getRowUpdates().values()) { | ||||
|  | ||||
|                                 if (rowUpdate.getNew() == null) { | ||||
| @@ -645,9 +656,9 @@ public class TipWlanOvsdbClient implements OvsdbClientInterface { | ||||
|  | ||||
|                             } | ||||
|                         } | ||||
|  | ||||
|                          | ||||
|                         // delete first | ||||
|                         extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateDelete, key); | ||||
|                         extIntegrationInterface.wifiInetStateDbTableDelete(inetStateDelete, key); | ||||
|  | ||||
|                         // now process updates and mutations | ||||
|                         extIntegrationInterface.wifiInetStateDbTableUpdate(inetStateInsertOrUpdate, key); | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package com.telecominfraproject.wlan.opensync.ovsdb; | ||||
|  | ||||
| import java.security.cert.Certificate; | ||||
| import java.security.cert.X509Certificate; | ||||
|  | ||||
| import javax.annotation.PostConstruct; | ||||
| @@ -14,13 +15,13 @@ import com.netflix.servo.DefaultMonitorRegistry; | ||||
| import com.netflix.servo.monitor.BasicCounter; | ||||
| import com.netflix.servo.monitor.Counter; | ||||
| import com.netflix.servo.monitor.MonitorConfig; | ||||
| import com.netflix.servo.monitor.Monitors; | ||||
| import com.netflix.servo.tag.TagList; | ||||
| import com.telecominfraproject.wlan.cloudmetrics.CloudMetricsTags; | ||||
| import com.telecominfraproject.wlan.opensync.ovsdb.dao.OvsdbDao; | ||||
| import com.telecominfraproject.wlan.opensync.util.SslUtil; | ||||
| import com.vmware.ovsdb.callback.ConnectionCallback; | ||||
| import com.vmware.ovsdb.service.OvsdbClient; | ||||
| import com.vmware.ovsdb.service.OvsdbConnectionInfo; | ||||
| import com.vmware.ovsdb.service.OvsdbPassiveConnectionListener; | ||||
|  | ||||
| import io.netty.handler.ssl.SslContext; | ||||
| @@ -77,11 +78,19 @@ public class TipWlanOvsdbRedirector { | ||||
|         ConnectionCallback connectionCallback = new ConnectionCallback() { | ||||
|             public void connected(OvsdbClient ovsdbClient) { | ||||
|                 connectionsAttempted.increment(); | ||||
|                 String remoteHost = ovsdbClient.getConnectionInfo().getRemoteAddress().getHostAddress(); | ||||
|                 int localPort = ovsdbClient.getConnectionInfo().getLocalPort(); | ||||
|                 String subjectDn = null; | ||||
|                  | ||||
|                 try { | ||||
|                     subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate()).getSubjectDN().getName(); | ||||
|                     OvsdbConnectionInfo connectionInfo = ovsdbClient.getConnectionInfo(); | ||||
|                     String remoteHost = connectionInfo.getRemoteAddress().getHostAddress(); | ||||
|                     Certificate remoteCertificate = connectionInfo.getRemoteCertificate(); | ||||
|                     if (remoteCertificate == null) { | ||||
|                     	LOG.debug("Connect attempt no certificate from {} on remote port {}", remoteHost, connectionInfo.getRemotePort()); | ||||
|                     	return; | ||||
|                     } | ||||
|                      | ||||
|                     int localPort = connectionInfo.getLocalPort(); | ||||
|                     String subjectDn = null; | ||||
| 					subjectDn = ((X509Certificate) remoteCertificate).getSubjectDN().getName(); | ||||
|                      | ||||
|                     String clientCn = SslUtil.extractCN(subjectDn); | ||||
|                     LOG.info("ovsdbClient redirector connected from {} on port {} clientCn {}", remoteHost, localPort, clientCn);                 | ||||
| @@ -101,7 +110,9 @@ public class TipWlanOvsdbRedirector { | ||||
|                 int localPort = ovsdbClient.getConnectionInfo().getLocalPort(); | ||||
|                 String subjectDn = null; | ||||
|                 try { | ||||
|                     subjectDn = ((X509Certificate) ovsdbClient.getConnectionInfo().getRemoteCertificate()).getSubjectDN().getName(); | ||||
|                 	Certificate remoteCertificate = ovsdbClient.getConnectionInfo().getRemoteCertificate(); | ||||
|                 	if (remoteCertificate != null) | ||||
|                 		subjectDn = ((X509Certificate) remoteCertificate).getSubjectDN().getName(); | ||||
|                 } catch (Exception e) { | ||||
|                     //do nothing | ||||
|                 } | ||||
|   | ||||
| @@ -86,11 +86,16 @@ public class OvsdbDao extends OvsdbDaoBase { | ||||
|         ovsdbNetwork.configureInterfaces(ovsdbClient); | ||||
|     } | ||||
|      | ||||
|     public void configureWiredPort(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { | ||||
|     	ovsdbNetwork.configureEthernetPorts(ovsdbClient, opensyncAPConfig); | ||||
|     } | ||||
|      | ||||
|     public void configureNode(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { | ||||
|         configureNtpServer(ovsdbClient, opensyncAPConfig); | ||||
|         configureSyslog(ovsdbClient, opensyncAPConfig); | ||||
|         processBlinkRequest(ovsdbClient, opensyncAPConfig.getCustomerEquipment().getInventoryId(), | ||||
|                 ((ApElementConfiguration) opensyncAPConfig.getCustomerEquipment().getDetails()).isBlinkAllLEDs()); | ||||
|         ovsdbNodeConfig.processLedControlEnabled(ovsdbClient, opensyncAPConfig); | ||||
|     } | ||||
|      | ||||
|     void configureNtpServer(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { | ||||
| @@ -242,7 +247,7 @@ public class OvsdbDao extends OvsdbDaoBase { | ||||
|     } | ||||
|  | ||||
|     public String processBlinkRequest(OvsdbClient ovsdbClient, String apId, boolean blinkAllLEDs) { | ||||
|         return ovsdbNodeConfig.processBlinkRequest(ovsdbClient,apId,blinkAllLEDs); | ||||
|         return ovsdbNodeConfig.processBlinkRequest(ovsdbClient, apId, blinkAllLEDs); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -93,6 +93,8 @@ public class OvsdbMonitor extends OvsdbDaoBase { | ||||
|             if (rowUpdate.getOld() != null) { | ||||
|                 row = rowUpdate.getOld(); | ||||
|                 row.getColumns().putAll(rowUpdate.getNew().getColumns()); | ||||
|             } else { | ||||
|             	row = rowUpdate.getNew(); | ||||
|             } | ||||
|         } else { | ||||
|             row = rowUpdate.getOld(); | ||||
|   | ||||
| @@ -21,6 +21,8 @@ import org.springframework.stereotype.Component; | ||||
| import com.telecominfraproject.wlan.equipment.models.NetworkForwardMode; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig; | ||||
| import com.telecominfraproject.wlan.opensync.ovsdb.dao.models.WifiInetConfigInfo; | ||||
| import com.telecominfraproject.wlan.profile.ethernetport.models.WiredEthernetPortConfiguration; | ||||
| import com.telecominfraproject.wlan.profile.ethernetport.models.WiredPort; | ||||
| import com.telecominfraproject.wlan.profile.models.Profile; | ||||
| import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration; | ||||
| import com.telecominfraproject.wlan.profile.network.models.GreTunnelConfiguration; | ||||
| @@ -45,7 +47,16 @@ import com.vmware.ovsdb.service.OvsdbClient; | ||||
| public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|  | ||||
|     @Autowired | ||||
|     OvsdbGet ovsdbGet; | ||||
|     private OvsdbGet ovsdbGet; | ||||
|  | ||||
|     private static final String VLAN_IF_TYPE = "vlan"; | ||||
|     private static final String VLAN_TRUNK_IF_TYPE = "vlan_trunk"; | ||||
|     private static final String BRIDGE_IF_TYPE = "bridge"; | ||||
|     private static final String LAN_IF_NAME = "lan"; | ||||
|     private static final String WAN_IF_NAME = "wan"; | ||||
|     private static final int DEFAULT_MAX_INTERNAL_VLAN_ID = 2; | ||||
|     private static final String SEPARATOR = " "; | ||||
|  | ||||
|  | ||||
|     void configureGreTunnel(OvsdbClient ovsdbClient, Profile apNetworkConfiguration) { | ||||
|         try { | ||||
| @@ -92,7 +103,7 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|                     LOG.info("configureGreTunnel {}", ((UpdateResult) res).toString()); | ||||
|                 } else if (res instanceof ErrorResult) { | ||||
|                     LOG.error("configureGreTunnel error {}", (res)); | ||||
|                     throw new RuntimeException("configureGreTunnel " + ((ErrorResult) res).getError() + " " | ||||
|                     throw new RuntimeException("configureGreTunnel " + ((ErrorResult) res).getError() + SEPARATOR | ||||
|                             + ((ErrorResult) res).getDetails()); | ||||
|                 } | ||||
|             } | ||||
| @@ -137,10 +148,216 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|             } else { | ||||
|                 operations.add(new Insert(wifiInetConfigDbTable, row)); | ||||
|             } | ||||
|              | ||||
|     } | ||||
|  | ||||
| 	void configureEthernetPorts(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncApConfig) { | ||||
| 		Profile wiredEthernetPortProfile = opensyncApConfig.getWiredEthernetPortProfile(); | ||||
|  | ||||
| 		if (wiredEthernetPortProfile != null) { | ||||
|             LOG.debug("Entering configure Ethernet Ports for wiredEthernetPortProfile {} for equipment {}", | ||||
|                     wiredEthernetPortProfile, opensyncApConfig.getCustomerEquipment().getId()); | ||||
| 			// Getting the config from the UI | ||||
| 			WiredEthernetPortConfiguration ethernetPortConfig = (WiredEthernetPortConfiguration) wiredEthernetPortProfile | ||||
| 					.getDetails(); | ||||
| 			LOG.debug("Configure EthernetPorts {}", ethernetPortConfig); | ||||
| 			Set<WiredPort> desiredWiredPorts = ethernetPortConfig.getEthPorts(); | ||||
|  | ||||
| 			handleEthernetPortConfiguration(ovsdbClient, desiredWiredPorts); | ||||
|  | ||||
| 		} else { | ||||
| 		    LOG.info("opensyncApConfig for Customer {}, Equipment {} has no wiredEthernetPortProfile attached" , | ||||
|                     opensyncApConfig.getCustomerEquipment().getCustomerId(), opensyncApConfig.getCustomerEquipment().getId()); | ||||
|         } | ||||
| 	} | ||||
|  | ||||
| 	private void handleEthernetPortConfiguration(OvsdbClient ovsdbClient, Set<WiredPort> desiredWiredPorts) { | ||||
|         if (desiredWiredPorts == null) { | ||||
|             LOG.info("Cannot handle the EthernetPort config for null desired Wired Ports. Exiting"); | ||||
|             return; | ||||
|         } | ||||
|         LOG.debug("In handleEthernetPortConfiguration with desiredWiredPorts {}", desiredWiredPorts); | ||||
|         WiredPort wanPort = getDefaultWanPort(desiredWiredPorts); | ||||
|         if (wanPort == null) { | ||||
|             LOG.error("Cannot find the default wan port from the desired list of ports {}" , desiredWiredPorts); | ||||
|             return; | ||||
|         } | ||||
|         for (WiredPort desiredPort : desiredWiredPorts) { | ||||
|             if (!desiredPort.equals(wanPort)) { | ||||
|                 if (isLanToBridgeConversion(desiredPort) && !desiredPort.isTrunkEnabled()) { | ||||
|                     // Flow 1: Desired Bridge + Access | ||||
|                     LOG.debug("Desired Config is Bridge with Access Mode"); | ||||
|                     changeLanToWan(ovsdbClient, desiredPort, wanPort); | ||||
|                     createVlanTag(ovsdbClient, desiredPort); | ||||
|                 } else if (isLanToBridgeConversion(desiredPort) && desiredPort.isTrunkEnabled()) { | ||||
|                     // Flow 2: Desired Bridge + Trunk | ||||
|                     LOG.debug("Desired Config is Bridge with Trunk Mode"); | ||||
|                     changeLanToWan(ovsdbClient, desiredPort, wanPort); | ||||
|                     createTrunkInterface(ovsdbClient, desiredPort); | ||||
|                 } else if (!BRIDGE_IF_TYPE.equalsIgnoreCase(desiredPort.getIfType())) { | ||||
|                     // Flow 3: Desired ifType is NAT | ||||
|                     LOG.debug("Desired Config is NAT (LAN) mode. Desired Port {} may still be tagged to WAN interface. Convert to LAN mode", desiredPort.getIfName()); | ||||
|                     changeWanToLan(ovsdbClient, desiredPort, wanPort); | ||||
|                 } else { | ||||
|                     LOG.info("Not a supported Config change requested for the port {}", desiredPort); | ||||
|                 } | ||||
|             } else { | ||||
|                 LOG.error("It's the default WAN port. No changes needed!"); | ||||
|             } | ||||
|         } // end of for loop | ||||
|     } | ||||
|  | ||||
|     private String generateInterfaceId(String portName, int vlanId, boolean trunk) { | ||||
|         if (!trunk) { | ||||
|             return String.format("%s_%s", portName, vlanId); | ||||
|         } else { | ||||
|             return String.format("%s_trunk", portName); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private boolean isLanToBridgeConversion(WiredPort desiredPort) { | ||||
|         return LAN_IF_NAME.equalsIgnoreCase(desiredPort.getIfName()) && | ||||
|                 BRIDGE_IF_TYPE.equals(desiredPort.getIfType()); | ||||
|     } | ||||
|  | ||||
| 	WiredPort getDefaultWanPort(Set<WiredPort> desiredPorts) { | ||||
| 		WiredPort wanWiredPort = desiredPorts.stream() | ||||
| 				.filter(entry -> WAN_IF_NAME.equals(entry.getIfName())).findFirst().orElse(null); | ||||
|  | ||||
| 		LOG.debug("Returning wanWiredPort {}", wanWiredPort); | ||||
| 		return wanWiredPort; | ||||
| 	} | ||||
|  | ||||
| 	void changeLanToWan(OvsdbClient ovsdbClient, WiredPort desiredWiredPort, WiredPort wanPort) { | ||||
|         LOG.debug("Moving Port {} with current ifName {} to WAN", desiredWiredPort.getName(), desiredWiredPort.getIfName()); | ||||
| 		List<Operation> operations = new ArrayList<>(); | ||||
| 		// Step1: remove lan from eth_ports | ||||
| 		// /usr/opensync/bin/ovsh u Wifi_Inet_Config eth_ports:=" " -w if_name==lan | ||||
| 		addEthPortsOperation(operations, SEPARATOR, LAN_IF_NAME); | ||||
| 		 | ||||
| 		// Step2: make lan to a wan port | ||||
| 		// /usr/opensync/bin/ovsh u Wifi_Inet_Config eth_ports:="eth0 eth1" -w if_name==wan | ||||
| 		// eth_ports syntax is set by AP (i.e, eth0 eth1) | ||||
| 		addEthPortsOperation(operations, desiredWiredPort.getName() + SEPARATOR + wanPort.getName(), WAN_IF_NAME); | ||||
| 		sendOperationsToAP(ovsdbClient, operations, "changeLanToWan"); | ||||
| 	} | ||||
|  | ||||
| 	private void createVlanTag(OvsdbClient ovsdbClient, WiredPort desiredWiredPort) { | ||||
|         LOG.debug("Creating a new VlanInterface for wiredPort {}", desiredWiredPort); | ||||
|         if (desiredWiredPort.getVlanId() > DEFAULT_MAX_INTERNAL_VLAN_ID) { | ||||
|             // Tag to vlan | ||||
|             // /usr/opensync/bin/ovsh i Wifi_Inet_Config NAT:=true enabled:=true | ||||
|             // if_name:=eth0_100 if_type:=vlan ip_assign_scheme:=none network:=true | ||||
|             // parent_ifname:=eth0 vlan_id:=100 dhcp_sniff:=false eth_ports:="eth0" | ||||
|             List<Operation> operations = new ArrayList<>(); | ||||
|             Map<String, Value> tableColumns = new HashMap<>(); | ||||
|             tableColumns.put("NAT", new Atom<>(true)); | ||||
|             tableColumns.put("enabled", new Atom<>(true)); | ||||
|             tableColumns.put("if_name", new Atom<>(generateInterfaceId(desiredWiredPort.getName(), desiredWiredPort.getVlanId(), false))); | ||||
|             tableColumns.put("if_type", new Atom<>(VLAN_IF_TYPE)); | ||||
|             tableColumns.put("ip_assign_scheme", new Atom<>("none")); | ||||
|             tableColumns.put("network", new Atom<>(true)); | ||||
|             tableColumns.put("parent_ifname", new Atom<>(desiredWiredPort.getName())); | ||||
|             tableColumns.put("vlan_id", new Atom<>(desiredWiredPort.getVlanId())); | ||||
|             tableColumns.put("dhcp_sniff", new Atom<>(false)); | ||||
|             tableColumns.put("eth_ports", new Atom<>(desiredWiredPort.getName())); | ||||
|             Row row = new Row(tableColumns); | ||||
|             operations.add(new Insert(wifiInetConfigDbTable, row)); | ||||
|  | ||||
|             sendOperationsToAP(ovsdbClient, operations, "createVlanTag"); | ||||
|         } else { | ||||
|             LOG.info("Desired vlanId {} is lower than default {}; no tagging needed", | ||||
|                     desiredWiredPort.getVlanId(), DEFAULT_MAX_INTERNAL_VLAN_ID); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void createTrunkInterface(OvsdbClient ovsdbClient, WiredPort desiredWiredPort) { | ||||
|         LOG.debug("Creating a new TrunkInterface for wiredPort {}", desiredWiredPort); | ||||
|  | ||||
|         // Create Trunk Interface | ||||
|         // /usr/opensync/bin/ovsh i Wifi_Inet_Config NAT:=true enabled:=true | ||||
|         // if_name:=eth0_trunk if_type:=vlan_trunk ip_assign_scheme:=none network:=true | ||||
|         // parent_ifname:=eth0 dhcp_sniff:=false eth_ports:="eth0" | ||||
|         // vlan_trunk:='["map",[["allowed_vlans","100 200 300"],["pvid","10"]]]' | ||||
|  | ||||
|         List<Operation> operations = new ArrayList<>(); | ||||
|         Map<String, Value> tableColumns = new HashMap<>(); | ||||
|         tableColumns.put("NAT", new Atom<>(true)); | ||||
|         tableColumns.put("enabled", new Atom<>(true)); | ||||
|         tableColumns.put("if_name", new Atom<>(generateInterfaceId(desiredWiredPort.getName(), desiredWiredPort.getVlanId(), true))); | ||||
|         tableColumns.put("if_type", new Atom<>(VLAN_TRUNK_IF_TYPE)); | ||||
|         tableColumns.put("ip_assign_scheme", new Atom<>("none")); | ||||
|         tableColumns.put("network", new Atom<>(true)); | ||||
|         tableColumns.put("parent_ifname", new Atom<>(desiredWiredPort.getName())); | ||||
|         tableColumns.put("dhcp_sniff", new Atom<>(false)); | ||||
|         tableColumns.put("eth_ports", new Atom<>(desiredWiredPort.getName())); | ||||
|  | ||||
|         Map<String, String> vlanTrunkMap = new HashMap<>(); | ||||
|  | ||||
|         if (desiredWiredPort.getAllowedVlanIds() != null) { | ||||
|             vlanTrunkMap.put("allowed_vlans", getAllowedVlanAsString(desiredWiredPort)); | ||||
|             if (desiredWiredPort.getVlanId() > DEFAULT_MAX_INTERNAL_VLAN_ID) { | ||||
|                 vlanTrunkMap.put("pvid", String.valueOf(desiredWiredPort.getVlanId())); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         com.vmware.ovsdb.protocol.operation.notation.Map<String, String> vlanTrunkVal = com.vmware.ovsdb.protocol.operation.notation.Map.of(vlanTrunkMap); | ||||
|  | ||||
|         tableColumns.put(VLAN_TRUNK_IF_TYPE, vlanTrunkVal); | ||||
|         Row row = new Row(tableColumns); | ||||
|         operations.add(new Insert(wifiInetConfigDbTable, row)); | ||||
|  | ||||
|         sendOperationsToAP(ovsdbClient, operations, "createTrunkInterface"); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private String getAllowedVlanAsString(WiredPort desiredWiredPort) { | ||||
|         return desiredWiredPort.getAllowedVlanIds().stream().map(String::valueOf).collect(Collectors.joining(SEPARATOR)); | ||||
|     } | ||||
|  | ||||
| 	void changeWanToLan(OvsdbClient ovsdbClient, WiredPort desiredWiredPort, WiredPort wanPort) { | ||||
| 		// Step1: set the correct port to lan | ||||
| 		// /usr/opensync/bin/ovsh u Wifi_Inet_Config eth_ports:="eth0" -w if_name==lan | ||||
| 		List<Operation> operations = new ArrayList<>(); | ||||
| 		addEthPortsOperation(operations, desiredWiredPort.getName(), LAN_IF_NAME); | ||||
|  | ||||
| 		// Step2: set the correct port to wan | ||||
| 		// /usr/opensync/bin/ovsh u Wifi_Inet_Config eth_ports:="eth1" -w if_name==wan | ||||
| 		addEthPortsOperation(operations, wanPort.getName(), WAN_IF_NAME); | ||||
|  | ||||
| 		sendOperationsToAP(ovsdbClient, operations, "changeWanToLan"); | ||||
| 	} | ||||
| 	 | ||||
| 	void addEthPortsOperation(List<Operation> operations, String ethPorts, String ifName) { | ||||
| 		Map<String, Value> tableColumn = new HashMap<>(); | ||||
| 		tableColumn.put("eth_ports", new Atom<>(ethPorts)); | ||||
| 		Row row = new Row(tableColumn); | ||||
| 		operations.add(new Update(wifiInetConfigDbTable, | ||||
| 				List.of(new Condition("if_name", Function.EQUALS, new Atom<>(ifName))), row)); | ||||
| 	} | ||||
|  | ||||
| 	void sendOperationsToAP(OvsdbClient ovsdbClient, List<Operation> operations, String methodName) { | ||||
| 		try { | ||||
| 			CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations); | ||||
| 			OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); | ||||
| 			for (OperationResult res : result) { | ||||
| 				if (res instanceof InsertResult) { | ||||
| 					LOG.info("{} - {}", methodName, res); | ||||
| 				} else if (res instanceof UpdateResult) { | ||||
| 					LOG.info("{} {}", methodName, res); | ||||
| 				} else if (res instanceof ErrorResult) { | ||||
| 					LOG.error("{} {}", methodName, res); | ||||
| 					throw new RuntimeException("createVlanNetworkInterfaces - " + ((ErrorResult) res).getError() + SEPARATOR | ||||
| 							+ ((ErrorResult) res).getDetails()); | ||||
| 				} | ||||
| 			} | ||||
| 		} catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { | ||||
| 			throw new RuntimeException(e); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|     /** | ||||
|      *  @param ovsdbClient | ||||
|      * @param ovsdbClient | ||||
|      * @param vifInterfaceName | ||||
|      * @param enabled | ||||
|      * @param networkForwardMode | ||||
| @@ -193,7 +410,7 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|                     LOG.info("createVlanNetworkInterfaces {}", ((UpdateResult) res).toString()); | ||||
|                 } else if (res instanceof ErrorResult) { | ||||
|                     LOG.error("createVlanNetworkInterfaces error {}", (res)); | ||||
|                     throw new RuntimeException("createVlanNetworkInterfaces " + ((ErrorResult) res).getError() + " " | ||||
|                     throw new RuntimeException("createVlanNetworkInterfaces " + ((ErrorResult) res).getError() + SEPARATOR | ||||
|                             + ((ErrorResult) res).getDetails()); | ||||
|                 } | ||||
|             } | ||||
| @@ -212,34 +429,8 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|             List<Operation> operations = new ArrayList<>(); | ||||
|             Map<String, Value> tableColumns = new HashMap<>(); | ||||
|             Map<String, WifiInetConfigInfo> inetConfigMap = ovsdbGet.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<>(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("ip_assign_scheme", new Atom<>(parentLanInterface.ipAssignScheme)); | ||||
|             tableColumns.put("NAT", new Atom<>(parentLanInterface.nat)); | ||||
|             tableColumns.put("mtu", new Atom<>(1500)); | ||||
|             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<>(parentLanInterface.netmask)); | ||||
|             tableColumns.put("dhcpd", com.vmware.ovsdb.protocol.operation.notation.Map.of(parentLanInterface.dhcpd)); | ||||
|             Row row = new Row(tableColumns); | ||||
|             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( | ||||
| @@ -251,8 +442,7 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|             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("ip_assign_scheme", new Atom<>(parentWanInterface.ipAssignScheme)); | ||||
|             tableColumns.put("ip_assign_scheme", new Atom<>("none")); | ||||
|             tableColumns.put("NAT", new Atom<>(parentWanInterface.nat)); | ||||
|             tableColumns.put("mtu", new Atom<>(1500)); | ||||
|             row = new Row(tableColumns); | ||||
| @@ -272,14 +462,13 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|                     LOG.info("createVlanNetworkInterfaces {}", ((UpdateResult) res).toString()); | ||||
|                 } else if (res instanceof ErrorResult) { | ||||
|                     LOG.error("createVlanNetworkInterfaces error {}", (res)); | ||||
|                     throw new RuntimeException("createVlanNetworkInterfaces " + ((ErrorResult) res).getError() + " " | ||||
|                     throw new RuntimeException("createVlanNetworkInterfaces " + ((ErrorResult) res).getError() + SEPARATOR | ||||
|                             + ((ErrorResult) res).getDetails()); | ||||
|                 } | ||||
|             } | ||||
|             inetConfigMap = ovsdbGet.getProvisionedWifiInetConfigs(ovsdbClient); | ||||
|             LOG.debug("Provisioned vlan on wan {} and lan {}", | ||||
|                     inetConfigMap.get(parentWanInterface.ifName + "_" + Integer.toString(vlanId)), | ||||
|                     inetConfigMap.get(parentLanInterface.ifName + "_" + Integer.toString(vlanId))); | ||||
|                     inetConfigMap.get(parentWanInterface.ifName + "_" + Integer.toString(vlanId))); | ||||
|         } catch (OvsdbClientException | TimeoutException | ExecutionException | InterruptedException e) { | ||||
|             LOG.error("Error in provisioning Vlan", e); | ||||
|             throw new RuntimeException(e); | ||||
| @@ -316,33 +505,34 @@ public class OvsdbNetworkConfig extends OvsdbDaoBase { | ||||
|             Collection<WifiInetConfigInfo> provisionedWifiInetConfigs = ovsdbGet | ||||
|                     .getProvisionedWifiInetConfigs(ovsdbClient).values(); | ||||
|             List<Operation> operations = new ArrayList<>(); | ||||
|             List<Condition> conditions = new ArrayList<>(); | ||||
|             for (WifiInetConfigInfo wifiInetConfigInfo : provisionedWifiInetConfigs) { | ||||
|                 if (wifiInetConfigInfo.vlanId > 1 || wifiInetConfigInfo.ifType.equals("vif") | ||||
|                         || wifiInetConfigInfo.ifName.startsWith("gre") || wifiInetConfigInfo.ifType.equals("gre")) { | ||||
|                     conditions = new ArrayList<>(); | ||||
|                 if (wifiInetConfigInfo.vlanId > 1 | ||||
|                         || wifiInetConfigInfo.ifType.equals("vif") | ||||
|                         || wifiInetConfigInfo.ifName.startsWith("gre") || wifiInetConfigInfo.ifType.equals("gre") | ||||
|                         || VLAN_IF_TYPE.equalsIgnoreCase(wifiInetConfigInfo.ifType) // Remove any existing vlan/vlan_trunk tagging | ||||
|                         || VLAN_TRUNK_IF_TYPE.equalsIgnoreCase(wifiInetConfigInfo.ifType) ) { | ||||
|                     List<Condition> conditions = new ArrayList<>(); | ||||
|                     conditions.add(new Condition("if_name", Function.EQUALS, new Atom<>(wifiInetConfigInfo.ifName))); | ||||
|                     operations.add(new Delete(wifiInetConfigDbTable, conditions)); | ||||
|                 } | ||||
|             } | ||||
|             CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations); | ||||
|             OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); | ||||
|             LOG.info("Removed all existing vif, vlan, and gre interface configs from {}:", wifiInetConfigDbTable); | ||||
|             LOG.info("Removed all existing vif, vlan, vlan_trunk and gre interface configs from {}:", wifiInetConfigDbTable); | ||||
|             for (OperationResult res : result) { | ||||
|                 LOG.info("Op Result {}", res); | ||||
|             } | ||||
|             provisionedWifiInetConfigs = ovsdbGet.getProvisionedWifiInetConfigs(ovsdbClient).values(); | ||||
|             for (WifiInetConfigInfo inetConfigInfo : provisionedWifiInetConfigs) { | ||||
|                 if (inetConfigInfo.ifType.equals("vif") || inetConfigInfo.ifType.equals("gre")) { | ||||
|                 if (inetConfigInfo.ifType.equals("vif") || inetConfigInfo.ifType.equals("gre") || | ||||
|                         VLAN_IF_TYPE.equals(inetConfigInfo.ifType) || VLAN_TRUNK_IF_TYPE.equals(inetConfigInfo.ifType)) { | ||||
|                     throw new RuntimeException( | ||||
|                             "Failed to remove all vif and gre interface configurations from Wifi_Inet_Config dbTable, still has " | ||||
|                             "Failed to remove all vif, gre, vlan interface configurations from Wifi_Inet_Config dbTable, still has " | ||||
|                                     + provisionedWifiInetConfigs.stream().filter(new Predicate<WifiInetConfigInfo>() { | ||||
|                                         @Override | ||||
|                                         public boolean test(WifiInetConfigInfo t) { | ||||
|                                             if ((t.ifType.equals("vif")) || (t.ifType.equals("gre"))) { | ||||
|                                                 return true; | ||||
|                                             } | ||||
|                                             return false; | ||||
|                                             return (t.ifType.equals("vif")) || (t.ifType.equals("gre")) || | ||||
|                                                   VLAN_IF_TYPE.equals(t.ifType) || VLAN_TRUNK_IF_TYPE.equals(t.ifType); | ||||
|                                         } | ||||
|                                     }).collect(Collectors.toList())); | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,7 @@ import java.util.concurrent.TimeoutException; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| import com.telecominfraproject.wlan.core.model.equipment.LedStatus; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig; | ||||
| import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguration; | ||||
| import com.vmware.ovsdb.exception.OvsdbClientException; | ||||
| @@ -120,51 +121,82 @@ public class OvsdbNodeConfig extends OvsdbDaoBase { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public String processBlinkRequest(OvsdbClient ovsdbClient, String apId, boolean blinkAllLEDs) { | ||||
| 	public void processLedControlEnabled(OvsdbClient ovsdbClient, OpensyncAPConfig opensyncAPConfig) { | ||||
| 		try { | ||||
| 			Map<String, Value> columns = new HashMap<>(); | ||||
| 			ApNetworkConfiguration apNetworkConfig = (ApNetworkConfiguration) opensyncAPConfig.getApProfile() | ||||
| 					.getDetails(); | ||||
| 			if (apNetworkConfig.isLedControlEnabled() == null) { | ||||
| 				LOG.info("Cannot configure isLedControlEnabled to null value. {}", apNetworkConfig); | ||||
| 				return; | ||||
| 			} | ||||
| 			if (apNetworkConfig.isLedControlEnabled()) { | ||||
| 				columns.put("module", new Atom<>("led")); | ||||
| 				columns.put("key", new Atom<>("led_state")); | ||||
| 				columns.put("value", new Atom<>("on")); | ||||
| 			} else { | ||||
| 				columns.put("module", new Atom<>("led")); | ||||
| 				columns.put("key", new Atom<>("led_state")); | ||||
| 				columns.put("value", new Atom<>("off")); | ||||
| 			} | ||||
|  | ||||
|         String ret = null; | ||||
|         try { | ||||
| 			List<Operation> operations = new ArrayList<>(); | ||||
| 			operations.add(new Update(nodeConfigTable, | ||||
| 					List.of(new Condition("module", Function.EQUALS, new Atom<>("led"))), new Row(columns))); | ||||
| 			CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations); | ||||
| 			OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); | ||||
| 			for (OperationResult res : result) { | ||||
| 				LOG.debug("processLedControlEnabled result {}", res); | ||||
| 			} | ||||
| 		} catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { | ||||
| 			throw new RuntimeException(e); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|             LOG.debug("processBlinkRequest set BlinkLEDs to {}", blinkAllLEDs); | ||||
|             Map<String, Value> columns = new HashMap<>(); | ||||
|             if (blinkAllLEDs) { | ||||
|                 columns.put("module", new Atom<>("led")); | ||||
|                 columns.put("key", new Atom<>("led_blink")); | ||||
|                 columns.put("value", new Atom<>("on")); | ||||
|             } else { | ||||
|                 columns.put("module", new Atom<>("led")); | ||||
|                 columns.put("key", new Atom<>("led_off")); | ||||
|                 columns.put("value", new Atom<>("off")); | ||||
|             } | ||||
|             List<Operation> operations = new ArrayList<>(); | ||||
|             operations.add(new Update(nodeConfigTable, List.of(new Condition("module", Function.EQUALS, new Atom<>("led"))), new Row(columns))); | ||||
|             CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations); | ||||
|             OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); | ||||
|             long numUpdates = 0; | ||||
|             for (OperationResult res : result) { | ||||
|                 if (res instanceof UpdateResult) { | ||||
|                     numUpdates += ((UpdateResult) res).getCount(); | ||||
|                     LOG.debug("processBlinkRequest update result {}", res); | ||||
|                     ret = "processBlinkRequest update result " + res; | ||||
|                 } | ||||
|             } | ||||
|             if (numUpdates == 0) { | ||||
|                 // no records existed, insert the row instead | ||||
|                 operations.clear(); | ||||
|                 operations.add(new Insert(nodeConfigTable, new Row(columns))); | ||||
|                 fResult = ovsdbClient.transact(ovsdbName, operations); | ||||
|                 result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); | ||||
|                 for (OperationResult res : result) { | ||||
|                     if (res instanceof InsertResult) { | ||||
|                         LOG.debug("processBlinkRequest insert result {}", res); | ||||
|                         ret = "processBlinkRequest insert result " + res; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|              | ||||
|             return ret; | ||||
|         } catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { | ||||
|             throw new RuntimeException(e); | ||||
|         } | ||||
|     } | ||||
| 	public String processBlinkRequest(OvsdbClient ovsdbClient, String apId, boolean blinkAllLEDs) { | ||||
|  | ||||
| 		String ret = null; | ||||
| 		try { | ||||
|  | ||||
| 			LOG.debug("processLEDRequest set LEDs status to {}", blinkAllLEDs ? "led_blink" : "led_state"); | ||||
| 			Map<String, Value> columns = new HashMap<>(); | ||||
| 			if (blinkAllLEDs) { | ||||
| 				columns.put("module", new Atom<>("led")); | ||||
| 				columns.put("key", new Atom<>("led_blink")); | ||||
| 			} else { | ||||
| 				columns.put("module", new Atom<>("led")); | ||||
| 				columns.put("key", new Atom<>("led_state")); | ||||
| 			} | ||||
| 			List<Operation> operations = new ArrayList<>(); | ||||
| 			operations.add(new Update(nodeConfigTable, | ||||
| 					List.of(new Condition("module", Function.EQUALS, new Atom<>("led"))), new Row(columns))); | ||||
| 			CompletableFuture<OperationResult[]> fResult = ovsdbClient.transact(ovsdbName, operations); | ||||
| 			OperationResult[] result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); | ||||
| 			long numUpdates = 0; | ||||
| 			for (OperationResult res : result) { | ||||
| 				if (res instanceof UpdateResult) { | ||||
| 					numUpdates += ((UpdateResult) res).getCount(); | ||||
| 					LOG.debug("processBlinkRequest update result {}", res); | ||||
| 					ret = "processBlinkRequest update result " + res; | ||||
| 				} | ||||
| 			} | ||||
| 			if (numUpdates == 0) { | ||||
| 				// no records existed, insert the row instead | ||||
| 				operations.clear(); | ||||
| 				operations.add(new Insert(nodeConfigTable, new Row(columns))); | ||||
| 				fResult = ovsdbClient.transact(ovsdbName, operations); | ||||
| 				result = fResult.get(ovsdbTimeoutSec, TimeUnit.SECONDS); | ||||
| 				for (OperationResult res : result) { | ||||
| 					if (res instanceof InsertResult) { | ||||
| 						LOG.debug("processBlinkRequest insert result {}", res); | ||||
| 						ret = "processBlinkRequest insert result " + res; | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			return ret; | ||||
| 		} catch (OvsdbClientException | InterruptedException | ExecutionException | TimeoutException e) { | ||||
| 			throw new RuntimeException(e); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -352,7 +352,7 @@ public class OvsdbStatsConfig extends OvsdbDaoBase { | ||||
|                     rowColumns.put("stats_type", new Atom<>("survey")); | ||||
|                     rowColumns.put("survey_type", new Atom<>("off-chan")); | ||||
|                     rowColumns.put("sampling_interval", new Atom<>(10)); | ||||
|                     rowColumns.put("survey_interval_ms", new Atom<>(50)); | ||||
|                     rowColumns.put("survey_interval_ms", new Atom<>(120)); | ||||
|                     rowColumns.put("threshold", thresholds); | ||||
|                     Row updateRow = new Row(rowColumns); | ||||
|                     operations.add(new Insert(wifiStatsConfigDbTable, updateRow)); | ||||
|   | ||||
| @@ -34,11 +34,8 @@ import org.springframework.context.annotation.Import; | ||||
| import org.springframework.test.context.ActiveProfiles; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
|  | ||||
| import com.google.common.collect.ImmutableList; | ||||
| import com.google.common.collect.ImmutableMap; | ||||
| import com.telecominfraproject.wlan.core.model.equipment.RadioType; | ||||
| import com.telecominfraproject.wlan.location.models.Location; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.ConnectNodeInfo; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPHotspot20Config; | ||||
| import com.telecominfraproject.wlan.profile.models.Profile; | ||||
| @@ -47,10 +44,8 @@ import com.telecominfraproject.wlan.profile.network.models.ApNetworkConfiguratio | ||||
| import com.telecominfraproject.wlan.profile.network.models.GreTunnelConfiguration; | ||||
| import com.telecominfraproject.wlan.profile.ssid.models.SsidConfiguration; | ||||
| import com.vmware.ovsdb.exception.OvsdbClientException; | ||||
| import com.vmware.ovsdb.protocol.operation.notation.Atom; | ||||
| import com.vmware.ovsdb.protocol.operation.notation.Row; | ||||
| import com.vmware.ovsdb.protocol.operation.notation.Uuid; | ||||
| import com.vmware.ovsdb.protocol.operation.notation.Value; | ||||
| import com.vmware.ovsdb.protocol.operation.result.ErrorResult; | ||||
| import com.vmware.ovsdb.protocol.operation.result.InsertResult; | ||||
| import com.vmware.ovsdb.protocol.operation.result.OperationResult; | ||||
|   | ||||
| @@ -0,0 +1,160 @@ | ||||
| package com.telecominfraproject.wlan.opensync.ovsdb.dao; | ||||
|  | ||||
| import com.telecominfraproject.wlan.equipment.models.Equipment; | ||||
| import com.telecominfraproject.wlan.opensync.external.integration.models.OpensyncAPConfig; | ||||
| import com.telecominfraproject.wlan.profile.ethernetport.models.WiredEthernetPortConfiguration; | ||||
| import com.telecominfraproject.wlan.profile.ethernetport.models.WiredPort; | ||||
| import com.telecominfraproject.wlan.profile.models.Profile; | ||||
| import com.telecominfraproject.wlan.profile.models.ProfileType; | ||||
| import com.vmware.ovsdb.exception.OvsdbClientException; | ||||
| import com.vmware.ovsdb.protocol.operation.result.OperationResult; | ||||
| import com.vmware.ovsdb.protocol.operation.result.UpdateResult; | ||||
| import com.vmware.ovsdb.service.OvsdbClient; | ||||
| import org.junit.After; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.mockito.Answers; | ||||
| import org.mockito.Mock; | ||||
| import org.mockito.Mockito; | ||||
| import org.mockito.MockitoSession; | ||||
| import org.mockito.quality.Strictness; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.boot.test.mock.mockito.MockBean; | ||||
| import org.springframework.context.annotation.Import; | ||||
| import org.springframework.test.context.ActiveProfiles; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Set; | ||||
| import java.util.concurrent.CompletableFuture; | ||||
| import java.util.concurrent.ExecutionException; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import java.util.concurrent.TimeoutException; | ||||
|  | ||||
| import static org.mockito.Mockito.times; | ||||
|  | ||||
| /** | ||||
|  * @author rsharma | ||||
|  */ | ||||
|  | ||||
| @RunWith(SpringRunner.class) | ||||
| @ActiveProfiles(profiles = { "integration_test", }) | ||||
| @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = OvsdbNetworkConfigTest.class) | ||||
| @Import(value = { OvsdbNetworkConfig.class | ||||
|  | ||||
| }) | ||||
| public class OvsdbNetworkConfigTest { | ||||
|  | ||||
|     @Mock(answer = Answers.RETURNS_MOCKS) | ||||
|     OvsdbClient ovsdbClient; | ||||
|  | ||||
|     @Autowired | ||||
|     OvsdbNetworkConfig ovsdbNetworkConfig; | ||||
|  | ||||
|     @MockBean(answer = Answers.RETURNS_MOCKS) | ||||
|     OvsdbGet ovsdbGet; | ||||
|  | ||||
|     @Mock(answer = Answers.RETURNS_MOCKS) | ||||
|     CompletableFuture<OperationResult[]> futureResult; | ||||
|  | ||||
|     private MockitoSession mockito; | ||||
|  | ||||
|     @Before | ||||
|     public void setUp() throws Exception { | ||||
|         mockito = Mockito.mockitoSession().initMocks(this).strictness(Strictness.STRICT_STUBS).startMocking(); | ||||
|         Mockito.when(ovsdbClient.transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList())).thenReturn(futureResult); | ||||
|     } | ||||
|  | ||||
|     @After | ||||
|     public void tearDown() throws Exception { | ||||
|         mockito.finishMocking(); | ||||
|     } | ||||
|  | ||||
|     // Eth0 port is in LAN mode and we need it to convert to eth0_trunk | ||||
|     @Test | ||||
|     public void testConfigureEthernetPorts_BridgeTrunkMode() throws ExecutionException, InterruptedException, TimeoutException, OvsdbClientException { | ||||
|         OperationResult[] updateResult = new OperationResult[] { new UpdateResult(1) }; | ||||
|         Mockito.when(futureResult.get(ovsdbNetworkConfig.ovsdbTimeoutSec, TimeUnit.SECONDS)) | ||||
|                 .thenReturn(updateResult); | ||||
|  | ||||
|         ovsdbNetworkConfig.configureEthernetPorts(ovsdbClient, createOpensyncApConfig(true, "bridge")); | ||||
|  | ||||
|         Mockito.verify(ovsdbClient, times(2)).transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList()); | ||||
|     } | ||||
|  | ||||
|     // Other tests that are useful to consider -- NOT anymore with GW deleting existing interfaces | ||||
|     // Case when ETH port is in eth0_trunk mode and no changes are required | ||||
|     // Case when ETH port is already in eth0_vlan100 and no changes are required | ||||
|  | ||||
|     // Case when ETH port is in LAN mode and we convert it into BRIDGE + VlanId | ||||
|     @Test | ||||
|     public void testConfigureEthernetPorts_BridgeAccessMode() throws ExecutionException, InterruptedException, TimeoutException, OvsdbClientException { | ||||
|         OperationResult[] updateResult = new OperationResult[] { new UpdateResult(1) }; | ||||
|         Mockito.when(futureResult.get(ovsdbNetworkConfig.ovsdbTimeoutSec, TimeUnit.SECONDS)) | ||||
|                 .thenReturn(updateResult); | ||||
|  | ||||
|         ovsdbNetworkConfig.configureEthernetPorts(ovsdbClient, createOpensyncApConfig(false, "bridge")); | ||||
|  | ||||
|         Mockito.verify(ovsdbClient, times(2)).transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList()); | ||||
|     } | ||||
|  | ||||
|     // Case when ETH port is in BRIDGE + VlanId and we convert it into NAT (LAN) | ||||
|     @Test | ||||
|     public void testConfigureEthernetPorts_BridgeAccessToNATConversion() throws ExecutionException, InterruptedException, TimeoutException, OvsdbClientException { | ||||
|         OperationResult[] updateResult = new OperationResult[] { new UpdateResult(1) }; | ||||
|         Mockito.when(futureResult.get(ovsdbNetworkConfig.ovsdbTimeoutSec, TimeUnit.SECONDS)) | ||||
|                 .thenReturn(updateResult); | ||||
|  | ||||
|         ovsdbNetworkConfig.configureEthernetPorts(ovsdbClient, createOpensyncApConfig(false, "NAT")); | ||||
|  | ||||
|         Mockito.verify(ovsdbClient, times(1)).transact(Mockito.eq(OvsdbDao.ovsdbName), Mockito.anyList()); | ||||
|     } | ||||
|  | ||||
|     private OpensyncAPConfig createOpensyncApConfig(boolean isTrunkEnabled, String ifType) { | ||||
|         OpensyncAPConfig opensyncApConfig = new OpensyncAPConfig(); | ||||
|  | ||||
|         Equipment customerEquip = new Equipment(); | ||||
|         customerEquip.setCustomerId(1); | ||||
|         customerEquip.setId(1L); | ||||
|         opensyncApConfig.setCustomerEquipment(customerEquip); | ||||
|         opensyncApConfig.setWiredEthernetPortProfile(createWiredEthernetPortProfile(isTrunkEnabled, ifType)); | ||||
|  | ||||
|         return opensyncApConfig; | ||||
|     } | ||||
|  | ||||
|     private Profile createWiredEthernetPortProfile(boolean isTrunkEnabled, String ifType) { | ||||
|         WiredPort portLan = createWiredPort("lan", ifType, isTrunkEnabled, 10, List.of(100, 200), "eth0", "ETHERNET"); | ||||
|         WiredPort portWan = createWiredPort("wan", "bridge", false, 0, null, "eth1", "INTERNET"); | ||||
|  | ||||
|         WiredEthernetPortConfiguration details = new WiredEthernetPortConfiguration(); | ||||
|         details.setEquipmentModel("EA8300"); | ||||
|         details.setEthPorts(Set.of(portLan, portWan)); | ||||
|  | ||||
|         Profile wiredEthernetPortProfile = new Profile(); | ||||
|         wiredEthernetPortProfile.setCustomerId(1); | ||||
|         wiredEthernetPortProfile.setProfileType(ProfileType.wired_ethernet_port); | ||||
|         wiredEthernetPortProfile.setId(10L); | ||||
|         wiredEthernetPortProfile.setName("WiredProfileForTest"); | ||||
|         wiredEthernetPortProfile.setCreatedTimestamp(1634060798000L); | ||||
|         wiredEthernetPortProfile.setLastModifiedTimestamp(1634060798000L); | ||||
|         wiredEthernetPortProfile.setDetails(details); | ||||
|  | ||||
|         return wiredEthernetPortProfile; | ||||
|     } | ||||
|  | ||||
|     private WiredPort createWiredPort(String ifName, String ifType, boolean isTrunkEnabled, int vlanId, List<Integer> allowedVlans, | ||||
|                                       String name, String displayName) { | ||||
|         WiredPort wiredPort = new WiredPort(); | ||||
|         wiredPort.setIfName(ifName); | ||||
|         wiredPort.setIfType(ifType); | ||||
|         wiredPort.setTrunkEnabled(isTrunkEnabled); | ||||
|         wiredPort.setVlanId(vlanId); | ||||
|         wiredPort.setAllowedVlanIds(allowedVlans); | ||||
|         wiredPort.setName(name); | ||||
|         wiredPort.setDisplayName(displayName); | ||||
|  | ||||
|         return wiredPort; | ||||
|     } | ||||
| } | ||||
| @@ -37,7 +37,6 @@ import com.vmware.ovsdb.service.OvsdbClient; | ||||
|         OvsdbHotspotConfig.class, OvsdbCommandConfig.class, OvsdbMonitor.class, OvsdbFirmwareConfig.class, | ||||
|         OvsdbStatsConfig.class, OvsdbSsidConfig.class, OvsdbRrmConfig.class, OvsdbNetworkConfig.class, | ||||
|         OvsdbNodeConfig.class,OvsdbRadiusProxyConfig.class | ||||
|  | ||||
| }) | ||||
| public class OvsdbNodeTest { | ||||
|  | ||||
|   | ||||
| @@ -42,7 +42,6 @@ import com.vmware.ovsdb.service.OvsdbClient; | ||||
|         OvsdbHotspotConfig.class, OvsdbCommandConfig.class, OvsdbMonitor.class, OvsdbFirmwareConfig.class, | ||||
|         OvsdbStatsConfig.class, OvsdbSsidConfig.class, OvsdbRrmConfig.class, OvsdbNetworkConfig.class, | ||||
|         OvsdbNodeConfig.class,OvsdbRadiusProxyConfig.class | ||||
|  | ||||
| }) | ||||
| public class OvsdbSsidConfigTest { | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user