use of org.pcap4j.packet.IcmpV4CommonPacket in project trex-stateless-gui by cisco-system-traffic-generator.
the class PortInfoTabConfig method runPingCmd.
private void runPingCmd(Event event) {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
trexClient.serviceMode(port.getIndex(), true);
savedPingIPv4 = textFieldTabConfigPortPingIPv4.getText();
guiLogger.appendText(LogType.PING, " Start ping " + savedPingIPv4 + ":");
AsyncResponseManager.getInstance().muteLogger();
try {
int icmp_id = new Random().nextInt(100);
for (int icmp_sec = 1; icmp_sec < 6; icmp_sec++) {
EthernetPacket reply = trexClient.sendIcmpEcho(port.getIndex(), savedPingIPv4, icmp_id, icmp_sec, 1000);
if (reply != null) {
IpV4Packet ip = reply.get(IpV4Packet.class);
String ttl = String.valueOf(ip.getHeader().getTtlAsInt());
IcmpV4CommonPacket echoReplyPacket = reply.get(IcmpV4CommonPacket.class);
IcmpV4Type replyType = echoReplyPacket.getHeader().getType();
if (IcmpV4Type.ECHO_REPLY.equals(replyType)) {
guiLogger.appendText(LogType.PING, " Reply from " + savedPingIPv4 + " size=" + reply.getRawData().length + " ttl=" + ttl + " icmp_sec=" + icmp_sec);
} else if (IcmpV4Type.DESTINATION_UNREACHABLE.equals(replyType)) {
guiLogger.appendText(LogType.PING, " Destination host unreachable");
}
} else {
guiLogger.appendText(LogType.PING, " Request timeout for icmp_seq " + icmp_sec);
}
}
} catch (UnknownHostException e) {
guiLogger.appendText(LogType.PING, " Unknown host");
} finally {
trexClient.serviceMode(port.getIndex(), false);
AsyncResponseManager.getInstance().unmuteLogger();
}
});
}
use of org.pcap4j.packet.IcmpV4CommonPacket in project trex-stateless-gui by cisco-system-traffic-generator.
the class PortLayerConfiguration method runPingCmd.
private void runPingCmd(Event event) {
if (model.getPortStatus().equalsIgnoreCase("tx")) {
guiLogger.appendText(LogType.ERROR, "Port " + model.getIndex() + " is in TX mode. Please stop traffic first.");
return;
}
if (Strings.isNullOrEmpty(pingDestination.getText())) {
guiLogger.appendText(LogType.ERROR, "Empty ping destination address.");
return;
}
if (!model.getL3LayerConfiguration().getState().equalsIgnoreCase("resolved")) {
guiLogger.appendText(LogType.ERROR, "ARP resolution required. Configure L3 mode properly.");
return;
}
pingCommandBtn.setDisable(true);
Task<Void> pingTask = new Task<Void>() {
@Override
public Void call() {
TRexClient trexClient = ConnectionManager.getInstance().getTrexClient();
trexClient.serviceMode(model.getIndex(), true);
String savedPingIPv4 = pingDestination.getText();
guiLogger.appendText(LogType.PING, " Start ping " + savedPingIPv4 + ":");
AsyncResponseManager.getInstance().muteLogger();
try {
int icmp_id = new Random().nextInt(100);
for (int icmp_sec = 1; icmp_sec < 6; icmp_sec++) {
EthernetPacket reply = trexClient.sendIcmpEcho(model.getIndex(), savedPingIPv4, icmp_id, icmp_sec, 1000);
if (reply != null) {
IpV4Packet ip = reply.get(IpV4Packet.class);
String ttl = String.valueOf(ip.getHeader().getTtlAsInt());
IcmpV4CommonPacket echoReplyPacket = reply.get(IcmpV4CommonPacket.class);
IcmpV4Type replyType = echoReplyPacket.getHeader().getType();
if (IcmpV4Type.ECHO_REPLY.equals(replyType)) {
guiLogger.appendText(LogType.PING, " Reply from " + savedPingIPv4 + " size=" + reply.getRawData().length + " ttl=" + ttl + " icmp_sec=" + icmp_sec);
} else if (IcmpV4Type.DESTINATION_UNREACHABLE.equals(replyType)) {
guiLogger.appendText(LogType.PING, " Destination host unreachable");
}
} else {
guiLogger.appendText(LogType.PING, " Request timeout for icmp_seq " + icmp_sec);
}
}
guiLogger.appendText(LogType.PING, " Ping finished.");
} catch (UnknownHostException e) {
guiLogger.appendText(LogType.PING, " Unknown host");
} finally {
pingCommandBtn.setDisable(false);
trexClient.serviceMode(model.getIndex(), false);
AsyncResponseManager.getInstance().unmuteLogger();
}
return null;
}
};
pingTask.setOnSucceeded(e -> pingCommandBtn.setDisable(false));
new Thread(pingTask).start();
}
Aggregations