Search in sources :

Example 16 with NetconfController

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();
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Example 17 with NetconfController

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();
}
Also used : NetconfDevice(org.onosproject.netconf.NetconfDevice) NetconfController(org.onosproject.netconf.NetconfController)

Example 18 with NetconfController

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");
    }
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) NetconfException(org.onosproject.netconf.NetconfException) NetconfDevice(org.onosproject.netconf.NetconfDevice) ExecutionException(java.util.concurrent.ExecutionException) NetconfController(org.onosproject.netconf.NetconfController) TimeoutException(java.util.concurrent.TimeoutException)

Example 19 with NetconfController

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());
}
Also used : Ciena5162DriversLoader(org.onosproject.drivers.ciena.c5162.Ciena5162DriversLoader) DeviceId(org.onosproject.net.DeviceId) MockDriverHandler(org.onosproject.drivers.netconf.MockDriverHandler) MockCoreService(org.onosproject.drivers.netconf.MockCoreService) NetconfController(org.onosproject.netconf.NetconfController) Before(org.junit.Before)

Example 20 with NetconfController

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;
}
Also used : NetconfSession(org.onosproject.netconf.NetconfSession) XPath(javax.xml.xpath.XPath) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) DeviceService(org.onosproject.net.device.DeviceService) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfController(org.onosproject.netconf.NetconfController) ConnectPoint(org.onosproject.net.ConnectPoint) NetconfException(org.onosproject.netconf.NetconfException) HashSet(java.util.HashSet) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription)

Aggregations

NetconfController (org.onosproject.netconf.NetconfController)80 NetconfException (org.onosproject.netconf.NetconfException)61 DeviceId (org.onosproject.net.DeviceId)42 NetconfSession (org.onosproject.netconf.NetconfSession)39 DriverHandler (org.onosproject.net.driver.DriverHandler)22 MastershipService (org.onosproject.mastership.MastershipService)20 NetconfDevice (org.onosproject.netconf.NetconfDevice)20 XPath (javax.xml.xpath.XPath)16 XPathExpressionException (javax.xml.xpath.XPathExpressionException)16 Node (org.w3c.dom.Node)16 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 ConnectPoint (org.onosproject.net.ConnectPoint)9 NodeList (org.w3c.dom.NodeList)8 DeviceService (org.onosproject.net.device.DeviceService)7 Device (org.onosproject.net.Device)6 PortDescription (org.onosproject.net.device.PortDescription)5 HashSet (java.util.HashSet)4 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)4