Search in sources :

Example 1 with PktCaptureServiceException

use of com.cisco.trex.stl.gui.services.capture.PktCaptureServiceException in project trex-stateless-gui by cisco-system-traffic-generator.

the class PacketCaptureDashboardController method initialize.

@Override
public void initialize(URL location, ResourceBundle resources) {
    final PktCaptureService pktCaptureService = new PktCaptureService();
    monitorController.setPktCaptureService(pktCaptureService);
    recordController.setPktCaptureService(pktCaptureService);
    monitorController.setStartHandler(() -> {
        startMonitorBtn.setDisable(true);
        stopMonitorBtn.setDisable(false);
        monitorIsActive = true;
    });
    monitorController.setStopHandler(() -> {
        stopMonitorBtn.setDisable(true);
        startMonitorBtn.setDisable(false);
        monitorIsActive = false;
    });
    startMonitorBtn.setOnMouseClicked(event -> {
        monitorController.startCapture();
    });
    stopMonitorBtn.setOnMouseClicked(event -> {
        monitorController.stopCapture();
    });
    clearMonitorBtn.setOnMouseClicked(event -> monitorController.clearCapture());
    startWiresharkBtn.setOnMouseClicked(event -> monitorController.startWireshark());
    startRecorderBtn.setOnMouseClicked(event -> {
        Dialog<AddRecordPojo> dialog = createAddRecorderDialog("Add Recorder", new AddRecorderController());
        Optional<AddRecordPojo> addRecordPojo = dialog.showAndWait();
        addRecordPojo.ifPresent(pojo -> {
            try {
                monitorController.startRecorder(pojo.rxPorts, pojo.txPorts, pojo.filter, pojo.pktLimit);
            } catch (PktCaptureServiceException e) {
                TrexAlertBuilder.build().setType(Alert.AlertType.ERROR).setTitle("Recorder error").setHeader("Unable to start the recorder").setContent(e.getLocalizedMessage()).getAlert().showAndWait();
            }
        });
    });
    captureTabPane.getSelectionModel().selectedItemProperty().addListener((o, oldVal, newVal) -> {
        boolean isMonitorTabSelected = newVal.getText().equalsIgnoreCase("Monitor");
        updateButtonBar(isMonitorTabSelected);
    });
    updateButtonBar(true);
}
Also used : PktCaptureService(com.cisco.trex.stl.gui.services.capture.PktCaptureService) PktCaptureServiceException(com.cisco.trex.stl.gui.services.capture.PktCaptureServiceException)

Example 2 with PktCaptureServiceException

use of com.cisco.trex.stl.gui.services.capture.PktCaptureServiceException in project trex-stateless-gui by cisco-system-traffic-generator.

the class RecordController method handleSavePkts.

public void handleSavePkts(int monitorId) {
    List<CapturedPkt> capturedPkts = new ArrayList<>();
    int pendingPkts = 1;
    while (pendingPkts > 0) {
        try {
            CapturedPackets capturedPackets = pktCaptureService.fetchCapturedPkts(monitorId, 1000);
            pendingPkts = capturedPackets.getPendingPkts();
            capturedPkts.addAll(capturedPackets.getPkts());
        } catch (PktCaptureServiceException e) {
            LOG.error("Unable to fetch packets.", e);
            break;
        }
    }
    File outFile = fileChooser.showSaveDialog(getScene().getWindow());
    if (outFile != null) {
        try {
            dumpPkts(capturedPkts, outFile.getAbsolutePath());
        } catch (Exception e) {
            LOG.error("Unable to dump packets.", e);
        }
    }
}
Also used : CapturedPackets(com.cisco.trex.stateless.model.capture.CapturedPackets) PktCaptureServiceException(com.cisco.trex.stl.gui.services.capture.PktCaptureServiceException) CapturedPkt(com.cisco.trex.stateless.model.capture.CapturedPkt) File(java.io.File) PktCaptureServiceException(com.cisco.trex.stl.gui.services.capture.PktCaptureServiceException) IllegalRawDataException(org.pcap4j.packet.IllegalRawDataException)

Aggregations

PktCaptureServiceException (com.cisco.trex.stl.gui.services.capture.PktCaptureServiceException)2 CapturedPackets (com.cisco.trex.stateless.model.capture.CapturedPackets)1 CapturedPkt (com.cisco.trex.stateless.model.capture.CapturedPkt)1 PktCaptureService (com.cisco.trex.stl.gui.services.capture.PktCaptureService)1 File (java.io.File)1 IllegalRawDataException (org.pcap4j.packet.IllegalRawDataException)1