use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class TerminalDevicePowerConfig method getNetconfSession.
/**
* Returns the NetconfSession with the device for which the method was called.
*
* @param deviceId device indetifier
* @param userName username to access the device
* @param passwd password to access the device
* @return The netconf session or null
*/
public NetconfSession getNetconfSession(DeviceId deviceId, String userName, String passwd) {
NetconfController controller = handler().get(NetconfController.class);
NetconfDevice ncdev = controller.getDevicesMap().get(deviceId);
if (ncdev == null) {
log.trace("No netconf device, returning null session");
return null;
}
return ncdev.getSession();
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class TerminalDeviceDiscovery method getNetconfSession.
/**
* Returns the NetconfSession with the device for which the method was called.
*
* @param deviceId device indetifier
*
* @return The netconf session or null
*/
private NetconfSession getNetconfSession(DeviceId deviceId) {
NetconfController controller = handler().get(NetconfController.class);
NetconfDevice ncdev = controller.getDevicesMap().get(deviceId);
if (ncdev == null) {
log.trace("No netconf device, returning null session");
return null;
}
return ncdev.getSession();
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class NetconfGetConfigCommand method doExecute.
@Override
protected void doExecute() {
deviceId = DeviceId.deviceId(uri);
NetconfController controller = get(NetconfController.class);
checkNotNull(controller, "Netconf controller is null");
NetconfDevice device = controller.getDevicesMap().get(deviceId);
if (device == null) {
print("Netconf device object not found for %s", deviceId);
return;
}
NetconfSession session = device.getSession();
if (session == null) {
print("Netconf session not found for %s", deviceId);
return;
}
try {
CharSequence res = session.asyncGetConfig(datastore(datastore.toLowerCase())).get(timeoutSec, TimeUnit.SECONDS);
print("%s", res);
} catch (NetconfException | InterruptedException | ExecutionException | TimeoutException e) {
log.error("Configuration could not be retrieved", e);
print("Error occurred retrieving configuration");
}
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class DeviceDiscoveryTest method setup.
@Before
public void setup() throws NetconfException {
MockCoreService coreService = new MockCoreService(101, "org.onosproject.drivers.netconf", "org.onosproject.linkdiscovery", "org.onosproject.drivers.ciena.c5162");
// Load the mock responses for mock device "netconf:1.2.3.4:830"
DeviceId mId = DeviceId.deviceId("netconf:1.2.3.4:830");
mockRequestDriver.load(DeviceDiscoveryTest.class, "/templates/responses/device_1_2_3_4/%s.j2", mId, "systemInfo", "softwareVersion", "logicalPorts", "link-info", "port-stats");
MockDriverHandler mockDriverHandler = new MockDriverHandler(Ciena5162DriversLoader.class, "/ciena-5162-drivers.xml", mId, coreService, deviceService);
NetconfController controller = mockDriverHandler.get(NetconfController.class);
mockDriverHandlers.put(mId, mockDriverHandler);
mockRequestDriver.setDeviceMap(controller.getDevicesMap());
// Load the mock responses for mock device "netconf:5.6.7.8:830"
mId = DeviceId.deviceId("netconf:5.6.7.8:830");
mockRequestDriver.load(DeviceDiscoveryTest.class, "/templates/responses/device_5_6_7_8/%s.j2", mId, "systemInfo", "softwareVersion", "logicalPorts", "link-info");
mockDriverHandler = new MockDriverHandler(Ciena5162DriversLoader.class, "/ciena-5162-drivers.xml", mId, coreService, deviceService);
controller = mockDriverHandler.get(NetconfController.class);
mockDriverHandlers.put(mId, mockDriverHandler);
mockRequestDriver.setDeviceMap(controller.getDevicesMap());
}
use of org.onosproject.netconf.NetconfController in project onos by opennetworkinglab.
the class Ciena5170DeviceDescription method getLinks.
@Override
public Set<LinkDescription> getLinks() {
log.debug("LINKS CHECKING ...");
Set<LinkDescription> links = new HashSet<LinkDescription>();
DeviceId deviceId = handler().data().deviceId();
NetconfController controller = checkNotNull(handler().get(NetconfController.class));
if (controller == null || controller.getDevicesMap() == null || controller.getDevicesMap().get(deviceId) == null) {
log.warn("NETCONF session to device {} not yet established, cannot load links, will be retried", deviceId);
return links;
}
NetconfSession session = controller.getDevicesMap().get(deviceId).getSession();
try {
DeviceService deviceService = this.handler().get(DeviceService.class);
Iterable<Device> devices = deviceService.getAvailableDevices();
Map<String, Device> lookup = new HashMap<String, Device>();
for (Device d : devices) {
lookup.put(d.chassisId().toString().toUpperCase(), d);
}
Node logicalPorts = TEMPLATE_MANAGER.doRequest(session, "link-info");
XPath xp = XPathFactory.newInstance().newXPath();
NodeList ifaces = (NodeList) xp.evaluate("interfaces/interface", logicalPorts, XPathConstants.NODESET);
int count = ifaces.getLength();
Node iface;
Node destChassis;
for (int i = 0; i < count; i += 1) {
iface = ifaces.item(i);
if (xp.evaluate("config/type/text()", iface).equals("ettp")) {
destChassis = (Node) xp.evaluate("state/lldp-remote-port-operational/chassis-id", iface, XPathConstants.NODE);
if (destChassis != null) {
Device dest = lookup.get(destChassis.getTextContent().toUpperCase());
if (dest != null) {
links.add(new DefaultLinkDescription(new ConnectPoint(dest.id(), PortNumber.portNumber(xp.evaluate("state/lldp-remote-port-operational/port-id/text()", iface))), new ConnectPoint(deviceId, PortNumber.portNumber(xp.evaluate("name/text()", iface))), Link.Type.DIRECT, true));
} else {
log.warn("DEST chassisID not found: chassis {} port {}", destChassis.getTextContent().toUpperCase(), xp.evaluate("name/text()", iface));
}
} else {
log.debug("NO LINK for {}", xp.evaluate("name/text()", iface));
}
}
}
} catch (NetconfException | XPathExpressionException e) {
log.error("Unable to retrieve links for device {}, {}", deviceId, e);
}
return links;
}
Aggregations