+ public NetconfClientConfiguration getClientConfiguration(final InetSocketAddress tcpAddress, final int timeout) {
+ final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create();
+ b.withAddress(tcpAddress);
+ b.withSessionListener(new SimpleNetconfClientSessionListener());
+ b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, timeout));
+ b.withConnectionTimeoutMillis(timeout);
+ return b.build();
+ }
+
+ public static final class HardcodedYangStoreService extends YangStoreService {
+ public HardcodedYangStoreService(final Collection<? extends InputStream> inputStreams) throws IOException {
+ super(new SchemaContextProvider() {
+ @Override
+ public SchemaContext getSchemaContext() {
+ return getSchema(inputStreams);
+ }
+ }, new BaseNetconfNotificationListener() {
+ @Override
+ public void onCapabilityChanged(final NetconfCapabilityChange capabilityChange) {
+ // NOOP
+ }
+ });
+ }
+
+ private static SchemaContext getSchema(final Collection<? extends InputStream> inputStreams) {
+ final ArrayList<InputStream> byteArrayInputStreams = new ArrayList<>();
+ for (final InputStream inputStream : inputStreams) {
+ assertNotNull(inputStream);
+ final byte[] content;
+ try {
+ content = ByteStreams.toByteArray(inputStream);
+ } catch (IOException e) {
+ throw new IllegalStateException("Cannot read " + inputStream, e);
+ }
+ final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content);
+ byteArrayInputStreams.add(byteArrayInputStream);
+ }
+
+ for (final InputStream inputStream : byteArrayInputStreams) {
+ try {
+ inputStream.reset();
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ final YangParserImpl yangParser = new YangParserImpl();
+ return yangParser.resolveSchemaContext(new HashSet<>(yangParser.parseYangModelsFromStreamsMapped(byteArrayInputStreams).values()));
+ }
+
+ @Override
+ public EnumResolver getEnumResolver() {
+ return new EnumResolver() {
+ @Override
+ public String fromYang(final String enumType, final String enumYangValue) {
+ return BindingMapping.getClassName(enumYangValue);
+ }
+
+ @Override
+ public String toYang(final String enumType, final String enumJavaValue) {
+ return enumJavaValue.toLowerCase();
+ }
+ };
+ }
+ }