use of com.exalttech.trex.ui.models.PacketInfo in project trex-stateless-gui by cisco-system-traffic-generator.
the class PacketUtil method getPacketInfoData.
/**
* Decode string and return packet info data
*
* @param encodedBinaryPacket
* @return packet info
* @throws IOException
*/
public PacketInfo getPacketInfoData(String encodedBinaryPacket) throws IOException {
// decode binary data
File pcapFile = trafficProfile.decodePcapBinary(encodedBinaryPacket);
PacketInfo packetInfo = new PacketInfo();
PacketParser parser = new PacketParser();
parser.parseFile(pcapFile.getAbsolutePath(), packetInfo);
return packetInfo;
}
use of com.exalttech.trex.ui.models.PacketInfo in project trex-stateless-gui by cisco-system-traffic-generator.
the class ImportedPacketTableView method setPcapFile.
/**
* Parse pcap file to get all streams
*
* @param pcapFile
* @return
*/
public boolean setPcapFile(File pcapFile) {
List<PacketInfo> packetInfoList = new ArrayList<>();
try {
PacketUpdater.getInstance().reset();
PcapHandle handler = Pcaps.openOffline(pcapFile.getAbsolutePath());
PacketParser parser = new PacketParser();
Packet packet;
while ((packet = handler.getNextPacketEx()) != null) {
if (!PacketUpdater.getInstance().validatePacket(packet)) {
break;
}
PacketInfo packetInfo = new PacketInfo();
packet = PacketUpdater.getInstance().updatePacketSrcDst(packet);
packetInfo.setPacket(packet);
packetInfo.setTimeStamp(handler.getTimestamp().getTime());
parser.parsePacket(packet, packetInfo);
packetInfoList.add(packetInfo);
}
} catch (EOFException e) {
LOG.info("End of pcap file");
} catch (PcapNativeException | TimeoutException | NotOpenException ex) {
LOG.error("Error parsing selectd pcap file", ex);
}
setTableData(packetInfoList);
return PacketUpdater.getInstance().isValidPacket();
}
use of com.exalttech.trex.ui.models.PacketInfo in project trex-stateless-gui by cisco-system-traffic-generator.
the class ImportedPacketTableView method setTableData.
/**
* Set table data
*
* @param packetInfoList
*/
private void setTableData(List<PacketInfo> packetInfoList) {
index = 1;
tableDataList.clear();
for (PacketInfo packetInfo : packetInfoList) {
ImportPcapTableData tableData = new ImportPcapTableData();
tableData.setName("packet_" + index);
tableData.setIndex(index);
tableData.setLength(packetInfo.getPacket().length());
tableData.setMacSrc(packetInfo.getSrcMac());
tableData.setMacDst(packetInfo.getDestMac());
tableData.setIpSrc(packetInfo.getSrcIpv4());
tableData.setIpDst(packetInfo.getDestIpv4());
tableData.setPacketType(trafficProfile.getPacketTypeText(packetInfo.getPacket()).getType());
tableData.setPacket(packetInfo.getPacket());
tableData.setHasVlan(packetInfo.hasVlan());
tableData.setTimeStamp(packetInfo.getTimeStamp());
tableDataList.add(tableData);
index++;
}
importedStreamTable.setItems(tableDataList);
}
use of com.exalttech.trex.ui.models.PacketInfo in project trex-stateless-gui by cisco-system-traffic-generator.
the class PacketBuilderHomeController method initialize.
@Override
public void initialize(URL url, ResourceBundle rb) {
trafficProfile = new TrafficProfile();
packetHex = new PacketHex(hexPane);
nextStreamBtn.setGraphic(new ImageView(new Image("/icons/next_stream.png")));
prevStreamBtn.setGraphic(new ImageView(new Image("/icons/prev_stream.png")));
packetInfo = new PacketInfo();
parser = new PacketParser();
}
use of com.exalttech.trex.ui.models.PacketInfo in project trex-stateless-gui by cisco-system-traffic-generator.
the class TrexEthernetPacketTest method testEthernetPacketWithoutVlan.
/**
* Test of buildPacket method, of class TrexEthernetPacket.
*/
@Test
@Parameters({ "macSrcAddress", "macDstAddress", "packetLength", "expectedHex" })
public void testEthernetPacketWithoutVlan(String macSrcAddress, String macDstAddress, int packetLength, String expectedHex) throws IOException, IllegalRawDataException {
LOG.info("------------Testing Ethernet packet");
// build ethernet packet
LOG.info("Building Ethernet packet");
AbstractPacket.AbstractBuilder builder = null;
TrexEthernetPacket instance = new TrexEthernetPacket();
instance.setSrcAddr(macSrcAddress);
instance.setDstAddr(macDstAddress);
instance.setLength(packetLength);
instance.buildPacket(builder);
LOG.info("Encoding packet data");
// Encode packet data
String encodedBinaryPacket = packetUtil.getEncodedPacket(instance.getPacket().getRawData());
LOG.info("Decoding packets and returning packet data information");
// Decode and return packet info
PacketInfo packetInfo = packetUtil.getPacketInfoData(encodedBinaryPacket);
LOG.info("Verifying packet data");
// Assert mac src/destination address
Assert.assertEquals(macSrcAddress, packetInfo.getSrcMac(), "Invalid MAC source address. ");
Assert.assertEquals(macDstAddress, packetInfo.getDestMac(), "Invalid MAC destination address. ");
// Verify packet length
Packet packet = packetUtil.getPacketFromEncodedString(encodedBinaryPacket);
Assert.assertEquals(packetLength, packetUtil.getPacketLength(packet), "Invalid Packet length. ");
// Verify packet data
String packetHex = DatatypeConverter.printHexBinary(packet.getRawData());
Assert.assertEquals(expectedHex.toLowerCase(), packetHex.toLowerCase(), "Invalid Packet hex. ");
}
Aggregations