1. Remove edit-content argument. Instead of using node config template
in form of file node config will be created, modified by corresponding
Java models and than converted to request body string with GSON.
2. Split auth argument to controller-auth-username,
controller-auth-password. Add default value(admin) for them.
3. Split controller-destination argument to controller-ip,
controller-port.
JIRA: NETCONF-758
Change-Id: Iccf19c9482727b88d3f21a85008d13f554a8da08
Signed-off-by: Illia <illia.ihushev@pantheon.tech>
.setBody(payload.getPayload())
.setRequestTimeout(Integer.MAX_VALUE);
.setBody(payload.getPayload())
.setRequestTimeout(Integer.MAX_VALUE);
- if (params.auth != null) {
- requestBuilder.setRealm(new Realm.RealmBuilder()
- .setScheme(Realm.AuthScheme.BASIC)
- .setPrincipal(params.auth.get(0))
- .setPassword(params.auth.get(1))
- .setMethodName("POST")
- .setUsePreemptiveAuth(true)
- .build());
- }
+ requestBuilder.setRealm(new Realm.RealmBuilder()
+ .setScheme(Realm.AuthScheme.BASIC)
+ .setPrincipal(params.controllerAuthUsername)
+ .setPassword(params.controllerAuthPassword)
+ .setMethodName("POST")
+ .setUsePreemptiveAuth(true)
+ .build());
+
this.payloads.add(requestBuilder.build());
}
}
this.payloads.add(requestBuilder.build());
}
}
LOG.error("Failed to start any simulated devices, exiting...");
System.exit(1);
}
LOG.error("Failed to start any simulated devices, exiting...");
System.exit(1);
}
- if (params.controllerDestination != null) {
+ //if ODL controller ip is not set NETCONF devices will be started, but not registered at the controller
+ if (params.controllerIp != null) {
final ArrayList<ArrayList<Execution.DestToPayload>> allThreadsPayloads = params
.getThreadsPayloads(openDevices);
final ArrayList<Execution> executions = new ArrayList<>();
final ArrayList<ArrayList<Execution.DestToPayload>> allThreadsPayloads = params
.getThreadsPayloads(openDevices);
final ArrayList<Execution> executions = new ArrayList<>();
private static final String HOST_KEY = "{HOST}";
private static final String PORT_KEY = "{PORT}";
private static final String TCP_ONLY = "{TCP_ONLY}";
private static final String HOST_KEY = "{HOST}";
private static final String PORT_KEY = "{PORT}";
private static final String TCP_ONLY = "{TCP_ONLY}";
- private static final String ADDRESS_PORT = "{ADDRESS:PORT}";
- private static final String DEST =
- "http://{ADDRESS:PORT}/restconf/config/network-topology:network-topology/topology/topology-netconf/";
+ private static final String RESTCONF_NETCONF_TOPOLOGY_PATH_TEMPLATE =
+ "http://%s:%s/restconf/config/network-topology:network-topology/topology/topology-netconf/";
private static final Pattern YANG_FILENAME_PATTERN = Pattern
.compile("(?<name>.*)@(?<revision>\\d{4}-\\d{2}-\\d{2})\\.yang");
private static final Pattern REVISION_DATE_PATTERN = Pattern.compile("revision\\s+\"?(\\d{4}-\\d{2}-\\d{2})\"?");
private static final String RESOURCE = "/config-template.json";
private static final Pattern YANG_FILENAME_PATTERN = Pattern
.compile("(?<name>.*)@(?<revision>\\d{4}-\\d{2}-\\d{2})\\.yang");
private static final Pattern REVISION_DATE_PATTERN = Pattern.compile("revision\\s+\"?(\\d{4}-\\d{2}-\\d{2})\"?");
private static final String RESOURCE = "/config-template.json";
- @Arg(dest = "edit-content")
- public File editContent;
@Arg(dest = "async")
public boolean async;
@Arg(dest = "thread-amount")
public int threadAmount;
@Arg(dest = "throttle")
public int throttle;
@Arg(dest = "async")
public boolean async;
@Arg(dest = "thread-amount")
public int threadAmount;
@Arg(dest = "throttle")
public int throttle;
- @Arg(dest = "auth")
- public ArrayList<String> auth;
- @Arg(dest = "controller-destination")
- public String controllerDestination;
+ @Arg(dest = "controller-auth-username")
+ public String controllerAuthUsername;
+ @Arg(dest = "controller-auth-password")
+ public String controllerAuthPassword;
+ @Arg(dest = "controller-ip")
+ public String controllerIp;
+ @Arg(dest = "controller-port")
+ public Integer controllerPort;
@Arg(dest = "schemas-dir")
public File schemasDir;
@Arg(dest = "devices-count")
@Arg(dest = "schemas-dir")
public File schemasDir;
@Arg(dest = "devices-count")
public File initialConfigXMLFile;
@Arg(dest = "time-out")
public long timeOut;
public File initialConfigXMLFile;
@Arg(dest = "time-out")
public long timeOut;
- private InputStream stream;
@Arg(dest = "ip")
public String ip;
@Arg(dest = "thread-pool-size")
@Arg(dest = "ip")
public String ip;
@Arg(dest = "thread-pool-size")
+ "with mutltiple threads this gets divided among all threads")
.dest("throttle");
+ "with mutltiple threads this gets divided among all threads")
.dest("throttle");
- parser.addArgument("--auth")
- .nargs(2)
- .help("Username and password for HTTP basic authentication in order username password.")
- .dest("auth");
+ parser.addArgument("--controller-auth-username")
+ .type(String.class)
+ .setDefault("admin")
+ .help("Username for HTTP basic authentication to destination controller.")
+ .dest("controller-auth-username");
+
+ parser.addArgument("--controller-auth-password")
+ .type(String.class)
+ .setDefault("admin")
+ .help("Password for HTTP basic authentication to destination controller.")
+ .dest("controller-auth-password");
- parser.addArgument("--controller-destination")
+ parser.addArgument("--controller-ip")
- .help("Ip address and port of controller. Must be in following format <ip>:<port> "
- + "if available it will be used for spawning netconf connectors via topology configuration as "
- + "a part of URI. Example (http://<controller destination>/restconf/config/network-topology:network-topology/topology/topology-netconf/node/<node-id>)"
+ .help("Ip of controller if available it will be used for spawning netconf connectors via topology"
+ + " configuration as a part of"
+ + " URI(http://<controller-ip>:<controller-port>/restconf/config/...)"
+ + " otherwise it will just start simulated devices and skip the execution of PUT requests")
+ .dest("controller-ip");
+
+ parser.addArgument("--controller-port")
+ .type(Integer.class)
+ .help("Port of controller if available it will be used for spawning netconf connectors via topology "
+ + "configuration as a part of"
+ + " URI(http://<controller-ip>:<controller-port>/restconf/config/...) "
+ "otherwise it will just start simulated devices and skip the execution of PUT requests")
+ "otherwise it will just start simulated devices and skip the execution of PUT requests")
- .dest("controller-destination");
+ .dest("controller-port");
parser.addArgument("--device-count")
.type(Integer.class)
parser.addArgument("--device-count")
.type(Integer.class)
@SuppressWarnings("checkstyle:regexpSinglelineJava")
void validate() {
@SuppressWarnings("checkstyle:regexpSinglelineJava")
void validate() {
- if (editContent == null) {
- stream = TesttoolParameters.class.getResourceAsStream(RESOURCE);
+ if (controllerIp != null) {
+ //FIXME Ip validation
+ checkArgument(controllerPort != null, "Controller port is missing");
+ //FIXME Is there specific bound
+ checkArgument(controllerPort >= 0, "Controller port should be non-negative integer");
+ checkArgument(controllerPort < 65354, "Controller port should be less than 65354");
- checkArgument(!editContent.isDirectory(), "Edit content file is a dir");
- checkArgument(editContent.canRead(), "Edit content file is unreadable");
- }
-
- if (controllerDestination != null) {
- checkArgument(controllerDestination.contains(":"),
- "Controller Destination needs to be in a following format <ip>:<port>");
- final String[] parts = controllerDestination.split(Pattern.quote(":"));
- checkArgument(Integer.parseInt(parts[1]) > 0, "Port =< 0");
+ checkArgument(controllerPort == null, "Controller ip is missing");
}
checkArgument(deviceCount > 0, "Device count has to be > 0");
}
checkArgument(deviceCount > 0, "Device count has to be > 0");
public ArrayList<ArrayList<Execution.DestToPayload>> getThreadsPayloads(final List<Integer> openDevices) {
final String editContentString;
try {
public ArrayList<ArrayList<Execution.DestToPayload>> getThreadsPayloads(final List<Integer> openDevices) {
final String editContentString;
try {
- if (stream == null) {
- editContentString = Files.readString(editContent.toPath());
- } else {
- editContentString = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
- }
+ final InputStream stream = TesttoolParameters.class.getResourceAsStream(RESOURCE);
+ editContentString = CharStreams.toString(new InputStreamReader(stream, StandardCharsets.UTF_8));
} catch (final IOException e) {
} catch (final IOException e) {
- throw new IllegalArgumentException("Cannot read content of " + editContent, e);
+ throw new IllegalArgumentException("Cannot read content of " + RESOURCE, e);
final int leftoverBatchedRequests = batchedRequests % threadAmount;
final int leftoverRequests = openDevices.size() - batchedRequests * generateConfigBatchSize;
final int leftoverBatchedRequests = batchedRequests % threadAmount;
final int leftoverRequests = openDevices.size() - batchedRequests * generateConfigBatchSize;
- final StringBuilder destBuilder = new StringBuilder(DEST);
- destBuilder.replace(destBuilder.indexOf(ADDRESS_PORT),
- destBuilder.indexOf(ADDRESS_PORT) + ADDRESS_PORT.length(),
- controllerDestination);
+ //FIXME Move this to validate() and rename it to init() or create init() and move there.
+ //FIXME Make it field.
+ final String restconfNetconfTopologyPath = String.format(RESTCONF_NETCONF_TOPOLOGY_PATH_TEMPLATE,
+ controllerIp, controllerPort);
for (int l = 0; l < threadAmount; l++) {
from = l * batchedRequests * batchedRequestsPerThread;
to = from + batchedRequests * batchedRequestsPerThread;
iterator = openDevices.subList(from, to).iterator();
allThreadsPayloads.add(createBatchedPayloads(batchedRequestsPerThread, iterator, editContentString,
for (int l = 0; l < threadAmount; l++) {
from = l * batchedRequests * batchedRequestsPerThread;
to = from + batchedRequests * batchedRequestsPerThread;
iterator = openDevices.subList(from, to).iterator();
allThreadsPayloads.add(createBatchedPayloads(batchedRequestsPerThread, iterator, editContentString,
- destBuilder.toString()));
+ restconfNetconfTopologyPath));
}
ArrayList<Execution.DestToPayload> payloads = null;
if (leftoverBatchedRequests > 0) {
}
ArrayList<Execution.DestToPayload> payloads = null;
if (leftoverBatchedRequests > 0) {
to = from + batchedRequests * batchedRequestsPerThread;
iterator = openDevices.subList(from, to).iterator();
payloads = createBatchedPayloads(leftoverBatchedRequests, iterator, editContentString,
to = from + batchedRequests * batchedRequestsPerThread;
iterator = openDevices.subList(from, to).iterator();
payloads = createBatchedPayloads(leftoverBatchedRequests, iterator, editContentString,
- destBuilder.toString());
+ restconfNetconfTopologyPath);
if (leftoverRequests > 0 || leftoverBatchedRequests > 0) {
if (payloads != null) {
if (leftoverRequests > 0 || leftoverBatchedRequests > 0) {
if (payloads != null) {
- payloads.add(new Execution.DestToPayload(destBuilder.toString(), payload));
+ payloads.add(new Execution.DestToPayload(restconfNetconfTopologyPath, payload));
}
allThreadsPayloads.add(payloads);
}
}
allThreadsPayloads.add(payloads);
}
final ArrayList<Execution.DestToPayload> payloads = new ArrayList<>();
while (openDevices.hasNext()) {
final ArrayList<Execution.DestToPayload> payloads = new ArrayList<>();
while (openDevices.hasNext()) {
- final StringBuilder destBuilder = new StringBuilder(DEST);
- destBuilder.replace(destBuilder.indexOf(ADDRESS_PORT),
- destBuilder.indexOf(ADDRESS_PORT) + ADDRESS_PORT.length(), controllerDestination);
+ //FIXME Move this to validate() and rename it to init() or create init() and move there.
+ //FIXME Make it field.
+ final String restconfNetconfTopologyPath = String.format(RESTCONF_NETCONF_TOPOLOGY_PATH_TEMPLATE,
+ controllerIp, controllerPort);
payloads.add(new Execution.DestToPayload(
payloads.add(new Execution.DestToPayload(
- destBuilder.toString(), prepareMessage(openDevices.next(), editContentString)));
+ restconfNetconfTopologyPath, prepareMessage(openDevices.next(), editContentString)));