use of org.onosproject.netconf.NetconfDeviceInfo in project onos by opennetworkinglab.
the class NetconfControllerImpl method createDeviceInfo.
private NetconfDeviceInfo createDeviceInfo(DeviceId deviceId) throws NetconfException {
Device device = deviceService.getDevice(deviceId);
String ip, path = null;
int port;
if (device != null) {
ip = device.annotations().value("ipaddress");
port = Integer.parseInt(device.annotations().value("port"));
} else {
Triple<String, Integer, Optional<String>> info = extractIpPortPath(deviceId);
ip = info.getLeft();
port = info.getMiddle();
path = (info.getRight().isPresent() ? info.getRight().get() : null);
}
try {
DeviceKey deviceKey = deviceKeyService.getDeviceKey(DeviceKeyId.deviceKeyId(deviceId.toString()));
if (deviceKey.type() == DeviceKey.Type.USERNAME_PASSWORD) {
UsernamePassword usernamepasswd = deviceKey.asUsernamePassword();
return new NetconfDeviceInfo(usernamepasswd.username(), usernamepasswd.password(), IpAddress.valueOf(ip), port, path);
} else if (deviceKey.type() == DeviceKey.Type.SSL_KEY) {
String username = deviceKey.annotations().value(AnnotationKeys.USERNAME);
String password = deviceKey.annotations().value(AnnotationKeys.PASSWORD);
String sshkey = deviceKey.annotations().value(AnnotationKeys.SSHKEY);
return new NetconfDeviceInfo(username, password, IpAddress.valueOf(ip), port, path, sshkey);
} else {
log.error("Unknown device key for device {}", deviceId);
throw new NetconfException("Unknown device key for device " + deviceId);
}
} catch (NullPointerException e) {
log.error("No Device Key for device {}, {}", deviceId, e);
throw new NetconfException("No Device Key for device " + deviceId, e);
}
}
use of org.onosproject.netconf.NetconfDeviceInfo in project onos by opennetworkinglab.
the class NetconfSessionMinaImplTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
Security.addProvider(new BouncyCastleProvider());
int portNumber = TestTools.findAvailablePort(50830);
sshServerNetconf = SshServer.setUpDefaultServer();
sshServerNetconf.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
return TEST_USERNAME.equals(username) && TEST_PASSWORD.equals(password);
}
});
TestUtils.setField(NetconfSessionMinaImpl.class, "directory", TEST_DIRECTORY);
sshServerNetconf.setPort(portNumber);
SimpleGeneratorHostKeyProvider provider = new SimpleGeneratorHostKeyProvider();
provider.setFile(new File(TEST_SERFILE));
sshServerNetconf.setKeyPairProvider(provider);
sshServerNetconf.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new NetconfSshdTestSubsystem.Factory()));
sshServerNetconf.open();
log.info("SSH Server opened on port {}", portNumber);
NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo(TEST_USERNAME, TEST_PASSWORD, Ip4Address.valueOf(TEST_HOSTNAME), portNumber);
deviceInfo.setConnectTimeoutSec(OptionalInt.of(30));
deviceInfo.setReplyTimeoutSec(OptionalInt.of(30));
session1 = new NetconfSessionMinaImpl(deviceInfo, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session1.getSessionId());
assertTrue("Incorrect sessionId", !session1.getSessionId().equalsIgnoreCase("-1"));
assertTrue("Incorrect sessionId", !session1.getSessionId().equalsIgnoreCase("0"));
assertThat(session1.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES.toArray()));
session2 = new NetconfSessionMinaImpl(deviceInfo, ImmutableList.of("urn:ietf:params:netconf:base:1.0"));
log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session2.getSessionId());
assertTrue("Incorrect sessionId", !session2.getSessionId().equalsIgnoreCase("-1"));
assertTrue("Incorrect sessionId", !session2.getSessionId().equalsIgnoreCase("0"));
assertThat(session2.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES.toArray()));
session3 = new NetconfSessionMinaImpl(deviceInfo);
log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session3.getSessionId());
assertTrue("Incorrect sessionId", !session3.getSessionId().equalsIgnoreCase("-1"));
assertTrue("Incorrect sessionId", !session3.getSessionId().equalsIgnoreCase("0"));
assertThat(session3.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES_1_1.toArray()));
session4 = new NetconfSessionMinaImpl(deviceInfo);
log.info("Started NETCONF Session {} with test SSHD server in Unit Test", session4.getSessionId());
assertTrue("Incorrect sessionId", !session4.getSessionId().equalsIgnoreCase("-1"));
assertTrue("Incorrect sessionId", !session4.getSessionId().equalsIgnoreCase("0"));
assertThat(session4.getDeviceCapabilitiesSet(), containsInAnyOrder(DEFAULT_CAPABILITIES_1_1.toArray()));
}
use of org.onosproject.netconf.NetconfDeviceInfo in project onos by opennetworkinglab.
the class NetconfStreamThread method dealWithReply.
private void dealWithReply(String deviceReply) {
if (deviceReply.contains(RPC_REPLY) || deviceReply.contains(RPC_ERROR) || deviceReply.contains(HELLO)) {
log.debug("Netconf device {} sessionDelegate.notify() DEVICE_REPLY {} {}", netconfDeviceInfo, getMsgId(deviceReply), deviceReply);
NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent(NetconfDeviceOutputEvent.Type.DEVICE_REPLY, null, deviceReply, getMsgId(deviceReply), netconfDeviceInfo);
sessionDelegate.notify(event);
netconfDeviceEventListeners.forEach(listener -> listener.event(event));
} else if (deviceReply.contains(NOTIFICATION_LABEL)) {
log.debug("Netconf device {} DEVICE_NOTIFICATION {} {} {}", netconfDeviceInfo, enableNotifications, getMsgId(deviceReply), deviceReply);
if (enableNotifications) {
log.debug("dispatching to {} listeners", netconfDeviceEventListeners.size());
final String finalDeviceReply = deviceReply;
netconfDeviceEventListeners.forEach(listener -> listener.event(new NetconfDeviceOutputEvent(NetconfDeviceOutputEvent.Type.DEVICE_NOTIFICATION, null, finalDeviceReply, getMsgId(finalDeviceReply), netconfDeviceInfo)));
}
} else {
log.debug("Error on reply from device {} {}", netconfDeviceInfo, deviceReply);
}
}
Aggregations