Skip to content

Commit ebaf840

Browse files
authored
Merge pull request #74 from cisco-system-traffic-generator/dummy-interfaces-support
Dummy interfaces support
2 parents ec3e906 + 8140da0 commit ebaf840

File tree

5 files changed

+29
-30
lines changed

5 files changed

+29
-30
lines changed

src/main/java/com/cisco/trex/stl/gui/controllers/dashboard/ports/PortsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void buildPortStatTable() {
6060
statTableContainer.getChildren().add(
6161
statsTableGenerator.getPortStatTable(
6262
StatsLoader.getInstance().getShadowStatsList(),
63-
portsManager.getPortList().size(),
63+
portsManager.getPortIndexes(),
6464
true,
6565
150,
6666
portsSelector.getSelectedPortIndexes()

src/main/java/com/exalttech/trex/ui/PortsManager.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void removePortServiceModeChangedListener(final PortServiceModeChangedLis
8181
public PortModel getPortModel(int portIndex) {
8282
PortModel model = portModels.get(portIndex);
8383
if (model == null) {
84-
model = PortModel.createModelFrom(portList.get(portIndex));
84+
model = PortModel.createModelFrom(getPortByIndex(portIndex));
8585
model.serviceModeProperty().addListener((observable, oldVal, newVal) -> {
8686
synchronized (portServiceModeChangedListeners) {
8787
portServiceModeChangedListeners.forEach(PortServiceModeChangedListener::serviceModeChanged);
@@ -118,6 +118,21 @@ public void setPortList(List<Port> portList) {
118118
this.portList = portList;
119119
}
120120

121+
/**
122+
* Get port with specified index
123+
* @param portIndex index of needed port
124+
* @return if port exists, returns acutal port with index portIndex , otherwise returns new empty port
125+
*/
126+
public Port getPortByIndex(int portIndex) {
127+
if (this.portList.stream().noneMatch(p -> p.getIndex() == portIndex)) {
128+
logger.error(String.format("Port with index %s was not found. Returning empty port", portIndex));
129+
}
130+
return this.portList.stream()
131+
.filter(p -> p.getIndex() == portIndex)
132+
.findFirst()
133+
.orElse(new Port());
134+
}
135+
121136
/**
122137
* Set port handler
123138
*
@@ -220,7 +235,7 @@ public String getActivePort() {
220235
* @return
221236
*/
222237
public boolean isCurrentUserOwner(int portIndex) {
223-
return portList.get(portIndex).getOwner().equals(ConnectionManager.getInstance().getClientName());
238+
return getPortByIndex(portIndex).getOwner().equalsIgnoreCase(ConnectionManager.getInstance().getClientName());
224239
}
225240

226241
/**
@@ -237,7 +252,7 @@ private boolean hasPorts() {
237252
* @return
238253
*/
239254
public boolean isPortFree(int portIndex) {
240-
return Util.isNullOrEmpty(portList.get(portIndex).getOwner());
255+
return Util.isNullOrEmpty(getPortByIndex(portIndex).getOwner());
241256
}
242257

243258
/**

src/main/java/com/exalttech/trex/ui/controllers/MainViewController.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,6 @@ public void initialize(URL url, ResourceBundle rb) {
287287
portManager.updatedPorts(Arrays.asList(portModel.getIndex()));
288288
onPortListUpdated(true);
289289
});
290-
boolean isAllPortsStopped = true;
291-
for (final Port port : portManager.getPortList()) {
292-
if (port.getIndex() == port.getIndex()) {
293-
continue;
294-
}
295-
final String portStatus = port.getStatus();
296-
if (portStatus.equals("TX") || portStatus.equals("PAUSE")) {
297-
isAllPortsStopped = false;
298-
break;
299-
}
300-
}
301290
}
302291
break;
303292
case SERVER_STOPPED:
@@ -559,7 +548,7 @@ private void updateCurrentProfile() { //TODO get rid of this method and implemen
559548
private void updateContextMenuState() {
560549
int portId = getSelectedPortIndex();
561550
if (portId != -1) {
562-
Port port = portManager.getPortList().get(portId);
551+
Port port = portManager.getPortByIndex(portId);
563552

564553
boolean isOwned = port.getOwner().equals(ConnectionManager.getInstance().getClientName());
565554

@@ -954,7 +943,7 @@ public void handleDuplicateProfile(ActionEvent ev) {
954943
int portID = getSelectedPortIndex();
955944

956945
if (portID > -1) {
957-
if (PortState.getPortStatus(portManager.getPortList().get(portID).getStatus()) == PortState.PAUSE
946+
if (PortState.getPortStatus(portManager.getPortByIndex(portID).getStatus()) == PortState.PAUSE
958947
&& !Util.isNullOrEmpty(duplicatedProfileName)) {
959948
profileListBox.getSelectionModel().select(duplicatedProfileName);
960949
}
@@ -1125,7 +1114,7 @@ public void startTransitBtnCLicked(MouseEvent event) {
11251114
private void doStartResume(int portID) {
11261115
// disable start button to avoid another quick click
11271116
startStream.setDisable(true);
1128-
if (PortState.getPortStatus(portManager.getPortList().get(portID).getStatus()) == PortState.PAUSE) {
1117+
if (PortState.getPortStatus(portManager.getPortByIndex(portID).getStatus()) == PortState.PAUSE) {
11291118
serverRPCMethods.resumeTraffic(portID);
11301119
} else {
11311120
startTraffic(portID);
@@ -1226,7 +1215,7 @@ public void pauseTransitBtnCLicked(MouseEvent event) {
12261215
int portID = getSelectedPortIndex();
12271216
LOG.trace("Clicked on the Pause Transit Button with selectedPort [" + portID + "]");
12281217
if (portID > -1) {
1229-
if (PortState.getPortStatus(portManager.getPortList().get(portID).getStatus()) == PortState.PAUSE) {
1218+
if (PortState.getPortStatus(portManager.getPortByIndex(portID).getStatus()) == PortState.PAUSE) {
12301219
serverRPCMethods.resumeTraffic(portID);
12311220
} else {
12321221
enableUpdateBtn(false, false);
@@ -1460,7 +1449,7 @@ private void updateHeaderBtnStat() {
14601449
int portIndex = getSelectedPortIndex();
14611450
resetBtnState();
14621451
if (portIndex != -1) {
1463-
Port port = portManager.getPortList().get(portIndex);
1452+
Port port = portManager.getPortByIndex(portIndex);
14641453
PortState state = PortState.getPortStatus(port.getStatus());
14651454

14661455
// enable state btn btn according to owner

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void bindModel(PortModel model, boolean runPolling) {
6060
if (refreshingService.isRunning()) {
6161
refreshingService.cancel();
6262
}
63-
port = portManager.getPortList().get(model.getIndex());
63+
port = portManager.getPortByIndex(model.getIndex());
6464

6565
if (runPolling) {
6666
startPolling();

src/main/java/com/exalttech/trex/ui/views/statistics/StatsTableGenerator.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Map;
3434
import java.util.Set;
3535
import java.util.function.Consumer;
36+
import java.util.stream.Collectors;
3637

3738
/**
3839
*
@@ -89,7 +90,7 @@ public StatsTableGenerator() {
8990
*/
9091
public GridPane getPortStatTable(
9192
Map<String, String> cached,
92-
int portIndex,
93+
List<Integer> portIndices,
9394
boolean isMultiPort,
9495
double columnWidth,
9596
Set<Integer> visiblePorts
@@ -99,12 +100,6 @@ public GridPane getPortStatTable(
99100
this.prevTotalValues = totalValues;
100101
this.cachedStatsList = cached;
101102

102-
int startPortIndex = portIndex;
103-
int endPortIndex = portIndex + 1;
104-
if (isMultiPort) {
105-
startPortIndex = 0;
106-
endPortIndex = portIndex;
107-
}
108103
rowIndex = 0;
109104
totalValues = new HashMap<>();
110105
statTable.getChildren().clear();
@@ -116,10 +111,10 @@ public GridPane getPortStatTable(
116111
double tx_bps_l1_total = 0;
117112
double rx_bps_l1_total = 0;
118113
int columnIndex = 1;
119-
for (int i = startPortIndex; i < endPortIndex; i++) {
114+
for (int i : portIndices) {
120115
rowIndex = 0;
121116
odd = true;
122-
Port port = PortsManager.getInstance().getPortList().get(i);
117+
Port port = PortsManager.getInstance().getPortByIndex(i);
123118
if (visiblePorts == null || visiblePorts.contains(port.getIndex())) {
124119
// add owner and port status
125120
addPortInfoCells(port, columnWidth, columnIndex);

0 commit comments

Comments
 (0)