/** * Gets the session key. * * @param srcIp * the src ip * @param dstIp * the dst ip * @param protocol * the protocol * @param srcPort * the src port * @param dstPort * the dst port * @return the session key */ public static String getSessionKey(String srcIp, String dstIp, String protocol, String srcPort, String dstPort) { return getSessionKey(srcIp, dstIp, protocol, srcPort, dstPort, null, null); }
public void nextTuple() { // System.out.println("nextTuple of PcapSimulatorSpout"); ipAddr.setLength(0); String srcAddr = ipAddr.append(randomIpSegmentGenerator.nextInt(255)).append('.').append(randomIpSegmentGenerator.nextInt(255)) .append('.').append(randomIpSegmentGenerator.nextInt(255)).append('.').append(randomIpSegmentGenerator.nextInt(255)).toString(); ipAddr.setLength(0); String dstAddr = ipAddr.append(randomIpSegmentGenerator.nextInt(255)).append('.').append(randomIpSegmentGenerator.nextInt(255)) .append('.').append(randomIpSegmentGenerator.nextInt(255)).append('.').append(randomIpSegmentGenerator.nextInt(255)).toString(); String key = PcapUtils.getSessionKey(srcAddr, dstAddr, String.valueOf(randomProtocolGenerator.nextInt(255)), String.valueOf(randomPortGenerator.nextInt(64000)), String.valueOf(randomPortGenerator.nextInt(64000)), "0", "0"); jsonDoc = jsonDocs[randomJsonGenerator.nextInt(8)]; ts = System.currentTimeMillis() + randomPortGenerator.nextInt(); randomPcapGenerator.nextBytes(pcap); collector.emit(new Values(srcAddr, key.toString(), jsonDoc, ts, pcap)); collector.emit("pcap_index_stream", new Values(jsonDoc, key)); collector.emit("pcap_header_stream", new Values(jsonDoc, key)); collector.emit("pcap_data_stream", new Values(key.toString(), ts, pcap)); }
String sessionKey = PcapUtils.getSessionKey(srcIp, dstIp, protocol, srcPort, dstPort); LOGGER.info("sessionKey =" + sessionKey);
/** * Gets the key. * * * @return the key */ public String getKey() { int sourcePort = 0; int destinationPort = 0; if (Constants.PROTOCOL_UDP == ipv4Packet.getProtocol()) { sourcePort = udpPacket.getSourcePort(); destinationPort = udpPacket.getDestinationPort(); } else if (Constants.PROTOCOL_TCP == ipv4Packet.getProtocol()) { sourcePort = tcpPacket.getSourcePort(); destinationPort = tcpPacket.getDestinationPort(); } return PcapUtils.getSessionKey(ipv4Packet.getSourceAddress().getHostAddress(), ipv4Packet.getDestinationAddress().getHostAddress(), ipv4Packet.getProtocol(), sourcePort, destinationPort, ipv4Packet.getId(), ipv4Packet.getFragmentOffset()); }