use of com.exalttech.trex.ui.models.PortLayerConfigurationModel in project trex-stateless-gui by cisco-system-traffic-generator.
the class PortLayerConfiguration method clearModelIPv6.
private void clearModelIPv6() {
final PortLayerConfigurationModel l3Conf = this.model.getL3LayerConfiguration();
l3Conf.setSrc6(null);
l3Conf.setDst6(null);
}
use of com.exalttech.trex.ui.models.PortLayerConfigurationModel 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;
}
int vlanIdsCount = Arrays.stream(model.getVlan().split(" ")).filter(vlanId -> !Strings.isNullOrEmpty(vlanId)).map(Integer::valueOf).collect(Collectors.toList()).size();
if (vlanIdsCount > 2) {
guiLogger.appendText(LogType.ERROR, "Maximum two nested VLAN tags are allowed.");
return;
}
if (l2Mode.isSelected()) {
if (Strings.isNullOrEmpty(l2Destination.getText())) {
guiLogger.appendText(LogType.ERROR, "Destination MAC is empty. ");
return;
}
} else {
final String dstAddress = l3Destination.getText();
if (!validateIpAddress(dstAddress)) {
return;
}
boolean isDstIPv4 = InetAddresses.forString(dstAddress).getAddress().length == 4;
if (isDstIPv4 && !validateIpv4Address(l3Source.getText())) {
return;
}
}
saveBtn.setDisable(true);
saveBtn.setText("Applying...");
Task saveConfigurationTask = new Task<Optional<String>>() {
@Override
public Optional<String> call() {
TRexClient trexClient = ConnectionManager.getInstance().getTrexClient();
List<Integer> vlanIds = new ArrayList<>();
if (!Strings.isNullOrEmpty(model.getVlan())) {
vlanIds.addAll(Arrays.stream(model.getVlan().split(" ")).filter(vlanId -> !Strings.isNullOrEmpty(vlanId)).map(Integer::valueOf).collect(Collectors.toList()));
}
AsyncResponseManager.getInstance().suppressIncomingEvents(true);
boolean serviceModeBeforeResolve = model.getServiceMode();
trexClient.serviceMode(model.getIndex(), true);
TRexClientResult<StubResult> vlanConfigResult = trexClient.setVlan(model.getIndex(), vlanIds);
if (vlanConfigResult.isFailed()) {
guiLogger.appendText(LogType.ERROR, "Unable to save VLAN configuration");
} else {
guiLogger.appendText(LogType.INFO, "VLAN configuration updated");
}
if (l2Mode.isSelected()) {
String dstMac = l2Destination.getText();
try {
serverRPCMethods.setSetL2(model.getIndex(), dstMac);
guiLogger.appendText(LogType.INFO, "L2 mode configured for " + model.getIndex());
clearModelIPv6();
} 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();
final boolean dstIsIPv6 = InetAddresses.forString(portDstIP).getAddress().length > 4;
final boolean srcIsIPv6 = InetAddresses.forString(portSrcIP).getAddress().length > 4;
if (srcIsIPv6 != dstIsIPv6) {
throw new Exception("src and dst addresses are different version");
}
if (dstIsIPv6) {
Map<String, Ipv6Node> result = getIPv6NDService().scan(model.getIndex(), 5, portDstIP, portSrcIP);
AsyncResponseManager.getInstance().unmuteLogger();
String statusString;
String logEntry;
if (result.size() == 1) {
Ipv6Node host = result.entrySet().iterator().next().getValue();
final String mac = host.getMac();
statusString = "resolved";
logEntry = "IPv6 destination resolved: " + mac;
setAsL2DstAction(mac);
try {
serverRPCMethods.setSetL2(model.getIndex(), mac);
guiLogger.appendText(LogType.INFO, "L2 mode configured for " + model.getIndex());
final PortLayerConfigurationModel l3Conf = model.getL3LayerConfiguration();
l3Conf.setSrc6(portSrcIP);
l3Conf.setDst6(portDstIP);
} catch (Exception e1) {
logger.error("Failed to set L2 mode: " + e1.getMessage());
}
} else {
statusString = "-";
logEntry = "Unable to resolve IPv6 destination.";
}
Platform.runLater(() -> {
arpStatus.setText("none");
ipv6NDStatus.setText(statusString);
guiLogger.appendText(LogType.INFO, logEntry);
});
} else {
trexClient.setL3Mode(model.getIndex(), null, portSrcIP, portDstIP);
clearModelIPv6();
String nextHopMac = trexClient.resolveArp(model.getIndex(), portSrcIP, portDstIP);
if (nextHopMac != null) {
trexClient.setL3Mode(model.getIndex(), nextHopMac, portSrcIP, portDstIP);
}
Platform.runLater(() -> {
ipv6NDStatus.setText("-");
});
return nextHopMac == null ? Optional.empty() : Optional.of(nextHopMac);
}
} catch (ServiceModeRequiredException e) {
AsyncResponseManager.getInstance().unmuteLogger();
Platform.runLater(() -> {
ipv6Hosts.setPlaceholder(ipv6HostsDefaultPlaceholder);
LogsController.getInstance().appendText(LogType.ERROR, "Service mode is not enabled for port: " + model.getIndex() + ". Enable Service Mode in Control tab.");
});
} catch (Exception e) {
logger.error("Failed to set L3 mode: " + e.getMessage());
guiLogger.appendText(LogType.ERROR, "Failed to set L3 mode: " + e.getMessage());
} finally {
trexClient.serviceMode(model.getIndex(), serviceModeBeforeResolve);
AsyncResponseManager.getInstance().suppressIncomingEvents(false);
AsyncResponseManager.getInstance().unmuteLogger();
}
}
return Optional.empty();
}
};
saveConfigurationTask.setOnSucceeded(e -> {
saveBtn.setText("Apply");
saveBtn.setDisable(false);
final boolean dstIsIPv6 = InetAddresses.forString(l3Source.getText()).getAddress().length > 4;
final boolean srcIsIPv6 = InetAddresses.forString(l3Destination.getText()).getAddress().length > 4;
Optional result = (Optional) (saveConfigurationTask.getValue());
if (l3Mode.isSelected() && !dstIsIPv6 && !srcIsIPv6) {
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 arpStatus: FAILED");
}
this.arpStatus.setText(status);
}
});
new Thread(saveConfigurationTask).start();
}
use of com.exalttech.trex.ui.models.PortLayerConfigurationModel in project trex-stateless-gui by cisco-system-traffic-generator.
the class PortLayerConfiguration method bindModel.
public void bindModel(PortModel model) {
unbindAll();
this.model = model;
l2Destination.textProperty().bindBidirectional(this.model.getL2LayerConfiguration().dstProperty());
l2Source.textProperty().bindBidirectional(this.model.getL2LayerConfiguration().srcProperty());
final PortLayerConfigurationModel l3Conf = this.model.getL3LayerConfiguration();
l3Destination.textProperty().bindBidirectional(l3Conf.dstProperty());
l3Source.textProperty().bindBidirectional(l3Conf.srcProperty());
final String src6 = l3Conf.getSrc6();
final String dst6 = l3Conf.getDst6();
if (src6 != null && !src6.equals("")) {
l3Source.textProperty().setValue(src6);
}
if (dst6 != null && !dst6.equals("")) {
l3Destination.textProperty().setValue(dst6);
}
vlan.textProperty().bindBidirectional(this.model.vlanProperty());
updateControlsState();
this.model.layerConfigurationTypeProperty().addListener(configurationModeChangeListener);
}
Aggregations