@Test public void testStartConnectAndConfig() throws Exception { Class<TelnetUtils> class1 = TelnetUtils.class; Method method = class1.getDeclaredMethod("startConnectAndConfig",new Class[]{SimpleChannelUpstreamHandler.class}); Method method1 = class1.getDeclaredMethod("sendNewConfig"); method.setAccessible(true); method1.setAccessible(true); SimpleChannelUpstreamHandler simpleChannelUpstreamHandler = mock(SimpleChannelUpstreamHandler.class); Assert.assertEquals(TelnetUtils.getCurrentDeviceName(),"deviceNamePE1"); method.invoke(telnetUtils,simpleChannelUpstreamHandler); method1.invoke(telnetUtils); }
private void startConnectAndConfig(SimpleChannelUpstreamHandler simpleChannelUpstreamHandler){ ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(() -> { ChannelPipeline p = Channels.pipeline(); p.addLast("encode", new StringEncoder()); p.addLast("decode", new StringDecoder()); p.addLast("handler", new ClientHandlerForClearOldConfig()); return p; }); bootstrap.setOption("tcpNoDelay" , true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("connectTimeoutMillis", 5000); String ipAddress = null; String deviceName = getCurrentDeviceName(); if(deviceName.contains("PE1")) { ipAddress = "191.4.1.114"; }else if(deviceName.contains("PE2")){ ipAddress = "191.4.1.77"; }else if(deviceName.contains("PE3")){ ipAddress = "191.4.1.103"; } System.out.println("Try to clear old configuration for device "+ deviceName+"\n"); bootstrap.connect(new InetSocketAddress(ipAddress, 23)); }
TelnetUtils implements AutoCloseable { private void startConnectAndConfig(SimpleChannelUpstreamHandler simpleChannelUpstreamHandler){ ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(() -> { ChannelPipeline p = Channels.pipeline(); p.addLast("encode", new StringEncoder()); p.addLast("decode", new StringDecoder()); p.addLast("handler", new ClientHandlerForClearOldConfig()); return p; }); bootstrap.setOption("tcpNoDelay" , true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("connectTimeoutMillis", 5000); String ipAddress = null; String deviceName = getCurrentDeviceName(); if(deviceName.contains("PE1")) { ipAddress = "191.4.1.114"; }else if(deviceName.contains("PE2")){ ipAddress = "191.4.1.77"; }else if(deviceName.contains("PE3")){ ipAddress = "191.4.1.103"; } System.out.println("Try to clear old configuration for device "+ deviceName+"\n"); bootstrap.connect(new InetSocketAddress(ipAddress, 23)); } }
TelnetUtils implements AutoCloseable { private void startConnectAndConfig(SimpleChannelUpstreamHandler simpleChannelUpstreamHandler){ ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(() -> { ChannelPipeline p = Channels.pipeline(); p.addLast("encode", new StringEncoder()); p.addLast("decode", new StringDecoder()); p.addLast("handler", new ClientHandlerForClearOldConfig()); return p; }); bootstrap.setOption("tcpNoDelay" , true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("connectTimeoutMillis", 5000); String ipAddress = null; String deviceName = getCurrentDeviceName(); if(deviceName.contains("PE1")) { ipAddress = "191.4.1.114"; }else if(deviceName.contains("PE2")){ ipAddress = "191.4.1.77"; }else if(deviceName.contains("PE3")){ ipAddress = "191.4.1.103"; } System.out.println("Try to clear old configuration for device "+ deviceName+"\n"); bootstrap.connect(new InetSocketAddress(ipAddress, 23)); } TelnetUtils(); }
TelnetUtils implements AutoCloseable { private void startConnectAndConfig(SimpleChannelUpstreamHandler simpleChannelUpstreamHandler){ ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(() -> { ChannelPipeline p = Channels.pipeline(); p.addLast("encode", new StringEncoder()); p.addLast("decode", new StringDecoder()); p.addLast("handler", new ClientHandlerForClearOldConfig()); return p; }); bootstrap.setOption("tcpNoDelay" , true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("connectTimeoutMillis", 5000); String ipAddress = null; String deviceName = getCurrentDeviceName(); if(deviceName.contains("PE1")) { ipAddress = "191.4.1.114"; }else if(deviceName.contains("PE2")){ ipAddress = "191.4.1.77"; }else if(deviceName.contains("PE3")){ ipAddress = "191.4.1.103"; } System.out.println("Try to clear old configuration for device "+ deviceName+"\n"); bootstrap.connect(new InetSocketAddress(ipAddress, 23)); } TelnetUtils(); @Override void close(); static Boolean isClearOver(); static void setClearOver(Boolean clearOver); static String getInstanceOfClearCliTemplate(); static void setInstanceOfClearCliTemplate(String instanceOfClearCliTemplate); static String getInstanceOfNewCliTemplate(); static void setInstanceOfNewCliTemplate(String instanceOfNewCliTemplate); static String getCurrentDeviceName(); static void setCurrentDeviceName(String currentDeviceName); static Boolean isConfigOver(); static void setConfigOver(Boolean configOver); void configL3vpnOnDeviceByCli(String deviceName,
                                     String clearOldConfigString,
                                     String cliExecutionSequences); }
TelnetUtils implements AutoCloseable { private void startConnectAndConfig(SimpleChannelUpstreamHandler simpleChannelUpstreamHandler){ ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool()); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(() -> { ChannelPipeline p = Channels.pipeline(); p.addLast("encode", new StringEncoder()); p.addLast("decode", new StringDecoder()); p.addLast("handler", new ClientHandlerForClearOldConfig()); return p; }); bootstrap.setOption("tcpNoDelay" , true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("connectTimeoutMillis", 5000); String ipAddress = null; String deviceName = getCurrentDeviceName(); if(deviceName.contains("PE1")) { ipAddress = "191.4.1.114"; }else if(deviceName.contains("PE2")){ ipAddress = "191.4.1.77"; }else if(deviceName.contains("PE3")){ ipAddress = "191.4.1.103"; } System.out.println("Try to clear old configuration for device "+ deviceName+"\n"); bootstrap.connect(new InetSocketAddress(ipAddress, 23)); } TelnetUtils(); @Override void close(); static Boolean isClearOver(); static void setClearOver(Boolean clearOver); static String getInstanceOfClearCliTemplate(); static void setInstanceOfClearCliTemplate(String instanceOfClearCliTemplate); static String getInstanceOfNewCliTemplate(); static void setInstanceOfNewCliTemplate(String instanceOfNewCliTemplate); static String getCurrentDeviceName(); static void setCurrentDeviceName(String currentDeviceName); static Boolean isConfigOver(); static void setConfigOver(Boolean configOver); void configL3vpnOnDeviceByCli(String deviceName,
                                     String clearOldConfigString,
                                     String cliExecutionSequences);  }