use of com.att.aro.core.peripheral.pojo.NetworkTypeObject in project VideoOptimzer by attdevsupport.
the class NetworkTypeReaderImpl method readData.
@Override
public NetworkTypeObject readData(String directory, double startTime, double traceDuration) {
NetworkTypeObject obj = null;
List<NetworkBearerTypeInfo> networkTypeInfos = new ArrayList<NetworkBearerTypeInfo>();
List<NetworkType> networkTypesList = new ArrayList<NetworkType>();
String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.NETWORKINFO_FILE;
if (!filereader.fileExist(filepath)) {
return obj;
}
String[] lines = null;
try {
lines = filereader.readAllLine(filepath);
} catch (IOException e1) {
LOGGER.error("failed to read network info file: " + filepath);
}
String line;
if (lines != null && lines.length > 0) {
line = lines[0];
// Clear any data that may have been added by device_details
networkTypeInfos.clear();
NetworkType networkType;
NetworkType overrideNetworkType = NetworkType.OVERRIDE_NETWORK_TYPE_NONE;
double beginTime;
double endTime;
String[] fields = line.split(" ");
if (fields.length >= 2) {
beginTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime);
try {
networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1]));
if (fields.length > 2) {
overrideNetworkType = getOverriderNetworkTypeFromCode(Integer.parseInt(fields[2]));
}
} catch (NumberFormatException e) {
networkType = NetworkType.UNKNOWN;
LOGGER.warn("Invalid network type [" + fields[1] + "]");
}
networkTypesList.add(networkType);
for (int i = 1; i < lines.length; i++) {
line = lines[i];
fields = line.split(" ");
if (fields.length >= 2) {
endTime = Util.normalizeTime(Double.parseDouble(fields[0]), startTime);
networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, endTime, networkType, overrideNetworkType));
try {
networkType = getNetworkTypeFromCode(Integer.parseInt(fields[1]));
if (fields.length > 2) {
overrideNetworkType = getOverriderNetworkTypeFromCode(Integer.parseInt(fields[2]));
}
} catch (NumberFormatException e) {
networkType = NetworkType.UNKNOWN;
LOGGER.warn("Invalid network type [" + fields[1] + "]");
}
beginTime = endTime;
if (!networkTypesList.contains(networkType)) {
networkTypesList.add(networkType);
}
}
}
networkTypeInfos.add(new NetworkBearerTypeInfo(beginTime, traceDuration, networkType, overrideNetworkType));
}
}
obj = new NetworkTypeObject();
obj.setNetworkTypeInfos(networkTypeInfos);
obj.setNetworkTypesList(networkTypesList);
return obj;
}
use of com.att.aro.core.peripheral.pojo.NetworkTypeObject in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImpl method readFileUtil.
/**
* some of the trace files read here
*
* Parses the user event trace
*
* @throws IOException
*
* Reads the screen rotations information contained in the
* "screen_rotations" file found inside the trace directory and adds
* them to the user events list.
* @throws IOException
* Reads the CPU trace information from the CPU file.
*
* @throws IOException
* Method to read the GPS data from the trace file and store it in
* the gpsInfos list. It also updates the active duration for GPS.
* Method to read the Bluetooth data from the trace file and store
* it in the bluetoothInfos list. It also updates the active
* duration for Bluetooth.
*
* @throws IOException
* Method to read the Camera data from the trace file and store it
* in the cameraInfos list. It also updates the active duration for
* Camera.
*
* Method to read the WIFI data from the trace file and store it in
* the wifiInfos list. It also updates the active duration for Wifi.
*
* Method to read the Screen State data from the trace file and
* store it in the ScreenStateInfos list.
*
* Method to read the Battery data from the trace file and store it
* in the batteryInfos list.
*
* Method to read the alarm event from the trace file and store it
* in the alarmInfos list.
*
* Reads the Radio data from the file and stores it in the
* RadioInfo.
* @param result
*/
public void readFileUtil(TraceDirectoryResult result) {
NetworkTypeObject obj = networktypereader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
if (obj != null) {
result.setNetworkTypeInfos(obj.getNetworkTypeInfos());
result.setNetworkTypesList(obj.getNetworkTypesList());
}
CollectOptions collectOptions = collectOptionsReader.readData(result.getTraceDirectory());
result.setCollectOptions(collectOptions);
List<UserEvent> userEvents = usereventreader.readData(result.getTraceDirectory(), result.getEventTime0(), result.getPcapTime0());
result.setUserEvents(userEvents);
List<UserEvent> list = this.screenrotationreader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setScreenRotationCounter(list.size());
result.getUserEvents().addAll(list);
List<TemperatureEvent> temperatureEvents = cputemperaturereader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setTemperatureInfos(temperatureEvents);
List<LocationEvent> locationEvents = locationreader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setLocationEventInfos(locationEvents);
CpuActivityList cpuActivityList = cpureader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setCpuActivityList(cpuActivityList);
List<GpsInfo> gpsInfos = gpsreader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setGpsInfos(gpsInfos);
result.setGpsActiveDuration(gpsreader.getGpsActiveDuration());
List<BluetoothInfo> bluetoothInfos = bluetoothreader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setBluetoothInfos(bluetoothInfos);
result.setBluetoothActiveDuration(bluetoothreader.getBluetoothActiveDuration());
List<WifiInfo> wifiInfos = wifireader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setWifiInfos(wifiInfos);
result.setWifiActiveDuration(wifireader.getWifiActiveDuration());
List<CameraInfo> cameraInfos = camerareader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setCameraInfos(cameraInfos);
result.setCameraActiveDuration(camerareader.getActiveDuration());
List<ThermalStatusInfo> thermalStatusInfos = new ThermalStatusReaderImpl(filereader).readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setThermalstatusInfos(thermalStatusInfos);
List<ScreenStateInfo> screenStateInfos = screenstatereader.readData(result.getTraceDirectory(), result.getPcapTime0(), result.getTraceDuration());
result.setScreenStateInfos(screenStateInfos);
List<BatteryInfo> batteryInfos = batteryinforeader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setBatteryInfos(batteryInfos);
// alarm info from kernel log file
List<AlarmInfo> alarmInfos = alarminforeader.readData(result.getTraceDirectory(), result.getDumpsysEpochTimestamp(), result.getDumpsysElapsedTimestamp(), result.getTraceDateTime());
result.setAlarmInfos(alarmInfos);
List<RadioInfo> radioInfos = radioinforeader.readData(result.getTraceDirectory(), result.getPcapTime0());
result.setRadioInfos(radioInfos);
VideoStreamStartupData videoStreamStartupData = videoStartupReader.readData(result.getTraceDirectory());
result.setVideoStartupData(videoStreamStartupData);
result.setMetaData(metaDataReadWrite.readData(result.getTraceDirectory()));
}
use of com.att.aro.core.peripheral.pojo.NetworkTypeObject in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImplTest method readTraceDir_.
@Test
public void readTraceDir_() throws IOException {
String[] time = { "1410212153 1410213352", "272927100", "1410213352.550" };
String[] appId = { "5", "5", "13", "-127" };
traceDataReaderImpl.setFileReader(filereader);
when(filereader.directoryExist(any(String.class))).thenReturn(true);
when(filereader.fileExist(any(String.class))).thenReturn(true);
when(filereader.readAllLine(any(String.class))).thenReturn(time);
when(filereader.readAllLine(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "appid")).thenReturn(appId);
when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "traffic1.cap")).thenReturn(false);
Map<String, List<ScheduledAlarmInfo>> scheduledAlarms = new HashMap<String, List<ScheduledAlarmInfo>>();
List<AlarmAnalysisInfo> statistics = new ArrayList<AlarmAnalysisInfo>();
AlarmAnalysisResult alarmResult = mock(AlarmAnalysisResult.class);
when(alarmResult.getScheduledAlarms()).thenReturn(scheduledAlarms);
when(alarmResult.getStatistics()).thenReturn(statistics);
when(alarmanalysisinfoparser.parse(any(String.class), any(String.class), any(String.class), any(double.class), any(double.class), any(Date.class))).thenReturn(alarmResult);
// Crypto
traceDataReaderImpl.setCrypto(crypto);
when(crypto.readSSLKeys(any(String.class))).thenReturn(1);
Mockito.doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
byte b = 3;
short s = 1;
InetAddress address1 = null;
InetAddress address2 = null;
try {
address2 = InetAddress.getByName("78.46.84.177");
address1 = InetAddress.getByName("78.46.84.171");
} catch (UnknownHostException e) {
e.printStackTrace();
}
Date date1 = new Date();
IPPacket ippack01 = mock(IPPacket.class);
when(ippack01.getIPVersion()).thenReturn(b);
when(ippack01.getFragmentOffset()).thenReturn(s);
when(ippack01.getSourceIPAddress()).thenReturn(address1);
when(ippack01.getDestinationIPAddress()).thenReturn(address2);
when(ippack01.getTimeStamp()).thenReturn((double) date1.getTime());
// pretend jpcap lib
traceDataReaderImpl.packetArrived("com.google.android.youtube", ippack01);
return null;
}
}).when(packetreader).readPacket(any(String.class), any(IPacketListener.class));
AppInfo app = new AppInfo();
Map<String, String> appMap = new HashMap<String, String>();
appMap.put("flipboard.app", "2.3.8");
appMap.put("com.att.android.arodatacollector", "3.1.1.6");
appMap.put("com.google.android.youtube", "4.0.23");
app.setAppVersionMap(appMap);
List<String> appInfos = new ArrayList<String>();
appInfos.add("flipboard.app");
appInfos.add("com.att.android.arodatacollector");
appInfos.add("com.google.android.youtube");
app.setAppInfos(appInfos);
when(appinforeader.readData(any(String.class))).thenReturn(app);
DeviceDetail device = new DeviceDetail();
device.setTotalLines(8);
device.setScreenSize("720*1280");
when(devicedetailreader.readData(any(String.class))).thenReturn(device);
CollectOptions cOptions = new CollectOptions();
when(collectOptionsReader.readData(any(String.class))).thenReturn(cOptions);
NetworkTypeObject obj = new NetworkTypeObject();
when(networktypereader.readData(any(String.class), any(double.class), any(double.class))).thenReturn(obj);
TraceDirectoryResult result = traceDataReaderImpl.readTraceDirectory(Util.getCurrentRunningDir());
assertSame(3, result.getAppIds().size());
}
use of com.att.aro.core.peripheral.pojo.NetworkTypeObject in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImplTest method readTraceDir_checkExternalVideoAndTime.
@Test
public void readTraceDir_checkExternalVideoAndTime() throws IOException {
String[] time = { "1410212153.578 1410213352.550", "272927100", "1410213352.550" };
String[] appId = {};
traceDataReaderImpl.setFileReader(filereader);
when(filereader.directoryExist(any(String.class))).thenReturn(true);
when(filereader.readAllLine(any(String.class))).thenReturn(time);
when(filereader.readAllLine(any(String.class))).thenReturn(appId);
when(filereader.readAllLine(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "exVideo_time")).thenReturn(time);
when(filereader.fileExist(any(String.class))).thenReturn(true);
when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "traffic1.cap")).thenReturn(false);
when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "time")).thenReturn(false);
Map<String, List<ScheduledAlarmInfo>> scheduledAlarms = new HashMap<String, List<ScheduledAlarmInfo>>();
List<AlarmAnalysisInfo> statistics = new ArrayList<AlarmAnalysisInfo>();
AlarmAnalysisResult alarmResult = mock(AlarmAnalysisResult.class);
when(alarmResult.getScheduledAlarms()).thenReturn(scheduledAlarms);
when(alarmResult.getStatistics()).thenReturn(statistics);
when(alarmanalysisinfoparser.parse(any(String.class), any(String.class), any(String.class), any(double.class), any(double.class), any(Date.class))).thenReturn(alarmResult);
Mockito.doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
byte b = 3;
short s = 1;
InetAddress address1 = null;
InetAddress address2 = null;
try {
address2 = InetAddress.getByName("78.46.84.177");
address1 = InetAddress.getByName("78.46.84.171");
} catch (UnknownHostException e) {
e.printStackTrace();
}
Date date1 = new Date();
IPPacket ippack01 = mock(IPPacket.class);
when(ippack01.getIPVersion()).thenReturn(b);
when(ippack01.getFragmentOffset()).thenReturn(s);
when(ippack01.getSourceIPAddress()).thenReturn(address1);
when(ippack01.getDestinationIPAddress()).thenReturn(address2);
when(ippack01.getTimeStamp()).thenReturn((double) date1.getTime());
// pretend jpcap lib
traceDataReaderImpl.packetArrived("com.google.android.youtube", ippack01);
return null;
}
}).when(packetreader).readPacket(any(String.class), any(IPacketListener.class));
AppInfo app = new AppInfo();
Map<String, String> appMap = new HashMap<String, String>();
appMap.put("flipboard.app", "2.3.8");
appMap.put("com.att.android.arodatacollector", "3.1.1.6");
appMap.put("com.google.android.youtube", "4.0.23");
app.setAppVersionMap(appMap);
List<String> appInfos = new ArrayList<String>();
appInfos.add("flipboard.app");
appInfos.add("com.att.android.arodatacollector");
appInfos.add("com.google.android.youtube");
app.setAppInfos(appInfos);
when(appinforeader.readData(any(String.class))).thenReturn(app);
DeviceDetail device = new DeviceDetail();
when(devicedetailreader.readData(any(String.class))).thenReturn(device);
NetworkTypeObject obj = new NetworkTypeObject();
when(networktypereader.readData(any(String.class), any(double.class), any(double.class))).thenReturn(obj);
TraceDirectoryResult result = traceDataReaderImpl.readTraceDirectory(Util.getCurrentRunningDir());
assertSame(0, result.getAppIds().size());
}
use of com.att.aro.core.peripheral.pojo.NetworkTypeObject in project VideoOptimzer by attdevsupport.
the class NetworkTypeReaderImplTest method readData.
@Test
public void readData() throws IOException {
Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
String[] arr = new String[] { // 0
"1.358205538539E9 10", // 1
"1.358205540396E9 15", // 2
"1.35820554882E9 3", // 3
"1.358205549444E9 1", // 4
"1.358205552859E9 9", // 5
"1.358205564577E9 3", // 6
"1.358205565208E9 10", // 7
"1.358205565834E9 15", // 8
"1.358205572238E9 3", // 9
"1.358205572969E9 8", // 10
"1.358205584581E9 3", // 11
"1.358205586095E9 13", // 12
"1.358205590906E9 3", // 13
"1.358205591561E9 2", // 14
"1.358205594481E9 5", // 15
"1.358205605874E9 3", // 16
"1.358205606144E9 0", // 17
"1.358205607302E9 15", // 18
"1.358205614199E9 -1", // 19
"1.358205623225E9 -1", // 20
"1.358205763101E9 15", // 21
"1.358205779064E9 3", // 22
"1.358205779663E9 33", // 23
"1.358205782276E9 fe", // 24
"1.358205790737E9 3", // 25
"1.358205791067E9 10", // 26
"1.358205801382E9 15" };
Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr);
networkTypeReader.setFileReader(filereader);
NetworkTypeObject info = networkTypeReader.readData("/", 0, 0);
List<NetworkType> listNetworkType = info.getNetworkTypesList();
assertEquals(11, listNetworkType.size(), 0);
List<NetworkBearerTypeInfo> listNetworkBearerTypeInfo = info.getNetworkTypeInfos();
assertEquals(27, listNetworkBearerTypeInfo.size(), 0);
assertEquals(1.358205538539E9, listNetworkBearerTypeInfo.get(0).getBeginTimestamp(), 0);
assertEquals(1.358205801382E9, listNetworkBearerTypeInfo.get(26).getBeginTimestamp(), 0);
assertEquals("HSPAP", listNetworkBearerTypeInfo.get(26).getNetworkType().toString());
Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(false);
Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr);
info = networkTypeReader.readData("/", 0, 0);
assertTrue(listNetworkType != null);
Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
arr = new String[] { "1.358205538539E9 bd", "1.358205540396E9 15" };
Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr);
info = networkTypeReader.readData("/", 0, 0);
listNetworkType = info.getNetworkTypesList();
assertEquals(2, listNetworkType.size(), 0);
}
Aggregations