Skip to content

Commit 983f4e8

Browse files
authored
Merge pull request #84 from cisco-system-traffic-generator/capture-on-disconnect-fixes
Capture on disconnect fixes
2 parents f8d184c + a3ad22a commit 983f4e8

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

src/main/java/com/cisco/trex/stl/gui/services/capture/PktCaptureService.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public class PktCaptureService extends ScheduledService<CapturedPackets> {
2020

2121
private int currentActiveMonitorId = 0;
2222

23-
private TRexClient tRexClient = ConnectionManager.getInstance().getTrexClient();
24-
2523
@Override
2624
protected Task<CapturedPackets> createTask() {
2725
return new Task<CapturedPackets>() {
@@ -49,7 +47,7 @@ public int startMonitor(
4947
List<Integer> tx,
5048
String filter,
5149
boolean serviceEnable) throws PktCaptureServiceException {
52-
TRexClientResult<CaptureMonitor> result = tRexClient.captureMonitorStart(rx, tx, filter);
50+
TRexClientResult<CaptureMonitor> result = getTrexClient().captureMonitorStart(rx, tx, filter);
5351
guardNotFailed(result);
5452
int captureId = result.get().getCaptureId();
5553
if (serviceEnable) {
@@ -59,13 +57,17 @@ public int startMonitor(
5957
return captureId;
6058
}
6159

60+
private TRexClient getTrexClient() {
61+
return ConnectionManager.getInstance().getTrexClient();
62+
}
63+
6264
public int updateMonitor(
6365
List<Integer> rx,
6466
List<Integer> tx,
6567
String filter) throws PktCaptureServiceException {
66-
tRexClient.captureMonitorStop(currentActiveMonitorId);
67-
tRexClient.captureMonitorRemove(currentActiveMonitorId);
68-
TRexClientResult<CaptureMonitor> result = tRexClient.captureMonitorStart(rx, tx, filter);
68+
getTrexClient().captureMonitorStop(currentActiveMonitorId);
69+
getTrexClient().captureMonitorRemove(currentActiveMonitorId);
70+
TRexClientResult<CaptureMonitor> result = getTrexClient().captureMonitorStart(rx, tx, filter);
6971
guardNotFailed(result);
7072
int captureId = result.get().getCaptureId();
7173
currentActiveMonitorId = captureId;
@@ -76,12 +78,12 @@ synchronized public void stopMonitor(int captureId) {
7678
if (currentActiveMonitorId == captureId) {
7779
currentActiveMonitorId = 0;
7880
}
79-
tRexClient.captureMonitorStop(captureId);
80-
tRexClient.captureMonitorRemove(captureId);
81+
getTrexClient().captureMonitorStop(captureId);
82+
getTrexClient().captureMonitorRemove(captureId);
8183
}
8284

8385
public CaptureMonitorStop stopRecorder(int caputureId) throws PktCaptureServiceException {
84-
TRexClientResult<CaptureMonitorStop> result = tRexClient.captureMonitorStop(caputureId);
86+
TRexClientResult<CaptureMonitorStop> result = getTrexClient().captureMonitorStop(caputureId);
8587
if (result.isFailed()) {
8688
LOG.error("Unable to stop monitor. "+result.getError());
8789
throw new PktCaptureServiceException(result.getError());
@@ -90,23 +92,23 @@ public CaptureMonitorStop stopRecorder(int caputureId) throws PktCaptureServiceE
9092
}
9193

9294
synchronized public CapturedPackets fetchCapturedPkts(int captureId, int chunkSize) throws PktCaptureServiceException {
93-
TRexClientResult<CapturedPackets> result = tRexClient.captureFetchPkts(captureId, chunkSize);
95+
TRexClientResult<CapturedPackets> result = getTrexClient().captureFetchPkts(captureId, chunkSize);
9496
guardNotFailed(result);
9597
return result.get();
9698
}
9799

98100
public CaptureMonitor addRecorder(List<Integer> rx, List<Integer> tx, String filter, int bufferSize) throws PktCaptureServiceException {
99-
TRexClientResult<CaptureMonitor> result = tRexClient.captureRecorderStart(rx, tx, filter, bufferSize);
101+
TRexClientResult<CaptureMonitor> result = getTrexClient().captureRecorderStart(rx, tx, filter, bufferSize);
100102
guardNotFailed(result);
101103
return result.get();
102104
}
103105

104106
public boolean removeRecorder(int recorderId) {
105-
return tRexClient.captureMonitorRemove(recorderId);
107+
return getTrexClient().captureMonitorRemove(recorderId);
106108
}
107109

108110
public List<CaptureInfo> getActiveCaptures() throws PktCaptureServiceException {
109-
TRexClientResult<CaptureInfo[]> result = tRexClient.getActiveCaptures();
111+
TRexClientResult<CaptureInfo[]> result = getTrexClient().getActiveCaptures();
110112
guardNotFailed(result);
111113
return Arrays.stream(result.get()).collect(Collectors.toList());
112114
}

src/main/java/com/exalttech/trex/ui/controllers/ports/tabs/PortLayerConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ public Optional<String> call() {
344344
}
345345

346346
AsyncResponseManager.getInstance().suppressIncomingEvents(true);
347+
boolean serviceModeBeforeResolve = model.getServiceMode();
347348
trexClient.serviceMode(model.getIndex(), true);
348349

349350
TRexClientResult<StubResult> vlanConfigResult = trexClient.setVlan(model.getIndex(), vlanIds);
@@ -432,7 +433,7 @@ public Optional<String> call() {
432433
logger.error("Failed to set L3 mode: " + e.getMessage());
433434
guiLogger.appendText(LogType.ERROR, "Failed to set L3 mode: " + e.getMessage());
434435
} finally {
435-
trexClient.serviceMode(model.getIndex(), false);
436+
trexClient.serviceMode(model.getIndex(), serviceModeBeforeResolve);
436437
AsyncResponseManager.getInstance().suppressIncomingEvents(false);
437438
AsyncResponseManager.getInstance().unmuteLogger();
438439
}

src/main/java/com/exalttech/trex/ui/models/PortModel.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ public class PortModel {
5757

5858
private BooleanProperty isOwnedProperty = new SimpleBooleanProperty(false);
5959
private RPCMethods serverRPCMethods;
60-
private TRexClient trexClient;
6160
private LogsController guiLogger;
6261
private boolean streamLoaded;
6362
private BooleanProperty isTransmitProperty = new SimpleBooleanProperty(false);
6463

6564
private PortModel() {
6665
guiLogger = LogsController.getInstance();
6766
serverRPCMethods = TrexApp.injector.getInstance(RPCMethods.class);
68-
trexClient = ConnectionManager.getInstance().getTrexClient();
6967
supportCapabilities.put("link", linkControlSupport);
7068
supportCapabilities.put("led", ledControlSupport);
7169
supportCapabilities.put("flowControl", flowControlSupport);
@@ -190,7 +188,7 @@ private void initHandlers(Port port) {
190188
if (!isOwnedProperty.get()) {
191189
return;
192190
}
193-
com.cisco.trex.stateless.model.PortStatus status = trexClient.serviceMode(portIndex, newValue);
191+
com.cisco.trex.stateless.model.PortStatus status = ConnectionManager.getInstance().getTrexClient().serviceMode(portIndex, newValue);
194192
if (!newValue.equals(status.service)) {
195193
guiLogger.appendText(LogType.ERROR, "Filed to change service mode for port " + portIndex+". Check active capturing mode or enabled rx queues.");
196194
Platform.runLater(() -> serviceModeProperty.set(oldValue));

0 commit comments

Comments
 (0)