use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class StressClient method main.
public static void main(final String[] args) {
params = parseArgs(args, Parameters.getParser());
params.validate();
final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
root.setLevel(params.debug ? Level.DEBUG : Level.INFO);
final int threadAmount = params.threadAmount;
LOG.info("thread amount: {}", threadAmount);
final int requestsPerThread = params.editCount / params.threadAmount;
LOG.info("requestsPerThread: {}", requestsPerThread);
final int leftoverRequests = params.editCount % params.threadAmount;
LOG.info("leftoverRequests: {}", leftoverRequests);
LOG.info("Preparing messages");
// Prepare all msgs up front
final List<List<NetconfMessage>> allPreparedMessages = new ArrayList<>(threadAmount);
for (int i = 0; i < threadAmount; i++) {
if (i != threadAmount - 1) {
allPreparedMessages.add(new ArrayList<>(requestsPerThread));
} else {
allPreparedMessages.add(new ArrayList<>(requestsPerThread + leftoverRequests));
}
}
final String editContentString;
try {
editContentString = Files.asCharSource(params.editContent, StandardCharsets.UTF_8).read();
} catch (final IOException e) {
throw new IllegalArgumentException("Cannot read content of " + params.editContent, e);
}
for (int i = 0; i < threadAmount; i++) {
final List<NetconfMessage> preparedMessages = allPreparedMessages.get(i);
int padding = 0;
if (i == threadAmount - 1) {
padding = leftoverRequests;
}
for (int j = 0; j < requestsPerThread + padding; j++) {
LOG.debug("id: {}", i * requestsPerThread + j);
preparedMessages.add(prepareMessage(i * requestsPerThread + j, editContentString));
}
}
final NioEventLoopGroup nioGroup = new NioEventLoopGroup();
final Timer timer = new HashedWheelTimer();
final NetconfClientDispatcherImpl netconfClientDispatcher = configureClientDispatcher(nioGroup, timer);
final List<StressClientCallable> callables = new ArrayList<>(threadAmount);
for (final List<NetconfMessage> messages : allPreparedMessages) {
callables.add(new StressClientCallable(params, netconfClientDispatcher, messages));
}
final ExecutorService executorService = Executors.newFixedThreadPool(threadAmount);
LOG.info("Starting stress test");
final Stopwatch started = Stopwatch.createStarted();
try {
final List<Future<Boolean>> futures = executorService.invokeAll(callables);
for (final Future<Boolean> future : futures) {
try {
future.get(4L, TimeUnit.MINUTES);
} catch (ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
}
executorService.shutdownNow();
} catch (final InterruptedException e) {
throw new RuntimeException("Unable to execute requests", e);
}
started.stop();
LOG.info("FINISHED. Execution time: {}", started);
LOG.info("Requests per second: {}", params.editCount * 1000.0 / started.elapsed(TimeUnit.MILLISECONDS));
// Cleanup
timer.stop();
try {
nioGroup.shutdownGracefully().get(20L, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.warn("Unable to close executor properly", e);
}
// stop the underlying ssh thread that gets spawned if we use ssh
if (params.ssh) {
AsyncSshHandler.DEFAULT_CLIENT.stop();
}
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class StressClient method prepareMessage.
static NetconfMessage prepareMessage(final int id, final String editContentString) {
final Document msg = XmlUtil.createDocumentCopy(params.candidateDatastore ? EDIT_CANDIDATE_BLUEPRINT : EDIT_RUNNING_BLUEPRINT);
msg.getDocumentElement().setAttribute("message-id", Integer.toString(id));
final NetconfMessage netconfMessage = new NetconfMessage(msg);
final Element editContentElement;
try {
// Insert message id where needed
String specificEditContent = editContentString.replaceAll(MSG_ID_PLACEHOLDER_REGEX, Integer.toString(id));
final StringBuilder stringBuilder = new StringBuilder(specificEditContent);
int idx = stringBuilder.indexOf(PHYS_ADDR_PLACEHOLDER);
while (idx != -1) {
stringBuilder.replace(idx, idx + PHYS_ADDR_PLACEHOLDER.length(), TestToolUtils.getMac(macStart++));
idx = stringBuilder.indexOf(PHYS_ADDR_PLACEHOLDER);
}
specificEditContent = stringBuilder.toString();
editContentElement = XmlUtil.readXmlToElement(specificEditContent);
final Node config = ((Element) msg.getDocumentElement().getElementsByTagName("edit-config").item(0)).getElementsByTagName("config").item(0);
config.appendChild(msg.importNode(editContentElement, true));
} catch (final IOException | SAXException e) {
throw new IllegalArgumentException("Edit content file is unreadable", e);
}
return netconfMessage;
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class TestToolTest method invokeRpc.
private Document invokeRpc(final Configuration simulatorConfig, final String xmlRequest) throws Exception {
// GIVEN
int localPort = launchSimulator(simulatorConfig);
SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
NetconfClientConfiguration clientConfig = getClientConfig("localhost", localPort, simulatorConfig, sessionListener);
Document docRequest = XmlUtil.readXmlToDocument(xmlRequest);
NetconfMessage request = new NetconfMessage(docRequest);
// WHEN
NetconfMessage response;
try (NetconfClientSession ignored = dispatcher.createClient(clientConfig).get()) {
response = sessionListener.sendRequest(request).get(RECEIVE_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
// THEN
assertNotNull(response);
return response.getDocument();
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class SimulatedCreateSubscription method parseNetconfNotification.
private static NetconfMessage parseNetconfNotification(String content) {
final int startEventTime = content.indexOf("<eventTime>") + "<eventTime>".length();
final int endEventTime = content.indexOf("</eventTime>");
final String eventTime = content.substring(startEventTime, endEventTime);
if (eventTime.equals("XXXX")) {
content = content.replace(eventTime, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").format(new Date()));
}
try {
return new NetconfMessage(XmlUtil.readXmlToDocument(content));
} catch (SAXException | IOException e) {
throw new IllegalArgumentException("Cannot parse notifications", e);
}
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfEXIHandlersTest method setUp.
@Before
public void setUp() throws Exception {
final NetconfEXICodec codec = NetconfEXICodec.forParameters(EXIParameters.empty());
netconfMessageToEXIEncoder = NetconfMessageToEXIEncoder.create(codec);
netconfEXIToMessageDecoder = NetconfEXIToMessageDecoder.create(codec);
msg = new NetconfMessage(XmlUtil.readXmlToDocument(msgAsString));
this.msgAsExi = msgToExi(msg, codec);
}
Aggregations