Search in sources :

Example 1 with Builder

use of org.pcap4j.packet.IpV4Packet.Builder 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)

Aggregations

TrexEthernetPacket (com.exalttech.trex.packets.TrexEthernetPacket)1 TrexVlanPacket (com.exalttech.trex.packets.TrexVlanPacket)1 Builder (org.pcap4j.packet.IpV4Packet.Builder)1