Search in sources :

Example 1 with PacketInfo

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;
}
Also used : PacketParser(com.exalttech.trex.ui.views.streams.viewer.PacketParser) PacketInfo(com.exalttech.trex.ui.models.PacketInfo) File(java.io.File)

Example 2 with 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();
}
Also used : PacketParser(com.exalttech.trex.ui.views.streams.viewer.PacketParser) Packet(org.pcap4j.packet.Packet) NotOpenException(org.pcap4j.core.NotOpenException) PcapHandle(org.pcap4j.core.PcapHandle) ArrayList(java.util.ArrayList) EOFException(java.io.EOFException) PacketInfo(com.exalttech.trex.ui.models.PacketInfo) PcapNativeException(org.pcap4j.core.PcapNativeException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with PacketInfo

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);
}
Also used : PacketInfo(com.exalttech.trex.ui.models.PacketInfo) ImportPcapTableData(com.exalttech.trex.ui.views.models.ImportPcapTableData)

Example 4 with PacketInfo

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();
}
Also used : PacketParser(com.exalttech.trex.ui.views.streams.viewer.PacketParser) TrafficProfile(com.exalttech.trex.util.TrafficProfile) PacketInfo(com.exalttech.trex.ui.models.PacketInfo) PacketHex(com.exalttech.trex.ui.views.streams.viewer.PacketHex) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 5 with PacketInfo

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. ");
}
Also used : Packet(org.pcap4j.packet.Packet) AbstractPacket(org.pcap4j.packet.AbstractPacket) AbstractPacket(org.pcap4j.packet.AbstractPacket) PacketInfo(com.exalttech.trex.ui.models.PacketInfo) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

PacketInfo (com.exalttech.trex.ui.models.PacketInfo)5 PacketParser (com.exalttech.trex.ui.views.streams.viewer.PacketParser)3 Packet (org.pcap4j.packet.Packet)2 ImportPcapTableData (com.exalttech.trex.ui.views.models.ImportPcapTableData)1 PacketHex (com.exalttech.trex.ui.views.streams.viewer.PacketHex)1 TrafficProfile (com.exalttech.trex.util.TrafficProfile)1 EOFException (java.io.EOFException)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 TimeoutException (java.util.concurrent.TimeoutException)1 Image (javafx.scene.image.Image)1 ImageView (javafx.scene.image.ImageView)1 NotOpenException (org.pcap4j.core.NotOpenException)1 PcapHandle (org.pcap4j.core.PcapHandle)1 PcapNativeException (org.pcap4j.core.PcapNativeException)1 AbstractPacket (org.pcap4j.packet.AbstractPacket)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1