@Test public void testSession1() throws IOException{ List<PacketInfo> packetList = null; packetList = getPacketList1(); InetAddress localIP = null; InetAddress remoteIP = null; int remotePort = 0; int localPort = 0; String key = ""; try { localIP = InetAddress.getByAddress(new byte[] { (byte) 192, (byte) 168, 1, 10 }); remoteIP = InetAddress.getByAddress(new byte[] { (byte) 192, (byte) 168, 1, 1 }); remotePort = 1234; localPort = 4321; key = localIP.getHostAddress() + " " + localPort + " " + remotePort + " " + remoteIP.getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } Session session = new Session(localIP, remoteIP, remotePort, localPort, key); session.setRemoteHostName("the.remote.host"); session.setPackets(packetList); byte[] storageUl = packetList.get(0).getPacket().getData(); session.setStorageUl(storageUl); byte[] storageDl = packetList.get(2).getPacket().getData(); session.setStorageDl(storageDl); SortedMap<Integer, PacketInfo> dlPacketOffsets = new TreeMap<Integer, PacketInfo>(); SortedMap<Integer, PacketInfo> ulPacketOffsets = new TreeMap<Integer, PacketInfo>(); session.setPacketOffsetsDl(dlPacketOffsets); session.setPacketOffsetsUl(ulPacketOffsets); List<HttpRequestResponseInfo> result = rrBuilder.createRequestResponseInfo(session); assertTrue(result.size() == 2); assertTrue(result.get(0).getAllHeaders().equals(" Date: Tue, 04 Jun 2013 20:23:44 GMT P3P: policyref=\"http: }
public List<HttpRequestResponseInfo> createRequestResponseInfo(Session session) throws IOException { Double sslNegotiationDuration = null; double contentDownloadDuration = 0; double requestDuration = 0; double timeToFirstByte = 0; result = new ArrayList<HttpRequestResponseInfo>(); this.session = session; extractHttpRequestResponseInfo(PacketDirection.UPLINK); extractHttpRequestResponseInfo(PacketDirection.DOWNLINK); Collections.sort(result); result.trimToSize(); if(!session.isUdpOnly() && !result.isEmpty()){ Double dns = null; if (session.getDnsRequestPacket() != null && session.getDnsResponsePacket() != null) { dns = session.getDnsRequestPacket().getTimeStamp(); } Double synTime = null; for (PacketInfo pinfo : session.getPackets()) { if (pinfo.getPacket() instanceof TCPPacket) { TCPPacket tcp = (TCPPacket) pinfo.getPacket(); if (tcp.isSYN()) { synTime = pinfo.getTimeStamp(); break; } } } Double sslNegTime = null; PacketInfo handshake = session.getLastSslHandshakePacket(); if (handshake != null) { sslNegTime = handshake.getTimeStamp(); } List<HttpRequestResponseInfo> reqs = new ArrayList<HttpRequestResponseInfo>(result.size()); for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() == HttpDirection.REQUEST) { reqs.add(rrinfo); } else if (rrinfo.getDirection() == HttpDirection.RESPONSE && !reqs.isEmpty()) { rrinfo.setAssocReqResp(reqs.remove(0)); rrinfo.getAssocReqResp().setAssocReqResp(rrinfo); } } for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() != HttpDirection.REQUEST || rrinfo.getAssocReqResp() == null || rrinfo.getFirstDataPacket() == null){ continue; } double startTime = -1; double firstReqPacket = rrinfo.getFirstDataPacket().getTimeStamp(); PacketInfo lastPkt = rrinfo.getLastDataPacket(); double lastReqPacket = lastPkt != null ? lastPkt.getTimeStamp() : -1; HttpRequestResponseInfo resp = rrinfo.getAssocReqResp(); if (resp == null || resp.getFirstDataPacket() == null || resp.getLastDataPacket() == null) { continue; } double firstRespPacket = resp.getFirstDataPacket().getTimeStamp(); double lastRespPacket = resp.getLastDataPacket().getTimeStamp(); Double dnsDuration = null; if (dns != null) { startTime = dns.doubleValue(); if (synTime != null) { dnsDuration = synTime.doubleValue() - dns.doubleValue(); } else { dnsDuration = firstReqPacket - dns.doubleValue(); } dns = null; } Double initConnDuration = null; if (synTime != null) { initConnDuration = firstReqPacket - synTime; if (startTime < 0.0) { startTime = synTime.doubleValue(); } synTime = null; } if (startTime < 0.0) { startTime = firstReqPacket; } if (sslNegTime != null && lastRespPacket >= sslNegTime) { sslNegotiationDuration = sslNegTime - firstReqPacket; contentDownloadDuration = lastRespPacket - sslNegTime; } else { if (firstRespPacket >= lastReqPacket && lastReqPacket != -1) { contentDownloadDuration = lastRespPacket - firstRespPacket; requestDuration = lastReqPacket - firstReqPacket; timeToFirstByte = firstRespPacket - lastReqPacket; } else { contentDownloadDuration = lastRespPacket - firstReqPacket; } } RequestResponseTimeline reqRespTimeline = new RequestResponseTimeline(startTime, dnsDuration, initConnDuration, sslNegotiationDuration, requestDuration, timeToFirstByte, contentDownloadDuration); rrinfo.setWaterfallInfos(reqRespTimeline); rrinfo.getWaterfallInfos().setLastRespPacketTime(lastRespPacket); } } return Collections.unmodifiableList(result); }
RequestResponseBuilderImpl implements IRequestResponseBuilder { public List<HttpRequestResponseInfo> createRequestResponseInfo(Session session) throws IOException { Double sslNegotiationDuration = null; double contentDownloadDuration = 0; double requestDuration = 0; double timeToFirstByte = 0; result = new ArrayList<HttpRequestResponseInfo>(); this.session = session; extractHttpRequestResponseInfo(PacketDirection.UPLINK); extractHttpRequestResponseInfo(PacketDirection.DOWNLINK); Collections.sort(result); result.trimToSize(); if(!session.isUdpOnly() && !result.isEmpty()){ Double dns = null; if (session.getDnsRequestPacket() != null && session.getDnsResponsePacket() != null) { dns = session.getDnsRequestPacket().getTimeStamp(); } Double synTime = null; for (PacketInfo pinfo : session.getPackets()) { if (pinfo.getPacket() instanceof TCPPacket) { TCPPacket tcp = (TCPPacket) pinfo.getPacket(); if (tcp.isSYN()) { synTime = pinfo.getTimeStamp(); break; } } } Double sslNegTime = null; PacketInfo handshake = session.getLastSslHandshakePacket(); if (handshake != null) { sslNegTime = handshake.getTimeStamp(); } List<HttpRequestResponseInfo> reqs = new ArrayList<HttpRequestResponseInfo>(result.size()); for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() == HttpDirection.REQUEST) { reqs.add(rrinfo); } else if (rrinfo.getDirection() == HttpDirection.RESPONSE && !reqs.isEmpty()) { rrinfo.setAssocReqResp(reqs.remove(0)); rrinfo.getAssocReqResp().setAssocReqResp(rrinfo); } } for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() != HttpDirection.REQUEST || rrinfo.getAssocReqResp() == null || rrinfo.getFirstDataPacket() == null){ continue; } double startTime = -1; double firstReqPacket = rrinfo.getFirstDataPacket().getTimeStamp(); PacketInfo lastPkt = rrinfo.getLastDataPacket(); double lastReqPacket = lastPkt != null ? lastPkt.getTimeStamp() : -1; HttpRequestResponseInfo resp = rrinfo.getAssocReqResp(); if (resp == null || resp.getFirstDataPacket() == null || resp.getLastDataPacket() == null) { continue; } double firstRespPacket = resp.getFirstDataPacket().getTimeStamp(); double lastRespPacket = resp.getLastDataPacket().getTimeStamp(); Double dnsDuration = null; if (dns != null) { startTime = dns.doubleValue(); if (synTime != null) { dnsDuration = synTime.doubleValue() - dns.doubleValue(); } else { dnsDuration = firstReqPacket - dns.doubleValue(); } dns = null; } Double initConnDuration = null; if (synTime != null) { initConnDuration = firstReqPacket - synTime; if (startTime < 0.0) { startTime = synTime.doubleValue(); } synTime = null; } if (startTime < 0.0) { startTime = firstReqPacket; } if (sslNegTime != null && lastRespPacket >= sslNegTime) { sslNegotiationDuration = sslNegTime - firstReqPacket; contentDownloadDuration = lastRespPacket - sslNegTime; } else { if (firstRespPacket >= lastReqPacket && lastReqPacket != -1) { contentDownloadDuration = lastRespPacket - firstRespPacket; requestDuration = lastReqPacket - firstReqPacket; timeToFirstByte = firstRespPacket - lastReqPacket; } else { contentDownloadDuration = lastRespPacket - firstReqPacket; } } RequestResponseTimeline reqRespTimeline = new RequestResponseTimeline(startTime, dnsDuration, initConnDuration, sslNegotiationDuration, requestDuration, timeToFirstByte, contentDownloadDuration); rrinfo.setWaterfallInfos(reqRespTimeline); rrinfo.getWaterfallInfos().setLastRespPacketTime(lastRespPacket); } } return Collections.unmodifiableList(result); } }
RequestResponseBuilderImpl implements IRequestResponseBuilder { public List<HttpRequestResponseInfo> createRequestResponseInfo(Session session) throws IOException { Double sslNegotiationDuration = null; double contentDownloadDuration = 0; double requestDuration = 0; double timeToFirstByte = 0; result = new ArrayList<HttpRequestResponseInfo>(); this.session = session; extractHttpRequestResponseInfo(PacketDirection.UPLINK); extractHttpRequestResponseInfo(PacketDirection.DOWNLINK); Collections.sort(result); result.trimToSize(); if(!session.isUdpOnly() && !result.isEmpty()){ Double dns = null; if (session.getDnsRequestPacket() != null && session.getDnsResponsePacket() != null) { dns = session.getDnsRequestPacket().getTimeStamp(); } Double synTime = null; for (PacketInfo pinfo : session.getPackets()) { if (pinfo.getPacket() instanceof TCPPacket) { TCPPacket tcp = (TCPPacket) pinfo.getPacket(); if (tcp.isSYN()) { synTime = pinfo.getTimeStamp(); break; } } } Double sslNegTime = null; PacketInfo handshake = session.getLastSslHandshakePacket(); if (handshake != null) { sslNegTime = handshake.getTimeStamp(); } List<HttpRequestResponseInfo> reqs = new ArrayList<HttpRequestResponseInfo>(result.size()); for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() == HttpDirection.REQUEST) { reqs.add(rrinfo); } else if (rrinfo.getDirection() == HttpDirection.RESPONSE && !reqs.isEmpty()) { rrinfo.setAssocReqResp(reqs.remove(0)); rrinfo.getAssocReqResp().setAssocReqResp(rrinfo); } } for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() != HttpDirection.REQUEST || rrinfo.getAssocReqResp() == null || rrinfo.getFirstDataPacket() == null){ continue; } double startTime = -1; double firstReqPacket = rrinfo.getFirstDataPacket().getTimeStamp(); PacketInfo lastPkt = rrinfo.getLastDataPacket(); double lastReqPacket = lastPkt != null ? lastPkt.getTimeStamp() : -1; HttpRequestResponseInfo resp = rrinfo.getAssocReqResp(); if (resp == null || resp.getFirstDataPacket() == null || resp.getLastDataPacket() == null) { continue; } double firstRespPacket = resp.getFirstDataPacket().getTimeStamp(); double lastRespPacket = resp.getLastDataPacket().getTimeStamp(); Double dnsDuration = null; if (dns != null) { startTime = dns.doubleValue(); if (synTime != null) { dnsDuration = synTime.doubleValue() - dns.doubleValue(); } else { dnsDuration = firstReqPacket - dns.doubleValue(); } dns = null; } Double initConnDuration = null; if (synTime != null) { initConnDuration = firstReqPacket - synTime; if (startTime < 0.0) { startTime = synTime.doubleValue(); } synTime = null; } if (startTime < 0.0) { startTime = firstReqPacket; } if (sslNegTime != null && lastRespPacket >= sslNegTime) { sslNegotiationDuration = sslNegTime - firstReqPacket; contentDownloadDuration = lastRespPacket - sslNegTime; } else { if (firstRespPacket >= lastReqPacket && lastReqPacket != -1) { contentDownloadDuration = lastRespPacket - firstRespPacket; requestDuration = lastReqPacket - firstReqPacket; timeToFirstByte = firstRespPacket - lastReqPacket; } else { contentDownloadDuration = lastRespPacket - firstReqPacket; } } RequestResponseTimeline reqRespTimeline = new RequestResponseTimeline(startTime, dnsDuration, initConnDuration, sslNegotiationDuration, requestDuration, timeToFirstByte, contentDownloadDuration); rrinfo.setWaterfallInfos(reqRespTimeline); rrinfo.getWaterfallInfos().setLastRespPacketTime(lastRespPacket); } } return Collections.unmodifiableList(result); } RequestResponseBuilderImpl(); }
RequestResponseBuilderImpl implements IRequestResponseBuilder { public List<HttpRequestResponseInfo> createRequestResponseInfo(Session session) throws IOException { Double sslNegotiationDuration = null; double contentDownloadDuration = 0; double requestDuration = 0; double timeToFirstByte = 0; result = new ArrayList<HttpRequestResponseInfo>(); this.session = session; extractHttpRequestResponseInfo(PacketDirection.UPLINK); extractHttpRequestResponseInfo(PacketDirection.DOWNLINK); Collections.sort(result); result.trimToSize(); if(!session.isUdpOnly() && !result.isEmpty()){ Double dns = null; if (session.getDnsRequestPacket() != null && session.getDnsResponsePacket() != null) { dns = session.getDnsRequestPacket().getTimeStamp(); } Double synTime = null; for (PacketInfo pinfo : session.getPackets()) { if (pinfo.getPacket() instanceof TCPPacket) { TCPPacket tcp = (TCPPacket) pinfo.getPacket(); if (tcp.isSYN()) { synTime = pinfo.getTimeStamp(); break; } } } Double sslNegTime = null; PacketInfo handshake = session.getLastSslHandshakePacket(); if (handshake != null) { sslNegTime = handshake.getTimeStamp(); } List<HttpRequestResponseInfo> reqs = new ArrayList<HttpRequestResponseInfo>(result.size()); for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() == HttpDirection.REQUEST) { reqs.add(rrinfo); } else if (rrinfo.getDirection() == HttpDirection.RESPONSE && !reqs.isEmpty()) { rrinfo.setAssocReqResp(reqs.remove(0)); rrinfo.getAssocReqResp().setAssocReqResp(rrinfo); } } for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() != HttpDirection.REQUEST || rrinfo.getAssocReqResp() == null || rrinfo.getFirstDataPacket() == null){ continue; } double startTime = -1; double firstReqPacket = rrinfo.getFirstDataPacket().getTimeStamp(); PacketInfo lastPkt = rrinfo.getLastDataPacket(); double lastReqPacket = lastPkt != null ? lastPkt.getTimeStamp() : -1; HttpRequestResponseInfo resp = rrinfo.getAssocReqResp(); if (resp == null || resp.getFirstDataPacket() == null || resp.getLastDataPacket() == null) { continue; } double firstRespPacket = resp.getFirstDataPacket().getTimeStamp(); double lastRespPacket = resp.getLastDataPacket().getTimeStamp(); Double dnsDuration = null; if (dns != null) { startTime = dns.doubleValue(); if (synTime != null) { dnsDuration = synTime.doubleValue() - dns.doubleValue(); } else { dnsDuration = firstReqPacket - dns.doubleValue(); } dns = null; } Double initConnDuration = null; if (synTime != null) { initConnDuration = firstReqPacket - synTime; if (startTime < 0.0) { startTime = synTime.doubleValue(); } synTime = null; } if (startTime < 0.0) { startTime = firstReqPacket; } if (sslNegTime != null && lastRespPacket >= sslNegTime) { sslNegotiationDuration = sslNegTime - firstReqPacket; contentDownloadDuration = lastRespPacket - sslNegTime; } else { if (firstRespPacket >= lastReqPacket && lastReqPacket != -1) { contentDownloadDuration = lastRespPacket - firstRespPacket; requestDuration = lastReqPacket - firstReqPacket; timeToFirstByte = firstRespPacket - lastReqPacket; } else { contentDownloadDuration = lastRespPacket - firstReqPacket; } } RequestResponseTimeline reqRespTimeline = new RequestResponseTimeline(startTime, dnsDuration, initConnDuration, sslNegotiationDuration, requestDuration, timeToFirstByte, contentDownloadDuration); rrinfo.setWaterfallInfos(reqRespTimeline); rrinfo.getWaterfallInfos().setLastRespPacketTime(lastRespPacket); } } return Collections.unmodifiableList(result); } RequestResponseBuilderImpl(); @Autowired void setByteArrayLineReader(IByteArrayLineReader reader); List<HttpRequestResponseInfo> createRequestResponseInfo(Session session); List<HttpRequestResponseInfo> getResult(); void extractHttpRequestResponseInfo(PacketDirection direction); }
RequestResponseBuilderImpl implements IRequestResponseBuilder { public List<HttpRequestResponseInfo> createRequestResponseInfo(Session session) throws IOException { Double sslNegotiationDuration = null; double contentDownloadDuration = 0; double requestDuration = 0; double timeToFirstByte = 0; result = new ArrayList<HttpRequestResponseInfo>(); this.session = session; extractHttpRequestResponseInfo(PacketDirection.UPLINK); extractHttpRequestResponseInfo(PacketDirection.DOWNLINK); Collections.sort(result); result.trimToSize(); if(!session.isUdpOnly() && !result.isEmpty()){ Double dns = null; if (session.getDnsRequestPacket() != null && session.getDnsResponsePacket() != null) { dns = session.getDnsRequestPacket().getTimeStamp(); } Double synTime = null; for (PacketInfo pinfo : session.getPackets()) { if (pinfo.getPacket() instanceof TCPPacket) { TCPPacket tcp = (TCPPacket) pinfo.getPacket(); if (tcp.isSYN()) { synTime = pinfo.getTimeStamp(); break; } } } Double sslNegTime = null; PacketInfo handshake = session.getLastSslHandshakePacket(); if (handshake != null) { sslNegTime = handshake.getTimeStamp(); } List<HttpRequestResponseInfo> reqs = new ArrayList<HttpRequestResponseInfo>(result.size()); for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() == HttpDirection.REQUEST) { reqs.add(rrinfo); } else if (rrinfo.getDirection() == HttpDirection.RESPONSE && !reqs.isEmpty()) { rrinfo.setAssocReqResp(reqs.remove(0)); rrinfo.getAssocReqResp().setAssocReqResp(rrinfo); } } for (HttpRequestResponseInfo rrinfo : result) { if (rrinfo.getDirection() != HttpDirection.REQUEST || rrinfo.getAssocReqResp() == null || rrinfo.getFirstDataPacket() == null){ continue; } double startTime = -1; double firstReqPacket = rrinfo.getFirstDataPacket().getTimeStamp(); PacketInfo lastPkt = rrinfo.getLastDataPacket(); double lastReqPacket = lastPkt != null ? lastPkt.getTimeStamp() : -1; HttpRequestResponseInfo resp = rrinfo.getAssocReqResp(); if (resp == null || resp.getFirstDataPacket() == null || resp.getLastDataPacket() == null) { continue; } double firstRespPacket = resp.getFirstDataPacket().getTimeStamp(); double lastRespPacket = resp.getLastDataPacket().getTimeStamp(); Double dnsDuration = null; if (dns != null) { startTime = dns.doubleValue(); if (synTime != null) { dnsDuration = synTime.doubleValue() - dns.doubleValue(); } else { dnsDuration = firstReqPacket - dns.doubleValue(); } dns = null; } Double initConnDuration = null; if (synTime != null) { initConnDuration = firstReqPacket - synTime; if (startTime < 0.0) { startTime = synTime.doubleValue(); } synTime = null; } if (startTime < 0.0) { startTime = firstReqPacket; } if (sslNegTime != null && lastRespPacket >= sslNegTime) { sslNegotiationDuration = sslNegTime - firstReqPacket; contentDownloadDuration = lastRespPacket - sslNegTime; } else { if (firstRespPacket >= lastReqPacket && lastReqPacket != -1) { contentDownloadDuration = lastRespPacket - firstRespPacket; requestDuration = lastReqPacket - firstReqPacket; timeToFirstByte = firstRespPacket - lastReqPacket; } else { contentDownloadDuration = lastRespPacket - firstReqPacket; } } RequestResponseTimeline reqRespTimeline = new RequestResponseTimeline(startTime, dnsDuration, initConnDuration, sslNegotiationDuration, requestDuration, timeToFirstByte, contentDownloadDuration); rrinfo.setWaterfallInfos(reqRespTimeline); rrinfo.getWaterfallInfos().setLastRespPacketTime(lastRespPacket); } } return Collections.unmodifiableList(result); } RequestResponseBuilderImpl(); @Autowired void setByteArrayLineReader(IByteArrayLineReader reader); List<HttpRequestResponseInfo> createRequestResponseInfo(Session session); List<HttpRequestResponseInfo> getResult(); void extractHttpRequestResponseInfo(PacketDirection direction);  }