Search in sources :

Example 1 with TrexEthernetPacket

use of com.exalttech.trex.packets.TrexEthernetPacket in project trex-stateless-gui by cisco-system-traffic-generator.

the class UDPTest method testUDPProfile.

@Test(dataProvider = "packetData", dependsOnGroups = { "init" })
public void testUDPProfile(PacketData packetData) throws IOException, InterruptedException, PcapNativeException, NotOpenException, URISyntaxException {
    TrexEthernetPacket ethernetPacket = buildIPV4Packet(packetData);
    // prepare and save yaml data
    LOG.info("Prepare and save Yaml file");
    packetUtil.prepareAndSaveYamlFile(ethernetPacket.getPacket().getRawData(), packetData);
    //Generate pcap files
    LOG.info("Generate Pcap file for " + packetData.getTestFileName() + ".yaml");
    packetUtil.generatePcapFile(packetData.getTestFileName());
    // compare pcaps
    boolean result = packetUtil.comparePcaps(packetData.getTestFileName(), "generated_" + packetData.getTestFileName());
    Assert.assertEquals(result, true, "Invalid generated " + packetData.getTestFileName() + " pcap. ");
}
Also used : TrexEthernetPacket(com.exalttech.trex.packets.TrexEthernetPacket) Test(org.testng.annotations.Test)

Example 2 with TrexEthernetPacket

use of com.exalttech.trex.packets.TrexEthernetPacket in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketUtil method prepareEthernetPacket.

/**
     * Prepare Ethernet packet
     *
     * @param packetData
     * @param packetLength
     * @param payload
     * @return
     */
public TrexEthernetPacket prepareEthernetPacket(PacketData packetData, int packetLength, Payload payload) {
    TrexEthernetPacket ethernetPacket = new TrexEthernetPacket();
    ethernetPacket.setSrcAddr(packetData.getEthernetData().getSrcAddress().getAddress());
    ethernetPacket.setDstAddr(packetData.getEthernetData().getDstAddress().getAddress());
    ethernetPacket.setLength(packetLength);
    ethernetPacket.setPayload(payload);
    return ethernetPacket;
}
Also used : TrexEthernetPacket(com.exalttech.trex.packets.TrexEthernetPacket)

Example 3 with TrexEthernetPacket

use of com.exalttech.trex.packets.TrexEthernetPacket in project trex-stateless-gui by cisco-system-traffic-generator.

the class ProtocolData method init.

private void init() {
    try {
        ethernetPacket = new TrexEthernetPacket();
        ipv4Packet = new TrexIpV4Packet();
        tcpPacket = new TrexTcpPacket();
        udpPacket = new TrexUdpPacket();
    } catch (Exception ex) {
        LOG.error("Couldn't initialize protocol data", ex);
    }
}
Also used : TrexIpV4Packet(com.exalttech.trex.packets.TrexIpV4Packet) TrexEthernetPacket(com.exalttech.trex.packets.TrexEthernetPacket) TrexTcpPacket(com.exalttech.trex.packets.TrexTcpPacket) TrexUdpPacket(com.exalttech.trex.packets.TrexUdpPacket)

Example 4 with TrexEthernetPacket

use of com.exalttech.trex.packets.TrexEthernetPacket in project trex-stateless-gui by cisco-system-traffic-generator.

the class ProtocolDataView method getProtocolData.

/**
     * Return protocol data view
     *
     * @return
     * @throws Exception
     */
