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. ");
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations