Search in sources :

Example 1 with TRexClient

use of com.cisco.trex.stateless.TRexClient in project trex-stateless-gui by cisco-system-traffic-generator.

the class MainViewController method unloadProfile.

private void unloadProfile() {
    if (currentSelectedProfile == null) {
        return;
    }
    Task<Void> unloadProfileTask = new Task<Void>() {

        @Override
        protected Void call() throws Exception {
            TRexClient trexClient = ConnectionManager.getInstance().getTrexClient();
            trexClient.stopTraffic(lastLoadedPortPtofileIndex);
            trexClient.removeAllStreams(lastLoadedPortPtofileIndex);
            return null;
        }
    };
    unloadProfileTask.setOnSucceeded(event -> {
        LogsController.getInstance().appendText(LogType.INFO, currentSelectedProfile + " profile unloaded");
        currentSelectedProfile = Constants.SELECT_PROFILE;
        assignedPortProfileMap.put(lastLoadedPortPtofileIndex, new AssignedProfile());
        trafficProfileLoadedProperty.set(false);
        portManager.updatedPorts(Arrays.asList(lastLoadedPortPtofileIndex));
    });
    LogsController.getInstance().appendText(LogType.INFO, "Unloading " + currentSelectedProfile + " profile");
    new Thread(unloadProfileTask).start();
}
Also used : Task(javafx.concurrent.Task) TRexClient(com.cisco.trex.stateless.TRexClient) AssignedProfile(com.exalttech.trex.ui.views.models.AssignedProfile)

Example 2 with TRexClient

use of com.cisco.trex.stateless.TRexClient in project trex-stateless-gui by cisco-system-traffic-generator.

the class ConnectionManager method initializeConnection.

/**
     *
     * @param ip
     * @param rpcPort
     * @param asyncPort
     * @param clientName
     * @param isReadOnly
     * @return
     */
public boolean initializeConnection(String ip, String rpcPort, String asyncPort, String scapyPort, String clientName, boolean isReadOnly) {
    this.ip = ip;
    this.rpcPort = rpcPort;
    this.asyncPort = asyncPort;
    this.scapyPort = scapyPort;
    this.clientName = clientName;
    this.isReadOnly = isReadOnly;
    trexClient = new TRexClient(ip, rpcPort, clientName);
    try {
        trexClient.connect();
    } catch (Exception ex) {
        return false;
    }
    // connect to zmq
    return connectToZMQ();
}
Also used : TRexClient(com.cisco.trex.stateless.TRexClient) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException) DataFormatException(java.util.zip.DataFormatException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with TRexClient

use of com.cisco.trex.stateless.TRexClient in project trex-stateless-gui by cisco-system-traffic-generator.

the class PortLayerConfiguration method saveConfiguration.

private void saveConfiguration(Event event) {
    if (model.getPortStatus().equalsIgnoreCase("tx")) {
        guiLogger.appendText(LogType.ERROR, "Port " + model.getIndex() + " is in TX mode. Please stop traffic first.");
        return;
    }
    if (l2Mode.isSelected()) {
        if (Strings.isNullOrEmpty(l2Destination.getText())) {
            guiLogger.appendText(LogType.ERROR, "Destination MAC is empty. ");
            return;
        }
    } else {
        if (!validateIpAddress(l3Source.getText())) {
            return;
        }
        if (!validateIpAddress(l3Destination.getText())) {
            return;
        }
    }
    saveBtn.setDisable(true);
    saveBtn.setText("Applying...");
    Task saveConfigurationTask = new Task<Optional<String>>() {

        @Override
        public Optional<String> call() {
            TRexClient trexClient = ConnectionManager.getInstance().getTrexClient();
            if (l2Mode.isSelected()) {
                String dstMac = l2Destination.getText();
                try {
                    serverRPCMethods.setSetL2(model.getIndex(), dstMac);
                    guiLogger.appendText(LogType.INFO, "L2 mode configured for " + model.getIndex());
                } catch (Exception e1) {
                    logger.error("Failed to set L2 mode: " + e1.getMessage());
                }
            } else if (l3Mode.isSelected()) {
                try {
                    AsyncResponseManager.getInstance().muteLogger();
                    String portSrcIP = l3Source.getText();
                    String portDstIP = l3Destination.getText();
                    trexClient.serviceMode(model.getIndex(), true);
                    trexClient.setL3Mode(model.getIndex(), null, portSrcIP, portDstIP);
                    String nextHopMac = trexClient.resolveArp(model.getIndex(), portSrcIP, portDstIP);
                    if (nextHopMac != null) {
                        trexClient.setL3Mode(model.getIndex(), nextHopMac, portSrcIP, portDstIP);
                        AsyncResponseManager.getInstance().unmuteLogger();
                    }
                    return nextHopMac == null ? Optional.empty() : Optional.of(nextHopMac);
                } catch (Exception e) {
                    logger.error("Failed to set L3 mode: " + e.getMessage());
                } finally {
                    trexClient.serviceMode(model.getIndex(), false);
                }
            }
            return Optional.empty();
        }
    };
    saveConfigurationTask.setOnSucceeded(e -> {
        saveBtn.setText("Apply");
        saveBtn.setDisable(false);
        Optional result = (Optional) (saveConfigurationTask.getValue());
        if (l3Mode.isSelected()) {
            String status = "unresolved";
            if (result.isPresent()) {
                status = "resolved";
                guiLogger.appendText(LogType.INFO, "ARP resolution for " + l3Destination.getText() + " is " + result.get());
            } else {
                guiLogger.appendText(LogType.ERROR, "ARP resolution status: FAILED");
            }
            arpStatus.setText(status);
        }
    });
    new Thread(saveConfigurationTask).start();
}
Also used : Task(javafx.concurrent.Task) TRexClient(com.cisco.trex.stateless.TRexClient) Optional(java.util.Optional) UnknownHostException(java.net.UnknownHostException)

Example 4 with TRexClient

use of com.cisco.trex.stateless.TRexClient 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();
}
Also used : Task(javafx.concurrent.Task) IcmpV4CommonPacket(org.pcap4j.packet.IcmpV4CommonPacket) TRexClient(com.cisco.trex.stateless.TRexClient) UnknownHostException(java.net.UnknownHostException) EthernetPacket(org.pcap4j.packet.EthernetPacket) IcmpV4Type(org.pcap4j.packet.namednumber.IcmpV4Type) Random(java.util.Random) IpV4Packet(org.pcap4j.packet.IpV4Packet)

Aggregations

TRexClient (com.cisco.trex.stateless.TRexClient)4 UnknownHostException (java.net.UnknownHostException)3 Task (javafx.concurrent.Task)3 IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)1 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)1 AssignedProfile (com.exalttech.trex.ui.views.models.AssignedProfile)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Optional (java.util.Optional)1 Random (java.util.Random)1 ExecutionException (java.util.concurrent.ExecutionException)1 DataFormatException (java.util.zip.DataFormatException)1 EthernetPacket (org.pcap4j.packet.EthernetPacket)1 IcmpV4CommonPacket (org.pcap4j.packet.IcmpV4CommonPacket)1 IpV4Packet (org.pcap4j.packet.IpV4Packet)1 IcmpV4Type (org.pcap4j.packet.namednumber.IcmpV4Type)1