public TrexEthernetPacket getProtocolData() throws Exception {
    int packetLength = PacketBuilderHelper.getPacketLength(selections.getFrameLengthType(), Integer.parseInt(selections.getFrameLength()), Integer.parseInt(selections.getMaxLength()));
    TrexEthernetPacket ethernetPacket = new TrexEthernetPacket();
    // set mac address
    ethernetPacket.setSrcAddr(macView.getSourceAddress().getAddress());
    ethernetPacket.setDstAddr(macView.getDestinationAddress().getAddress());
    ethernetPacket.setLength(packetLength);
    // set payload in ethernet
    ethernetPacket.setPayload(payloadView.getPayload());
    if (ethernetView.isOverrideType()) {
        ethernetPacket.setType(ethernetView.getType());
    }
    Builder ipV4Packet = getIPV4Packet(PacketBuilderHelper.getIPV4TotalLength(selections.isTaggedVlanSelected()), packetLength);
    if (selections.isTaggedVlanSelected()) {
        if (!ethernetView.isOverrideType()) {
            ethernetPacket.setType(EtherType.DOT1Q_VLAN_TAGGED_FRAMES.value());
        }
        TrexVlanPacket vlanPacket = vlanView.getVlan();
        /// IF IPV4 is selected
        if (!vlanPacket.isOverrideType()) {
            if (!selections.isIPV4Selected()) {
                ethernetPacket.setAddPad(true);
                vlanPacket.setType((short) 0xFFFF);
            } else {
                vlanPacket.setType(EtherType.IPV4.value());
            }
        }
        vlanPacket.buildPacket(ipV4Packet);
        ethernetPacket.buildPacket(vlanPacket.getBuilder());
    } else {
        ethernetPacket.buildPacket(ipV4Packet);
    }
    return ethernetPacket;
}
Also used : TrexVlanPacket(com.exalttech.trex.packets.TrexVlanPacket) TrexEthernetPacket(com.exalttech.trex.packets.TrexEthernetPacket) Builder(org.pcap4j.packet.IpV4Packet.Builder)

Example 5 with TrexEthernetPacket

use of com.exalttech.trex.packets.TrexEthernetPacket in project trex-stateless-gui by cisco-system-traffic-generator.

the class AbstractIPV4Test method buildIPV4Packet.

/**
     * Build IPV4 packet
     *
     * @param packetData
     * @return
     * @throws IOException
     * @throws InterruptedException
     * @throws PcapNativeException
     * @throws NotOpenException
     * @throws java.net.URISyntaxException
     */
public TrexEthernetPacket buildIPV4Packet(PacketData packetData) throws IOException, InterruptedException, PcapNativeException, NotOpenException, URISyntaxException {
    LOG.info("create ethernet packet");
    int packetLength = PacketBuilderHelper.getPacketLength(packetData.getPacketLength().getLengthType(), packetData.getPacketLength().getFrameLength(), packetData.getPacketLength().getMaxLength());
    Payload payload = packetUtil.getPayload(packetData.getPayload());
    TrexEthernetPacket ethernetPacket = packetUtil.prepareEthernetPacket(packetData, packetLength, payload);
    // define VLAN 
    IpV4Packet.Builder ipV4Packet = getIPV4PacketBuilder(PacketBuilderHelper.getIPV4TotalLength(packetData.isTaggedVlan()), packetLength, payload, packetData);
    if (!packetData.isTaggedVlan()) {
        LOG.info("Add IPV4 packet");
        ethernetPacket.buildPacket(ipV4Packet);
    } else {
        packetUtil.addVlanToPacket(ethernetPacket, ipV4Packet);
    }
    return ethernetPacket;
}
Also used : TrexEthernetPacket(com.exalttech.trex.packets.TrexEthernetPacket) TrexIpV4Packet(com.exalttech.trex.packets.TrexIpV4Packet) IpV4Packet(org.pcap4j.packet.IpV4Packet) Payload(com.exalttech.trex.ui.views.streams.builder.Payload)

Aggregations

TrexEthernetPacket (com.exalttech.trex.packets.TrexEthernetPacket)8 Test (org.testng.annotations.Test)4 TrexIpV4Packet (com.exalttech.trex.packets.TrexIpV4Packet)2 Payload (com.exalttech.trex.ui.views.streams.builder.Payload)2 TrexTcpPacket (com.exalttech.trex.packets.TrexTcpPacket)1 TrexUdpPacket (com.exalttech.trex.packets.TrexUdpPacket)1 TrexVlanPacket (com.exalttech.trex.packets.TrexVlanPacket)1 IpV4Packet (org.pcap4j.packet.IpV4Packet)1 Builder (org.pcap4j.packet.IpV4Packet.Builder)1